
    Bwg4              
          d dl mZmZmZmZ d dlZd dlZd dlZd dlZd dl	Z	ddl
mZmZ ddlmZ ddlmZ ej"                  dk(  r	ddlmZmZ n ej"                  d	k(  r	ddlmZmZ nddlmZmZ g d
Z e	j0                         Z e	j0                         ZdddZ edg       edg       edg       edg       eddg       eddg       eg d      dZddZddZddZ ddZ!d Z"d Z#d Z$y)    )unicode_literalsdivisionabsolute_importprint_functionN   )armorCertificate)pretty_message)CACertsErrorwin32)extract_from_systemsystem_pathdarwin)clear_cacheget_listget_path)last_updatecertsz1.3.6.1.5.5.7.3.4z1.3.6.1.5.5.7.3.3z1.3.6.1.5.5.7.3.81.3.6.1.5.5.7.3.1z1.3.6.1.5.5.7.3.2z1.3.6.1.5.5.7.3.13z1.3.6.1.5.5.7.3.14)z1.3.6.1.5.5.7.3.5z1.3.6.1.5.5.7.3.6z1.3.6.1.5.5.7.3.7z1.3.6.1.5.5.7.3.17)z1.2.840.113635.100.1.8z1.2.840.113635.100.1.16z1.2.840.113635.100.1.20z1.3.6.1.4.1.311.10.3.21.2.840.113635.100.1.3z1.2.840.113635.100.1.9z1.2.840.113635.100.1.11c           	      \   t        |       \  }}|rut        ||      rht               }d}d}d}t        5  t        ||      r<t	        |d      5 }	t        |d      D ]  \  }
}}t        j                  dk(  rX||k7  r'||vr#||vr|r |t        j                  |
      d       G||k7  r||v s||v r|r |t        j                  |
      d       st        j                  d	k(  rX||k7  r'||vr#||vr|r |t        j                  |
      d       ||k7  r'||v s||v r|r |t        j                  |
      d       |r |t        j                  |
      d
       |	j                  t        d|
              	 d
d
d
       d
d
d
       |st        d      |S # 1 sw Y    xY w# 1 sw Y   $xY w)a  
    Get the filesystem path to a file that contains OpenSSL-compatible CA certs.

    On OS X and Windows, there are extracted from the system certificate store
    and cached in a file on the filesystem. This path should not be writable
    by other users, otherwise they could inject CA certs into the trust list.

    :param temp_dir:
        The temporary directory to cache the CA certs in on OS X and Windows.
        Needs to have secure permissions so other users can not modify the
        contents.

    :param cache_length:
        The number of hours to cache the CA certs on OS X and Windows

    :param cert_callback:
        A callback that is called once for each certificate in the trust store.
        It should accept two parameters: an asn1crypto.x509.Certificate object,
        and a reason. The reason will be None if the certificate is being
        exported, otherwise it will be a unicode string of the reason it won't.
        This is only called on Windows and OS X when passed to this function.

    :raises:
        oscrypto.errors.CACertsError - when an error occurs exporting/locating certs

    :return:
        The full filesystem path to a CA certs file
    z2.5.29.37.0r   r   wbTr   zimplicitly distrusted for TLSzexplicitly distrusted for TLSr   NCERTIFICATEzNo CA certs found)_ca_path_cached_path_needs_updateset	path_lockopenr   sysplatformr	   loadwriter   r   )temp_dircache_lengthcert_callbackca_pathtemp	empty_setany_purpose	apple_sslwin_server_authfcert
