Prv8 Shell
Server : Apache
System : Linux server.mata-lashes.com 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64
User : matalashes ( 1004)
PHP Version : 8.1.29
Disable Function : NONE
Directory :  /usr/local/lib/python3.6/site-packages/urllib3/contrib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/local/lib/python3.6/site-packages/urllib3/contrib/__pycache__/securetransport.cpython-36.pyc
3

G�Kdp��&@s�dZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlmZmZmZdd	lmZmZmZmZmZmZydd
l	mZWn$ek
r�dZddl m!Z!YnXdd
gZ"dZ#ej#Z$ej%j&Z'e
j(�Z)ej*�Z+dZ,ej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDejEejFejGejHejIejJgZKejLejMejNfeejMejNfiZOePe
d��r�ejQejQfeOe
jR<ePe
d��r�ejSejSfeOe
jT<ePe
d��rejMejMfeOe
jU<ePe
d��r*ejVejVfeOe
jW<ePe
d��rHejNejNfeOe
jX<dd�ZYdd
�ZZdd�Z[dd�Z\ej]e[�Z^ej_e\�Z`Gdd�dea�Zbe�r�d$dd�Zcn
d%d d�Zceceb_cGd!d"�d"ea�ZddS)&a�	
SecureTranport support for urllib3 via ctypes.

This makes platform-native TLS available to urllib3 users on macOS without the
use of a compiler. This is an important feature because the Python Package
Index is moving to become a TLSv1.2-or-higher server, and the default OpenSSL
that ships with macOS is not capable of doing TLSv1.2. The only way to resolve
this is to give macOS users an alternative solution to the problem, and that
solution is to use SecureTransport.

We use ctypes here because this solution must not require a compiler. That's
because pip is not allowed to require a compiler either.

This is not intended to be a seriously long-term solution to this problem.
The hope is that PEP 543 will eventually solve this issue for us, at which
point we can retire this contrib module. But in the short term, we need to
solve the impending tire fire that is Python on Mac without this kind of
contrib module. So...here we are.

To use this module, simply import and inject it::

    import urllib3.contrib.securetransport
    urllib3.contrib.securetransport.inject_into_urllib3()

Happy TLSing!

This code is a bastardised version of the code found in Will Bond's oscrypto
library. An enormous debt is owed to him for blazing this trail for us. For
that reason, this code should be considered to be covered both by urllib3's
license and by oscrypto's:

.. code-block::

    Copyright (c) 2015-2016 Will Bond <will@wbond.net>

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
�)�absolute_importN�)�util)�PROTOCOL_TLS_CLIENT�)�CoreFoundation�Security�
SecurityConst)�_assert_no_error�_build_tls_unknown_ca_alert�_cert_array_from_pem�_create_cfstring_array�_load_client_cert_chain�_temporary_keychain)�_fileobject)�backport_makefile�inject_into_urllib3�extract_from_urllib3Ti@�PROTOCOL_SSLv2�PROTOCOL_SSLv3�PROTOCOL_TLSv1�PROTOCOL_TLSv1_1�PROTOCOL_TLSv1_2cCs.tt_ttj_tt_ttj_dt_dtj_dS)zG
    Monkey-patch urllib3 with SecureTransport-backed SSL-support.
    TN)�SecureTransportContextr�
SSLContext�ssl_�HAS_SNI�IS_SECURETRANSPORT�rr�B/tmp/pip-build-8nxjc3nm/urllib3/urllib3/contrib/securetransport.pyr�scCs.tt_ttj_tt_ttj_dt_dtj_dS)z>
    Undo monkey-patching by :func:`inject_into_urllib3`.
    FN)�orig_util_SSLContextrrr�orig_util_HAS_SNIrrrrrrr�sc
Csxd}�y8tj|�}|dkr tjS|j}|d}|j�}d}d}y|xv||kr�|dksZ|dkrttj||�sttjt	j
d��||}	tj|	j
||�}
|j|
|	�}||7}|sB|s�tjSPqBWWnhtjk
�r"}zH|j	}|dk	o�|t	j
k�r||d<|t	jk�s
|t	jk�rtjS�WYdd}~XnX||d<||k�r<tjSdStk
�rr}z|dk	�rb||_tjSd}~XnXdS)zs
    SecureTransport read callback. This is called by ST to request that data
    be returned from the socket.
    Nrz	timed out)�_connection_refs�getr	�errSSLInternal�socket�
gettimeoutr�
wait_for_read�error�errno�EAGAIN�ctypes�c_char�from_address�	recv_into�errSSLClosedGraceful�
ECONNRESET�EPIPE�errSSLClosedAbort�errSSLWouldBlock�	Exception�
_exception)
�
connection_id�data_buffer�data_length_pointer�wrapped_socket�base_socketZrequested_length�timeoutr(Z
read_count�	remaining�buffer�
chunk_size�errr�_read_callback�sN






r@cCs\d}�ytj|�}|dkr tjS|j}|d}tj||�}|j�}d}d}	yZxT|	|kr�|dksf|dkr�tj	||�s�tj
tjd��|j
|�}
|	|
7}	||
d�}qNWWnbtj
k
�r}zB|j}|dk	r�|tjkr�|	|d<|tjks�|tjkr�tjS�WYdd}~XnX|	|d<|	|k�r tjSdStk
�rV}z|dk	�rF||_tjSd}~XnXdS)zx
    SecureTransport write callback. This is called by ST to request that data
    actually be sent on the network.
    Nrz	timed out)r"r#r	r$r%r+�	string_atr&r�wait_for_writer(r)r*�sendr0r1r2r3r4r5)r6r7r8r9r:Zbytes_to_write�datar;r(�sentZ
chunk_sentr?rrr�_write_callbacksD




rFc@s�eZdZdZdd�Zejdd��Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zd.dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd/d&d'�Zd(d)�Zd*d+�Zd,d-�ZdS)0�
WrappedSocketz�
    API-compatibility wrapper for Python's OpenSSL wrapped socket object.

    Note: _makefile_refs, _drop(), and _reuse() are needed for the garbage
    collector of PyPy.
    cCsL||_d|_d|_d|_d|_d|_d|_d|_|jj�|_	|jj
d�dS)NrF)r%�context�_makefile_refs�_closedr5�	_keychain�
_keychain_dir�_client_cert_chainr&�_timeout�
settimeout)�selfr%rrr�__init__NszWrappedSocket.__init__ccs4d|_dV|jdk	r0|jd}|_|j�|�dS)a]
        A context manager that can be used to wrap calls that do I/O from
        SecureTransport. If any of the I/O callbacks hit an exception, this
        context manager will correctly propagate the exception after the fact.
        This avoids silently swallowing those exceptions.

        It also correctly forces the socket closed.
        N)r5�close)rP�	exceptionrrr�_raise_on_error`s

zWrappedSocket._raise_on_errorcCs2tjtt�t�}tj|j|tt��}t|�dS)a4
        Sets up the allowed ciphers. By default this matches the set in
        util.ssl_.DEFAULT_CIPHERS, at least as supported by macOS. This is done
        custom and doesn't allow changing at this time, mostly because parsing
        OpenSSL cipher strings is going to be a freaking nightmare.
        N)rZSSLCipherSuite�len�
