U .Ѫ_#:@s0ddlmZddlZddlZddlZddlZddlZddlmZm Z ddl m Z m Z m Z ddlmZmZddlmZmZmZdd lmZdZd Zd Zd Ze e e d Zd d ZeedeZz(ddlZddlm Z m!Z!ddlmZWne"k rYnXzddlm#Z#e#Z$WnJe"k rTzddlm$Z#e#Z$Wne"k rNdZ$Z#YnXYnXzddlm%Z%m&Z&m'Z'Wn"e"k rd\Z%Z&dZ'YnXd(dddddddddd d!d"d#d$gZ)zdd%lmZWn&e"k rGd&d'd'e*ZYnXd(d)Z+d*d+Z,d,d-Z-d6d.d/Z.d7d0d1Z/d2d3Z0d4d5Z1dS)8)absolute_importN)hexlify unhexlify)md5sha1sha256)IPV4_REBRACELESS_IPV6_ADDRZ_RE)SSLErrorInsecurePlatformWarningSNIMissingWarning)sixF) (@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)abresultleftrightr8/Users/cjl/code/aws-vpc-ipam/lambda/urllib3/util/ssl_.py_const_compare_digest_backportsrZcompare_digest) wrap_socket CERT_REQUIRED)HAS_SNI) PROTOCOL_TLS)PROTOCOL_SSLv23) OP_NO_SSLv2 OP_NO_SSLv3OP_NO_COMPRESSION)iii: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__lszSSLContext.__init__cCs||_||_dSN)r0r1)r3r0r1rrrload_cert_chainwszSSLContext.load_cert_chainNcCs*||_|dk rtd|dk r&tddS)Nz-CA directories not supported in older Pythonsz&CA data not supported in older Pythons)r.r )r3cafilecapathcadatarrrload_verify_locations{s z SSLContext.load_verify_locationscCs ||_dSr5r2)r3Z 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/latest/advanced-usage.html#ssl-warnings)r1r0r. cert_reqs ssl_version server_sider2) warningswarnr r1r0r.r-r)rr2)r3socketserver_hostnamer?kwargsrrrrs zSSLContext.wrap_socket)NNN)NF)__name__ __module__ __qualname__r4r6r:r<rrrrrr(ks   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)certZ fingerprintZ digest_lengthZhashfuncZfingerprint_bytesZ cert_digestrrrassert_fingerprints     rRcCs@|dkr tSt|trr=r/r2contextZ sslkeylogfilerrrcreate_urllib3_contexts4$   rhc  CsH|} | dkrt|||d} |s&| s&| rz| || | Wqtk rb} z t| W5d} ~ XYqtk r} z| jtjkrt| W5d} ~ XYqXn|dkrt| dr| |r| dkrt |rtd|r| dkr| ||n| ||| |dk rt |rt r>t r2|dk r2| j||dStdt| |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() Nr;load_default_certsz5Client private key is encrypted, password is required)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)rhr:IOErrorr OSErrorerrnoZENOENTrdri_is_key_file_encryptedr6 is_ipaddressIS_SECURETRANSPORTr!rr@rAr)sockr1r0r=r.rCr>r2 ssl_context ca_cert_dir key_password ca_cert_datargerrrssl_wrap_socket4sB#   rvcCs2tjst|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) rPY2rSbytesdecodeboolr matchr )hostnamerrrrns rnc Cs<t|d(}|D]}d|krW5QRdSqW5QRXdS)z*Detects if a key file is encrypted or not.rZ ENCRYPTEDTF)open)key_fileflinerrrrms  rm)NNNN) NNNNNNNNNNN)2 __future__rrlr@Zhmacrerbbinasciirrhashlibrrrurlr r exceptionsr r rpackagesrr(r! IS_PYOPENSSLrorKrrUrPr+rr ImportErrorr"r#r$r%r&joinraobjectrRrYrZrhrvrnrmrrrrs       1 V ^