Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/__pycache__/pyopenssl.cpython-36.pyc

3

�Pf�;�@s,dZddlmZddlZddlmZddlmZ	ddl
mZddlm
Z
mZddlmZydd	lmZWn$ek
r�dZd
dlmZYnXddlZddlZd
dlmZddlZd
d
lmZddgZdZejej j!ej"ej j#iZ$e%ed�o�e%ej d��rej j&e$ej'<e%ed��r0e%ej d��r0ej j(e$ej)<ye$j*ej+ej j,i�Wne-k
�r^YnXej.ej j/ej0ej j1ej2ej j1ej j3iZ4e5dd�e4j6�D��Z7dZ8ejZ9ej:j;Z<ej=e>�Z?dd�Z@dd�ZAdd�ZBdd�ZCdd�ZDGd d!�d!eE�ZFe�rd*d#d$�ZGneZGeGeF_GGd%d&�d&eE�ZHd'd(�ZIdS)+ab
SSL with SNI_-support for Python 2. Follow these instructions if you would
like to verify SSL certificates in Python 2. Note, the default libraries do
*not* do certificate checking; you need to do additional work to validate
certificates yourself.

This needs the following packages installed:

* pyOpenSSL (tested with 16.0.0)
* cryptography (minimum 1.3.4, from pyopenssl)
* idna (minimum 2.0, from cryptography)

However, pyopenssl depends on cryptography, which depends on idna, so while we
use all three directly here we end up having relatively few packages required.

You can install them with the following command:

    pip install pyopenssl cryptography idna

To activate certificate checking, call
:func:`~urllib3.contrib.pyopenssl.inject_into_urllib3` from your Python code
before you begin making HTTP requests. This can be done in a ``sitecustomize``
module, or at any other time before your application begins using ``urllib3``,
like this::

    try:
        import urllib3.contrib.pyopenssl
        urllib3.contrib.pyopenssl.inject_into_urllib3()
    except ImportError:
        pass

Now you can use :mod:`urllib3` as you normally would, and it will support SNI
when the required modules are installed.

Activating this module also has the positive side effect of disabling SSL/TLS
compression in Python 2 (see `CRIME attack`_).

If you want to configure the default list of supported cipher suites, you can
set the ``urllib3.contrib.pyopenssl.DEFAULT_SSL_CIPHER_LIST`` variable.

