Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/urllib3/contrib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/urllib3/contrib/__pycache__/securetransport.cpython-310.pyc
o

�~�`q��@s�dZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlmZmZmZdd	lmZmZmZmZmZmZzdd
l	mZWneysdZddl m!Z!Ynwdd
gZ"dZ#ej#Z$ej%j&Z'e
�(�Z)e�*�Z+dZ,ej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDejEejFejGejHejIejJgZKejLejMejNfeejMejNfiZOePe
d�r�ejQejQfeOe
jR<ePe
d�r�ejSejSfeOe
jT<ePe
d��rejMejMfeOe
jU<ePe
d��rejVejVfeOe
jW<ePe
d��r!ejNejNfeOe
jX<dd�ZYdd
�ZZdd�Z[dd�Z\e�]e[�Z^e�_e\�Z`Gdd�dea�Zbe�rLd$dd�Zcnd%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�A/usr/lib/python3/dist-packages/urllib3/contrib/securetransport.pyr��cCs.tt_ttj_tt_ttj_dt_dtj_dS)z>
    Undo monkey-patching by :func:`inject_into_urllib3`.
    FN)�orig_util_SSLContextrrr�orig_util_HAS_SNIrrrrrr r�r!c

Cs�d}z�t�|�}|durtjWS|j}|d}|��}d}d}zA||kr_|dus,|dkr9t�||�s9t�t	j
d��||}	tj|	�
||�}
|�|
|	�}||7}|s[|sZtjWWSn||ks$Wn8tjy�}z+|j	}|dur�|t	j
kr�||d<|t	jks�|t	jkr�tjWYd}~WS�WYd}~nd}~ww||d<||kr�tjWSWdSty�}z|dur�||_tjWYd}~Sd}~ww)zs
    SecureTransport read callback. This is called by ST to request that data
    be returned from the socket.
    Nr�	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_socket�requested_length�timeoutr+�
read_count�	remaining�buffer�
chunk_size�errr �_read_callback�s\

�
����	��rEc
Csnd}z�t�|�}|durtjWS|j}|d}t�||�}|��}d}d}	z.|	|krR|dus2|dkr?t�	||�s?t�
tjd��|�
|�}
|	|
7}	||
d�}|	|ks*Wn8tj
y�}z+|j}|dur�|tjkr�|	|d<|tjksv|tjkr�tjWYd}~WS�WYd}~nd}~ww|	|d<|	|kr�tjWSWdSty�}z|dur�||_tjWYd}~Sd}~ww)zx
    SecureTransport write callback. This is called by ST to request that data
    actually be sent on the network.
    Nrr$)r%r&r	r'r(r.�	string_atr)r�wait_for_writer+r,r-�sendr3r4r5r6r7r8)r9r:r;r<r=�bytes_to_write�datar?r+�sent�
chunk_sentrDrrr �_write_callbacksP

��
��	��rMc@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|_|j��|_	|j�
d�dS�NrF)r(�context�_makefile_refs�_closedr8�	_keychain�
_keychain_dir�_client_cert_chainr)�_timeout�
settimeout)�selfr(rrr �__init__NszWrappedSocket.__init__ccs6�d|_dV|jdur|jd}|_|��|�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)r8�close)rX�	exceptionrrr �_raise_on_error`s�

�zWrappedSocket._raise_on_errorcCs2tjtt�t�}t�|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)r�SSLCipherSuite�len�
CIPHER_SUITES�SSLSetEnabledCiphersrPr
)rX�ciphers�resultrrr �_set_ciphersus
�zWrappedSocket._set_ciphersc	CsD|sdSt|�}zt�|j|�}t|�Wt�|�dSt�|�w)z<
        Sets up the ALPN protocols on the context.
        N)r
r�SSLSetALPNProtocolsrPr
r�	CFRelease)rX�	protocols�
protocols_arrrbrrr �_set_alpn_protocols�s
z!WrappedSocket._set_alpn_protocolsc	
Cs�|sdStjtjf}z|�|�}||vrWdSd|f}Wnty4}zd|f}WYd}~nd}~wwt|���}|j�|�t	�
ddd�}|j�tjtj
|�|��t�d|��)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	�kSecTrustResultUnspecified�kSecTrustResultProceed�_evaluate_trustr7r�versionr(�sendall�struct�pack�
setsockopt�
SOL_SOCKET�	SO_LINGERrZ�ssl�SSLError)	rX�verify�trust_bundle�	successes�trust_result�reasonrD�rec�optsrrr �_custom_validate�s(�
��zWrappedSocket._custom_validatec	Cstj�|�rt|d��}|��}Wd�n1swYd}t��}zRt|�}t�|j	t
�|��}t|�|s?t
�d��t�||�}t|�t�|d�}t|�t��}t�|t
�|��}t|�W|rlt�|�|durut�|�|jS|rt�|�|dur�t�|�ww)N�rbzFailed to copy trust referenceT)�os�path�isfile�open�readr�SecTrustRefr�SSLCopyPeerTrustrPr.�byrefr
rtru�SecTrustSetAnchorCertificates�!SecTrustSetAnchorCertificatesOnly�SecTrustResultType�SecTrustEvaluaterre�value)rXrw�f�
cert_array�trustrbryrrr rl�s:
�



�
�zWrappedSocket._evaluate_trustc
Cs�t�dtjtj�|_t�|jtt�}
t	|
�t
� t|�d}|tvr-|dd}|tvs#|t|<Wd�n1s;wYt�
|j|�}
t	|
�|ret|t�sW|�d�}t�|j|t|��}
t	|
�|��|�|	�t�|j|�}
t	|
�t�|j|�}
t	|
�|r�|dur�t�|jtjd�}
t	|
�|r�t�\|_|_t|j||�|_t�|j|j�}
t	|
�	|���1t� |j�}
|
tj!kr�t"�#d��|
tj$kr�|�%||�	Wd�q�t	|
�	Wd�dS1s�wYq�)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)&r�SSLCreateContextr	�kSSLClientSide�kSSLStreamTyperP�
SSLSetIOFuncs�_read_callback_pointer�_write_callback_pointerr
�_connection_ref_lock�idr%�SSLSetConnection�
isinstance�bytes�encode�SSLSetPeerDomainNamer^rcrh�SSLSetProtocolVersionMin�SSLSetProtocolVersionMax�SSLSetSessionOption�"kSSLSessionOptionBreakOnServerAuthrrSrTrrU�SSLSetCertificater\�SSLHandshaker6r(r?�errSSLServerAuthCompletedr})rX�server_hostnamervrw�min_version�max_version�client_cert�
client_key�client_key_passphrase�alpn_protocolsrb�handlerrr �	handshake�sl
���
�

�

��



�	 ��zWrappedSocket.handshakecCs
|j��S�N)r(�fileno�rXrrr r�7�
zWrappedSocket.filenocCs.|jdkr|jd8_|jr|��dSdS)Nrr)rQrRrZr�rrr �_decref_socketios;s

�zWrappedSocket._decref_socketioscCs&t�|�}|�||�}|d|�}|Sr�)r.�create_string_bufferr1)rX�bufsizrB�
bytes_readrJrrr �recvAs
zWrappedSocket.recvNc	Cs�|jrdS|dur
t|�}tj|�|�}t�d�}|���t�|j	||t�
|��}Wd�n1s5wY|tjkrL|j
dkrIt�d��|j
S|tjtjfvr[|��|j
St|�|j
S)Nrzrecv timed out)rRr^r.r/�from_buffer�c_size_tr\r�SSLReadrPr�r	r6r�r(r?r2�errSSLClosedNoNotifyrZr
)rXrB�nbytes�processed_bytesrbrrr r1Gs.

��


���zWrappedSocket.recv_intocC�
||_dSr��rV)rXr?rrr rWrr�zWrappedSocket.settimeoutcC�|jSr�r�r�rrr r)uszWrappedSocket.gettimeoutc	Cszt�d�}|���t�|j|t|�t�|��}Wd�n1s"wY|tj	kr6|j
dkr6t�d��t
|�|j
S)Nrzsend timed out)r.r�r\r�SSLWriterPr^r�r	r6r�r(r?r
)rXrJr�rbrrr rHxs

��
zWrappedSocket.sendcCsBd}|t|�kr|�|||t��}||7}|t|�ksdSdS�Nr)r^rH�SSL_WRITE_BLOCKSIZE)rXrJ�
total_sentrKrrr rn�s
�zWrappedSocket.sendallcCs:|���t�|j�Wd�dS1swYdSr�)r\r�SSLCloserPr�rrr �shutdown�s
"�zWrappedSocket.shutdowncCs�|jdkr@d|_|jrt�|j�d|_|jr t�|j�d|_|jr;t�|j�t�|j�t	�
|j�d|_|_|j�
�S|jd8_dS)NrT)rQrRrPrrerUrSr�SecKeychainDelete�shutil�rmtreerTr(rZr�rrr rZ�s

zWrappedSocket.closeFc
	Cs |std��t��}d}d}zqt�|jt�|��}t|�|s2W|r't�	|�|r0t�	|�dSdSt�
|�}|sLW|rAt�	|�|rJt�	|�dSdSt�|d�}|sVJ�t�|�}|s_J�t�
|�}t�|�}	t�|	|�}W|rwt�	|�|r~t�	|�|S|r�t�	|�|r�t�	|�ww)Nz2SecureTransport only supports dumping binary certsr)�
ValueErrorrr�r�rPr.r�r
rre�SecTrustGetCertificateCount�SecTrustGetCertificateAtIndex�SecCertificateCopyData�CFDataGetLength�CFDataGetBytePtrrF)
rX�binary_formr��certdata�	der_bytesrb�
cert_count�leaf�data_lengthr:rrr �getpeercert�sP
�
�
��




�
�zWrappedSocket.getpeercertcCs�t��}t�|jt�|��}t|�|jtj	krt
�d��|jtjkr%dS|jtj
kr-dS|jtjkr5dS|jtjkr=dS|jtjkrEdSt
�d|��)Nz(SecureTransport does not support TLS 1.3zTLSv1.2zTLSv1.1�TLSv1�SSLv3�SSLv2zUnknown TLS version: %r)r�SSLProtocol�SSLGetNegotiatedProtocolVersionrPr.r�r
r�r	�kTLSProtocol13rtru�kTLSProtocol12�kTLSProtocol11�
kTLSProtocol1�
kSSLProtocol3�
kSSLProtocol2)rX�protocolrbrrr rm�s$�
zWrappedSocket.versioncCs|jd7_dS�Nr)rQr�rrr �_reuse�szWrappedSocket._reusecCs(|jdkr|��dS|jd8_dSr�)rQrZr�rrr �_drop�s
zWrappedSocket._dropr�)F)�__name__�
__module__�__qualname__�__doc__rY�
contextlib�contextmanagerr\rcrhr}rlr�r�r�r�r1rWr)rHrnr�rZr�rmr�r�rrrr rNFs0


#(]
+
:rN���cCs|jd7_t|||dd�S)NrT)rZ)rQr)rX�mode�bufsizerrr �makefilesr��rcOsd}t|||g|�Ri|��Sr�r)rXr��	buffering�args�kwargsrrr r�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�Z				d 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|_	dSrO)
�_protocol_to_min_max�_min_version�_max_version�_options�_verify�
_trust_bundle�_client_cert�_client_key�_client_key_passphrase�_alpn_protocols)rXr�rrr rYs
zSecureTransportContext.__init__cC�dS)��
        SecureTransport cannot have its hostname checking disabled. For more,
        see the comment on getpeercert() in this file.
        Trr�rrr �check_hostname#�z%SecureTransportContext.check_hostnamecCr�)r�Nr�rXr�rrr r�+r�cCr�r��r�r�rrr �options3szSecureTransportContext.optionscCr�r�rr�rrr r=s
cCs|jrtjStjSr�)r�rt�
CERT_REQUIRED�	CERT_NONEr�rrr �verify_modeBsz"SecureTransportContext.verify_modecCs|tjkr
d|_dSd|_dS)NTF)rtrr�r�rrr rFscCsdSr�rr�rrr �set_default_verify_pathsJs
z/SecureTransportContext.set_default_verify_pathscCs|��Sr�)rr�rrr �load_default_certsVsz)SecureTransportContext.load_default_certscCs|tjjkr
td��dS)Nz5SecureTransport doesn't support custom cipher strings)rr�DEFAULT_CIPHERSr�)rXrarrr �set_ciphersYs�z"SecureTransportContext.set_ciphersNcCsN|durtd��|dur t|��Wd�n1swY|p#||_dS)Nz1SecureTransport does not support cert directories)r�r�r�)rX�cafile�capath�cadatarrr �load_verify_locations^s
�z,SecureTransportContext.load_verify_locationscCs||_||_||_dSr�)r�r��_client_cert_passphrase)rX�certfile�keyfile�passwordrrr �load_cert_chainjs
z&SecureTransportContext.load_cert_chaincCs&ttd�s	td��dd�|D�|_dS)z�
        Sets the ALPN protocols that will later be set on the context.

        Raises a NotImplementedError if ALPN is not supported.
        rdz2SecureTransport supports ALPN only in macOS 10.12+cSsg|]}t�|��qSr)�six�
ensure_binary)�.0�prrr �
<listcomp>ysz=SecureTransportContext.set_alpn_protocols.<locals>.<listcomp>N)�hasattrr�NotImplementedErrorr�)rXrfrrr �set_alpn_protocolsos

�z)SecureTransportContext.set_alpn_protocolsFTcCsN|rJ�|sJ�|sJ�t|�}|�||j|j|j|j|j|j|j|j	�	|Sr�)
rNr�r�r�r�r�r�r�r�r�)rX�sock�server_side�do_handshake_on_connect�suppress_ragged_eofsr�r<rrr �wrap_socket{s �z"SecureTransportContext.wrap_socket)NNN)NN)FTTN)r�r�r�r�rY�propertyr��setterrrrrrrrrrrrrr rs4



	




�r)r�)r�N)er��
__future__rr�r.r,�os.pathrr�r(rtro�	threading�weakrefr�r�	util.ssl_r�_securetransport.bindingsrrr	�_securetransport.low_levelr
rrr
rrr�ImportError�packages.backports.makefiler�__all__rr#rrr"�WeakValueDictionaryr%�Lockr�r��'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384�'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256�%TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384�%TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256�-TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256�+TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256�#TLS_DHE_RSA_WITH_AES_256_GCM_SHA384�#TLS_DHE_RSA_WITH_AES_128_GCM_SHA256�'TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384�$TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA�'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256�$TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA�%TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384�"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA�%TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256�"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA�#TLS_DHE_RSA_WITH_AES_256_CBC_SHA256� TLS_DHE_RSA_WITH_AES_256_CBC_SHA�#TLS_DHE_RSA_WITH_AES_128_CBC_SHA256� TLS_DHE_RSA_WITH_AES_128_CBC_SHA�TLS_AES_256_GCM_SHA384�TLS_AES_128_GCM_SHA256�TLS_RSA_WITH_AES_256_GCM_SHA384�TLS_RSA_WITH_AES_128_GCM_SHA256�TLS_AES_128_CCM_8_SHA256�TLS_AES_128_CCM_SHA256�TLS_RSA_WITH_AES_256_CBC_SHA256�TLS_RSA_WITH_AES_128_CBC_SHA256�TLS_RSA_WITH_AES_256_CBC_SHA�TLS_RSA_WITH_AES_128_CBC_SHAr_�PROTOCOL_TLSr�r�r�rr�rr�rrr�rrrrrErM�SSLReadFuncr��SSLWriteFuncr��objectrNr�rrrrr �<module>s�5 	��%�

�

�
�
�
�7
6
<


Spamworldpro Mini