1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Ë
ñúhb6ãóö—dZddlZddlZddlZddlZddlZddlZddlZddlZddl    m
Z
m Z m Z ejdej«Zd„Zd„Zd„Zd    „Zd
„Zdd „Zd „Zd „Zd„Zd„Zd„Zd„ZddddddœZd„Zy)a¦
Low-level helpers for the SecureTransport bindings.
 
These are Python functions that are not directly related to the high-level APIs
but are necessary to get them to work. They include a whole bunch of low-level
CoreFoundation messing about and memory management. The concerns in this module
are almost entirely about trying to avoid memory leaks and providing
appropriate and useful assistance to the higher-level code.
éNé)ÚCFConstÚCoreFoundationÚSecuritys;-----BEGIN CERTIFICATE-----
(.*?)
-----END CERTIFICATE-----có^—tjtj|t|««S)zv
    Given a bytestring, create a CFData object from it. This CFData object must
    be CFReleased by the caller.
    )rÚ CFDataCreateÚkCFAllocatorDefaultÚlen)Ú
bytestrings úiH:\Change_password\venv_build\Lib\site-packages\pip/_vendor/urllib3/contrib/_securetransport/low_level.pyÚ_cf_data_from_bytesr s(€ô
× &Ñ &Ü×*Ñ*¨J¼¸J»ó ðócó—t|«}d„|D«}d„|D«}tj|z|Ž}tj|z|Ž}tjtj|||tj
tj «S)zK
    Given a list of Python tuples, create an associated CFDictionary.
    c3ó&K—|]    }|d–—Œ y­w)rN©©Ú.0Úts  r ú    <genexpr>z-_cf_dictionary_from_tuples.<locals>.<genexpr>,sèø€Ò !QˆAˆaDÑ !ùó‚c3ó&K—|]    }|d–—Œ y­w)rNrrs  r rz-_cf_dictionary_from_tuples.<locals>.<genexpr>-sèø€Ò #qˆadÑ #ùr)r
rÚ    CFTypeRefÚCFDictionaryCreater    ÚkCFTypeDictionaryKeyCallBacksÚkCFTypeDictionaryValueCallBacks)ÚtuplesÚdictionary_sizeÚkeysÚvaluesÚcf_keysÚ    cf_valuess      r Ú_cf_dictionary_from_tuplesr"%s„€ô˜&“k€Oñ "˜&Ô !€DÙ #˜FÔ #€FÜ×'Ñ'¨/Ñ9¸DÐA€GÜ×)Ñ)¨OÑ;¸fÐE€Iä × ,Ñ ,Ü×*Ñ*ØØØÜ×4Ñ4Ü×6Ñ6ó  ðrcó–—tj|«}tjtj|t
j «}|S)zi
    Given a Python binary data, create a CFString.
    The string must be CFReleased by the caller.
    )ÚctypesÚc_char_prÚCFStringCreateWithCStringr    rÚkCFStringEncodingUTF8)Úpy_bstrÚc_strÚcf_strs   r Ú_cfstrr+;s>€ô
O‰O˜GÓ $€EÜ × 5Ñ 5Ü×*Ñ*Ø Ü×%Ñ%ó€Fð
€Mrcóþ—d}    tjtjdtjtj
««}|s t d«‚|D]F}t|«}|s t d«‚    tj||«tj|«ŒH    |S#tj|«wxYw#t$r4}|rtj|«tjd|›«‚d}~wwxYw)zª
    Given a list of Python binary data, create an associated CFMutableArray.
    The array must be CFReleased by the caller.
 
    Raises an ssl.SSLError on failure.
    NrúUnable to allocate memory!zUnable to allocate array: ) rÚCFArrayCreateMutabler    r$ÚbyrefÚkCFTypeArrayCallBacksÚ MemoryErrorr+ÚCFArrayAppendValueÚ    CFReleaseÚ BaseExceptionÚsslÚSSLError)ÚlstÚcf_arrÚitemr*Úes     r Ú_create_cfstring_arrayr;Iså€ð€FðBÜ×4Ñ4Ü × .Ñ .Ø Ü L‰Lœ×=Ñ=Ó >ó
