%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/urllib3/contrib/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyc

�
nf�\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@ejAejBejCejDejEejFejGejHejIg!ZJiejKejLfe
jM6ZNeOe
d�rfejPejPfeNe
jQ<neOe
d�r�ejRejRfeNe
jS<neOe
d�r�ejKejKfeNe
jT<neOe
d�r�ejUejUfeNe
jV<neOe
d�rejLejLfeNe
jW<neOe
d�r8eNe
jMeNe
jX<nd�ZYd�ZZd�Z[d�Z\ej]e[�Z^ej_e\�Z`deafd��YZber�dd�Zcnded�Zceceb_cdeafd��YZddS( 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_makefiletinject_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(((sC/usr/lib/python2.7/site-packages/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(((sC/usr/lib/python2.7/site-packages/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((sC/usr/lib/python2.7/site-packages/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(RRRRRR R&t	string_atR!Rtwait_for_writeR#R$R%tsendR+R,R-R.R/R0(R1R2R3R4R5tbytes_to_writetdataR7R#tsentt
chunk_sentR<((sC/usr/lib/python2.7/site-packages/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_closedR0t	_keychaint
_keychain_dirt_client_cert_chainR!t_timeoutt
settimeout(tselfR ((sC/usr/lib/python2.7/site-packages/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(RR0tclose(ROt	exception((sC/usr/lib/python2.7/site-packages/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_SUITEStSSLSetEnabledCiphersRGR(ROtcipherstresult((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyt_set_ciphersOsc	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(tostpathtisfiletopentreadRRtSecTrustRefRtSSLCopyPeerTrustRGR&tbyrefRtssltSSLErrortSecTrustSetAnchorCertificatest!SecTrustSetAnchorCertificatesOnlyRtSecTrustResultTypetSecTrustEvaluateRt	CFReleaseRtkSecTrustResultUnspecifiedtkSecTrustResultProceedtvalue(	ROtverifyttrust_bundletft
cert_arrayttrustRYttrust_resultt	successes((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyt_custom_validate\s@


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('RtSSLCreateContextRRtkSSLClientSidetkSSLStreamTypeRGt
SSLSetIOFuncst_read_callback_pointert_write_callback_pointerRt_connection_ref_locktidRtSSLSetConnectiont
isinstancetbytestencodetSSLSetPeerDomainNameRURZtSSLSetProtocolVersionMintSSLSetProtocolVersionMaxtSSLSetSessionOptiont"kSSLSessionOptionBreakOnServerAuthRRRJRKRRLtSSLSetCertificateRStSSLHandshakeR.R R7terrSSLServerAuthCompletedRu(ROtserver_hostnameRnRotmin_versiontmax_versiontclient_certt
client_keytclient_key_passphraseRYthandle((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyt	handshake�s\





	

	

cC@s
|jj�S(N(R tfileno(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyR��scC@s;|jdkr!|jd8_n|jr7|j�ndS(Nii(RHRIRQ(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyt_decref_socketios�s	cC@s/tj|�}|j||�}|| }|S(N(R&tcreate_string_bufferR)(ROtbufsizR:t
bytes_readRB((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytrecv�s
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(RIRRUR&R'tfrom_buffertc_size_tRSRtSSLReadRGRcRR.RmR R7R*terrSSLClosedNoNotifyRQR(ROR:tnbytestprocessed_bytesRY((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyR)s 	
$

cC@s
||_dS(N(RM(ROR7((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyRN,scC@s|jS(N(RM(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyR!/sc
C@s�tjd�}|j��/tj|j|t|�tj|��}WdQX|tj	kr||j
dkr|tjd��n
t
|�|j
S(Nissend timed out(R&R�RSRtSSLWriteRGRURcRR.RmR R7R(RORBR�RY((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyR@2s
*
cC@sGd}x:|t|�krB|j|||t!�}||7}q	WdS(Ni(RUR@tSSL_WRITE_BLOCKSIZE(RORBt
total_sentRC((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytsendallCscC@s'|j��tj|j�WdQXdS(N(RSRtSSLCloseRG(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytshutdownIs
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(RHRRIRGRRjRRLRJRtSecKeychainDeletetshutiltrmtreeRKR RQ(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyRQMs				
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
ValueErrorRRaRRbRGR&RcRtSecTrustGetCertificateCounttSecTrustGetCertificateAtIndextAssertionErrortSecCertificateCopyDataRtCFDataGetLengthtCFDataGetBytePtrR>Rj(
ROtbinary_formRrtcertdatat	der_bytesRYt
cert_counttleaftdata_lengthR2((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytgetpeercert`s6
cC@s|jd7_dS(Ni(RH(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyt_reuse�scC@s/|jdkr|j�n|jd8_dS(Ni(RHRQ(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyt_drop�s
N(t__name__t
__module__t__doc__RPt
contextlibtcontextmanagerRSRZRuR�R�R�R�RR)RNR!R@R�R�RQRR�R�R�(((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyRF!s&		
	>	Z			(						>	i����cC@s%|jd7_t|||dt�S(NiRQ(RHR	R(ROtmodetbufsize((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytmakefile�strcO@sd}t|||||�S(Ni(R
(ROR�t	bufferingtargstkwargs((sC/usr/lib/python2.7/site-packages/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(ROtprotocol((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyRP�s					cC@stS(s�
        SecureTransport cannot have its hostname checking disabled. For more,
        see the comment on getpeercert() in this file.
        (R(RO((sC/usr/lib/python2.7/site-packages/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((RORm((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyR��scC@s|jS(N(R�(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytoptions�scC@s
||_dS(N(R�(RORm((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyR��scC@s|jrtjStjS(N(R�Rdt
CERT_REQUIREDt	CERT_NONE(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytverify_mode�scC@s"|tjkrtnt|_dS(N(RdR�RRR�(RORm((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyR��scC@sdS(N((RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytset_default_verify_paths�s
cC@s
|j�S(N(R�(RO((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytload_default_certs�scC@s%|tjjkr!td��ndS(Ns5SecureTransport doesn't support custom cipher strings(RRtDEFAULT_CIPHERSR�(RORX((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytset_ciphers�scC@s.|dk	rtd��n|p$||_dS(Ns1SecureTransport does not support cert directories(RR�R�(ROtcafiletcapathtcadata((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytload_verify_locationsscC@s||_||_||_dS(N(R�R�t_client_cert_passphrase(ROtcertfiletkeyfiletpassword((sC/usr/lib/python2.7/site-packages/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�RFR�R�R�R�R�R�R�R�(ROtsocktserver_sidetdo_handshake_on_connecttsuppress_ragged_eofsR�R4((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pytwrap_sockets
N(R�R�R�RPtpropertyR�tsetterR�R�R�R�R�RR�R�RRR�(((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyR�s 		
				(eR�t
__future__RR�R&R$tos.pathR\R�R Rdt	threadingtweakreftRt_securetransport.bindingsRRRt_securetransport.low_levelRRRRR	tImportErrorRtpackages.backports.makefileR
t__all__RRRRRRtWeakValueDictionaryRtLockR|R�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_SHARVt
kTLSProtocol1tkTLSProtocol12tPROTOCOL_SSLv23R�thasattrt
kSSLProtocol2R
t
kSSLProtocol3RRtkTLSProtocol11RRRRRR=REtSSLReadFuncRztSSLWriteFuncR{tobjectRFR�R(((sC/usr/lib/python2.7/site-packages/urllib3/contrib/securetransport.pyt<module>s�"
				7	6��	

Zerion Mini Shell 1.0