CIPHER_SUITESZSSLSetEnabledCiphersrHr
)rP�ciphers�resultrrr�_set_ciphersuszWrappedSocket._set_cipherscCs<|sdSt|�}ztj|j|�}t|�Wdtj|�XdS)z<
        Sets up the ALPN protocols on the context.
        N)r
r�SSLSetALPNProtocolsrHr
r�	CFRelease)rP�	protocolsZ
protocols_arrrXrrr�_set_alpn_protocols�sz!WrappedSocket._set_alpn_protocolsc	Cs�|sdStjtjf}y$|j|�}||kr,dSd|f}Wn,tk
rd}zd|f}WYdd}~XnXt|j��}|jj|�t	j
ddd�}|jjtjtj
|�|j�tjd|��dS)z�
        Called when we have set custom validation. We do this in two cases:
        first, when cert validation is entirely disabled; and second, when
        using a custom trust DB.
        Raises an SSLError if the connection is not trusted.
        Nzerror code: %dz
exception: %r�iirrzcertificate verify failed, %s)r	ZkSecTrustResultUnspecifiedZkSecTrustResultProceed�_evaluate_trustr4r�versionr%�sendall�struct�pack�
setsockopt�
SOL_SOCKET�	SO_LINGERrR�ssl�SSLError)	rP�verify�trust_bundleZ	successes�trust_result�reasonr?Zrec�optsrrr�_custom_validate�s"
zWrappedSocket._custom_validatecCs�tjj|�r*t|d��}|j�}WdQRXd}tj�}z�t|�}tj|j	t
j|��}t|�|sjt
jd��tj||�}t|�tj|d�}t|�tj�}tj|t
j|��}t|�Wd|r�tj|�|dk	r�tj|�X|jS)N�rbzFailed to copy trust referenceT)�os�path�isfile�open�readr�SecTrustRefr�SSLCopyPeerTrustrHr+�byrefr
rgrhZSecTrustSetAnchorCertificatesZ!SecTrustSetAnchorCertificatesOnlyZSecTrustResultTypeZSecTrustEvaluaterr[�value)rPrj�fZ
cert_array�trustrXrkrrrr_�s.

zWrappedSocket._evaluate_trustc
Cs�tjdtjtj�|_tj|jtt�}
t	|
�t
�4t|�d}x|tkrV|dd}q@W|t|<WdQRXtj
|j|�}
t	|
�|r�t|t�s�|jd�}tj|j|t|��}
t	|
�|j�|j|	�tj|j|�}
t	|
�tj|j|�}
t	|
�|�s|dk	�rtj|jtjd�}
t	|
�|�rZt�\|_|_t|j||�|_tj|j|j�}
t	|
�xf|j��Rtj |j�}
|
tj!k�r�t"j#d��n(|
tj$k�r�|j%||��w\n
t	|
�PWdQRX�q\WdS)z�
        Actually performs the TLS handshake. This is run automatically by
        wrapped socket, and shouldn't be needed in user code.
        Ni���rzutf-8Tzhandshake timed out)&rZSSLCreateContextr	ZkSSLClientSideZkSSLStreamTyperHZ
SSLSetIOFuncs�_read_callback_pointer�_write_callback_pointerr
�_connection_ref_lock�idr"ZSSLSetConnection�
isinstance�bytes�encodeZSSLSetPeerDomainNamerUrYr]ZSSLSetProtocolVersionMinZSSLSetProtocolVersionMaxZSSLSetSessionOptionZ"kSSLSessionOptionBreakOnServerAuthrrKrLrrMZSSLSetCertificaterTZSSLHandshaker3r%r;ZerrSSLServerAuthCompletedrn)rP�server_hostnamerirj�min_versionZmax_version�client_certZ
client_keyZclient_key_passphrase�alpn_protocolsrX�handlerrr�	handshake�sX




zWrappedSocket.handshakecCs
|jj�S)N)r%�fileno)rPrrrr�7szWrappedSocket.filenocCs*|jdkr|jd8_|jr&|j�dS)Nrr)rIrJrR)rPrrr�_decref_socketios;s
zWrappedSocket._decref_socketioscCs&tj|�}|j||�}|d|�}|S)N)r+�create_string_bufferr.)rPZbufsizr=�
bytes_readrDrrr�recvAs
zWrappedSocket.recvNc
Cs�|jr
dS|dkrt|�}tj|j|�}tjd�}|j��tj|j	||tj
|��}WdQRX|tjkr�|j
dkr�tjd��n"|tjtjfkr�|j�nt|�|j
S)Nrzrecv timed out)rJrUr+r,�from_buffer�c_size_trTrZSSLReadrHrwr	r3rxr%r;r/ZerrSSLClosedNoNotifyrRr
)rPr=�nbytes�processed_bytesrXrrrr.Gs$





zWrappedSocket.recv_intocCs
||_dS)N)rN)rPr;rrrrOrszWrappedSocket.settimeoutcCs|jS)N)rN)rPrrrr&uszWrappedSocket.gettimeoutc
Cshtjd�}|j��"tj|j|t|�tj|��}WdQRX|tj	krZ|j
dkrZtjd��nt
|�|j
S)Nrzsend timed out)r+r�rTrZSSLWriterHrUrwr	r3rxr%r;r
)rPrDr�rXrrrrCxs

"zWrappedSocket.sendcCs8d}x.|t|�kr2|j|||t��}||7}qWdS)Nr)rUrC�SSL_WRITE_BLOCKSIZE)rPrD�
total_sentrErrrra�szWrappedSocket.sendallc	Cs$|j��tj|j�WdQRXdS)N)rTrZSSLCloserH)rPrrr�shutdown�s
zWrappedSocket.shutdowncCs�|jdkr�d|_|jr(tj|j�d|_|jr@tj|j�d|_|jrvtj|j�tj|j�t	j
|j�d|_|_|jj
�S|jd8_dS)NrT)rIrJrHrr[rMrKrZSecKeychainDelete�shutil�rmtreerLr%rR)rPrrrrR�s

zWrappedSocket.closeFc
Cs�|std��tj�}d}d}z�tj|jtj|��}t|�|sBdStj|�}|sTdStj	|d�}|sht
�tj|�}|szt
�tj
|�}tj|�}	tj|	|�}Wd|r�tj|�|r�tj|�X|S)Nz2SecureTransport only supports dumping binary certsr)�
ValueErrorrrurvrHr+rwr
ZSecTrustGetCertificateCountZSecTrustGetCertificateAtIndex�AssertionErrorZSecCertificateCopyDatarZCFDataGetLengthZCFDataGetBytePtrrAr[)
rP�binary_formrzZcertdataZ	der_bytesrXZ
cert_countZleafZdata_lengthr7rrr�getpeercert�s2




zWrappedSocket.getpeercertcCs�tj�}tj|jtj|��}t|�|jtj	kr<t
jd��n^|jtjkrLdS|jtj
kr\dS|jtjkrldS|jtjkr|dS|jtjkr�dSt
jd|��dS)Nz(SecureTransport does not support TLS 1.3zTLSv1.2zTLSv1.1ZTLSv1ZSSLv3ZSSLv2zUnknown TLS version: %r)rZSSLProtocolZSSLGetNegotiatedProtocolVersionrHr+rwr
rxr	ZkTLSProtocol13rgrh�kTLSProtocol12�kTLSProtocol11�
kTLSProtocol1�
kSSLProtocol3�
kSSLProtocol2)rP�protocolrXrrrr`�s"zWrappedSocket.versioncCs|jd7_dS)Nr)rI)rPrrr�_reuse�szWrappedSocket._reusecCs&|jdkr|j�n|jd8_dS)Nr)rIrR)rPrrr�_drop�s

zWrappedSocket._drop)N)F)�__name__�
__module__�__qualname__�__doc__rQ�
contextlib�contextmanagerrTrYr]rnr_r�r�r�r�r.rOr&rCrar�rRr�r`r�r�rrrrrGFs,

#(]
+
:rGcCs|jd7_t|||dd�S)NrT)rR)rIr)rP�mode�bufsizerrr�makefilesr��rcOsd}t|||f|�|�S)Nr)r)rPr��	buffering�args�kwargsrrrr�sc@s�eZdZdZdd�Zedd��Zejdd��Zedd��Zejd	d��Zed
d��Z	e	jdd��Z	d
d�Z
dd�Zdd�Zddd�Z
ddd�Zdd�Zd dd�ZdS)!rz�
    I am a wrapper class for the SecureTransport library, to translate the
    interface of the standard library ``SSLContext`` object to calls into
    SecureTransport.
    cCs>t|\|_|_d|_d|_d|_d|_d|_d|_d|_	dS)NrF)
�_protocol_to_min_max�_min_version�_max_version�_options�_verify�
_trust_bundle�_client_cert�_client_key�_client_key_passphrase�_alpn_protocols)rPr�rrrrQszSecureTransportContext.__init__cCsdS)z�
        SecureTransport cannot have its hostname checking disabled. For more,
        see the comment on getpeercert() in this file.
        Tr)rPrrr�check_hostname"sz%SecureTransportContext.check_hostnamecCsdS)z�
        SecureTransport cannot have its hostname checking disabled. For more,
        see the comment on getpeercert() in this file.
        Nr)rPrxrrrr�*scCs|jS)N)r�)rPrrr�options2szSecureTransportContext.optionscCs
||_dS)N)r�)rPrxrrrr�<scCs|jrtjStjS)N)r�rg�
CERT_REQUIRED�	CERT_NONE)rPrrr�verify_modeAsz"SecureTransportContext.verify_modecCs|tjkrdnd|_dS)NTF)rgr�r�)rPrxrrrr�EscCsdS)Nr)rPrrr�set_default_verify_pathsIs
z/SecureTransportContext.set_default_verify_pathscCs|j�S)N)r�)rPrrr�load_default_certsUsz)SecureTransportContext.load_default_certscCs|tjjkrtd��dS)Nz5SecureTransport doesn't support custom cipher strings)rr�DEFAULT_CIPHERSr�)rPrWrrr�set_ciphersXsz"SecureTransportContext.set_ciphersNc	Cs:|dk	rtd��|dk	r,t|��WdQRX|p2||_dS)Nz1SecureTransport does not support cert directories)r�rsr�)rP�cafile�capath�cadatarrr�load_verify_locations]s

z,SecureTransportContext.load_verify_locationscCs||_||_||_dS)N)r�r�Z_client_cert_passphrase)rP�certfile�keyfile�passwordrrr�load_cert_chainisz&SecureTransportContext.load_cert_chaincCs&ttd�std��dd�|D�|_dS)z�
        Sets the ALPN protocols that will later be set on the context.

        Raises a NotImplementedError if ALPN is not supported.
        rZz2SecureTransport supports ALPN only in macOS 10.12+cSsg|]}tj|��qSr)�sixZ
ensure_binary)�.0�prrr�
<listcomp>xsz=SecureTransportContext.set_alpn_protocols.<locals>.<listcomp>N)�hasattrr�NotImplementedErrorr�)rPr\rrr�set_alpn_protocolsns
z)SecureTransportContext.set_alpn_protocolsFTc
CsP|s
t�|st�|st�t|�}|j||j|j|j|j|j|j|j	|j
�	|S)N)r�rGr�r�r�r�r�r�r�r�r�)rP�sock�server_side�do_handshake_on_connect�suppress_ragged_eofsr�r9rrr�wrap_socketzs
z"SecureTransportContext.wrap_socket)NNN)NN)FTTN)r�r�r�r�rQ�propertyr��setterr�r�r�r�r�r�r�r�r�rrrrrs$



r���)r�)r�N)er��
__future__rr�r+r)�os.pathrpr�r%rgrb�	threading�weakrefr��rZ	util.ssl_rZ_securetransport.bindingsrrr	Z_securetransport.low_levelr
rrr
rrr�ImportErrorZpackages.backports.makefiler�__all__rr!rrr �WeakValueDictionaryr"�Lockr}r�Z'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384Z'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256Z%TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384Z%TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256Z-TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256Z+TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256Z#TLS_DHE_RSA_WITH_AES_256_GCM_SHA384Z#TLS_DHE_RSA_WITH_AES_128_GCM_SHA256Z'TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384Z$TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHAZ'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256Z$TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHAZ%TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384Z"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHAZ%TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256Z"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHAZ#TLS_DHE_RSA_WITH_AES_256_CBC_SHA256Z TLS_DHE_RSA_WITH_AES_256_CBC_SHAZ#TLS_DHE_RSA_WITH_AES_128_CBC_SHA256Z TLS_DHE_RSA_WITH_AES_128_CBC_SHAZTLS_AES_256_GCM_SHA384ZTLS_AES_128_GCM_SHA256ZTLS_RSA_WITH_AES_256_GCM_SHA384ZTLS_RSA_WITH_AES_128_GCM_SHA256ZTLS_AES_128_CCM_8_SHA256ZTLS_AES_128_CCM_SHA256ZTLS_RSA_WITH_AES_256_CBC_SHA256ZTLS_RSA_WITH_AES_128_CBC_SHA256ZTLS_RSA_WITH_AES_256_CBC_SHAZTLS_RSA_WITH_AES_128_CBC_SHArV�PROTOCOL_TLSr�r�r�r�r�rr�rrr�rrrrr@rFZSSLReadFuncr{ZSSLWriteFuncr|�objectrGr�rrrrr�<module>5s� 	76

<


haha - 2025