trust_oidsreject_oidss                J/var/www/horilla/myenv/lib/python3.12/site-packages/oscrypto/trust_list.pyr   r   A   s   < X&MGT )'<@E	#,	- 	<(,?'4( <A9L]\`9a <5j+<<83)Y6;j;X(1(C#0$1+2B2B42HJi$j (*i7Y+=U@K{@Z#0$1+2B2B42HJi$j ( \\W4)Y6;j;X(7z(I#0$1+2B2B42HJi$j (*i7_P[=[@K{@Z#0$1+2B2B42HJi$j (()+*:*:4*@$GmT :;3<<	<< .//N?< <	< 	<s$   F"D'F7F"F	F""F+c                 z   t        |       st        5  t        |       syg }t        |      D ]E  \  }}}|rt        |      }t        |      }|j	                  t        j                  |      ||f       G |t        d<   t        j                         t        d<   ddd       t        t        d         S # 1 sw Y   xY w)af  
    Retrieves (and caches in memory) the list of CA certs from the OS. Includes
    trust information from the OS - purposes the certificate should be trusted
    or rejected for.

    Trust information is encoded via object identifiers (OIDs) that are sourced
    from various RFCs and vendors (Apple and Microsoft). This trust information
    augments what is in the certificate itself. Any OID that is in the set of
    trusted purposes indicates the certificate has been explicitly trusted for
    a purpose beyond the extended key purpose extension. Any OID in the reject
    set is a purpose that the certificate should not be trusted for, even if
    present in the extended key purpose extension.

    *A list of common trust OIDs can be found as part of the `KeyPurposeId()`
    class in the `asn1crypto.x509` module of the `asn1crypto` package.*

    :param cache_length:
        The number of hours to cache the CA certs in memory before they are
        refreshed

    :param map_vendor_oids:
        A bool indicating if the following mapping of OIDs should happen for
        trust information from the OS trust list:
         - 1.2.840.113635.100.1.3 (apple_ssl) -> 1.3.6.1.5.5.7.3.1 (server_auth)
         - 1.2.840.113635.100.1.3 (apple_ssl) -> 1.3.6.1.5.5.7.3.2 (client_auth)
         - 1.2.840.113635.100.1.8 (apple_smime) -> 1.3.6.1.5.5.7.3.4 (email_protection)
         - 1.2.840.113635.100.1.9 (apple_eap) -> 1.3.6.1.5.5.7.3.13 (eap_over_ppp)
         - 1.2.840.113635.100.1.9 (apple_eap) -> 1.3.6.1.5.5.7.3.14 (eap_over_lan)
         - 1.2.840.113635.100.1.11 (apple_ipsec) -> 1.3.6.1.5.5.7.3.5 (ipsec_end_system)
         - 1.2.840.113635.100.1.11 (apple_ipsec) -> 1.3.6.1.5.5.7.3.6 (ipsec_tunnel)
         - 1.2.840.113635.100.1.11 (apple_ipsec) -> 1.3.6.1.5.5.7.3.7 (ipsec_user)
         - 1.2.840.113635.100.1.11 (apple_ipsec) -> 1.3.6.1.5.5.7.3.17 (ipsec_ike)
         - 1.2.840.113635.100.1.16 (apple_code_signing) -> 1.3.6.1.5.5.7.3.3 (code_signing)
         - 1.2.840.113635.100.1.20 (apple_time_stamping) -> 1.3.6.1.5.5.7.3.8 (time_stamping)
         - 1.3.6.1.4.1.311.10.3.2 (microsoft_time_stamp_signing) -> 1.3.6.1.5.5.7.3.8 (time_stamping)

    :param cert_callback:
        A callback that is called once for each certificate in the trust store.
        It should accept two parameters: an asn1crypto.x509.Certificate object,
        and a reason. The reason will be None if the certificate is being
        exported, otherwise it will be a unicode string of the reason it won't.

    :raises:
        oscrypto.errors.CACertsError - when an error occurs exporting/locating certs

    :return:
        A (copied) list of 3-element tuples containing CA certs from the OS
        trust ilst:
         - 0: an asn1crypto.x509.Certificate object
         - 1: a set of unicode strings of OIDs of trusted purposes
         - 2: a set of unicode strings of OIDs of rejected purposes
    r   r   N)
_in_memory_up_to_datememory_lockr   	_map_oidsappendr	   r!   _module_valuestimelist)r$   map_vendor_oidsr%   r   
cert_bytesr.   r/   s          r0   r   r      s    l !. 		<(6;N};] Z7J
K&%.z%:
&/&<LL+"2"2:">
K!XY	Z
 +0w'04		}-		< w'((		< 		<s   BB11B:c                    t         5  dt        d<   dt        d<   ddd       t        |       \  }}|rDt        5  t        j
                  j                  |      rt	        j                  |       ddd       yy# 1 sw Y   ^xY w# 1 sw Y   yxY w)a  
    Clears any cached info that was exported from the OS trust store. This will
    ensure the latest changes are returned from calls to get_list() and
    get_path(), but at the expense of re-exporting and parsing all certificates.

    :param temp_dir:
        The temporary directory to cache the CA certs in on OS X and Windows.
        Needs to have secure permissions so other users can not modify the
        contents. Must be the same value passed to get_path().
    Nr   r   )r3   r6   r   r   ospathexistsremove)r#   r&   r'   s      r0   r   r      s     
 '(,}%"&w' X&MGT 	#ww~~g&		'"	# 	# ' '	# 	#s   A75B7B Bc                     t               }|n| t        j                         } t        j                  j                  |       st        t        d|             t        j                  j                  | d      }|dfS |dfS )a  
    Returns the file path to the CA certs file

    :param temp_dir:
        The temporary directory to cache the CA certs in on OS X and Windows.
        Needs to have secure permissions so other users can not modify the
        contents.

    :return:
        A 2-element tuple:
         - 0: A unicode string of the file path
         - 1: A bool if the file is a temporary file
    zR
                The temp dir specified, "%s", is not a directory
                zoscrypto-ca-bundle.crtTF)	r   tempfile
gettempdirr<   r=   isdirr   r
   join)r#   r&   s     r0   r   r      s     mG **,Hww}}X&~ 	    '',,x)ABU    c                 X    t               }| D ]  }|t        v s|t        |   z  } | |z  S )a  
    Takes a set of unicode string OIDs and converts vendor-specific OIDs into
    generics OIDs from RFCs.

     - 1.2.840.113635.100.1.3 (apple_ssl) -> 1.3.6.1.5.5.7.3.1 (server_auth)
     - 1.2.840.113635.100.1.3 (apple_ssl) -> 1.3.6.1.5.5.7.3.2 (client_auth)
     - 1.2.840.113635.100.1.8 (apple_smime) -> 1.3.6.1.5.5.7.3.4 (email_protection)
     - 1.2.840.113635.100.1.9 (apple_eap) -> 1.3.6.1.5.5.7.3.13 (eap_over_ppp)
     - 1.2.840.113635.100.1.9 (apple_eap) -> 1.3.6.1.5.5.7.3.14 (eap_over_lan)
     - 1.2.840.113635.100.1.11 (apple_ipsec) -> 1.3.6.1.5.5.7.3.5 (ipsec_end_system)
     - 1.2.840.113635.100.1.11 (apple_ipsec) -> 1.3.6.1.5.5.7.3.6 (ipsec_tunnel)
     - 1.2.840.113635.100.1.11 (apple_ipsec) -> 1.3.6.1.5.5.7.3.7 (ipsec_user)
     - 1.2.840.113635.100.1.11 (apple_ipsec) -> 1.3.6.1.5.5.7.3.17 (ipsec_ike)
     - 1.2.840.113635.100.1.16 (apple_code_signing) -> 1.3.6.1.5.5.7.3.3 (code_signing)
     - 1.2.840.113635.100.1.20 (apple_time_stamping) -> 1.3.6.1.5.5.7.3.8 (time_stamping)
     - 1.3.6.1.4.1.311.10.3.2 (microsoft_time_stamp_signing) -> 1.3.6.1.5.5.7.3.8 (time_stamping)

    :param oids:
        A set of unicode strings

    :return:
        The original set of OIDs with any mapped OIDs added
    )r   _oid_map)oidsnew_oidsoids      r0   r4   r4     s;    2 uH &(?%H& (?rE   c                     t         j                  j                  |       }|syt        j                  |       }|j                  t        j
                         |dz  dz  z
  k  ry|j                  dk(  ryy)a_  
    Checks to see if a cache file needs to be refreshed

    :param ca_path:
        A unicode string of the path to the cache file

    :param cache_length:
        An integer representing the number of hours the cache is valid for

    :return:
        A boolean - True if the cache needs to be updated, False if the file
        is up-to-date
    T<   r   F)r<   r=   r>   statst_mtimer7   st_size)r&   r$   r>   statss       r0   r   r   -  s`     WW^^G$FGGGE~~		lR&7"&<<<}}rE   c                 |    t         d   xr2 t         d   xr' t         d   t        j                         | dz  dz  z
  kD  S )a  
    Checks to see if the in-memory cache of certificates is fresh

    :param cache_length:
        An integer representing the number of hours the cache is valid for

    :return:
        A boolean - True if the cache is up-to-date, False if it needs to be
        refreshed
    r   r   rL   )r6   r7   )r$   s    r0   r2   r2   K  sG     	w 	O}%	O}%		|b7H27M(NNrE   )N   N)rR   TN)N)%
__future__r   r   r   r   r<   r7   r   rA   	threading_asn1r   r	   _errorsr
   errorsr   r    _win.trust_listr   r   _mac.trust_list_linux_bsd.trust_list__all__Lockr   r3   r6   r   rG   r   r   r   r   r4   r   r2    rE   r0   <module>r^      s   R R 	  
   % #  <<7AA\\XAAG INN	inn "#6"78"$7#89"$7#89!#6"78!# 
 "# 
  # $  ):IXB)J#.!H@<rE   