Hacked By AnonymousFox

Current Path : /proc/thread-self/root/proc/self/root/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/
Upload File :
Current File : //proc/thread-self/root/proc/self/root/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyc

�
��abc!@@sdZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZmZmZddlmZmZmZmZydd	l	mZWn'ek
r
eZdd
lmZnXyed�Wnek
r;ed��nXd
dgZe Z!ej!Z"ej#j$Z%ej&�Z'ej(�Z)dZ*ej+ej,ej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDejEejFejGejHejIejJejKg!ZLiejMejNfe
jO6ZPeQe
d�r�ejRejRfePe
jS<neQe
d�r�ejTejTfePe
jU<neQe
d�r�ejMejMfePe
jV<neQe
d�rejWejWfePe
jX<neQe
d�r@ejNejNfePe
jY<neQe
d�rfePe
jOePe
jZ<nd�Z[d�Z\d�Z]d�Z^ej_e]�Z`ejae^�Zbdecfd��YZder�dd�Zended�Zeeeed_ed ecfd!��YZfdS("sU
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!
i(tabsolute_importNi(tutili(tSecurityt
SecurityConsttCoreFoundation(t_assert_no_errort_cert_array_from_pemt_temporary_keychaint_load_client_cert_chain(t_fileobject(tbackport_makefilets5SecureTransport only works on Pythons with memoryviewtinject_into_urllib3textract_from_urllib3i@tPROTOCOL_SSLv2tPROTOCOL_SSLv3tPROTOCOL_TLSv1tPROTOCOL_TLSv1_1tPROTOCOL_TLSv1_2tPROTOCOL_TLScC@s:ttj_tt_ttj_tt_ttj_dS(sG
    Monkey-patch urllib3 with SecureTransport-backed SSL-support.
    N(tSecureTransportContextRtssl_t
SSLContexttHAS_SNItTruetIS_SECURETRANSPORT(((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR�s
		cC@s:ttj_tt_ttj_tt_ttj_dS(s>
    Undo monkey-patching by :func:`inject_into_urllib3`.
    N(torig_util_SSLContextRRRtorig_util_HAS_SNIRtFalseR(((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR
�s
		cC@s�d}y�tj|�}|dkr+tjS|j}|d}|j�}d}d}tj|j	|�}	t
|	�}
y�x�||kr|dks�|dkr�tj|g|�}|s�tj
tjd��q�n|j|
||!�}||7}|s~|stjSPq~q~WWnVtj
k
rl}
|
j}|dk	rm|tjkrm|tjkrctjS�qmnX||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
gettimeouttctypestc_chartfrom_addresst
memoryviewRt
wait_for_readterrorterrnotEAGAINt	recv_intoterrSSLClosedGracefult
ECONNRESETterrSSLClosedAbortterrSSLWouldBlockt	Exceptiont
_exception(t
connection_idtdata_buffertdata_length_pointertwrapped_sockettbase_sockettrequested_lengthttimeoutR(t
read_counttbuffertbuffer_viewt	readablest
chunk_sizete((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_read_callback�sN	

	

c
C@s�d}yetj|�}|dkr+tjS|j}|d}tj||�}|j�}d}d}	y�x�|	|kr�|dks�|dkr�t	j
|g|�}
|
s�tjtj
d��q�n|j|�}|	|7}	||}qnWWnVtjk
rH}|j}|dk	rI|tj
krI|tjkr?tjS�qInX|	|d<|	|krftjSdSWn/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(RRRRR R!R#t	string_atR"Rtwait_for_writeR(R)R*tsendR-R.R/R0R1(
R2R3R4R5R6tbytes_to_writetdataR8R(tsentt	writablest
chunk_sentR>((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_write_callback�sD	

	

t
WrappedSocketcB@s�eZdZd�Zejd��Zd�Zd�Zd�Z	d�Z
d�Zd�Zdd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zed�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(
R!Rtcontextt_makefile_refsRt_closedR1t	_keychaint
_keychain_dirt_client_cert_chainR"t_timeoutt
settimeout(tselfR!((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt__init__.s								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(RR1tclose(RRt	exception((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_raise_on_error@s
	
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_SUITEStSSLSetEnabledCiphersRJR(RRtcipherstresult((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_set_ciphersUsc	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|dkrCtj|�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(tostpathtisfiletopentreadRRtSecTrustRefRtSSLCopyPeerTrustRJR#tbyrefRtssltSSLErrortSecTrustSetAnchorCertificatest!SecTrustSetAnchorCertificatesOnlyRtSecTrustResultTypetSecTrustEvaluateRt	CFReleaseRtkSecTrustResultUnspecifiedtkSecTrustResultProceedtvalue(	RRtverifyttrust_bundletft
cert_arrayttrustR\ttrust_resultt	successes((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_custom_validatebs@


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('RtSSLCreateContextRRtkSSLClientSidetkSSLStreamTypeRJt
SSLSetIOFuncst_read_callback_pointert_write_callback_pointerRt_connection_ref_locktidRtSSLSetConnectiont
isinstancetbytestencodetSSLSetPeerDomainNameRXR]tSSLSetProtocolVersionMintSSLSetProtocolVersionMaxtSSLSetSessionOptiont"kSSLSessionOptionBreakOnServerAuthRRRMRNRROtSSLSetCertificateRVtSSLHandshakeR/R!R8terrSSLServerAuthCompletedRx(RRtserver_hostnameRqRrtmin_versiontmax_versiontclient_certt
client_keytclient_key_passphraseR\thandle((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt	handshake�s\





	

	

cC@s
|jj�S(N(R!tfileno(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR��scC@s;|jdkr!|jd8_n|jr7|j�ndS(Nii(RKRLRT(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_decref_socketios�s	cC@s/tj|�}|j||�}|| }|S(N(R#tcreate_string_bufferR+(RRtbufsizR:t
bytes_readRD((sO/usr/lib/python2.7/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(RLRRXR#R$tfrom_buffertc_size_tRVRtSSLReadRJRfRR/RpR!R8R,terrSSLClosedNoNotifyRTR(RRR:tnbytestprocessed_bytesR\((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR+
s 	
$

cC@s
||_dS(N(RP(RRR8((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyRQ2scC@s|jS(N(RP(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR"5sc
C@s�tjd�}|j��/tj|j|t|�tj|��}WdQX|tj	kr||j
dkr|tjd��n
t
|�|j
S(Nissend timed out(R#R�RVRtSSLWriteRJRXRfRR/RpR!R8R(RRRDR�R\((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyRB8s
*
cC@sGd}x:|t|�krB|j|||t!�}||7}q	WdS(Ni(RXRBtSSL_WRITE_BLOCKSIZE(RRRDt
total_sentRE((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytsendallIscC@s'|j��tj|j�WdQXdS(N(RVRtSSLCloseRJ(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytshutdownOs
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(RKRRLRJRRmRRORMRtSecKeychainDeletetshutiltrmtreeRNR!RT(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyRTSs				
c
C@s|std��ntj�}d}d}z�tj|jtj|��}t|�|sbdStj	|�}|s{dStj
|d�}|s�t�tj|�}|s�t�t
j|�}t
j|�}	tj|	|�}Wd|r�t
j|�n|rt
j|�nX|S(Ns2SecureTransport only supports dumping binary certsi(t
ValueErrorRRdRReRJR#RfRtSecTrustGetCertificateCounttSecTrustGetCertificateAtIndextAssertionErrortSecCertificateCopyDataRtCFDataGetLengthtCFDataGetBytePtrR@Rm(
RRtbinary_formRutcertdatat	der_bytesR\t
cert_counttleaftdata_lengthR3((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytgetpeercertfs6
cC@s|jd7_dS(Ni(RK(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_reuse�scC@s/|jdkr|j�n|jd8_dS(Ni(RKRT(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt_drop�s
N(t__name__t
__module__t__doc__RSt
contextlibtcontextmanagerRVR]RxR�R�R�R�RR+RQR"RBR�R�RTRR�R�R�(((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyRI's&		
	>	Z			(						>	i����cC@s%|jd7_t|||dt�S(NiRT(RKR	R(RRtmodetbufsize((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytmakefile�strcO@sd}t|||||�S(Ni(R
(RRR�t	bufferingtargstkwargs((sO/usr/lib/python2.7/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(RRtprotocol((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyRS�s					cC@stS(s�
        SecureTransport cannot have its hostname checking disabled. For more,
        see the comment on getpeercert() in this file.
        (R(RR((sO/usr/lib/python2.7/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((RRRp((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR��scC@s|jS(N(R�(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytoptions�scC@s
||_dS(N(R�(RRRp((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR��scC@s|jrtjStjS(N(R�Rgt
CERT_REQUIREDt	CERT_NONE(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytverify_mode�scC@s"|tjkrtnt|_dS(N(RgR�RRR�(RRRp((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR��scC@sdS(N((RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytset_default_verify_paths�s
cC@s
|j�S(N(R�(RR((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytload_default_certs�scC@s%|tjjkr!td��ndS(Ns5SecureTransport doesn't support custom cipher strings(RRtDEFAULT_CIPHERSR�(RRR[((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytset_ciphersscC@s.|dk	rtd��n|p$||_dS(Ns1SecureTransport does not support cert directories(RR�R�(RRtcafiletcapathtcadata((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytload_verify_locationsscC@s||_||_||_dS(N(R�R�t_client_cert_passphrase(RRtcertfiletkeyfiletpassword((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytload_cert_chains		c	C@sl|s
t�|st�|s%t�t|�}|j||j|j|j|j|j|j|j	�|S(N(
R�RIR�R�R�R�R�R�R�R�(RRtsocktserver_sidetdo_handshake_on_connecttsuppress_ragged_eofsR�R5((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pytwrap_sockets
N(R�R�R�RStpropertyR�tsetterR�R�R�R�R�RR�R�RRR�(((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyR�s 		
				(gR�t
__future__RR�R#R)tos.pathR_R�R!Rgt	threadingtweakrefRRt_securetransport.bindingsRRRt_securetransport.low_levelRRRRR	tImportErrorRtpackages.backports.makefileR
R&t	NameErrort__all__RRRRRRtWeakValueDictionaryRtLockRR�tTLS_AES_256_GCM_SHA384tTLS_CHACHA20_POLY1305_SHA256tTLS_AES_128_GCM_SHA256t'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384t%TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384t'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256t%TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256t#TLS_DHE_DSS_WITH_AES_256_GCM_SHA384t#TLS_DHE_RSA_WITH_AES_256_GCM_SHA384t#TLS_DHE_DSS_WITH_AES_128_GCM_SHA256t#TLS_DHE_RSA_WITH_AES_128_GCM_SHA256t'TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384t%TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384t$TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHAt"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHAt#TLS_DHE_RSA_WITH_AES_256_CBC_SHA256t#TLS_DHE_DSS_WITH_AES_256_CBC_SHA256t TLS_DHE_RSA_WITH_AES_256_CBC_SHAt TLS_DHE_DSS_WITH_AES_256_CBC_SHAt'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256t%TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256t$TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHAt"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHAt#TLS_DHE_RSA_WITH_AES_128_CBC_SHA256t#TLS_DHE_DSS_WITH_AES_128_CBC_SHA256t TLS_DHE_RSA_WITH_AES_128_CBC_SHAt TLS_DHE_DSS_WITH_AES_128_CBC_SHAtTLS_RSA_WITH_AES_256_GCM_SHA384tTLS_RSA_WITH_AES_128_GCM_SHA256tTLS_RSA_WITH_AES_256_CBC_SHA256tTLS_RSA_WITH_AES_128_CBC_SHA256tTLS_RSA_WITH_AES_256_CBC_SHAtTLS_RSA_WITH_AES_128_CBC_SHARYt
kTLSProtocol1tkTLSProtocol12tPROTOCOL_SSLv23R�thasattrt
kSSLProtocol2Rt
kSSLProtocol3RRtkTLSProtocol11RRRRR
R?RHtSSLReadFuncR}tSSLWriteFuncR~tobjectRIR�R(((sO/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/securetransport.pyt<module>s�"

				9	5��	

Hacked By AnonymousFox1.0, Coded By AnonymousFox