Re~&@sdZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlmZmZmZddlmZmZmZmZydd l mZWn(ek rdZdd lmZYnXd d gZd ZejZejj Z!e j"Z#e j$Z%dZ&ej'ej(ej)ej*ej+ej,ej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDgZEejFejGejHfiZIeJe drQejKejKfeIe jL Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. )absolute_importN)util)Security SecurityConstCoreFoundation)_assert_no_error_cert_array_from_pem_temporary_keychain_load_client_cert_chain) _fileobject)backport_makefileinject_into_urllib3extract_from_urllib3Ti@PROTOCOL_SSLv2PROTOCOL_SSLv3PROTOCOL_TLSv1PROTOCOL_TLSv1_1PROTOCOL_TLSv1_2cCsCtt_ttj_tt_ttj_dt_dtj_dS)zG Monkey-patch urllib3 with SecureTransport-backed SSL-support. TN)SecureTransportContextr SSLContextssl_HAS_SNIIS_SECURETRANSPORTrr/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyrs      cCsCtt_ttj_tt_ttj_dt_dtj_dS)z> Undo monkey-patching by :func:`inject_into_urllib3`. FN)orig_util_SSLContextrrrorig_util_HAS_SNIrrrrrrrs      c Csd}ytj|}|dkr+tjS|j}|d}|j}d}d}yx||kr|dks|dkrtj||stjt j d||} t j | j ||} |j| | } || 7}| s\|stjSPq\WWn~tjk r} z[| j }|dk rn|t j krn||d<|t jksd|t jkrktjSWYdd} ~ XnX||d<||krtjSdSWnAtk r} z!|dk r| |_tjSWYdd} ~ XnXdS)zs SecureTransport read callback. This is called by ST to request that data be returned from the socket. Nrz timed out)_connection_refsgetrerrSSLInternalsocket gettimeoutr wait_for_readerrorerrnoEAGAINctypesc_char from_address recv_intoerrSSLClosedGraceful ECONNRESETEPIPEerrSSLClosedAborterrSSLWouldBlock Exception _exception) connection_id data_bufferdata_length_pointerwrapped_socket base_socketZrequested_lengthtimeoutr%Z read_count remainingbuffer chunk_sizeerrr_read_callbacksN               r=c Csd}ytj|}|dkr+tjS|j}|d}tj||}|j}d}d} yxx| |kr|dks|dkrtj ||stj t j d|j |} | | 7} || d}qnWWn~tj k rg} z[| j }|dk rU|t j krU| |d<|t jksK|t jkrRtjSWYdd} ~ XnX| |d<| |krtjSdSWnAtk r} z!|dk r| |_tjSWYdd} ~ XnXdS)zx SecureTransport write callback. This is called by ST to request that data actually be sent on the network. Nrz timed out)rr rr!r"r( string_atr#rwait_for_writer%r&r'sendr-r.r/r0r1r2) r3r4r5r6r7Zbytes_to_writedatar8r%sentZ chunk_sentr<rrr_write_callbacksD           rCc@s eZdZdZddZejddZddZdd Z d d Z d d Z ddZ ddZ dddZddZddZddZddZddZdd Zd!d"d#Zd$d%Zd&d'Zd(d)ZdS)* WrappedSocketz API-compatibility wrapper for Python's OpenSSL wrapped socket object. Note: _makefile_refs, _drop(), and _reuse() are needed for the garbage collector of PyPy. cCsn||_d|_d|_d|_d|_d|_d|_d|_|jj|_ |jj ddS)NrF) r"context_makefile_refs_closedr2 _keychain _keychain_dir_client_cert_chainr#_timeout settimeout)selfr"rrr__init__Es        zWrappedSocket.__init__ccsDd|_dV|jdk r@|jd}|_|j|dS)a] A context manager that can be used to wrap calls that do I/O from SecureTransport. If any of the I/O callbacks hit an exception, this context manager will correctly propagate the exception after the fact. This avoids silently swallowing those exceptions. It also correctly forces the socket closed. N)r2close)rM exceptionrrr_raise_on_errorWs  zWrappedSocket._raise_on_errorcCsEtjttt}tj|j|tt}t|dS)a4 Sets up the allowed ciphers. By default this matches the set in util.ssl_.DEFAULT_CIPHERS, at least as supported by macOS. This is done custom and doesn't allow changing at this time, mostly because parsing OpenSSL cipher strings is going to be a freaking nightmare. N)rZSSLCipherSuitelen CIPHER_SUITESZSSLSetEnabledCiphersrEr )rMciphersresultrrr _set_cipherslszWrappedSocket._set_ciphersc Cst|s dStjj|rAt|d}|j}WdQRXd}tj}zt|}tj|j t j |}t ||st jdtj||}t |tj|d}t |tj}tj|t j |}t |Wd|rtj||dk r8tj|Xtjtjf}|j|krpt jd|jdS)z Called when we have set custom validation. We do this in two cases: first, when cert validation is entirely disabled; and second, when using a custom trust DB. NrbzFailed to copy trust referenceTz)certificate verify failed, error code: %d)ospathisfileopenreadr SecTrustRefr SSLCopyPeerTrustrEr(byrefr sslSSLErrorZSecTrustSetAnchorCertificatesZ!SecTrustSetAnchorCertificatesOnlyZSecTrustResultTypeZSecTrustEvaluater CFReleaserZkSecTrustResultUnspecifiedZkSecTrustResultProceedvalue) rMverify trust_bundlefZ cert_arraytrustrUZ trust_resultZ successesrrr_custom_validateys:         zWrappedSocket._custom_validatec CsKtjdtjtj|_tj|jtt} t | t @t |d} x| t krw| dd} qZW|t | rb) rM binary_formrgZcertdataZ der_bytesrUZ cert_countZleafZ data_lengthr4rrr getpeercertzs2      zWrappedSocket.getpeercertcCstj}tj|jtj|}t||jtj krXt j dn|jtj krndS|jtj krdS|jtjkrdS|jtjkrdS|jtjkrdSt j d|dS)Nz(SecureTransport does not support TLS 1.3zTLSv1.2zTLSv1.1ZTLSv1ZSSLv3ZSSLv2zUnknown TLS version: %r)rZ SSLProtocolZSSLGetNegotiatedProtocolVersionrEr(r_r rcrZkTLSProtocol13r`rakTLSProtocol12kTLSProtocol11 kTLSProtocol1 kSSLProtocol3 kSSLProtocol2)rMprotocolrUrrrversions"  zWrappedSocket.versioncCs|jd7_dS)Nr)rF)rMrrr_reuseszWrappedSocket._reusecCs/|jdkr|jn|jd8_dS)Nr)rFrO)rMrrr_drops zWrappedSocket._drop)__name__ __module__ __qualname____doc__rN contextlibcontextmanagerrQrVrhrtrurvryr+rLr#r@rrrOrrrrrrrrrD=s(   9 Y   +      :  rDcCs%|jd7_t|||ddS)NrrOT)rFr )rMmodebufsizerrrmakefilesrrcOsd}t|||||S)Nr)r)rMr bufferingargskwargsrrrrsc@seZdZdZddZeddZejddZeddZejd dZed d Z e jd d Z d dZ ddZ ddZ dddddZ ddddZddddddZdS)rz I am a wrapper class for the SecureTransport library, to translate the interface of the standard library ``SSLContext`` object to calls into SecureTransport. cCsPt|\|_|_d|_d|_d|_d|_d|_d|_dS)NrF) _protocol_to_min_max _min_version _max_version_options_verify _trust_bundle _client_cert _client_key_client_key_passphrase)rMrrrrrNs     zSecureTransportContext.__init__cCsdS)z SecureTransport cannot have its hostname checking disabled. For more, see the comment on getpeercert() in this file. Tr)rMrrrcheck_hostnamesz%SecureTransportContext.check_hostnamecCsdS)z SecureTransport cannot have its hostname checking disabled. For more, see the comment on getpeercert() in this file. Nr)rMrcrrrrscCs|jS)N)r)rMrrroptionsszSecureTransportContext.optionscCs ||_dS)N)r)rMrcrrrrscCs|jrtjStjS)N)rr` CERT_REQUIRED CERT_NONE)rMrrr verify_modesz"SecureTransportContext.verify_modecCs"|tjkrdnd|_dS)NTF)r`rr)rMrcrrrrscCsdS)Nr)rMrrrset_default_verify_pathss z/SecureTransportContext.set_default_verify_pathscCs |jS)N)r)rMrrrload_default_certs)sz)SecureTransportContext.load_default_certscCs"|tjjkrtddS)Nz5SecureTransport doesn't support custom cipher strings)rrDEFAULT_CIPHERSr)rMrTrrr set_ciphers,sz"SecureTransportContext.set_ciphersNc CsK|dk rtd|dk r8t|WdQRX|pA||_dS)Nz1SecureTransport does not support cert directories)rr[r)rMcafilecapathcadatarrrload_verify_locations1s     z,SecureTransportContext.load_verify_locationscCs||_||_||_dS)N)rrZ_client_cert_passphrase)rMcertfilekeyfilepasswordrrrload_cert_chain=s  z&SecureTransportContext.load_cert_chainFTc Csl| s t|st|s%tt|}|j||j|j|j|j|j|j|j |S)N) rrDrtrrrrrrr)rMsock server_sidedo_handshake_on_connectsuppress_ragged_eofsrpr6rrr wrap_socketBs     z"SecureTransportContext.wrap_socket)rrrrrNpropertyrsetterrrrrrrrrrrrrrs"      r)_r __future__rrr(r&os.pathrXrr"r` threadingweakrefrZ_securetransport.bindingsrrrZ_securetransport.low_levelr r r r r ImportErrorZpackages.backports.makefiler__all__rrrrrWeakValueDictionaryrLockrkr~Z'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384Z'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256Z%TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384Z%TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256Z-TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256Z+TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256Z#TLS_DHE_RSA_WITH_AES_256_GCM_SHA384Z#TLS_DHE_RSA_WITH_AES_128_GCM_SHA256Z'TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384Z$TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHAZ'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256Z$TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHAZ%TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384Z"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHAZ%TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256Z"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHAZ#TLS_DHE_RSA_WITH_AES_256_CBC_SHA256Z TLS_DHE_RSA_WITH_AES_256_CBC_SHAZ#TLS_DHE_RSA_WITH_AES_128_CBC_SHA256Z TLS_DHE_RSA_WITH_AES_128_CBC_SHAZTLS_AES_256_GCM_SHA384ZTLS_AES_128_GCM_SHA256ZTLS_RSA_WITH_AES_256_GCM_SHA384ZTLS_RSA_WITH_AES_128_GCM_SHA256ZTLS_AES_128_CCM_8_SHA256ZTLS_AES_128_CCM_SHA256ZTLS_RSA_WITH_AES_256_CBC_SHA256ZTLS_RSA_WITH_AES_128_CBC_SHA256ZTLS_RSA_WITH_AES_256_CBC_SHAZTLS_RSA_WITH_AES_128_CBC_SHArS PROTOCOL_TLSrrrhasattrrrrrrrrrrrr=rCZ SSLReadFuncriZ SSLWriteFuncrjobjectrDrrrrrr3s         "        7 6