
) Xf-              #   @   s#  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z d  d l m	 Z	 m
 Z
 m Z d d l m Z m Z m Z d Z d Z d Z d Z i e	 d 6e
 d	 6e d
 6Z d d   Z e e d e  Z y< d  d l Z d  d l m Z m Z m Z d  d l m Z Wn e k
 r#Yn Xy  d  d l m Z m Z m Z Wn$ e k
 rjd" \ Z Z d Z Yn Xd Z  y d  d l m Z Wn4 e k
 rd  d l! Z! Gd d   d e"  Z Yn Xd d   Z# d d   Z$ d d   Z% d d d d d d  Z& d d d d d d d d d d  d! 	 Z' d S)#    )absolute_importN)hexlify	unhexlify)md5sha1sha256   )SSLErrorInsecurePlatformWarningSNIMissingWarningF    (   @   c             C   s`   t  t |   t |   } x7 t t |   t |   D] \ } } | | | AO} q8 W| d k S)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   S/home/ubuntu/projects/ifolica/build/requests/requests/packages/urllib3/util/ssl_.py_const_compare_digest_backport   s    (r   Zcompare_digest)wrap_socket	CERT_NONEPROTOCOL_SSLv23)HAS_SNI)OP_NO_SSLv2OP_NO_SSLv3OP_NO_COMPRESSION      i   zECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+HIGH:RSA+3DES:!aNULL:!eNULL:!MD5)
SSLContextc               @   s   e  Z d  Z d e j k o& d k  n p7 d e j k Z d d   Z d d   Z d d d	 d
  Z d d   Z	 d d d d  Z
 d S)r$   r         c             C   sO   | |  _  d |  _ t j |  _ d  |  _ d |  _ d  |  _ d  |  _ d  |  _	 d  S)NFr   )
protocolcheck_hostnamesslr   verify_modeca_certsoptionscertfilekeyfileciphers)selfZprotocol_versionr   r   r   __init__T   s    						zSSLContext.__init__c             C   s   | |  _  | |  _ d  S)N)r-   r.   )r0   r-   r.   r   r   r   load_cert_chain_   s    	zSSLContext.load_cert_chainNc             C   s(   | |  _  | d  k	 r$ t d   n  d  S)Nz-CA directories not supported in older Pythons)r+   r	   )r0   cafilecapathr   r   r   load_verify_locationsc   s    	z SSLContext.load_verify_locationsc             C   s%   |  j  s t d   n  | |  _ d  S)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	TypeErrorr/   )r0   Zcipher_suiter   r   r   set_ciphersi   s    	zSSLContext.set_ciphersFc             C   s   t  j d t  i |  j d 6|  j d 6|  j d 6|  j d 6|  j d 6| d 6} |  j rn t	 | d |  j
 | St	 | |  Sd  S)	Na8  A 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/security.html#insecureplatformwarning.r.   r-   r+   	cert_reqsssl_versionserver_sider/   )warningswarnr
   r.   r-   r+   r*   r'   r6   r   r/   )r0   socketserver_hostnamer;   kwargsr   r   r   r   r   s    





	zSSLContext.wrap_socket)r   r%   )r&   )r&   r   )__name__
__module____qualname__sysversion_infor6   r1   r2   r5   r8   r   r   r   r   r   r$   P   s   	r$   c             C   s   | j  d d  j   } t |  } t j |  } | sQ t d j |    n  t | j    } | |   j	   } t
 | |  s t d j | t |     n  d S)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.
    : z"Fingerprint of invalid length: {0}z6Fingerprints did not match. Expected "{0}", got "{1}".N)replacelowerr   HASHFUNC_MAPgetr	   formatr   encodedigest_const_compare_digestr   )certfingerprintdigest_lengthhashfuncfingerprint_bytescert_digestr   r   r   assert_fingerprint   s    
	rV   c             C   s[   |  d k r t  St |  t  rW t t |  d  } | d k rS t t d |   } n  | 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.
    NCERT_)r   
isinstancestrgetattrr)   )	candidateresr   r   r   resolve_cert_reqs   s    r]   c             C   s[   |  d k r t  St |  t  rW t t |  d  } | d k rS t t d |   } n  | S|  S)z 
    like resolve_cert_reqs
    N	PROTOCOL_)r   rX   rY   rZ   r)   )r[   r\   r   r   r   resolve_ssl_version   s    r_   c             C   s   t  |  p t j  } | d k r* t j n | } | d k rc d } | t O} | t O} | t O} n  | j | O_ t | d d  r | j	 | p t
  n  | | _ t | d d  d k	 r d | _ n  | 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   r6   Tr(   F)r$   r)   r   CERT_REQUIREDr   r    r!   r,   rZ   r8   DEFAULT_CIPHERSr*   r(   )r:   r9   r,   r/   contextr   r   r   create_urllib3_context   s    #

	rc   c
             C   s  | }
 |
 d k r* t  | | d | }
 n  | s6 |	 r y |
 j | |	  Wq t k
 r} } z t |   WYd d } ~ Xq t k
 r } z) | j t j k r t |   n    WYd d } ~ Xq Xn  | r |
 j | |  n  t r |
 j	 |  d | St
 j d t  |
 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().
    Nr/   r?   a  An 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/security.html#snimissingwarning.)rc   r5   IOErrorr	   OSErrorerrnoENOENTr2   r   r   r<   r=   r   )sockr.   r-   r9   r+   r?   r:   r/   Zssl_contextZca_cert_dirrb   er   r   r   ssl_wrap_socket  s*    rj   )r"   r#   )(
__future__r   rf   r<   Zhmacbinasciir   r   hashlibr   r   r   
exceptionsr	   r
   r   r$   r   create_default_contextZIS_PYOPENSSLrJ   r   rZ   rO   r)   r   r   r   ImportErrorr   r    r!   ra   rD   objectrV   r]   r_   rc   rj   r   r   r   r   <module>   sV   
		 :>		