Your IP : 18.217.104.36


Current Path : /usr/lib/python3.6/site-packages/urllib3/util/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/urllib3/util/__pycache__/ssl_.cpython-36.pyc

3

h��f35�)@sddlmZddlZddlZddlZddlZddlmZmZddl	m
Z
mZmZddl
mZmZmZddlmZdZdZdZdZe
ee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-SHA256zECDH+AESGCMz
ECDH+CHACHA20z	DH+AESGCMzDH+CHACHA20zECDH+AES256z	DH+AES256zECDH+AES128zDH+AESz
RSA+AESGCMzRSA+AESz!aNULLz!eNULLz!MD5)�
SSLContextc@s8eZdZdd�Zdd�Zd
dd�Zdd	�Zddd�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)ZcertZfingerprintZ
digest_lengthZhashfuncZfingerprint_bytesZcert_digestrrr�assert_fingerprint�s


rPcCs@|dkrtSt|t�r<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 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.
    NZCERT_)rr'�str�getattrr2)�	candidate�resrrr�resolve_cert_reqs�s
rUcCs@|dkrtSt|t�r<tt|d�}|dkr8ttd|�}|S|S)z 
    like resolve_cert_reqs
    NZ	PROTOCOL_)rr'rQrRr2)rSrTrrr�resolve_ssl_version�s
rVcCs�t|p
tj�}|j|pt�|dkr*tjn|}|dkrRd}|tO}|tO}|tO}|j	|O_	t
|dd�dk	rvd|_||_t
|dd�dk	r�d|_
|S)a�All 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
    Nr�post_handshake_authTr1F)r/r2rr=�DEFAULT_CIPHERSZ
CERT_REQUIREDr r!r"r5rRrWr3r1)r?r>r5r8�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�tr�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?r8Zssl_contextZca_cert_dirrY�errr�ssl_wrap_socket*s2rdcCsztjrt|t�r|jd�}tjg}ttd�r8|jtj	�x<|D]4}yt
||�Wntjt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
rZpackagesrr/rZIS_PYOPENSSLrbrKrrRrOr2rrr�ImportErrorr r!r"r`r%r*�joinrX�sys�objectrPrUrVrZrdrarrrr�<module>s�

.
D
E

?>