
    hD              	          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mZmZm	Z	m
Z
mZmZmZ d dlmZ ddlmZ  ej$                         d    Z e eeej/                  d                  Zedk  r eded     ded          d	ed
edefdZ edd      Z edd      ZeZe
ZeZ eZ!eZ"eZ#eZ$eZ%eZ&eZ' ee&      Z(eZ)e	Z* ee%      Z+ ee!      Z, ee"      Z- ee#      Z. ee$      Z/eZ0eZ1 ee      Z2 ee      Z3 ee      Z4eZ5eZ6	 e)e,gejn                  _8        e2ejn                  _9        e2gejt                  _8        e,ejt                  _9        e*egejv                  _8        e-ejv                  _9        e4e.gejx                  _8        e*ejx                  _9        e4egejz                  _8        e*ejz                  _9        e1gej|                  _8        e3ej|                  _9        ee-gej~                  _8        e3ej~                  _9        e(e( ee4      gej                  _8        e*ej                  _9        e4 ee5      gej                  _8        e*ej                  _9        e4e_4        e5e_5        e*e_*        dZBdZCe(gej                  _8        dej                  _9        e(gej                  _8        e'ej                  _9        e)ee gej                  _8        e-ej                  _9        e-e gej                  _8        eej                  _9        e-eee gej                  _8        eej                  _9        e)eegej                  _8        e,ej                  _9        e,gej                  _8        eej                  _9        e,gej                  _8        eej                  _9        e) ee(      ee0gej                  _8        e.ej                  _9        e)ee0gej                  _8        e/ej                  _9        e/egej                  _8        dej                  _9        e.gej                  _8        eej                  _9        e.egej                  _8        eej                  _9        e+gej                  _8        eej                  _9        e+gej                  _8        e-ej                  _9        e)j                  ed      e_T         ej                  ed      e_U        e(e_(        e.e_.        e-e_-        e+e_+        de*dej                  dej                  dej                  fdZXeXej                  _Y        eXejx                  _Y        eXejz                  _Y        eXej                  _Y         G d d      ZZde[de,fdZ\de[de"fdZ]de-dedz  fd Z^d!e_e[   de/fd"Z`e j                  d#ej                  dej                  d   fd$       Zd	 d)d%ej                  d&e_e[   d'edz  ddfd(Zey# eV$ r
  ed      dw xY w)*    N)	CDLLPOINTERc_boolc_char_pc_int32c_longc_uint32c_ulongc_void_p)find_library   )_set_ssl_context_verify_mode.)
      z,Only OS X 10.8 and newer are supported, not namemacos10_16_pathreturnc                     	 t         dk\  r|}nt        |       }|st        t        |d      S # t        $ r t	        d|  d      dw xY w)z:Loads a CDLL by name, falling back to known path on 10.16+)r      T)	use_errnozThe library z failed to loadN)_mac_version_infor   OSErrorr   ImportError)r   r   paths      FD:\EasyAligner\venv\Lib\site-packages\pip/_vendor/truststore/_macos.py
_load_cdllr      s]    J ("D%DMDD)) JLo>?TIJs	   +. ASecurityz6/System/Library/Frameworks/Security.framework/SecurityCoreFoundationzB/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation   r   kCFAllocatorDefaultkCFTypeArrayCallBackszError initializing ctypesresult_argsc                 b   t        |       dk(  r|S d}	 t        j                  | d      }t        j                  |t        j
                  t        j                              }t        j                  |t        j                        }|Tt        j                  d      }t        j                  ||dt        j                        } | st        d      |j                  }|t        j                  |       	 ||dk(  rd|  }t!        j"                  |      # |t        j                  |       w w xY w)z<
    Raises an error if the OSStatus value is non-zero.
    r   N   'Error copying C string from CFStringRef z8SecureTransport operation returned a non-zero OSStatus: )intr   SecCopyErrorMessageStringctypescastr   r   r   CFStringGetCStringPtrCFConstkCFStringEncodingUTF8create_string_bufferCFStringGetCStringr   value	CFReleasesslSSLError)r#   r$   r%   error_message_cfstringerror_message_cfstring_c_void_pmessagebuffers          r   _handle_osstatusr;      s%    6{a "!=!)!C!CFD!Q +1++"FNN6??$C+
' !66+W-J-J
 ?006F#66/--	F GHHllG "-$$%;< 'R-LVHU
,,w
 "-$$%;< .s   CD D.c                   0    e Zd ZdZ ed      ZdZdZdZdZ	y)r/   zCoreFoundation constantsi  iiiiN)