ˆñ
ÜÐ:Ó;Ð ;Øò    1ˆDܘD“\ˆFÙÜ!Ð">Ó?Ð?ð 1Ü×1Ñ1°&¸&ÔAä×(Ñ(¨Õ0ñ    1ð €Møô ×(Ñ(¨Õ0ûÜ òBÙ Ü × $Ñ $ VÔ ,܏lŠl¹QÐ@ÓAÐAûðBús0„A0B?Á5B% B?Â%B<Â<B?Â?    C<Ã/C7Ã7C<cóŽ—tj|tjtj««}t    j
|t j«}|€Ttjd«}t    j||dt j«}|s td«‚|j}||jd«}|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.
    iz'Error copying C string from CFStringRefúutf-8) r$ÚcastÚPOINTERÚc_void_prÚCFStringGetCStringPtrrr'Úcreate_string_bufferÚCFStringGetCStringÚOSErrorÚvalueÚdecode)rEÚvalue_as_void_pÚstringÚbufferÚresults     r Ú_cf_string_to_unicoderKhs¥€ô—k‘k %¬¯©¼¿¹Ó)HÓI€Oä × 1Ñ 1Øœ×6Ñ6ó€Fð€~Ü×,Ñ,¨TÓ2ˆÜ×2Ñ2Ø ˜V T¬7×+HÑ+Hó
ˆñÜÐCÓDÐ DØ—‘ˆØ ÐØ—‘˜wÓ'ˆØ €MrcóƗ|dk(rytj|d«}t|«}tj|«||dk(rd|z}|€t
j }||«‚)z[
    Checks the return code and throws an exception if there is an error to
    report
    rNÚz OSStatus %s)rÚSecCopyErrorMessageStringrKrr3r5r6)ÚerrorÚexception_classÚcf_error_stringÚoutputs    r Ú_assert_no_errorrSsg€ð
 ‚zØä×8Ñ8¸ÀÓE€OÜ " ?Ó 3€FÜ×ј_Ô-à €~˜ 3šØ %Ñ'ˆàÐÜŸ,™,ˆá
˜&Ó
!Ð!rcó6—|jdd«}tj|«Dcgc]&}tj|j d««‘Œ(}}|st jd«‚tjtjdtjtj««}|st jd«‚    |D]Ÿ}t|«}|st jd«‚tj tj|«}tj"|«|st jd«‚tj$||«tj"|«Œ¡    |Scc}w#t&$rtj"|«‚wxYw)z‚
    Given a bundle of certs in PEM format, turns them into a CFArray of certs
    that can be used to validate a cert chain.
    s
