
    Bwgb                         d dl mZmZmZmZ d dlZd dlZddlmZ ddl	m
Z
mZ ddlmZmZ ddlmZmZmZ ej&                  d	k  reZd
dgZd ZddZd Zd Zy)    )unicode_literalsdivisionabsolute_importprint_functionN   )Certificate)newunwrap   )CoreFoundation	CFHelpers)SecuritySecurityConsthandle_sec_error)   extract_from_systemsystem_pathc                       y )N r       O/var/www/horilla/myenv/lib/python3.12/site-packages/oscrypto/_mac/trust_list.pyr   r      s    r   c                    t        t        d      }t        j                  |      }t	        |       t        |      }i }i }d}t               t               f}t        j                  |      }	t        d|	      D ]+  }
t        j                  ||
      }t        |      \  }}|||<   - t        j                  |       t        j                  t        j                  fD ]P  }t        t        d      }t        j                  ||      }|t        j                   k(  r>t	        |       t        |      }t        j                  |      }	t        d|	      D ]  }
t        j                  ||
      }t        t        d      }t        j"                  |||      }|t        j$                  k(  rU|t        j&                  k(  r&t        |      \  }}||v rt)        | ||   d       ||= t	        |       t        |      }t               }t               }t        j                  |      }t        d|      D ]  }t        j                  ||      }t+        j,                  |      }|j/                  di       j/                  d|      }|j/                  dd      }|dk7  xr |d	k7  }|r|j1                  |       |j1                  |        t        |      \  }}||v r||v r+t)        | ||   d
       ||= n||v rt        |g      }||f||<   t        j                  |        t        j                  |       S g }|D ]C  }|st)        | ||   d       |j/                  ||      }|j3                  ||   |d   |d   f       E |S )a  
    Extracts trusted CA certificates from the OS X trusted root keychain.

    :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.

    :param callback_only_on_failure:
        A boolean - if the callback should only be called when a certificate is
        not exported.

    :raises:
        OSError - when an error is returned by the OS crypto library

    :return:
        A list of 3-element tuples:
         - 0: a byte string of a DER-encoded certificate
         - 1: a set of unicode strings that are OIDs of purposes to trust the
              certificate for
         - 2: a set of unicode strings that are OIDs of purposes to reject the
              certificate for
    zCFArrayRef *z2.5.29.37.0r   zinvalid trust settingskSecTrustSettingsPolicySecPolicyOidkSecTrustSettingsResultr   r   zexplicitly distrustedN)r	   r   r   SecTrustCopyAnchorCertificatesr   r
   setCFArrayGetCountrangeCFArrayGetValueAtIndex_cert_details	CFReleaser   kSecTrustSettingsDomainUserkSecTrustSettingsDomainAdmin SecTrustSettingsCopyCertificateserrSecNoTrustSettings!SecTrustSettingsCopyTrustSettingserrSecItemNotFounderrSecInvalidTrustSettings_cert_callbackr   cf_dictionary_to_dictgetaddappend)cert_callbackcallback_only_on_failurecerts_pointer_pointerrescerts_pointercertificates
trust_infoall_purposesdefault_trustlengthindexcert_pointerder_cert	cert_hashdomain#cert_trust_settings_pointer_pointercert_trust_settings_pointertrust_settings_pointer_pointertrust_settings_pointer
trust_oidsreject_oidssettings_lengthsettings_indexsettings_dict_entrysettings_dict
policy_oidtrust_resultshould_trustoutputcert_trust_infos                                 r   r   r      s   4  ?

1
12G
HCS01MLJ LUCENM++M:Fq&! +%<<]ER+L9)"*Y+
 ]+ <<m>h>hi P>.1...Q+77@cd-555&,-P&Q#//0KL1f% D	=E)@@A\^cdL-0-P*<<\6SqrC
 m666 m>>>&3L&A#),"%$Y/0
 %Y/S!%+,J%K"J%K,<<=STO"'?"; 0&4&K&KLbdr&s# ) ? ?@S T +../H"MQQR`bno
  -001JAN+q0F\Q5FNN:.OOJ/%0( #0"=Hi {*,"%$Y//
 %Y/:-!$l^!4J)3[(A
9%$$%;<ID	=L 	  !<=aP>d F! Y	'=,y*A4H$..MB|I.0BOTUDVWX	Y
 Mr   c                 B    | sy | t        j                  |      |       y)aY  
    Constructs an asn1crypto.x509.Certificate object and calls the export
    callback

    :param callback:
        The callback to call

    :param der_cert:
        A byte string of the DER-encoded certificate

    :param reason:
        None if cert is being exported, or a unicode string of the reason it
        is not being exported
    N)r   load)callbackr;   reasons      r   r*   r*      s      [h'0r   c                    d}	 t        j                  |       }t        j                  |      }t	        j
                  |      j                         }||f|t        j                  |       S S # |t        j                  |       w w xY w)a  
    Return the certificate and a hash of it

    :param cert_pointer:
        A SecCertificateRef

    :return:
        A 2-element tuple:
         - [0]: A byte string of the SHA1 hash of the cert
         - [1]: A byte string of the DER-encoded contents of the cert
    N)	r   SecCertificateCopyDatar   cf_data_to_byteshashlibsha1digestr   r"   )r:   data_pointerr;   r<   s       r   r!   r!      s     L	366|D--l;LL*113	)$ #$$\2 $<#$$\2 $s   AA- -B)NF)
__future__r   r   r   r   rT   sys_asn1r   _ffir	   r
   _core_foundationr   r   	_securityr   r   r   version_infoxranger   __all__r   r   r*   r!   r   r   r   <module>ra      sX    R R  
   7 @ @dE FR1*3r   