__name__
__module____qualname____doc__CFStringEncodingr0   #errSecIncompleteCertRevocationCheckerrSecHostNameMismatcherrSecCertificateExpirederrSecNotTrusted     r   r/   r/     s(    ",Z8*0'#%rG   r/   r3   c                 ^    t         j                  t         j                  | t        |             S N)r   CFDataCreater!   len)r3   s    r   _bytes_to_cf_data_refrL     s&    &&**E3u: rG   c                     t        j                  |       }t        j                  t        j                  |t
        j                        }|S )zi
    Given a Python binary data, create a CFString.
    The string must be CFReleased by the caller.
    )r,   r   r   CFStringCreateWithCStringr!   r/   r0   )r3   c_strcf_strs      r   _bytes_to_cf_stringrQ     s>    
 OOE"E55**%%F
 MrG   cf_string_refc                     t         j                  | t        j                        }|Tt	        j
                  d      }t         j                  | |dt        j                        }|st        d      |j                  }||j                  d      }|S )z
    Creates a Unicode string from a CFString object. Used entirely for error
    reporting.
    Yes, it annoys me quite a lot that this function is this complex.
    r'   r(   zutf-8)
r   r.   r/   r0   r,   r1   r2   r   r3   decode)rR   stringr:   r#   s       r   _cf_string_ref_to_strrV   &  s     11w44F ~,,T22264)F)F
 CDDw'MrG   certsc                    t         j                  t         j                  dt        j                  t         j
                              }|st        d      | D ]{  }d}d}	 t        |      }t        j                  t         j                  |      }t         j                  ||       |rt         j                  |       |sgt         j                  |       } |S # |rt         j                  |       |rt         j                  |       w w xY w)zBuilds a CFArray of SecCertificateRefs from a list of DER-encoded certificates.
    Responsibility of the caller to call CoreFoundation.CFRelease on the CFArray.
    r   zUnable to allocate memory!N)r   CFArrayCreateMutabler!   r,   byrefr"   MemoryErrorrL   r   SecCertificateCreateWithDataCFArrayAppendValuer4   )rW   cf_array	cert_datacf_datasec_cert_refs        r   _der_certs_to_cf_cert_arrayrb   =  s     22**	^99:H
 677	
	7+I6G#@@22GL --hE((1((6  O ((1((6 s   AC1Dctxc              #      K   | j                   }| j                  }d| _         t        | t        j                         	 d  || _         t        | |       y # || _         t        | |       w xY ww)NF)check_hostnameverify_moder   r5   	CERT_NONE)rc   re   rf   s      r   _configure_contextrh   [  s_     ''N//KC cmm47+$S+6 ,$S+6s   :A-A A-A**A-ssl_context
cert_chainserver_hostnamec                 	   d }d }d }d }	 |Kd }	 t        |j                  d            }t        j                  d|      }|r,t        j                  |       nt        j                  dd       }|}| j                  t        j                  z  rt        j                  t        j                  dt        j                  t        j                              }t        j                  ||       t        j                  |       t        j                  t         t"        z        }	t        j                  ||	       t        j                  |	       n(| j                  t        j$                  z  rt'        d      d }	 t)        |      }t        j+                         }t        j-                  ||t        j                  |             |rt        j                  |       	 | j/                  d      }
|
r<d }	 t)        |
      }t        j1                  ||       |rt        j                  |       	 t        j3                  |d       t        j5                         }t        j7                  |t        j                  |            }|dk(  rd}n |dk(  rd}nt        j8                  d|      d}|s|t        j;                  |      }| j<                  t        j>                  k7  r)|t@        jB                  k(  s|t@        jD                  k(  rd}n!| jF                  s|t@        jH                  k(  rd}|sd }	 t        jK                  |      }tM        |      xs d	}t        jO                         }t        jQ                  |t        j                  |             t        jR                  |      }||_*        ||_+        |	 |rt        j                  |       |rt        j                  |       y y # |rt        j                  |       w w xY w# |rt        j                  |       w w xY w# |rt        j                  |       w w xY w# |rt        j                  |       w w xY w# |rt        j                  |       |rt        j                  |       w w xY w)