ó
rzNo root certificates specifiedrr-zUnable to build cert object!)ÚreplaceÚ _PEM_CERTS_REÚfinditerÚbase64Ú    b64decodeÚgroupr5r6rr.r    r$r/r0r rÚSecCertificateCreateWithDatar3r2Ú    Exception)Ú
pem_bundleÚmatchÚ    der_certsÚ
cert_arrayÚ    der_bytesÚcertdataÚcerts       r Ú_cert_array_from_pemre–sh€ð ×#Ñ# G¨UÓ3€Jô7D×6LÑ6LÈZÓ6XöØ-2Œ×јŸ™ Q›Õ(ð€Iðñ ܏l‰lÐ;Ó<Ð<ä×4Ñ4Ü×*Ñ*Ø    Ü ‰ ”^×9Ñ9Ó:ó€Jñ
܏l‰lÐ7Ó8Ð8ðØ"ò     +ˆIÜ*¨9Ó5ˆHÙÜ—l‘lÐ#?Ó@Ð@Ü×8Ñ8Ü×2Ñ2°HóˆDô × $Ñ $ XÔ .ÙÜ—l‘lÐ#AÓBÐBä × -Ñ -¨j¸$Ô ?Ü × $Ñ $ TÕ *ñ     +ð( ÐùòGøô8 òô    × Ñ  Ô,Ø ð úsª+E3à B$E8Å8 FcóZ—tj«}tj|«|k(S)z=
    Returns True if a given CFTypeRef is a certificate.
    )rÚSecCertificateGetTypeIDrÚ CFGetTypeID©r9Úexpecteds  r Ú_is_certrkÄs(€ô×/Ñ/Ó1€HÜ × %Ñ % dÓ +¨xÑ 7Ð7rcóZ—tj«}tj|«|k(S)z;
    Returns True if a given CFTypeRef is an identity.
    )rÚSecIdentityGetTypeIDrrhris  r Ú _is_identityrnÌs(€ô×,Ñ,Ó.€HÜ × %Ñ % dÓ +¨xÑ 7Ð7rc
óâ—tjd«}tj|dd«j    d«}tj|dd«}t j «}tjj||«jd«}tj«}tj|t|«|ddtj|««}t!|«||fS)a³
    This function creates a temporary Mac keychain that we can use to work with
    credentials. This keychain uses a one-time password and a temporary file to
    store the data. We expect to have one keychain per socket. The returned
    SecKeychainRef must be freed by the caller, including calling
    SecKeychainDelete.
 
    Returns a tuple of the SecKeychainRef and the path to the temporary
    directory that contains it.
    é(Nér=F)ÚosÚurandomrYÚ    b16encoderFÚtempfileÚmkdtempÚpathÚjoinÚencoderÚSecKeychainRefÚSecKeychainCreater
r$r/rS)Ú random_bytesÚfilenameÚpasswordÚ tempdirectoryÚ keychain_pathÚkeychainÚstatuss       r Ú_temporary_keychainrƒÔsȀô"—:‘:˜b“>€LÜ×Ñ  ¨R¨aР0Ó1×8Ñ8¸ÓA€HÜ×Ñ  ¨Q¨RР0Ó1€HÜ×$Ñ$Ó&€Mä—G‘G—L‘L °Ó9×@Ñ@ÀÓI€Mô×&Ñ&Ó(€HÜ × 'Ñ 'Ø”s˜8“} h°°t¼V¿\¹\È(Ó=Só€FôVÔð ]Ð "Ð"rc ó¶—g}g}d}t|d«5}|j«}ddd«    tjtjt |««}tj «}tj|ddddd|tj|««}t|«tj|«}    t|    «D] }
tj||
«} tj| tj «} t#| «r'tj$| «|j'| «Œot)| «sŒ{tj$| «|j'| «Œ¢    |rtj*|«tj*|«||fS#1swYŒ{xYw#|rtj*|«tj*«wxYw)zÊ
    Given a single file, loads all the trust objects from it into arrays and
    the keychain.
    Returns a tuple of lists: the first list is a list of identities, the
    second a list of certs.
    NÚrbr)ÚopenÚreadrrr    r
