3 ”ReÆ@ã@s\dZddlmZddlZddlmZddlmZ ddl m Z yddl m Z Wn$ek rpGdd „d eƒZ YnXdd lmZmZdd lmZydd lmZWn$ek rÂdZd dlmZYnXddlZddlZd dlmZddlZd dlmZddgZ dZ!ej"ej#j$ej%ej#j&iZ'e(edƒ�r@e(ej#dƒ�r@ej#j)e'ej*<e(edƒ�rhe(ej#dƒ�rhej#j+e'ej,<e(edƒ�r�e(ej#dƒ�r�ej#j-e'ej.<ej/ej#j0ej1ej#j2ej3ej#j2ej#j4iZ5e6dd„e5j7ƒDƒƒZ8dZ9ej!Z:ej;je?ƒZ@dd„ZAdd„ZBdd „ZCd!d"„ZDd#d$„ZEGd%d&„d&eFƒZGe�r6d/d(d)„ZHneZHeHeG_HGd*d+„d+eFƒZId,d-„ZJdS)0ab 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) é)Úabsolute_importN)Úx509)Úbackend)Ú _Certificate)ÚUnsupportedExtensionc@s eZdZdS)rN)Ú__name__Ú __module__Ú __qualname__©r r ú”/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyr7sr)ÚtimeoutÚerror)ÚBytesIO)Ú _fileobjecté)Úbackport_makefile)Úsix)ÚutilÚinject_into_urllib3Úextract_from_urllib3TÚPROTOCOL_SSLv3Ú SSLv3_METHODÚPROTOCOL_TLSv1_1ÚTLSv1_1_METHODÚPROTOCOL_TLSv1_2ÚTLSv1_2_METHODccs|]\}}||fVqdS)Nr )Ú.0ÚkÚvr r r ú gsri@cCs4tƒtt_ttj_tt_ttj_dt_dtj_dS)z7Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.TN)Ú_validate_dependencies_metÚPyOpenSSLContextrÚ SSLContextÚssl_ÚHAS_SNIÚ IS_PYOPENSSLr r r r rsscCs.tt_ttj_tt_ttj_dt_dtj_dS)z4Undo monkey-patching by :func:`inject_into_urllib3`.FN)Úorig_util_SSLContextrr"r#Úorig_util_HAS_SNIr$r%r r r r r€s cCsRddlm}t|ddƒdkr$tdƒ‚ddlm}|ƒ}t|ddƒdkrNtdƒ‚dS) z{ Verifies that PyOpenSSL's package-level dependencies have been met. Throws `ImportError` if they are not met. r)Ú ExtensionsÚget_extension_for_classNzX'cryptography' module missing required functionality. Try upgrading to v1.3.4 or newer.)ÚX509Ú_x509zS'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.)Zcryptography.x509.extensionsr(ÚgetattrÚ ImportErrorZOpenSSL.cryptor*)r(r*rr r r r ‹s  r cCs@dd„}d|kr|S||ƒ}|dkr(dStjdkr<|jdƒ}|S) a% 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). If the name cannot be idna-encoded then we return None signalling that the name given should be skipped. c Sspddlm}yFx:dD]2}|j|ƒr|t|ƒd…}|jdƒ|j|ƒSqW|j|ƒS|jjk rjdSXdS)zÒ 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. r)Úidnaú*.Ú.NÚascii)r/r0)Ú pip._vendorr.Ú startswithÚlenÚencodeÚcoreÚ IDNAError)Únamer.Úprefixr r r Ú idna_encode³s    z'_dnsname_to_stdlib..idna_encodeú:Nérzutf-8)r<r)ÚsysÚ version_infoÚdecode)r8r:r r r Ú_dnsname_to_stdlib¥s  r@cCs¾t|dƒr|jƒ}n tt|jƒ}y|jjtjƒj }WnLtj k rJgStj t tj tfk r€}ztjd|ƒgSd}~XnXdd„tt|jtjƒƒDƒ}|jdd„|jtjƒDƒƒ|S)zU Given an PyOpenSSL certificate, provides all the subject alternative names. Úto_cryptographyz­A problem was encountered with the certificate that prevented urllib3 from finding the SubjectAlternativeName field. This can affect certificate validation. The error was %sNcSsg|]}|dk rd|f‘qS)NÚDNSr )rr8r r r ú ûsz%get_subj_alt_name..css|]}dt|ƒfVqdS)z IP AddressN)Ústr)rr8r r r rsz$get_subj_alt_name..)ÚhasattrrArÚopenssl_backendr+Ú extensionsr)rZSubjectAlternativeNameÚvalueZExtensionNotFoundZDuplicateExtensionrZUnsupportedGeneralNameTypeÚ UnicodeErrorÚlogÚwarningÚmapr@Zget_values_for_typeZDNSNameÚextendZ IPAddress)Z peer_certÚcertÚextÚeÚnamesr r r Úget_subj_alt_nameÐs*    rRc@s„eZdZdZd!dd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z d"dd„Zdd„Zdd„Zdd„Zd S)#Ú WrappedSocketz§API-compatibility wrapper for Python OpenSSL's Connection-class. Note: _makefile_refs, _drop() and _reuse() are needed for the garbage collector of pypy. TcCs"||_||_||_d|_d|_dS)NrF)Ú connectionÚsocketÚsuppress_ragged_eofsÚ_makefile_refsÚ_closed)ÚselfrTrUrVr r r Ú__init__ s zWrappedSocket.__init__cCs |jjƒS)N)rUÚfileno)rYr r r r[szWrappedSocket.filenocCs*|jdkr|jd8_|jr&|jƒdS)Nré)rWrXÚclose)rYr r r Ú_decref_socketioss zWrappedSocket._decref_socketioscOsy|jj||Ž}Wnètjjk rX}z&|jr<|jdkrtˆtjƒs*ˆjdƒ‰|jj‡fdd„ƒ|jj|pJ|ƒdS)Nzutf-8csˆS)Nr )Ú_)Úpasswordr r ÚÑsz2PyOpenSSLContext.load_cert_chain..)r�Zuse_certificate_chain_filer–rÚ binary_typer5Z set_passwd_cbZuse_privatekey_file)rYÚcertfileÚkeyfilerŸr )rŸr Úload_cert_chainÌs    z PyOpenSSLContext.load_cert_chainFTcCsÄtjj|j|ƒ}t|tjƒr&|jdƒ}|dk r8|j|ƒ|j ƒxxy |j ƒWndtjj k r€t j ||jƒƒsztdƒ‚wBYn4tjjk r²}ztjd|ƒ‚WYdd}~XnXPqBWt||ƒS)Nzutf-8zselect timed outzbad handshake: %r)rcrdÚ Connectionr�r–rr—r5Zset_tlsext_host_nameZset_connect_stateÚ do_handshakerkrrlrmr rnrorprS)rYÚsockÚ server_sideÚdo_handshake_on_connectrVÚserver_hostnameÚcnxrPr r r Ú wrap_socketÔs"     zPyOpenSSLContext.wrap_socket)NNN)NN)FTTN)rrr r†rZÚpropertyr�Úsetterr’r•r™ršr¤r¬r r r r r!šs   r!cCs|dkS)Nrr )r«rZerr_noZ err_depthZ return_coder r r r”ôsr”ra)ra)Kr†Ú __future__rZ OpenSSL.SSLrcZ cryptographyrZ$cryptography.hazmat.backends.opensslrrFZ)cryptography.hazmat.backends.openssl.x509rZcryptography.x509rr-Ú ExceptionrUr r rgÚiorrZpackages.backports.makefilerÚloggingroÚpackagesrr=ÚrÚ__all__r$Ú PROTOCOL_TLSrdZ SSLv23_METHODÚPROTOCOL_TLSv1Z TLSv1_METHODrŠrErrrrrrÚ CERT_NONEZ VERIFY_NONEÚ CERT_OPTIONALZ VERIFY_PEERÚ CERT_REQUIREDZVERIFY_FAIL_IF_NO_PEER_CERTr“ÚdictÚitemsr‘ryr'r#r"r&Ú getLoggerrrJrrr r@rRÚobjectrSr‰r!r”r r r r Ú+sj               +6 Z