NasciiTr   z/VERIFY_CRL_CHECK_LEAF not implemented for macOS)binary_formFr   z8Unknown result from Security.SecTrustEvaluateWithError: zCertificate verification failed),rQ   encoder   SecPolicyCreateSSLr   r4   verify_flagsr5   VERIFY_CRL_CHECK_CHAINrY   r!   r,   rZ   r"   r]   SecPolicyCreateRevocation#kSecRevocationUseAnyAvailableMethod%kSecRevocationRequirePositiveResponseVERIFY_CRL_CHECK_LEAFNotImplementedErrorrb   SecTrustRefSecTrustCreateWithCertificatesget_ca_certsSecTrustSetAnchorCertificates!SecTrustSetAnchorCertificatesOnly
CFErrorRefSecTrustEvaluateWithErrorr6   CFErrorGetCoderf   CERT_REQUIREDr/   rE   rD   re   rC   CFErrorCopyDescriptionrV   SecTrustResultTypeSecTrustGetTrustResultSSLCertVerificationErrorverify_messageverify_code)ri   rj   rk   rW   policiestrustcf_errorcf_str_hostname
ssl_policyrevocation_policyctx_ca_certs_derctx_ca_certssec_trust_eval_result
is_trustedcf_error_codecf_error_string_refcf_error_messagesec_trust_result_typeerrs                      r   _verify_peercerts_implr   h  s   
 EHEHB,&"O>"5o6L6LW6U"V%88O
"",,_=!44T4@J##c&@&@@%::22^AABH
 --h
C$$Z0 ( B B378! --h8IJ$$%67%%(A(AA%&WXX	0/
;E ((*E33xe!4 ((/ 0;/G/G 0H 0
 L;:;KL66ulK",,\: 	225%@!,,. ( B B6<<)!

 !A%J"a'J,,JK`Jcd  *99(CM
 &&#*;*;;!9!99 G$D$DD!
..!W%C%CC!
 "&B&4&K&KH&U# **=> 98 ! )1(C(C(E%//6<<(=> 223CD%5""/	+ 6 $$X.$$U+ u #",,_= #L ((/   ",,\:  @ '",,-@A ' $$X.$$U+ sg   Q 0O D4Q 4A	O9 =.Q ,!P DQ %BP3 O66Q 9PQ P00Q 3QQ 1RrI   )f
contextlibr,   platformr5   typingr   r   r   r   r   r   r	   r
   r   ctypes.utilr   _ssl_constantsr   mac_ver_mac_versiontuplemapr*   splitr   r   strr   r   r   BooleanCFIndexrA   CFDataCFStringCFArrayCFMutableArrayCFErrorCFTypeCFTypeID	CFTypeRefCFAllocatorRefOSStatusr}   	CFDataRefCFStringRef
CFArrayRefCFMutableArrayRefCFArrayCallBacksCFOptionFlagsSecCertificateRefSecPolicyRefrx   r   SecTrustOptionFlagsr\   argtypesrestypeSecCertificateCopyDatar+   r{   r|   rs   rp   ry   r   rt   ru   r4   CFGetTypeIDrN   r.   r2   rJ   CFDataGetLengthCFDataGetBytePtrCFArrayCreaterY   r]   CFArrayGetCountCFArrayGetValueAtIndexr   r   in_dllr!   r"   AttributeErrorAnyr;   errcheckr/   bytesrL   rQ   rV   listrb   contextmanager
SSLContextIteratorrh   r   rF   rG   r   <module>r      s      
 
 
 
 % 8x!!$#c<#5#5c#:;< w

67H7K6LAN_`aNbMcd 
JS J3 J4 J" H H
 
 	

	FO	W
FO	hW
N+  H% x h  v=6Di5PH))24EH))10A/BH##,.7H##+3;X2FH&&/1<H&&.7BJ6OH**35=H**2;F:PH..79AH..63@/H&&/1=H&&.,3[+AH(*6H' 	8H++4
 7?H++3 	"#0H##, /7H##+&H"4H H*+',-))2N%'+N$+4+N')1N& 	9N,,5
 8CN,,45@BR4SN((13;N((0 		2N%%. 17N%%-,:Hg+NN(*3N'/8kN""+-4N""*09{N##,.6N##+ 			-N  ) ,6N  ( 	4N''0
 3DN''/2CX1NN%%.04N%%-/9lN""+-4N""*6@'5JN))24<N))1.8\N!!*,3N!!)6@\N))24?N))1)7)>)>-*N& ,;8??/,N(  )N *N!,N *N2 X 2 &** 2 FJJ 2 6:: 2 j 4D ' ' 02B & & /6F * * 3+;   (  9 u   t .tE{ 7H < 	7CNN 	7vt/D 	7 	7 #'K,K,UK, 4ZK, 
	K,A  =
1
2<=s   OW W