Ú
CFArrayRefrÚ SecItemImportr$r/rSÚCFArrayGetCountÚrangeÚCFArrayGetValueAtIndexr>rrkÚCFRetainÚappendrnr3) rrwÚ certificatesÚ
identitiesÚ result_arrayÚfÚ raw_filedataÚfiledatarJÚ result_countÚindexr9s             r Ú_load_items_from_filer—÷s–€ð€LØ€JØ€Lä     ˆdDÓ    ð ˜QØ—v‘v“xˆ ÷ ð$+Ü!×.Ñ.Ü × .Ñ .° ¼cÀ,Ó>Oó
ˆô&×0Ñ0Ó2ˆ Ü×'Ñ'Ø Ø Ø Ø Ø Ø Ø Ü L‰L˜Ó &ó    
ˆô    ˜Ô ô &×5Ñ5°lÓCˆ ܘ<Ó(ò        (ˆEÜ!×8Ñ8¸ÀuÓMˆDÜ—;‘;˜t¤^×%=Ñ%=Ó>ˆD䘌~Ü×'Ñ'¨Ô-Ø×#Ñ# DÕ)ܘdÕ#Ü×'Ñ'¨Ô-Ø×!Ñ! $Õ'ñ        (ñ Ü × $Ñ $ \Ô 2ä× Ñ  Ô*à ˜ Ð %Ð%÷S ñ ûñH Ü × $Ñ $ \Ô 2ä× Ñ  Õ*ús“F­DF*Å(F*ÆF'Æ*.GcóP—g}g}d„|D«}    |D]3}t||«\}}|j|«|j|«Œ5|stj«}tj||dt j |««}t|«|j|«tj|jd««tjtjdt j tj««}    tj ||«D]}
tj"|    |
«Œ|    tj ||«D]} tj| «ŒS#tj ||«D]} tj| «ŒwxYw)zü
    Load certificates and maybe keys from a number of files. Has the end goal
    of returning a CFArray containing one SecIdentityRef, and then zero or more
    SecCertificateRef objects, suitable for use as a client certificate trust
    chain.
    c3ó&K—|]    }|sŒ|–—Œ y­w©Nr)rrws  r rz*_load_client_cert_chain.<locals>.<genexpr>Rsèø€Ò ,d¢tŒTÑ ,ùs‚Šr)r—ÚextendrÚSecIdentityRefÚ SecIdentityCreateWithCertificater$r/rSrŽrr3Úpopr.r    r0Ú    itertoolsÚchainr2) rÚpathsrrÚ    file_pathÚnew_identitiesÚ    new_certsÚ new_identityr‚Ú trust_chainr9Úobjs             r Ú_load_client_cert_chainr¨.s|€ð@€LØ€Jñ -˜eÔ ,€Eð"*Øò    +ˆIÜ(=¸hÈ    Ó(RÑ %ˆN˜IØ × Ñ ˜nÔ -Ø × Ñ      Õ *ð    +ñÜ#×2Ñ2Ó4ˆLÜ×>Ñ>ؘ, q™/¬6¯<©<¸ Ó+EóˆFô ˜VÔ $Ø × Ñ ˜lÔ +ô × $Ñ $ \×%5Ñ%5°aÓ%8Ô 9ô%×9Ñ9Ü × .Ñ .Ø Ü L‰Lœ×=Ñ=Ó >ó
ˆ ô
—O‘O J° Ó=ò    AˆDô × -Ñ -¨k¸4Õ @ð    Að
ä—?‘? :¨|Ó<ò    *ˆCÜ × $Ñ $ SÕ )ñ    *ø”9—?‘? :¨|Ó<ò    *ˆCÜ × $Ñ $ SÕ )ñ    *ús D3E3Å32F%)ré)ér)rªr)rªr©)rªrª)ÚSSLv2ÚSSLv3ÚTLSv1zTLSv1.1zTLSv1.2có¦—t|\}}d}d}tjd||«}t|«}d}tjd||||«|z}|S)z6
    Builds a TLS alert record for an unknown CA.
    r©é0z>BBéz>BBBH)ÚTLS_PROTOCOL_VERSIONSÚstructÚpackr
)    ÚversionÚver_majÚver_minÚseverity_fatalÚdescription_unknown_caÚmsgÚmsg_lenÚrecord_type_alertÚrecords             r Ú_build_tls_unknown_ca_alertr½‚sb€ô-¨WÑ5Ñ€GˆWØ€NØ!ÐÜ
+‰+e˜^Ð-CÓ
D€Cܐ#‹h€GØÐÜ [‰[˜Ð"3°W¸gÀwÓ OÐRUÑ U€FØ €Mrrš)Ú__doc__rYr$rŸrrÚrer5r²ruÚbindingsrrrÚcompileÚDOTALLrWr r"r+r;rKrSrerkrnrƒr—r¨r±r½rrr ú<module>rÃs¤ðñóÛ ÛÛ    Û    Û
Û Ûç7Ñ7ð—
‘
ØDÀbÇiÁió€ ò
òò, òò>ó2"ò*+ò\8ò8ò #òF4&ònH*ðXØ Ø ØØñ Ðó r