AlkantarClanX12

Your IP : 3.145.62.7


Current Path : /opt/alt/python38/lib/python3.8/site-packages/urllib3/contrib/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib/python3.8/site-packages/urllib3/contrib/__pycache__/pyopenssl.cpython-38.pyc

U

��`�A�@sxdZddlmZddlZddlmZddlmZ	ddl
mZzddlm
Z
Wn$ek
rpGdd	�d	e�Z
YnXdd
lmZddlmZddlmZzdd
lmZWn$ek
r�dZddlmZYnXddlZddlZddlZddlmZddlmZddl m!Z!ddgZ"dZ#ej$ej%j&e!ej%j&ej'ej%j(iZ)e*ed��r\e*ej%d��r\ej%j+e)ej,<e*ed��r�e*ej%d��r�ej%j-e)ej.<e*ed��r�e*ej%d��r�ej%j/e)ej0<ej1ej%j2ej3ej%j4ej5ej%j4ej%j6iZ7e8dd�e7�9�D��Z:dZ;ej#Z<ej=j>Z?e�@eA�ZBdd�ZCd d�ZDd!d"�ZEd#d$�ZFd%d&�ZGGd'd(�d(eH�ZIe�rRd0d*d+�ZJneZJeJeI_JGd,d-�d-eH�ZKd.d/�ZLdS)1a�
TLS with SNI_-support for Python 2. Follow these instructions if you would
like to verify TLS 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:

.. code-block:: bash

    $ python -m 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:

.. code-block:: python

    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`_).

.. _sni: https://en.wikipedia.org/wiki/Server_Name_Indication
.. _crime attack: https://en.wikipedia.org/wiki/CRIME_(security_exploit)
.. _pyopenssl: https://www.pyopenssl.org
.. _cryptography: https://cryptography.io
.. _idna: https://github.com/kjd/idna
�)�absolute_importN)�x509)�backend)�_Certificate)�UnsupportedExtensionc@seZdZdS)rN)�__name__�
__module__�__qualname__�r
r
�J/opt/alt/python38/lib/python3.8/site-packages/urllib3/contrib/pyopenssl.pyr;sr)�BytesIO)�error)�timeout)�_fileobject�)�backport_makefile)�util)�six)�PROTOCOL_TLS_CLIENT�inject_into_urllib3�extract_from_urllib3T�PROTOCOL_SSLv3�SSLv3_METHOD�PROTOCOL_TLSv1_1�TLSv1_1_METHOD�PROTOCOL_TLSv1_2�TLSv1_2_METHODccs|]\}}||fVqdS�Nr
)�.0�k�vr
r
r�	<genexpr>msr!i@cCs4t�tt_ttj_tt_ttj_dt_dtj_dS)z7Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.TN)�_validate_dependencies_met�PyOpenSSLContextr�
SSLContext�ssl_�HAS_SNI�IS_PYOPENSSLr
r
r
rryscCs.tt_ttj_tt_ttj_dt_dtj_dS)z4Undo monkey-patching by :func:`inject_into_urllib3`.FN)�orig_util_SSLContextrr$r%�orig_util_HAS_SNIr&r'r
r
r
rr�s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,rr
r
rr"�s��r"cCs@dd�}d|kr|S||�}|dkr(dStjdkr<|�d�}|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).

    If the name cannot be idna-encoded then we return None signalling that
    the name given should be skipped.
    cSsrddl}zJdD]8}|�|�r|t|�d�}|�d�|�|�WSq|�|�WS|jjk
rlYdSXdS)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)z*.�.�ascii)�idna�
startswith�len�encode�coreZ	IDNAError)�namer2�prefixr
r
r�idna_encode�s
z'_dnsname_to_stdlib.<locals>.idna_encode�:N)�r�utf-8)�sys�version_info�decode)r7r9r
r
r�_dnsname_to_stdlib�s

r@cCs�t|d�r|��}ntt|j�}z|j�tj�j	}WnZtj
k
rNgYStjttj
tfk
r�}zt�d|�gWY�Sd}~XYnXdd�tt|�tj��D�}|�dd�|�tj�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|]}|dk	rd|f�qS)NZDNSr
�rr7r
r
r�
<listcomp>s�z%get_subj_alt_name.<locals>.<listcomp>css|]}dt|�fVqdS)z
IP AddressN)�strrBr
r
rr!sz$get_subj_alt_name.<locals>.<genexpr>)�hasattrrAr�openssl_backendr-�
extensionsr+rZSubjectAlternativeName�valueZExtensionNotFoundZDuplicateExtensionrZUnsupportedGeneralNameType�UnicodeError�log�warning�mapr@Zget_values_for_typeZDNSName�extendZ	IPAddress)Z	peer_certZcert�ext�e�namesr
r
r�get_subj_alt_name�s2

