a *Na C @sddlmZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z ddl mZmZmZmZddlmZdd lmZmZdZdZd Zd Zd Zd gZe e e d Zd dZeedeZ zddl!Z!ddl!m"Z"m#Z#Wne$yYn0zddl!mZWne$yYn0zddl%mZWne$y8Yn0zddl!m&Z&e&Z'WnFe$yzddl!m'Z&e&Z'Wne$ydZ'Z&Yn0Yn0zddl!m(Z(Wne$ye&Z(Yn0zddl!m)Z)m*Z*m+Z+Wn e$yd\Z*Z+dZ)Yn0zddl!m,Z,Wne$y"dZ,Yn0d-gdZ.zddl!mZWn$e$yfGddde/ZYn0d d!Z0d"d#Z1d$d%Z2d0d&d'Z3d1d(d)Z4d*d+Z5d,d-Z6d2d.d/Z7dS)3)absolute_importN)hexlify unhexlify)md5sha1sha256)InsecurePlatformWarningProxySchemeUnsupportedSNIMissingWarningSSLError)six)BRACELESS_IPV6_ADDRZ_REIPV4_REFzhttp/1.1) (@cCsDtt|t|}tt|t|D]\}}|||AO}q&|dkS)z Compare two digests of equal length in constant time. The digests must be of type str/bytes. Returns True if the digests match, and False otherwise. r)abslenzip bytearray)abresultleftrightrl/private/var/folders/js/6pj4vh5d4zd0k6bxv74qrbhr0000gr/T/pip-target-22xwyzbs/lib/python/urllib3/util/ssl_.py_const_compare_digest_backportsrcompare_digest) CERT_REQUIRED wrap_socket)HAS_SNI) SSLTransport) PROTOCOL_TLS)PROTOCOL_SSLv23)PROTOCOL_TLS_CLIENT)OP_NO_COMPRESSION OP_NO_SSLv2 OP_NO_SSLv3)iii) OP_NO_TICKETi@:)z ECDHE+AESGCMzECDHE+CHACHA20z DHE+AESGCMz DHE+CHACHA20z ECDH+AESGCMz DH+AESGCMzECDH+AESzDH+AESz RSA+AESGCMzRSA+AESz!aNULLz!eNULLz!MD5z!DSS) SSLContextc@s8eZdZddZddZd ddZdd Zdd d ZdS)r-cCs6||_d|_tj|_d|_d|_d|_d|_d|_ dS)NFr) protocolcheck_hostnamessl CERT_NONE verify_modeca_certsoptionscertfilekeyfileciphers)selfZprotocol_versionrrr__init__szSSLContext.__init__cCs||_||_dSN)r5r6)r8r5r6rrrload_cert_chainszSSLContext.load_cert_chainNcCs*||_|durtd|dur&tddS)Nz-CA directories not supported in older Pythonsz&CA data not supported in older Pythons)r3r )r8cafilecapathcadatarrrload_verify_locationss z SSLContext.load_verify_locationscCs ||_dSr:r7)r8Z cipher_suiterrr set_ciphersszSSLContext.set_ciphersFcCs>tdt|j|j|j|j|j|d}t|fd|j i|S)Na2A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings)r6r5r3 cert_reqs ssl_version server_sider7) warningswarnr r6r5r3r2r.r"r7)r8socketserver_hostnamerDkwargsrrrr"s zSSLContext.wrap_socket)NNN)NF)__name__ __module__ __qualname__r9r;r?rAr"rrrrr-s   r-cCsn|dd}t|}t|}|s4td|t|}|| }t ||sjtd|t |dS)z Checks if given fingerprint matches the supplied certificate. :param cert: Certificate as bytes object. :param fingerprint: Fingerprint as string of hexdigits, can be interspersed by colons. r,z"Fingerprint of invalid length: {0}z6Fingerprints did not match. Expected "{0}", got "{1}".N) replacelowerr HASHFUNC_MAPgetr formatrencodedigest_const_compare_digestr)cert fingerprint digest_lengthhashfuncfingerprint_bytes cert_digestrrrassert_fingerprints     r\cCs@|dur tSt|tr.disable_check_hostnamekeylog_filename SSLKEYLOGFILE)r%r'r-rADEFAULT_CIPHERSr0r!r)r*r(r+r4sys version_infor`rjr2hasattrosenvironrQrn)rCrBr4r7rm sslkeylogfilerrkrcreate_urllib3_contexts:%    rwc  Cs\|} | durt|||d} |s&| s&| rlz| || | Wqttfyh}zt|WYd}~qd}~00n|durt| dr| |r| durt|rtd|r| dur| ||n| ||| zt| dr| t Wnt yYn0|ot | }|rt pto|}t s4|r4tdt|rLt|| | |d}n t|| | }|S)a All arguments except for server_hostname, ssl_context, and ca_cert_dir have the same meaning as they do when using :func:`ssl.wrap_socket`. :param server_hostname: When SNI is supported, the expected hostname of the certificate :param ssl_context: A pre-made :class:`SSLContext` object. If none is provided, one will be created using :func:`create_urllib3_context`. :param ciphers: A string of ciphers we wish the client to support. :param ca_cert_dir: A directory containing CA certificates in multiple separate files, as supported by OpenSSL's -CApath flag or the capath argument to SSLContext.load_verify_locations(). :param key_password: Optional password if the keyfile is encrypted. :param ca_cert_data: Optional string containing CA certificates in PEM format suitable for passing as the cadata parameter to SSLContext.load_verify_locations() :param tls_in_tls: Use SSLTransport to wrap the existing socket. Nr@load_default_certsz5Client private key is encrypted, password is requiredset_alpn_protocolsaAn HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warningsrH)rwr?IOErrorOSErrorr rsrx_is_key_file_encryptedr;ryALPN_PROTOCOLSNotImplementedError is_ipaddressr#IS_SECURETRANSPORTrErFr _ssl_wrap_socket_impl)sockr6r5rBr3rHrCr7 ssl_context ca_cert_dir key_password ca_cert_data tls_in_tlsrleuse_sni_hostnamesend_snissl_sockrrrssl_wrap_socketcsH&        rcCs2tjst|tr|d}tt|p.t|S)zDetects whether the hostname given is an IPv4 or IPv6 address. Also detects IPv6 addresses with Zone IDs. :param str hostname: Hostname to examine. :return: True if the hostname is an IP address, False otherwise. ascii) r PY2r^bytesdecodeboolrmatchr)hostnamerrrrs rcCsRt|d4}|D]}d|vrWddSqWdn1sD0YdS)z*Detects if a key file is encrypted or not.r ENCRYPTEDNTF)open)key_fileflinerrrr}s  2r}cCsF|r&tstdt|t|||S|r8|j||dS||SdS)Nz0TLS in TLS requires support for the 'ssl' modulerz)r$r $_validate_ssl_context_for_tls_in_tlsr")rrrrHrrrrs  r)NNNN) NNNNNNNNNNNF)N)8 __future__rhmacrtrqrEbinasciirrhashlibrrr exceptionsr r r r packagesr urlrrr-r$r# IS_PYOPENSSLrr~rPrr`rUr0r!r" ImportError ssltransportr%r&r'r(r)r*r+joinrpobjectr\rdrfrwrrr}rrrrrs          1 k f