ok

Mini Shell

Direktori : /opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/
Upload File :
Current File : //opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyo

�
Bu�_c@@s�dZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZmZmZddlmZmZmZmZydd	l	mZWn'ek
r
eZdd
lmZnXddgZeZejZ ej!j"Z#ej$�Z%ej&�Z'd
Z(ej)ej*ej+ej,ej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDejEejFgZGiejHejIfejJ6ZKeLe
d�rTejMejMfeKe
jN<neLe
d�rejOejOfeKe
jP<neLe
d�r�ejHejHfeKe
jQ<neLe
d�r�ejRejRfeKe
jS<neLe
d�rejIejIfeKe
jT<nd�ZUd�ZVd�ZWd�ZXejYeW�ZZej[eX�Z\de]fd��YZ^ermdd�Z_nded�Z_e_e^__de]fd��YZ`dS(s�	
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:

    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.
i(tabsolute_importNi(tutili(tSecurityt
SecurityConsttCoreFoundation(t_assert_no_errort_cert_array_from_pemt_temporary_keychaint_load_client_cert_chain(t_fileobject(tbackport_makefiletinject_into_urllib3textract_from_urllib3i@tPROTOCOL_SSLv2tPROTOCOL_SSLv3tPROTOCOL_TLSv1tPROTOCOL_TLSv1_1tPROTOCOL_TLSv1_2cC@sCtt_ttj_tt_ttj_tt_ttj_dS(sG
    Monkey-patch urllib3 with SecureTransport-backed SSL-support.
    N(tSecureTransportContextRt
SSLContexttssl_tHAS_SNItTruetIS_SECURETRANSPORT(((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR�s			cC@sCtt_ttj_tt_ttj_tt_ttj_dS(s>
    Undo monkey-patching by :func:`inject_into_urllib3`.
    N(torig_util_SSLContextRRRtorig_util_HAS_SNIRtFalseR(((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR�s			c
C@s�d}y�tj|�}|dkr+tjS|j}|d}|j�}d}d}y�x�||kr|dks�|dkr�tj||�s�tj	t
jd��q�n||}	tj
|	j||�}
|j|
|	�}||7}|s\|stjSPq\q\WWnotj	k
rz}|j
}|dk	r{|t
jkr{||d<|t
jksj|t
jkrqtjS�q{nX||d<||kr�tjSdSWn/tk
r�}|dk	r�||_ntjSXdS(ss
    SecureTransport read callback. This is called by ST to request that data
    be returned from the socket.
    is	timed outN(tNonet_connection_refstgetRterrSSLInternaltsockett
gettimeoutRt
wait_for_readterrorterrnotEAGAINtctypestc_chartfrom_addresst	recv_intoterrSSLClosedGracefult
ECONNRESETtEPIPEterrSSLClosedAbortterrSSLWouldBlockt	Exceptiont
_exception(
t
connection_idtdata_buffertdata_length_pointertwrapped_sockettbase_sockettrequested_lengthttimeoutR"t
read_countt	remainingtbuffert
chunk_sizete((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_read_callback�sN	




	


cC@s�d}yutj|�}|dkr+tjS|j}|d}tj||�}|j�}d}d}	yxx|	|kr�|dks�|dkr�t	j
||�s�tjtj
d��q�n|j|�}
|	|
7}	||
}qnWWnotjk
rX}|j}|dk	rY|tj
krY|	|d<|tjksH|tjkrOtjS�qYnX|	|d<|	|krvtjSdSWn/tk
r�}|dk	r�||_ntjSXdS(sx
    SecureTransport write callback. This is called by ST to request that data
    actually be sent on the network.
    is	timed outN(RRRRRRR%t	string_atR Rtwait_for_writeR"R#R$tsendR*R+R,R-R.R/(R0R1R2R3R4tbytes_to_writetdataR6R"tsentt
chunk_sentR;((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_write_callbacksD	

	


t
WrappedSocketcB@s�eZdZd�Zejd��Zd�Zd�Zd�Z	d�Z
d�Zd�Zdd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zed�Zd�Zd�Zd�ZRS(s�
    API-compatibility wrapper for Python's OpenSSL wrapped socket object.

    Note: _makefile_refs, _drop(), and _reuse() are needed for the garbage
    collector of PyPy.
    cC@sn||_d|_d|_t|_d|_d|_d|_d|_	|jj
�|_|jjd�dS(Ni(
RRtcontextt_makefile_refsRt_closedR/t	_keychaint
_keychain_dirt_client_cert_chainR t_timeoutt
settimeout(tselfR((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt__init__Es								cc@sGd|_dV|jdk	rC|jd}|_|j�|�ndS(s]
        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(RR/tclose(RNt	exception((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_raise_on_errorWs
	
cC@sEtjtt�t�}tj|j|tt��}t|�dS(s4
        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(RtSSLCipherSuitetlent
CIPHER_SUITEStSSLSetEnabledCiphersRFR(RNtcipherstresult((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_set_cipherslsc	C@s�|s
dStjj|�rCt|d��}|j�}WdQXnd}tj�}z�t|�}tj	|j
tj|��}t
|�|s�tjd��ntj||�}t
|�tj|t�}t
|�tj�}tj|tj|��}t
|�Wd|r'tj|�n|dk	rCtj|�nXtjtjf}|j|kr~tjd|j��ndS(s�
        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.
        NtrbsFailed to copy trust references)certificate verify failed, error code: %d(tostpathtisfiletopentreadRRtSecTrustRefRtSSLCopyPeerTrustRFR%tbyrefRtssltSSLErrortSecTrustSetAnchorCertificatest!SecTrustSetAnchorCertificatesOnlyRtSecTrustResultTypetSecTrustEvaluateRt	CFReleaseRtkSecTrustResultUnspecifiedtkSecTrustResultProceedtvalue(	RNtverifyttrust_bundletft
cert_arrayttrustRXttrust_resultt	successes((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_custom_validateys:


c		C@s[tjdtjtj�|_tj|jtt	�}	t
|	�t�@t|�d}
x|
t
krw|
dd}
qZW|t
|
<WdQXtj|j|
�}	t
|	�|r�t|t�s�|jd�}ntj|j|t|��}	t
|	�n|j�tj|j|�}	t
|	�tj|j|�}	t
|	�|sT|dk	r|tj|jtjt�}	t
|	�n|r�t�\|_|_t|j||�|_tj|j|j�}	t
|	�nx�trV|j ��htj!|j�}	|	tj"krt#j$d��n0|	tj%krB|j&||�w�nt
|	�PWdQXq�WdS(s�
        Actually performs the TLS handshake. This is run automatically by
        wrapped socket, and shouldn't be needed in user code.
        i���iNsutf-8shandshake timed out('RtSSLCreateContextRRtkSSLClientSidetkSSLStreamTypeRFt
SSLSetIOFuncst_read_callback_pointert_write_callback_pointerRt_connection_ref_locktidRtSSLSetConnectiont
isinstancetbytestencodetSSLSetPeerDomainNameRTRYtSSLSetProtocolVersionMintSSLSetProtocolVersionMaxtSSLSetSessionOptiont"kSSLSessionOptionBreakOnServerAuthRRRIRJRRKtSSLSetCertificateRRtSSLHandshakeR-RR6terrSSLServerAuthCompletedRt(RNtserver_hostnameRmRntmin_versiontmax_versiontclient_certt
client_keytclient_key_passphraseRXthandle((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt	handshake�sV







	

cC@s
|jj�S(N(Rtfileno(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR�scC@s;|jdkr!|jd8_n|jr7|j�ndS(Nii(RGRHRP(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_decref_socketioss	cC@s/tj|�}|j||�}|| }|S(N(R%tcreate_string_bufferR((RNtbufsizR9t
bytes_readRA((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytrecvs
c
C@s�|jr
dS|dkr(t|�}ntj|j|�}tjd�}|j��)tj	|j
||tj|��}WdQX|tj
kr�|jdkr�tjd��q�n/|tjtjfkr�|j�n
t|�|jS(Nisrecv timed out(RHRRTR%R&tfrom_buffertc_size_tRRRtSSLReadRFRbRR-RlRR6R)terrSSLClosedNoNotifyRPR(RNR9tnbytestprocessed_bytesRX((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR(s$	
$

cC@s
||_dS(N(RL(RNR6((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyRMFscC@s|jS(N(RL(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR Isc
C@s�tjd�}|j��/tj|j|t|�tj|��}WdQX|tj	kr||j
dkr|tjd��n
t
|�|j
S(Nissend timed out(R%R�RRRtSSLWriteRFRTRbRR-RlRR6R(RNRAR�RX((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR?Ls
*
cC@sGd}x:|t|�krB|j|||t!�}||7}q	WdS(Ni(RTR?tSSL_WRITE_BLOCKSIZE(RNRAt
total_sentRB((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytsendall]scC@s'|j��tj|j�WdQXdS(N(RRRtSSLCloseRF(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytshutdowncs
cC@s�|jdkr�t|_|jr=tj|j�d|_n|jrbtj|j�d|_n|jr�t	j
|j�tj|j�tj|j
�d|_|_
n|jj�S|jd8_dS(Ni(RGRRHRFRRiRRKRIRtSecKeychainDeletetshutiltrmtreeRJRRP(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyRPgs				
c
C@s|std��ntj�}d}d}z�tj|jtj|��}t|�|sbdStj	|�}|s{dStj
|d�}tj|�}tj
|�}tj|�}	tj|	|�}Wd|r�tj|�n|r�tj|�nX|S(Ns2SecureTransport only supports dumping binary certsi(t
ValueErrorRR`RRaRFR%RbRtSecTrustGetCertificateCounttSecTrustGetCertificateAtIndextSecCertificateCopyDataRtCFDataGetLengthtCFDataGetBytePtrR=Ri(
RNtbinary_formRqtcertdatat	der_bytesRXt
cert_counttleaftdata_lengthR1((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytgetpeercertzs.
cC@s�tj�}tj|jtj|��}t|�|jtj	krXt
jd��n�|jtjkrndS|jtj
kr�dS|jtjkr�dS|jtjkr�dS|jtjkr�dSt
jd|��dS(Ns(SecureTransport does not support TLS 1.3sTLSv1.2sTLSv1.1tTLSv1tSSLv3tSSLv2sUnknown TLS version: %r(RtSSLProtocoltSSLGetNegotiatedProtocolVersionRFR%RbRRlRtkTLSProtocol13RcRdtkTLSProtocol12tkTLSProtocol11t
kTLSProtocol1t
kSSLProtocol3t
kSSLProtocol2(RNtprotocolRX((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytversion�s"
cC@s|jd7_dS(Ni(RG(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_reuse�scC@s/|jdkr|j�n|jd8_dS(Ni(RGRP(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_drop�s
N(t__name__t
__module__t__doc__ROt
contextlibtcontextmanagerRRRYRtR�R�R�R�RR(RMR R?R�R�RPRR�R�R�R�(((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyRE=s(		
	9	Y			+						:		i����cC@s%|jd7_t|||dt�S(NiRP(RGR	R(RNtmodetbufsize((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytmakefile�strcO@sd}t|||||�S(Ni(R
(RNR�t	bufferingtargstkwargs((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR��sRcB@s�eZdZd�Zed��Zejd��Zed��Zejd��Zed��Zejd��Zd�Z	d	�Z
d
�Zdddd�Z
ddd�Zeeedd
�ZRS(s�
    I am a wrapper class for the SecureTransport library, to translate the
    interface of the standard library ``SSLContext`` object to calls into
    SecureTransport.
    cC@sPt|\|_|_d|_t|_d|_d|_d|_	d|_
dS(Ni(t_protocol_to_min_maxt_min_versiont_max_versiont_optionsRt_verifyRt
_trust_bundlet_client_certt_client_keyt_client_key_passphrase(RNR�((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyRO�s					cC@stS(s�
        SecureTransport cannot have its hostname checking disabled. For more,
        see the comment on getpeercert() in this file.
        (R(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytcheck_hostname�scC@sdS(s�
        SecureTransport cannot have its hostname checking disabled. For more,
        see the comment on getpeercert() in this file.
        N((RNRl((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR��scC@s|jS(N(R�(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytoptionsscC@s
||_dS(N(R�(RNRl((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR�scC@s|jrtjStjS(N(R�Rct
CERT_REQUIREDt	CERT_NONE(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytverify_modescC@s"|tjkrtnt|_dS(N(RcR�RRR�(RNRl((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR�scC@sdS(N((RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytset_default_verify_pathss
cC@s
|j�S(N(R�(RN((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytload_default_certs)scC@s%|tjjkr!td��ndS(Ns5SecureTransport doesn't support custom cipher strings(RRtDEFAULT_CIPHERSR�(RNRW((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytset_ciphers,scC@sP|dk	rtd��n|dk	r=t|��WdQXn|pF||_dS(Ns1SecureTransport does not support cert directories(RR�R^R�(RNtcafiletcapathtcadata((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytload_verify_locations1s
	cC@s||_||_||_dS(N(R�R�t_client_cert_passphrase(RNtcertfiletkeyfiletpassword((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytload_cert_chain=s		c	C@sGt|�}|j||j|j|j|j|j|j|j�|S(N(	RER�R�R�R�R�R�R�R�(RNtsocktserver_sidetdo_handshake_on_connecttsuppress_ragged_eofsR�R3((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytwrap_socketBs
N(R�R�R�ROtpropertyR�tsetterR�R�R�R�R�RR�R�RRR�(((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR�s"		
			(aR�t
__future__RR�R%R#tos.pathR[R�RRct	threadingtweakreftRt_securetransport.bindingsRRRt_securetransport.low_levelRRRRR	tImportErrorRtpackages.backports.makefileR
t__all__RRRRRRtWeakValueDictionaryRtLockR{R�t'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384t'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256t%TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384t%TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256t-TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256t+TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256t#TLS_DHE_RSA_WITH_AES_256_GCM_SHA384t#TLS_DHE_RSA_WITH_AES_128_GCM_SHA256t'TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384t$TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHAt'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256t$TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHAt%TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384t"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHAt%TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256t"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHAt#TLS_DHE_RSA_WITH_AES_256_CBC_SHA256t TLS_DHE_RSA_WITH_AES_256_CBC_SHAt#TLS_DHE_RSA_WITH_AES_128_CBC_SHA256t TLS_DHE_RSA_WITH_AES_128_CBC_SHAtTLS_AES_256_GCM_SHA384tTLS_AES_128_GCM_SHA256tTLS_RSA_WITH_AES_256_GCM_SHA384tTLS_RSA_WITH_AES_128_GCM_SHA256tTLS_AES_128_CCM_8_SHA256tTLS_AES_128_CCM_SHA256tTLS_RSA_WITH_AES_256_CBC_SHA256tTLS_RSA_WITH_AES_128_CBC_SHA256tTLS_RSA_WITH_AES_256_CBC_SHAtTLS_RSA_WITH_AES_128_CBC_SHARUR�R�tPROTOCOL_TLSR�thasattrR�R
R�RRR�RRRRR<RDtSSLReadFuncRytSSLWriteFuncRztobjectRER�R(((s\/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt<module>3s�"
				7	6��	

Zerion Mini Shell 1.0