Hacked By AnonymousFox

Current Path : /lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/
Upload File :
Current File : //lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyo

�
��abc@@s�dZddlmZddlZddlmZddlmZ	ddl
mZddlm
Z
mZddlmZydd	lmZWn'ek
r�dZd
dlmZnXddlZddlZd
dlmZddlZd
d
lmZddgZeZ iej!j"ej#6ej!j$ej%6Z&e'ed�rie'ej!d�riej!j(e&ej)<ne'ed�r�e'ej!d�r�ej!j*e&ej+<ny!e&j,iej!j-ej.6�Wne/k
r�nXiej!j0ej16ej!j2ej36ej!j2ej!j4ej56Z6e7d�e6j8�D��Z9dZ:ej Z;ej<j=Z>ej?e@�ZAd�ZBd�ZCd�ZDd�ZEd�ZFdeGfd��YZHer�dd�ZIneZIeIeH_IdeGfd ��YZJd!�ZKdS("sb
SSL with SNI_-support for Python 2. Follow these instructions if you would
like to verify SSL certificates in Python 2. Note, the default libraries do
*not* do certificate checking; you need to do additional work to validate
certificates yourself.

This needs the following packages installed:

* pyOpenSSL (tested with 16.0.0)
* cryptography (minimum 1.3.4, from pyopenssl)
* idna (minimum 2.0, from cryptography)

However, pyopenssl depends on cryptography, which depends on idna, so while we
use all three directly here we end up having relatively few packages required.

You can install them with the following command:

    pip install pyopenssl cryptography idna

To activate certificate checking, call
:func:`~urllib3.contrib.pyopenssl.inject_into_urllib3` from your Python code
before you begin making HTTP requests. This can be done in a ``sitecustomize``
module, or at any other time before your application begins using ``urllib3``,
like this::

    try:
        import urllib3.contrib.pyopenssl
        urllib3.contrib.pyopenssl.inject_into_urllib3()
    except ImportError:
        pass

Now you can use :mod:`urllib3` as you normally would, and it will support SNI
when the required modules are installed.

Activating this module also has the positive side effect of disabling SSL/TLS
compression in Python 2 (see `CRIME attack`_).

If you want to configure the default list of supported cipher suites, you can
set the ``urllib3.contrib.pyopenssl.DEFAULT_SSL_CIPHER_LIST`` variable.

.. _sni: https://en.wikipedia.org/wiki/Server_Name_Indication
.. _crime attack: https://en.wikipedia.org/wiki/CRIME_(security_exploit)
i(tabsolute_importN(tx509(tbackend(t_Certificate(ttimeoutterror(tBytesIO(t_fileobjecti(tbackport_makefile(tsix(tutiltinject_into_urllib3textract_from_urllib3tPROTOCOL_TLSv1_1tTLSv1_1_METHODtPROTOCOL_TLSv1_2tTLSv1_2_METHODcc@s!|]\}}||fVqdS(N((t.0tktv((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pys	<genexpr>`si@cC@sAt�ttj_tt_ttj_tt_ttj_dS(s7Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.N(t_validate_dependencies_mettPyOpenSSLContextR
tssl_t
SSLContexttHAS_SNItTruetIS_PYOPENSSL(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRms		cC@s:ttj_tt_ttj_tt_ttj_dS(s4Undo monkey-patching by :func:`inject_into_urllib3`.N(torig_util_SSLContextR
RRtorig_util_HAS_SNIRtFalseR(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRys
		cC@s{ddlm}t|dd�dkr7td��nddlm}|�}t|dd�dkrwtd��ndS(	s{
    Verifies that PyOpenSSL's package-level dependencies have been met.
    Throws `ImportError` if they are not met.
    i(t
Extensionstget_extension_for_classsX'cryptography' module missing required functionality.  Try upgrading to v1.3.4 or newer.(tX509t_x509sS'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.N(tcryptography.x509.extensionsRtgetattrtNonetImportErrortOpenSSL.cryptoR (RR R((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyR�s	cC@s:d�}||�}tjdkr6|jd�}n|S(s�
    Converts a dNSName SubjectAlternativeName field to the form used by the
    standard library on the given Python version.

    Cryptography produces a dNSName as a unicode string that was idna-decoded
    from ASCII bytes. We need to idna-encode that string to get it back, and
    then on Python 3 we also need to convert to unicode via UTF-8 (the stdlib
    uses PyUnicode_FromStringAndSize on it, which decodes via UTF-8).
    cS@siddl}xMddgD]?}|j|�r|t|�}|jd�|j|�SqW|j|�S(s�
        Borrowed wholesale from the Python Cryptography Project. It turns out
        that we can't just safely call `idna.encode`: it can explode for
        wildcard names. This avoids that problem.
        iNu*.u.tascii(tidnat
startswithtlentencode(tnameR(tprefix((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytidna_encode�siisutf-8(ii(tsystversion_infotdecode(R,R.((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyt_dnsname_to_stdlib�s

	cC@s�t|d�r|j�}ntt|j�}y|jjtj�j	}WnMtj
k
rcgStjtjtj
tfk
r�}tjd|�gSXg|jtj�D]}dt|�f^q�}|jd�|jtj�D��|S(sU
    Given an PyOpenSSL certificate, provides all the subject alternative names.
    tto_cryptographys�A problem was encountered with the certificate that prevented urllib3 from finding the SubjectAlternativeName field. This can affect certificate validation. The error was %stDNScs@s!|]}dt|�fVqdS(s
IP AddressN(tstr(RR,((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pys	<genexpr>�s(thasattrR3Rtopenssl_backendR!t
extensionsRRtSubjectAlternativeNametvaluetExtensionNotFoundtDuplicateExtensiontUnsupportedExtensiontUnsupportedGeneralNameTypetUnicodeErrortlogtwarningtget_values_for_typetDNSNameR2textendt	IPAddress(t	peer_certtcerttextteR,tnames((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytget_subj_alt_name�s(	
	.t
WrappedSocketcB@s�eZdZed�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
ed�Zd�Zd
�ZRS(s�API-compatibility wrapper for Python OpenSSL's Connection-class.

    Note: _makefile_refs, _drop() and _reuse() are needed for the garbage
    collector of pypy.
    cC@s1||_||_||_d|_t|_dS(Ni(t
connectiontsockettsuppress_ragged_eofst_makefile_refsRt_closed(tselfRMRNRO((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyt__init__�s
				cC@s
|jj�S(N(RNtfileno(RR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRT�scC@s;|jdkr!|jd8_n|jr7|j�ndS(Nii(RPRQtclose(RR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyt_decref_socketios�s	cO@s�y|jj||�}Wn�tjjk
rb}|jrM|jdkrMdStt|���n�tjj	k
r�}|jj
�tjjkr�dS�n^tjjk
r�t
j|j|jj��}|s�td��q�|j||�SnX|SdS(Ni����sUnexpected EOFtsThe read operation timed out(i����sUnexpected EOF(RMtrecvtOpenSSLtSSLtSysCallErrorROtargstSocketErrorR5tZeroReturnErrortget_shutdowntRECEIVED_SHUTDOWNt
WantReadErrorR
t
wait_for_readRNt
gettimeoutR(RRR\tkwargstdataRItrd((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRXs cO@s�y|jj||�SWn�tjjk
r`}|jrK|jdkrKdStt|���n�tjj	k
r�}|jj
�tjjkr�dS�nZtjjk
r�t
j|j|jj��}|s�td��q�|j||�SnXdS(Ni����sUnexpected EOFisThe read operation timed out(i����sUnexpected EOF(RMt	recv_intoRYRZR[ROR\R]R5R^R_R`RaR
RbRNRcR(RRR\RdRIRf((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRgscC@s|jj|�S(N(RNt
settimeout(RRR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRh*scC@s�x�tr�y|jj|�SWqtjjk
ritj|j|jj	��}|st
��qqqtjjk
r�}tt
|���qXqWdS(N(RRMtsendRYRZtWantWriteErrorR
twait_for_writeRNRcRR[R]R5(RRRetwrRI((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyt_send_until_done-s	cC@sGd}x:|t|�krB|j|||t!�}||7}q	WdS(Ni(R*RmtSSL_WRITE_BLOCKSIZE(RRRet
total_senttsent((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytsendall9scC@s|jj�dS(N(RMtshutdown(RR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRr?scC@sZ|jdkrGyt|_|jj�SWqVtjjk
rCdSXn|jd8_dS(Ni(RPRRQRMRURYRZtError(RR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRUCs	cC@se|jj�}|s|S|r8tjjtjj|�Sid|j�jfffd6t|�d6S(Nt
commonNametsubjecttsubjectAltName(	RMtget_peer_certificateRYtcryptotdump_certificatet
FILETYPE_ASN1tget_subjecttCNRK(RRtbinary_formR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytgetpeercertMs		cC@s|jd7_dS(Ni(RP(RR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyt_reuse_scC@s/|jdkr|j�n|jd8_dS(Ni(RPRU(RR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyt_dropbs
(t__name__t
__module__t__doc__RRSRTRVRXRgRhRmRqRrRURR~RR�(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRL�s									
	i����cC@s%|jd7_t|||dt�S(NiRU(RPRR(RRtmodetbufsize((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytmakefilejsRcB@s�eZdZd�Zed��Zejd��Zed��Zejd��Zd�Zd�Z	dddd�Zddd	�Ze
eedd
�ZRS(s�
    I am a wrapper class for the PyOpenSSL ``Context`` object. I am responsible
    for translating the interface of the standard library ``SSLContext`` object
    to calls into PyOpenSSL.
    cC@s;t||_tjj|j�|_d|_t|_dS(Ni(	t_openssl_versionstprotocolRYRZtContextt_ctxt_optionsRtcheck_hostname(RRR�((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRSys
	cC@s|jS(N(R�(RR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytoptionsscC@s||_|jj|�dS(N(R�R�tset_options(RRR:((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyR��s	cC@st|jj�S(N(t_openssl_to_stdlib_verifyR�tget_verify_mode(RR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytverify_mode�scC@s|jjt|t�dS(N(R�t
set_verifyt_stdlib_to_openssl_verifyt_verify_callback(RRR:((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyR��s	cC@s|jj�dS(N(R�tset_default_verify_paths(RR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyR��scC@s8t|tj�r$|jd�}n|jj|�dS(Nsutf-8(t
isinstanceR	t	text_typeR+R�tset_cipher_list(RRtciphers((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytset_ciphers�scC@sx|dk	r|jd�}n|dk	r<|jd�}n|jj||�|dk	rt|jjt|��ndS(Nsutf-8(R$R+R�tload_verify_locationsR(RRtcafiletcapathtcadata((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyR��sc@sR|jj|��dk	r8|jj�fd��n|jj|pJ|�dS(Nc@s�S(N((t
max_lengthtprompt_twicetuserdata(tpassword(sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyt<lambda>�RW(R�tuse_certificate_fileR$t
set_passwd_cbtuse_privatekey_file(RRtcertfiletkeyfileR�((R�sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytload_cert_chain�sc	C@stjj|j|�}t|tj�r<|jd�}n|dk	rX|j	|�n|j
�x�tr�y|j�Wnrtjj
k
r�tj||j��}|setd��qeqen,tjjk
r�}tjd|��nXPqeWt||�S(Nsutf-8sselect timed outsbad handshake: %r(RYRZt
ConnectionR�R�R	R�R+R$tset_tlsext_host_nametset_connect_stateRtdo_handshakeRaR
RbRcRRstssltSSLErrorRL(	RRtsocktserver_sidetdo_handshake_on_connectROtserver_hostnametcnxRfRI((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pytwrap_socket�s$
	N(R�R�R�RStpropertyR�tsetterR�R�R�R$R�R�RRR�(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyRss				cC@s
|dkS(Ni((R�Rterr_not	err_depthtreturn_code((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyR��s(LR�t
__future__RtOpenSSL.SSLRYtcryptographyRt$cryptography.hazmat.backends.opensslRR7t)cryptography.hazmat.backends.openssl.x509RRNRRR]tioRRR%R$tpackages.backports.makefileRtloggingR�tpackagesR	R/RWR
t__all__RRRZt
SSLv23_METHODtPROTOCOL_SSLv23tTLSv1_METHODtPROTOCOL_TLSv1R�R6RR
RRtupdatetSSLv3_METHODtPROTOCOL_SSLv3tAttributeErrortVERIFY_NONEt	CERT_NONEtVERIFY_PEERt
CERT_OPTIONALtVERIFY_FAIL_IF_NO_PEER_CERTt
CERT_REQUIREDR�tdicttitemsR�RnRRRRt	getLoggerR�R@RRRR2RKtobjectRLR�RR�(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyt<module>+sh
!!!
			
			3�	S

Hacked By AnonymousFox1.0, Coded By AnonymousFox