Re83@sddlmZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z ddl mZmZddlmZmZmZdd lmZdZd Zd Zd Zd e d e d e iZddZeedeZy6ddlZddlmZm Z ddlmZWne!k rLYnXyddlm"Z"e"Z#WnKe!k ryddlm#Z"e"Z#Wne!k rdZ#Z"YnXYnXy ddlm$Z$m%Z%m&Z&Wn$e!k rd9\Z$Z%dZ&YnXdj'ddddddd d!d"d#d$d%d&d'gZ(ydd(lmZWn(e!k rsGd)d*d*e)ZYnXd+d,Z*d-d.Z+d/d0Z,ddddd1d2Z-dddddddddddd3d4 Z.d5d6Z/d7d8Z0dS):)absolute_importN)hexlify unhexlify)md5sha1sha256)IPV4_REBRACELESS_IPV6_ADDRZ_RE)SSLErrorInsecurePlatformWarningSNIMissingWarning)sixF (@cCs`tt|t|}x7tt|t|D]\}}|||AO}q8W|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/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/util/ssl_.py_const_compare_digest_backports(rcompare_digest) wrap_socket CERT_REQUIRED)HAS_SNI) PROTOCOL_TLS)PROTOCOL_SSLv23) OP_NO_SSLv2 OP_NO_SSLv3OP_NO_COMPRESSIONi:z ECDHE+AESGCMzECDHE+CHACHA20z DHE+AESGCMz DHE+CHACHA20z ECDH+AESGCMz DH+AESGCMzECDH+AESzDH+AESz RSA+AESGCMzRSA+AESz!aNULLz!eNULLz!MD5z!DSS) SSLContextc@s[eZdZddZddZdddddZdd Zdd d d ZdS) r+cCsO||_d|_tj|_d|_d|_d|_d|_d|_ dS)NFr) protocolcheck_hostnamessl CERT_NONE verify_modeca_certsoptionscertfilekeyfileciphers)selfZprotocol_versionrrr__init__ks       zSSLContext.__init__cCs||_||_dS)N)r3r4)r6r3r4rrrload_cert_chainvs zSSLContext.load_cert_chainNcCs=||_|dk r!td|dk r9tddS)Nz-CA directories not supported in older Pythonsz&CA data not supported in older Pythons)r1r )r6cafilecapathcadatarrrload_verify_locationszs     z SSLContext.load_verify_locationscCs ||_dS)N)r5)r6Z cipher_suiterrr set_ciphersszSSLContext.set_ciphersFc Cs_tjdtd|jd|jd|jd|jd|jd|i}t|d|j |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-warningsr4r3r1 cert_reqs ssl_version server_sider5) warningswarnr r4r3r1r0r,r r5)r6socketserver_hostnamer@kwargsrrrr s      zSSLContext.wrap_socket)__name__ __module__ __qualname__r7r8r<r=r rrrrr+js   r+cCs|jddj}t|}tj|}|sNtdj|t|j}||j }t ||stdj|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  rXcCsX|dkrtSt|trTtt|d}|dkrPttd|}|S|S)a Resolves the argument to a numeric constant, which can be passed to the wrap_socket function/method from the ssl module. Defaults to :data:`ssl.CERT_REQUIRED`. If given a string it is assumed to be the name of the constant in the :mod:`ssl` module or its abbreviation. (So you can specify `REQUIRED` instead of `CERT_REQUIRED`. If it's neither `None` nor a string we assume it is already the numeric constant which can directly be passed to wrap_socket. NCERT_)r! isinstancestrgetattrr.) candidateresrrrresolve_cert_reqss  r_cCsX|dkrtSt|trTtt|d}|dkrPttd|}|S|S)z like resolve_cert_reqs N PROTOCOL_)r#rZr[r\r.)r]r^rrrresolve_ssl_versions  racCst|p t}|j|p!t|dkr:tjn|}|dkrpd}|tO}|tO}|tO}|j |O_ |tjkst j d krt |dddk rd|_ ||_t |dddk rd |_|S) aAll arguments have the same meaning as ``ssl_wrap_socket``. By default, this function does a lot of the same work that ``ssl.create_default_context`` does on Python 3.4+. It: - Disables SSLv2, SSLv3, and compression - Sets a restricted set of server ciphers If you wish to enable SSLv3, you can do:: from pip._vendor.urllib3.util import ssl_ context = ssl_.create_urllib3_context() context.options &= ~ssl_.OP_NO_SSLv3 You can do the same to enable compression (substituting ``COMPRESSION`` for ``SSLv3`` in the last line above). :param ssl_version: The desired protocol version to use. This will default to PROTOCOL_SSLv23 which will negotiate the highest protocol that both the server and your installation of OpenSSL support. :param cert_reqs: Whether to require the certificate verification. This defaults to ``ssl.CERT_REQUIRED``. :param options: Specific OpenSSL options. These default to ``ssl.OP_NO_SSLv2``, ``ssl.OP_NO_SSLv3``, ``ssl.OP_NO_COMPRESSION``. :param ciphers: Which cipher suites to allow the server to select. :returns: Constructed SSLContext object with specified options :rtype: SSLContext Nrpost_handshake_authTr-F)rbrcrd)r+r#r=DEFAULT_CIPHERSr.r!r%r&r'r2sys version_infor\rer0r-)r?r>r2r5contextrrrcreate_urllib3_contexts"$    !     rjc Cs|} | dkr't||d|} |s9| s9| ry| j|| | Wqtk r} zt| WYdd} ~ Xqtk r} z&| jtjkrt| WYdd} ~ XqXn%|dkrt| dr| j|r| dkrt |rtd|rS| dkr@| j ||n| j ||| |dk rlt | srt rt 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(). :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() Nr5load_default_certsz5Client private key is encrypted, password is requiredrDaAn 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)rjr<IOErrorr OSErrorerrnoENOENThasattrrk_is_key_file_encryptedr8 is_ipaddressIS_SECURETRANSPORTr"r rArBr)sockr4r3r>r1rDr?r5 ssl_context ca_cert_dir key_password ca_cert_datarierrrssl_wrap_socket+s8#     rzcCsJtj r(t|tr(|jd}ttj|pFtj|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) rPY2rZbytesdecodeboolr matchr )hostnamerrrrrsrrc Cs>t|d(}x|D]}d|krdSqWWdQRXdS)z*Detects if a key file is encrypted or not.r ENCRYPTEDTNF)open)key_fileflinerrrrqs   rq)r(r))1 __future__rrnrAhmacrgbinasciirrhashlibrrrurlr r exceptionsr r rpackagesrr+r" IS_PYOPENSSLrsrLrr\rQr.r r! ImportErrorr#r$r%r&r'joinrfobjectrXr_rarjrzrrrqrrrrs                 1   MR