3 »nNj35ã)@sddlmZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z ddl mZmZmZddlmZdZdZdZdZe e e d œZd d „Zeed eƒZy,ddlZdd lmZmZmZddlmZWnek ràYnXyddlm Z m!Z!m"Z"Wn"ek �rd6\Z Z!dZ"YnXe#edƒ�r2ej$Z$n4yddl%Z%dd„Z$Wnek �rddd„Z$YnXdj&dddddddddd d!d"d#d$d%d&gƒZ'ydd'lmZWn.ek �rÎddl(Z(Gd(d)„d)e)ƒZYnXd*d+„Z*d,d-„Z+d.d/„Z,d7d0d1„Z-d8d2d3„Z.d4d5„Z/dS)9é)Úabsolute_importN)ÚhexlifyÚ unhexlify)Úmd5Úsha1Úsha256é)ÚSSLErrorÚInsecurePlatformWarningÚSNIMissingWarning)Ú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)ÚabsÚlenÚzipÚ bytearray)ÚaÚbÚresultÚlÚr©rú/usr/lib/python3.6/ssl_.pyÚ_const_compare_digest_backportsrZcompare_digest)Ú wrap_socketÚ CERT_NONEÚPROTOCOL_SSLv23)ÚHAS_SNI)Ú OP_NO_SSLv2Ú OP_NO_SSLv3ÚOP_NO_COMPRESSIONééiÚ inet_ptoncCst|tƒr|jdƒ}tj|ƒS)NÚascii)Ú isinstanceÚbytesÚdecodeÚ 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@s8eZdZdd„Zdd„Zd dd„Zdd „Zdd d „ZdS)r/cCs6||_d|_tj|_d|_d|_d|_d|_d|_ dS)NFr) ÚprotocolÚcheck_hostnameÚsslrÚ verify_modeÚca_certsÚoptionsÚcertfileÚkeyfileÚciphers)ÚselfZprotocol_versionrrrÚ__init__vszSSLContext.__init__cCs||_||_dS)N)r6r7)r9r6r7rrrÚload_cert_chain�szSSLContext.load_cert_chainNcCs||_|dk rtdƒ‚dS)Nz-CA directories not supported in older Pythons)r4r )r9ZcafileZcapathrrrÚload_verify_locations…sz SSLContext.load_verify_locationscCs ||_dS)N)r8)r9Z cipher_suiterrrÚ set_ciphers‹szSSLContext.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) ÚwarningsÚwarnr r7r6r4r3r0rr8)r9r-Úserver_hostnamer@ÚkwargsrrrrŽszSSLContext.wrap_socket)NN)NF)Ú__name__Ú __module__Ú __qualname__r:r;r<r=rrrrrr/us   r/cCsn|jddƒjƒ}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) ÚreplaceÚlowerrÚ HASHFUNC_MAPÚgetr ÚformatrÚencodeZdigestÚ_const_compare_digestr)ZcertZ fingerprintZ digest_lengthZhashfuncZfingerprint_bytesZ cert_digestrrrÚassert_fingerprint£s      rPcCs@|dkr tSt|tƒrr5r8ÚcontextrrrÚcreate_urllib3_contextås#rZc Cs|} | dkrt|||d�} |s"| r–y| j|| ƒWq°tk r\} zt| ƒ‚WYdd} ~ Xq°tk r’} z| jtjkr€t| ƒ‚‚WYdd} ~ Xq°Xn|dkr°t| dƒr°| jƒ|rÀ| j ||ƒ|dk rÒt |ƒ sÖt rüt rð|dk rð| j ||d�Stjdtƒ| 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)r8Úload_default_certs)rCa€An 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 ÚOSErrorÚerrnoÚENOENTÚhasattrr[r;Ú is_ipaddressÚIS_SECURETRANSPORTrrrArBr ) Zsockr7r6r>r4rCr?r8Z ssl_contextZ ca_cert_dirrYÚerrrÚssl_wrap_socket*s2   rdcCsztjrt|tƒr|jdƒ}tjg}ttdƒr8|jtj ƒx<|D]4}yt ||ƒWntj t t fk rlYq>XdSq>WdS)z­Detects 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*ÚjoinrXÚsysÚobjectrPrUrVrZrdrarrrrÚsˆ      . D E