3 $c CR@sddlmZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z ddl mZmZmZmZddlmZdd lmZmZdZdZd Zd Zd Zd gZe e e d Zd dZeedeZ yddl!Z!ddl!m"Z"m#Z#Wne$k rYnXyddl!mZWne$k rYnXyddl%mZWne$k r>YnXyddl!m&Z&e&Z'WnJe$k ryddl!m'Z&e&Z'Wne$k rdZ'Z&YnXYnXyddl!m(Z(Wne$k re&Z(YnXyddl!m)Z)m*Z*m+Z+Wn"e$k rd>\Z*Z+dZ)YnXyddl!m,Z,Wne$k r2dZ,YnXdj-dddd d!d"d#d$d%d&d'd(d)d*gZ.ydd+l!mZWn&e$k rGd,d-d-e/ZYnXd.d/Z0d0d1Z1d2d3Z2d?d4d5Z3d@d6d7Z4d8d9Z5d:d;Z6dAdtjdt|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)r8r7r5 cert_reqs ssl_version server_sider9) warningswarnr r8r7r5r4r0r"r9)r:socketserver_hostnamerDkwargsrrrr"szSSLContext.wrap_socket)NNN)NF)__name__ __module__ __qualname__r;r<r@rAr"rrrrr/s   r/cCsn|jddj}t|}tj|}|s4tdj|t|j}||j }t ||sjtdj|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@|dkr tSt|tr.disable_check_hostnamekeylog_filename SSLKEYLOGFILE)rfrgrh)r%r'r/rADEFAULT_CIPHERSr2r!r)r*r(r-r6sys version_infor`rir4hasattrosenvironrQrl)rCrBr6r9rk sslkeylogfiler)rjrcreate_urllib3_contexts6%   ruc Cs^|} | dkrt|||d} |s&| s&| rjy| j|| | Wqttfk rf}zt|WYdd}~XqXn|dkrt| dr| j|r| dkrt|rtd|r| dkr| j||n| j||| yt| dr| j t Wnt k rYnX|ot | }|rt pto|}t r6|r6tjdt|rNt|| | |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. N)r9load_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-warnings)rH)rur@IOErrorOSErrorr rqrv_is_key_file_encryptedr<rwALPN_PROTOCOLSNotImplementedError is_ipaddressr#IS_SECURETRANSPORTrErFr _ssl_wrap_socket_impl)sockr8r7rBr5rHrCr9 ssl_context ca_cert_dir key_password ca_cert_data tls_in_tlsrjeuse_sni_hostnamesend_snissl_sockrrrssl_wrap_socketcsB&     rcCs4tj rt|tr|jd}ttj|p0tj|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)hostnamerrrr}s r}c Cs4t|d }x|D]}d|krdSqWWdQRXdS)z*Detects if a key file is encrypted or not.r ENCRYPTEDTNF)open)key_fileflinerrrrzs   rzcCsF|r&tstdtj|t|||S|r8|j||dS|j|SdS)Nz0TLS in TLS requires support for the 'ssl' module)rH)r$r $_validate_ssl_context_for_tls_in_tlsr")rrrrHrrrrs  r)r+r,)NNNN) NNNNNNNNNNNF)N)8 __future__rhmacrrrorEbinasciirrhashlibrrr exceptionsr r r r packagesr urlrrr/r$r# IS_PYOPENSSLr~r{rPrr`rUr2r!r" ImportError ssltransportr%r&r'r(r)r*r-joinrnobjectr\rcrerurr}rzrrrrrs         1 j Y