3 hf35)@sddlmZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z ddl mZmZmZddlmZdZdZdZdZe e e d Zd d Zeed eZy,ddlZdd lmZmZmZddlmZWnek rYnXyddlm Z m!Z!m"Z"Wn"ek rd6\Z Z!dZ"YnXe#edr2ej$Z$n4yddl%Z%ddZ$Wnek rdddZ$YnXdj&dddddddddd d!d"d#d$d%d&gZ'ydd'lmZWn.ek rddl(Z(Gd(d)d)e)ZYnXd*d+Z*d,d-Z+d.d/Z,d7d0d1Z-d8d2d3Z.d4d5Z/dS)9)absolute_importN)hexlify unhexlify)md5sha1sha256)SSLErrorInsecurePlatformWarningSNIMissingWarning)sixF) (@cCsHtt|t|}x*tt|t|D]\}}|||AO}q(W|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)abresultlrr/usr/lib/python3.6/ssl_.py_const_compare_digest_backportsrZcompare_digest) wrap_socket CERT_NONEPROTOCOL_SSLv23)HAS_SNI) OP_NO_SSLv2 OP_NO_SSLv3OP_NO_COMPRESSIONi inet_ptoncCst|tr|jd}tj|S)Nascii) isinstancebytesdecode ipaddressZ ip_address)_hostrrrr%Ds  cCs tj|S)N)socketZ inet_aton)r+r,rrrr%Js:zTLS13-AES-256-GCM-SHA384zTLS13-CHACHA20-POLY1305-SHA256zTLS13-AES-128-GCM-SHA256z ECDH+AESGCMz ECDH+CHACHA20z DH+AESGCMz DH+CHACHA20z ECDH+AES256z DH+AES256z ECDH+AES128zDH+AESz RSA+AESGCMzRSA+AESz!aNULLz!eNULLz!MD5) SSLContextc@s8eZdZddZddZd ddZdd Zdd d ZdS)r/cCs6||_d|_tj|_d|_d|_d|_d|_d|_ dS)NFr) protocolcheck_hostnamesslr verify_modeca_certsoptionscertfilekeyfileciphers)selfZprotocol_versionrrr__init__vszSSLContext.__init__cCs||_||_dS)N)r6r7)r9r6r7rrrload_cert_chainszSSLContext.load_cert_chainNcCs||_|dk rtddS)Nz-CA directories not supported in older Pythons)r4r )r9ZcafileZcapathrrrload_verify_locationssz SSLContext.load_verify_locationscCs ||_dS)N)r8)r9Z cipher_suiterrr set_ciphersszSSLContext.set_ciphersFcCs>tjdt|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/latest/advanced-usage.html#ssl-warnings)r7r6r4 cert_reqs ssl_version server_sider8) warningswarnr r7r6r4r3r0rr8)r9r-server_hostnamer@kwargsrrrrszSSLContext.wrap_socket)NN)NF)__name__ __module__ __qualname__r:r;r<r=rrrrrr/us   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 formatrencodeZdigest_const_compare_digestr)ZcertZ fingerprintZ digest_lengthZhashfuncZfingerprint_bytesZ cert_digestrrrassert_fingerprints      rPcCs@|dkr tSt|trr5r8contextrrrcreate_urllib3_contexts#rZc Cs|} | dkrt|||d} |s"| ry| j|| Wqtk r\} zt| WYdd} ~ Xqtk r} z| jtjkrt| WYdd} ~ XqXn|dkrt| dr| j|r| j |||dk rt | st rt r|dk r| j ||dStjdt| j |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(). N)r8load_default_certs)rCaAn 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/latest/advanced-usage.html#ssl-warnings)rZr<IOErrorr OSErrorerrnoENOENThasattrr[r; is_ipaddressIS_SECURETRANSPORTrrrArBr ) Zsockr7r6r>r4rCr?r8Z ssl_contextZ ca_cert_dirrYerrrssl_wrap_socket*s2   rdcCsztjrt|tr|jd}tjg}ttdr8|jtj x<|D]4}yt ||Wntj t t fk rlYq>XdSq>WdS)zDetects whether the hostname given is an IP address. :param str hostname: Hostname to examine. :return: True if the hostname is an IP address, False otherwise. r&AF_INET6TF)r ZPY3r'r(r)r-ZAF_INETr`appendrer%error ValueErrorr])ZhostnameZfamiliesZafrrrrars    ra)r#r$)NNNN) NNNNNNNNN)0Z __future__rr^rAZhmacr-ZbinasciirrZhashlibrrr exceptionsr r r Zpackagesr r/rZ IS_PYOPENSSLrbrKrrRrOr2rrr ImportErrorr r!r"r`r%r*joinrXsysobjectrPrUrVrZrdrarrrrs      . D E