Viewing File: /usr/lib/python3.6/site-packages/pip/_vendor/urllib3/util/__pycache__/ssl_.cpython-36.opt-1.pyc

3

aj/!@sddlmZddlZddlZddlZddlmZmZddlm	Z	m
Z
mZddlm
Z
mZmZdZdZdZdZe	e
edZd	d
ZeedeZy,ddlZddlmZmZmZdd
lmZWnek
rYnXyddlmZmZmZWn"ek
rd0\ZZdZYnXdj dddddddddddddd d!d"gZ!ydd#lmZWn.ek
rrddl"Z"Gd$d%d%e#ZYnXd&d'Z$d(d)Z%d*d+Z&d1d,d-Z'd2d.d/Z(dS)3)absolute_importN)hexlify	unhexlify)md5sha1sha256)SSLErrorInsecurePlatformWarningSNIMissingWarningF) (@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_SSLv2OP_NO_SSLv3OP_NO_COMPRESSIONi:zTLS13-AES-256-GCM-SHA384zTLS13-CHACHA20-POLY1305-SHA256zTLS13-AES-128-GCM-SHA256zECDH+AESGCMz
ECDH+CHACHA20z	DH+AESGCMzDH+CHACHA20zECDH+AES256z	DH+AES256zECDH+AES128zDH+AESz
RSA+AESGCMzRSA+AESz!aNULLz!eNULLz!MD5)
SSLContextc@s\eZdZdejkodknp*dejkZddZddZdd	d
ZddZ	dddZ
dS)r%rcCs6||_d|_tj|_d|_d|_d|_d|_d|_	dS)NFr)
protocolcheck_hostnamesslrverify_modeca_certsoptionscertfilekeyfileciphers)selfZprotocol_versionrrr__init__cszSSLContext.__init__cCs||_||_dS)N)r.r/)r1r.r/rrrload_cert_chainnszSSLContext.load_cert_chainNcCs||_|dk	rtddS)Nz-CA directories not supported in older Pythons)r,r	)r1ZcafileZcapathrrrload_verify_locationsrsz SSLContext.load_verify_locationscCs|jstd||_dS)NzYour version of Python does not support setting a custom cipher suite. Please upgrade to Python 2.7, 3.2, or later if you need this functionality.)supports_set_ciphers	TypeErrorr0)r1Zcipher_suiterrrset_ciphersxszSSLContext.set_ciphersFcCsTtjdt|j|j|j|j|j|d}|jrDt	|fd|j
i|St	|f|SdS)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)r/r.r,	cert_reqsssl_versionserver_sider0)warningswarnr
r/r.r,r+r(r5rr0)r1Zsocketserver_hostnamer:kwargsrrrrszSSLContext.wrap_socket)rr&)r')r'r)NN)NF)__name__
__module____qualname__sysversion_infor5r2r3r4r7rrrrrr%_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	formatrencodeZdigest_const_compare_digestr)ZcertZfingerprintZ
digest_lengthZhashfuncZfingerprint_bytesZcert_digestrrrassert_fingerprints


rLcCs@|dkrtSt|tr<tt|d}|dkr8ttd|}|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_NONE`.
    If given a string it is assumed to be the name of the constant in the
    :mod:`ssl` module or its abbrevation.
    (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.
    NZCERT_)r
isinstancestrgetattrr*)	candidateresrrrresolve_cert_reqss
rRcCs@|dkrtSt|tr<tt|d}|dkr8ttd|}|S|S)z 
    like resolve_cert_reqs
    NZ	PROTOCOL_)rrMrNrOr*)rPrQrrrresolve_ssl_versions
rScCst|p
tj}|dkrtjn|}|dkrDd}|tO}|tO}|tO}|j|O_t|ddrl|j	|pht
||_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 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
    Nrr5Tr)F)
r%r*rZ
CERT_REQUIREDrr r!r-rOr7DEFAULT_CIPHERSr+r))r9r8r-r0contextrrrcreate_urllib3_contexts#rVc
Cs|}
|
dkrt|||d}
|s"|	ry|
j||	Wqtk
r\}zt|WYdd}~Xqtk
r}z|jtjkrt|WYdd}~XqXn|dkrt|
dr|
j|r|
j	||t
r|
j||dStj
dt|
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. This is not
        supported on Python 2.6 as the ssl module does not support it.
    :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)r0load_default_certs)r=aAn HTTPS request has been made, but the SNI (Subject 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)rVr4IOErrorr	OSErrorerrnoENOENThasattrrWr3rrr;r<r)Zsockr/r.r8r,r=r9r0Zssl_contextZca_cert_dirrUerrrssl_wrap_sockets.r^)r"r#)NNNN)	NNNNNNNNN))Z
__future__rrZr;ZhmacZbinasciirrZhashlibrrr
exceptionsr	r
rr%rZIS_PYOPENSSLZIS_SECURETRANSPORTrGrrOrKr*rrrImportErrorrr r!joinrTrBobjectrLrRrSrVr^rrrr<module>st

:
>
Back to Directory File Manager