��	�

�rQc@s�eZdZdZd!dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
d"dd�Zdd�Zdd�Zdd�Zd S)#�
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)�selfrTrUrVr
r
r�__init__s
zWrappedSocket.__init__cCs
|j��Sr)rU�fileno�rYr
r
rr[szWrappedSocket.filenocCs*|jdkr|jd8_|jr&|��dS)Nr�)rWrX�closer\r
r
r�_decref_socketioss
zWrappedSocket._decref_socketiosc
Osz|jj||�}Wn�tjjk
r^}z*|jrB|jdkrBWY�dStt|���W5d}~XYn�tjj	k
r�|j�
�tjjkr�YdS�Yn~tjjk
r�t
�|j|j���s�td��n|j||�YSYn:tjjk
�r}zt�d|��W5d}~XYnX|SdS)N����zUnexpected EOF��The read operation timed out�read error: %r)rT�recv�OpenSSL�SSL�SysCallErrorrV�args�SocketErrorrD�ZeroReturnError�get_shutdown�RECEIVED_SHUTDOWN�
WantReadErrorr�
wait_for_readrU�
gettimeoutr�Error�ssl�SSLError)rYri�kwargs�datarOr
r
rre$s"

 zWrappedSocket.recvc
Os
z|jj||�WStjjk
r\}z*|jr@|jdkr@WY�dStt|���W5d}~XYn�tjj	k
r�|j�
�tjjkr�YdS�Ynztjjk
r�t
�|j|j���s�td��n|j||�YSYn6tjjk
�r}zt�d|��W5d}~XYnXdS)Nr`rrcrd)rT�	recv_intorfrgrhrVrirjrDrkrlrmrnrrorUrprrqrrrs)rYrirtrOr
r
rrv=s 

zWrappedSocket.recv_intocCs|j�|�Sr)rU�
settimeout)rYrr
r
rrwTszWrappedSocket.settimeoutc
Cs|z|j�|�WStjjk
rDt�|j|j���s<t	��YqYqtjj
k
rt}ztt|���W5d}~XYqXqdSr)
rT�sendrfrgZWantWriteErrorrZwait_for_writerUrprrhrjrD)rYrurOr
r
r�_send_until_doneWszWrappedSocket._send_until_donecCs4d}|t|�kr0|�|||t��}||7}qdS�Nr)r4ry�SSL_WRITE_BLOCKSIZE)rYru�
total_sent�sentr
r
r�sendallbs�zWrappedSocket.sendallcCs|j��dSr)rT�shutdownr\r
r
rrjszWrappedSocket.shutdowncCsL|jdkr:zd|_|j��WStjjk
r6YdSXn|jd8_dS)Nr]T)rWrXrTr^rfrgrqr\r
r
rr^ns

zWrappedSocket.closeFcCsD|j��}|s|S|r(tj�tjj|�Sd|��jffft|�d�S)NZ
commonName)ZsubjectZsubjectAltName)	rTZget_peer_certificaterfZcryptoZdump_certificateZ
FILETYPE_ASN1Zget_subjectZCNrQ)rYZbinary_formrr
r
r�getpeercertxs
�zWrappedSocket.getpeercertcCs
|j��Sr)rTZget_protocol_version_namer\r
r
r�version�szWrappedSocket.versioncCs|jd7_dS�Nr])rWr\r
r
r�_reuse�szWrappedSocket._reusecCs&|jdkr|��n|jd8_dSr�)rWr^r\r
r
r�_drop�s

zWrappedSocket._dropN)T)F)rrr	�__doc__rZr[r_rervrwryr~rr^r�r�r�r�r
r
r
rrRs


rRracCs|jd7_t|||dd�S)Nr]T)r^)rWr)rY�mode�bufsizer
r
r�makefile�sr�c@s�eZdZdZdd�Zedd��Zejdd��Zedd��Zejd	d��Zd
d�Z	dd
�Z
ddd�Zddd�Zdd�Z
ddd�ZdS)r#z�
    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||_tj�|j�|_d|_d|_dSrS)�_openssl_versions�protocolrfrgZContext�_ctx�_optionsZcheck_hostname)rYr�r
r
rrZ�s
zPyOpenSSLContext.__init__cCs|jSr)r�r\r
r
r�options�szPyOpenSSLContext.optionscCs||_|j�|�dSr)r�r��set_options�rYrHr
r
rr��scCst|j��Sr)�_openssl_to_stdlib_verifyr�Zget_verify_moder\r
r
r�verify_mode�szPyOpenSSLContext.verify_modecCs|j�t|t�dSr)r�Z
set_verify�_stdlib_to_openssl_verify�_verify_callbackr�r
r
rr��scCs|j��dSr)r��set_default_verify_pathsr\r
r
rr��sz)PyOpenSSLContext.set_default_verify_pathscCs&t|tj�r|�d�}|j�|�dS)Nr<)�
isinstancer�	text_typer5r�Zset_cipher_list)rYZciphersr
r
r�set_ciphers�s
zPyOpenSSLContext.set_ciphersNc
Cs�|dk	r|�d�}|dk	r$|�d�}z*|j�||�|dk	rL|j�t|��Wn4tjjk
r�}zt�d|��W5d}~XYnXdS)Nr<z'unable to load trusted certificates: %r)	r5r��load_verify_locationsrrfrgrqrrrs)rYZcafileZcapathZcadatarOr
r
rr��s

z&PyOpenSSLContext.load_verify_locationscsR|j�|��dk	r>t�tj�s*��d��|j��fdd��|j�|pJ|�dS)Nr<cs�Srr
)�_��passwordr
r�<lambda>�rbz2PyOpenSSLContext.load_cert_chain.<locals>.<lambda>)r�Zuse_certificate_chain_filer�rZbinary_typer5Z
set_passwd_cbZuse_privatekey_file)rYZcertfileZkeyfiler�r
r�r�load_cert_chain�s
z PyOpenSSLContext.load_cert_chaincCsdd�|D�}|j�|�S)NcSsg|]}t�|��qSr
)rZ
ensure_binary)r�pr
r
rrC�sz7PyOpenSSLContext.set_alpn_protocols.<locals>.<listcomp>)r�Zset_alpn_protos)rYZ	protocolsr
r
r�set_alpn_protocols�sz#PyOpenSSLContext.set_alpn_protocolsFTc
Cs�tj�|j|�}t|tj�r&|�d�}|dk	r8|�|�|�	�z|�
�Wq�tjjk
r�t�
||���sxtd��Yq@Yq�tjjk
r�}zt�d|��W5d}~XYq�Xq�q@t||�S)Nr<zselect timed outzbad handshake: %r)rfrgZ
Connectionr�r�rr�r5Zset_tlsext_host_nameZset_connect_stateZdo_handshakernrrorprrqrrrsrR)rY�sockZserver_sideZdo_handshake_on_connectrVZserver_hostname�cnxrOr
r
r�wrap_socket�s 

 zPyOpenSSLContext.wrap_socket)NNN)NN)FTTN)rrr	r�rZ�propertyr��setterr�r�r�r�r�r�r�r
r
r
rr#�s(





�r#cCs|dkSrzr
)r�rZerr_noZ	err_depthZreturn_coder
r
rr��sr�)ra)Mr��
__future__rZOpenSSL.SSLrfZcryptographyrZ$cryptography.hazmat.backends.opensslrrFZ)cryptography.hazmat.backends.openssl.x509rZcryptography.x509rr/�	Exception�iorrUr
rjrrZpackages.backports.makefiler�loggingrrr=�r�packagesrZ	util.ssl_r�__all__r&ZPROTOCOL_TLSrgZ
SSLv23_METHODZPROTOCOL_TLSv1ZTLSv1_METHODr�rErrrrrrZ	CERT_NONEZVERIFY_NONEZ
CERT_OPTIONALZVERIFY_PEERZ
CERT_REQUIREDZVERIFY_FAIL_IF_NO_PEER_CERTr��dict�itemsr�r{r)r%r$r(�	getLoggerrrJrrr"r@rQ�objectrRr�r#r�r
r
r
r�<module>s�/���

+6^