.. _sni: https://en.wikipedia.org/wiki/Server_Name_Indication
.. _crime attack: https://en.wikipedia.org/wiki/CRIME_(security_exploit)
�)�absolute_importN)�x509)�backend)�_Certificate)�timeout�error)�BytesIO)�_fileobject�)�backport_makefile)�six)�util�inject_into_urllib3�extract_from_urllib3T�PROTOCOL_TLSv1_1�TLSv1_1_METHOD�PROTOCOL_TLSv1_2�TLSv1_2_METHODccs|]\}}||fVqdS)N�)�.0�k�vrr�/usr/lib/python3.6/pyopenssl.py�	<genexpr>`sri@cCs.t�ttj_tt_ttj_dt_dtj_dS)z7Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.TN)�_validate_dependencies_met�PyOpenSSLContextr
�ssl_�
SSLContext�HAS_SNI�IS_PYOPENSSLrrrrrmscCs(ttj_tt_ttj_dt_dtj_dS)z4Undo monkey-patching by :func:`inject_into_urllib3`.FN)�orig_util_SSLContextr
rr�orig_util_HAS_SNIrrrrrrrys
cCsRddlm}t|dd�dkr$td��ddlm}|�}t|dd�dkrNtd��dS)	z{
    Verifies that PyOpenSSL's package-level dependencies have been met.
    Throws `ImportError` if they are not met.
    r)�
Extensions�get_extension_for_classNzX'cryptography' module missing required functionality.  Try upgrading to v1.3.4 or newer.)�X509�_x509zS'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.)Zcryptography.x509.extensionsr"�getattr�ImportErrorZOpenSSL.cryptor$)r"r$rrrrr�srcCs(dd�}||�}tjdkr$|jd�}|S)a�
    Converts a dNSName SubjectAlternativeName field to the form used by the
    standard library on the given Python version.

    Cryptography produces a dNSName as a unicode string that was idna-decoded
    from ASCII bytes. We need to idna-encode that string to get it back, and
    then on Python 3 we also need to convert to unicode via UTF-8 (the stdlib
    uses PyUnicode_FromStringAndSize on it, which decodes via UTF-8).
    cSsNddl}x:dD]2}|j|�r|t|�d�}|jd�|j|�SqW|j|�S)z�
        Borrowed wholesale from the Python Cryptography Project. It turns out
        that we can't just safely call `idna.encode`: it can explode for
        wildcard names. This avoids that problem.
        rN�*.�.�ascii)r(r))�idna�
startswith�len�encode)�namer+�prefixrrr�idna_encode�s

z'_dnsname_to_stdlib.<locals>.idna_encode�rzutf-8)r2r)�sys�version_info�decode)r/r1rrr�_dnsname_to_stdlib�s



r6cCs�t|d�r|j�}ntt|j�}y|jjtj�j	}WnNtj
k
rJgStjtjtj
tfk
r�}ztjd|�gSd}~XnXdd�|jtj�D�}|jdd�|jtj�D��|S)zU
    Given an PyOpenSSL certificate, provides all the subject alternative names.
    �to_cryptographyz�A problem was encountered with the certificate that prevented urllib3 from finding the SubjectAlternativeName field. This can affect certificate validation. The error was %sNcSsg|]}dt|�f�qS)ZDNS)r6)rr/rrr�
<listcomp>�sz%get_subj_alt_name.<locals>.<listcomp>css|]}dt|�fVqdS)z
IP AddressN)�str)rr/rrrr�sz$get_subj_alt_name.<locals>.<genexpr>)�hasattrr7r�openssl_backendr%�
extensionsr#rZSubjectAlternativeName�valueZExtensionNotFoundZDuplicateExtensionZUnsupportedExtensionZUnsupportedGeneralNameType�UnicodeError�logZwarningZget_values_for_typeZDNSName�extendZ	IPAddress)Z	peer_certZcertZext�e�namesrrr�get_subj_alt_name�s(


	rCc@s|eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
d dd�Zdd�Zdd�ZdS)!�
WrappedSocketz�API-compatibility wrapper for Python OpenSSL's Connection-class.

    Note: _makefile_refs, _drop() and _reuse() are needed for the garbage
    collector of pypy.
    TcCs"||_||_||_d|_d|_dS)NrF)�
connection�socket�suppress_ragged_eofs�_makefile_refs�_closed)�selfrErFrGrrr�__init__�s
zWrappedSocket.__init__cCs
|jj�S)N)rF�fileno)rJrrrrL�szWrappedSocket.filenocCs*|jdkr|jd8_|jr&|j�dS)Nr�)rHrI�close)rJrrr�_decref_socketios�s
zWrappedSocket._decref_socketioscOs�y|jj||�}Wn�tjjk
rX}z&|jr<|jdkr<dStt|���WYdd}~Xn�tjj	k
r�}z|jj
�tjjkr�dS�WYdd}~XnJtjjk
r�t
j|j|jj��}|s�td��n|j||�SYnX|SdS)NrM�Unexpected EOF�zThe read operation timed out���)rRrP)rE�recv�OpenSSL�SSL�SysCallErrorrG�args�SocketErrorr9�ZeroReturnError�get_shutdown�RECEIVED_SHUTDOWN�
WantReadErrorr
�
wait_for_readrF�
gettimeoutr)rJrW�kwargs�datarA�rdrrrrSs 
zWrappedSocket.recvcOs�y|jj||�Stjjk
rT}z&|jr8|jdkr8dStt|���WYdd}~Xn�tjj	k
r�}z|jj
�tjjkr~dS�WYdd}~XnFtjjk
r�t
j|j|jj��}|s�td��n|j||�SYnXdS)NrM�Unexpected EOFrzThe read operation timed outrR)rRrb)rE�	recv_intorTrUrVrGrWrXr9rYrZr[r\r
r]rFr^r)rJrWr_rArarrrrcs
zWrappedSocket.recv_intocCs|jj|�S)N)rF�
settimeout)rJrrrrrd*szWrappedSocket.settimeoutcCs�xzy|jj|�Stjjk
rFtj|j|jj��}|s@t	��wYqtjj
k
rv}ztt|���WYdd}~XqXqWdS)N)
rE�sendrTrUZWantWriteErrorr
Zwait_for_writerFr^rrVrXr9)rJr`�wrrArrr�_send_until_done-szWrappedSocket._send_until_donecCs8d}x.|t|�kr2|j|||t��}||7}qWdS)Nr)r-rg�SSL_WRITE_BLOCKSIZE)rJr`Z
total_sentZsentrrr�sendall9szWrappedSocket.sendallcCs|jj�dS)N)rE�shutdown)rJrrrrj?szWrappedSocket.shutdowncCsH|jdkr6yd|_|jj�Stjjk
r2dSXn|jd8_dS)NrMT)rHrIrErNrTrU�Error)rJrrrrNCs

zWrappedSocket.closeFcCsD|jj�}|s|S|r(tjjtjj|�Sd|j�jffft|�d�S)NZ
commonName)ZsubjectZsubjectAltName)	rEZget_peer_certificaterTZcryptoZdump_certificateZ
FILETYPE_ASN1Zget_subjectZCNrC)rJZbinary_formrrrr�getpeercertMs
zWrappedSocket.getpeercertcCs|jd7_dS)NrM)rH)rJrrr�_reuse_szWrappedSocket._reusecCs&|jdkr|j�n|jd8_dS)NrM)rHrN)rJrrr�_dropbs

zWrappedSocket._dropN)T)F)�__name__�
__module__�__qualname__�__doc__rKrLrOrSrcrdrgrirjrNrlrmrnrrrrrD�s


rDrMcCs|jd7_t|||dd�S)NrMT)rN)rHr	)rJ�mode�bufsizerrr�makefilejsruc@szeZdZdZdd�Zedd��Zejdd��Zedd��Zejd	d��Zd
d�Z	dd
�Z
ddd�Zddd�Zddd�Z
dS)rz�
    I am a wrapper class for the PyOpenSSL ``Context`` object. I am responsible
    for translating the interface of the standard library ``SSLContext`` object
    to calls into PyOpenSSL.
    cCs*t||_tjj|j�|_d|_d|_dS)NrF)�_openssl_versions�protocolrTrUZContext�_ctx�_optionsZcheck_hostname)rJrwrrrrKys
zPyOpenSSLContext.__init__cCs|jS)N)ry)rJrrr�optionsszPyOpenSSLContext.optionscCs||_|jj|�dS)N)ryrxZset_options)rJr=rrrrz�scCst|jj�S)N)�_openssl_to_stdlib_verifyrxZget_verify_mode)rJrrr�verify_mode�szPyOpenSSLContext.verify_modecCs|jjt|t�dS)N)rxZ
set_verify�_stdlib_to_openssl_verify�_verify_callback)rJr=rrrr|�scCs|jj�dS)N)rx�set_default_verify_paths)rJrrrr�sz)PyOpenSSLContext.set_default_verify_pathscCs&t|tj�r|jd�}|jj|�dS)Nzutf-8)�
isinstancer�	text_typer.rxZset_cipher_list)rJZciphersrrr�set_ciphers�s
zPyOpenSSLContext.set_ciphersNcCsN|dk	r|jd�}|dk	r$|jd�}|jj||�|dk	rJ|jjt|��dS)Nzutf-8)r.rx�load_verify_locationsr)rJZcafileZcapathZcadatarrrr��s

z&PyOpenSSLContext.load_verify_locationscs<|jj|��dk	r(|jj�fdd��|jj|p4|�dS)Ncs�S)Nr)Z
max_lengthZprompt_twiceZuserdata)�passwordrr�<lambda>�sz2PyOpenSSLContext.load_cert_chain.<locals>.<lambda>)rxZuse_certificate_fileZ
set_passwd_cbZuse_privatekey_file)rJZcertfileZkeyfiler�r)r�r�load_cert_chain�sz PyOpenSSLContext.load_cert_chainFTc	Cs�tjj|j|�}t|tj�r&|jd�}|dk	r8|j|�|j	�x|y|j
�Wnhtjjk
r�tj
||j��}|s~td��wBYn4tjjk
r�}ztjd|��WYdd}~XnXPqBWt||�S)Nzutf-8zselect timed outzbad handshake: %r)rTrUZ
Connectionrxr�rr�r.Zset_tlsext_host_nameZset_connect_stateZdo_handshaker\r
r]r^rrk�sslZSSLErrorrD)	rJZsockZserver_sideZdo_handshake_on_connectrGZserver_hostname�cnxrarArrr�wrap_socket�s$

 zPyOpenSSLContext.wrap_socket)NNN)NN)FTTN)rorprqrrrK�propertyrz�setterr|rr�r�r�r�rrrrrss
	
rcCs|dkS)Nrr)r�rZerr_noZ	err_depthZreturn_coderrrr~�sr~rR)rR)JrrZ
__future__rZOpenSSL.SSLrTZcryptographyrZ$cryptography.hazmat.backends.opensslrr;Z)cryptography.hazmat.backends.openssl.x509rrFrrrX�iorr	r'Zpackages.backports.makefilerZloggingr�Zpackagesrr3�r
�__all__rZPROTOCOL_SSLv23rUZ
SSLv23_METHODZPROTOCOL_TLSv1ZTLSv1_METHODrvr:rrrr�updateZPROTOCOL_SSLv3ZSSLv3_METHOD�AttributeErrorZ	CERT_NONEZVERIFY_NONEZ
CERT_OPTIONALZVERIFY_PEERZ
CERT_REQUIREDZVERIFY_FAIL_IF_NO_PEER_CERTr}�dict�itemsr{rhr!rrr Z	getLoggerror?rrrr6rC�objectrDrurr~rrrr�<module>+sh




3S

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists