hBndZddlmZddlZddlZddlmZddlm Z  ddl m Z n#e $rGddeZ YnwxYwdd lmZdd lmZdd lmZ dd lmZn#e $r dZd dlmZYnwxYwddlZddlZddlZddlZd dlmZd dlmZd dl m!Z!ej"de#d ddgZ$dZ%ej&ej'j(e!ej'j(ej)ej'j*iZ+e,edr%e,ej'drej'j-e+ej.<e,edr%e,ej'drej'j/e+ej0<e,edr%e,ej'drej'j1e+ej2<ej3ej'j4ej5ej'j6ej7ej'j6ej'j8ziZ9e:de9;DZej?j@ZAejBeCZDdZEd ZFd!ZGd"ZHd#ZIGd$d%eJZKerd+d'ZLneZLeLeK_LGd(d)eJZMd*ZNdS),a TLS with SNI_-support for Python 2. Follow these instructions if you would like to verify TLS 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: .. code-block:: bash $ python -m 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: .. code-block:: python try: import pip._vendor.urllib3.contrib.pyopenssl as pyopenssl 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`_). .. _sni: https://en.wikipedia.org/wiki/Server_Name_Indication .. _crime attack: https://en.wikipedia.org/wiki/CRIME_(security_exploit) .. _pyopenssl: https://www.pyopenssl.org .. _cryptography: https://cryptography.io .. _idna: https://github.com/kjd/idna )absolute_importN)x509)backend)UnsupportedExtensionceZdZdS)rN)__name__ __module__ __qualname__/builddir/build/BUILD/imunify360-venv-2.5.2/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyrr;s r r)BytesIO)error)timeout) _fileobject)backport_makefile)util)six)PROTOCOL_TLS_CLIENTz'urllib3.contrib.pyopenssl' module is deprecated and will be removed in a future release of urllib3 2.x. Read more in this issue: https://github.com/urllib3/urllib3/issues/2680)category stacklevelinject_into_urllib3extract_from_urllib3TPROTOCOL_SSLv3 SSLv3_METHODPROTOCOL_TLSv1_1TLSv1_1_METHODPROTOCOL_TLSv1_2TLSv1_2_METHODc#$K|] \}}||fV dSNr ).0kvs r r&vs* V VDAq!Q V V V V V Vr i@cttt_ttj_t t_t tj_dt_dtj_dS)z7Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.TN)_validate_dependencies_metPyOpenSSLContextr SSLContextssl_HAS_SNI IS_PYOPENSSLr r r rrsJ   &DO+DIDLDID!DIr ctt_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 rrs>+DO/DI$DL)DID"DIr cddlm}t|ddtdddlm}|}t|ddtddS) z{ Verifies that PyOpenSSL's package-level dependencies have been met. Throws `ImportError` if they are not met. r) Extensionsget_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.)cryptography.x509.extensionsr2getattr ImportErrorOpenSSL.cryptor4)r2r4rs r r(r(s 877777z4d;;C 0   $##### 466DtWd##+ /   ,+r cd}d|vr|S||}|dStjdkr|d}|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"ddlm} dD][}||rD|t|d}|d||zcS\||S#|jj$rYdSwxYw)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)z*..Nascii) pip._vendorr< startswithlenencodecore IDNAError)namer<prefixs r idna_encodez'_dnsname_to_stdlib..idna_encodes %$$$$$ ' F F??6**FF .D!==11DKK4E4EEEEEF;;t$$ $y"   44 sAA;%A;;B B:N)rutf-8)sys version_infodecode)rErGs r _dnsname_to_stdlibrNs^$ d{{ ;t  D |t V # #{{7## Kr ct|dr|}nItjtjj|}t j|t} |j t j j }nc#t j $rgcYSt jtt jt"f$r'}t$d|gcYd}~Sd}~wwxYwdt)t*|t jD}|d|t jD|S)zU Given an PyOpenSSL certificate, provides all the subject alternative names. to_cryptographyzA problem was encountered with the certificate that prevented urllib3 from finding the SubjectAlternativeName field. This can affect certificate validation. The error was %sNcg|]}|d|f S)NDNSr r#rEs r z%get_subj_alt_name..s,          r c38K|]}dt|fVdS)z IP AddressN)strrSs r r&z$get_subj_alt_name.. s>&*s4yy!r )hasattrrPOpenSSLcryptodump_certificate FILETYPE_ASN1rload_der_x509_certificateopenssl_backend extensionsr3SubjectAlternativeNamevalueExtensionNotFoundDuplicateExtensionrUnsupportedGeneralNameType UnicodeErrorlogwarningmaprNget_values_for_typeDNSNameextend IPAddress) peer_certcertderextenamess r get_subj_alt_namerrs y+,,D((**n--gn.JIVV-c?CCo55d6QRRX  !   '    >      .  *C,C,CDL,Q,QRR   E  LL.1.E.Edn.U.U Ls$0)BC:-&C:C5/C:5C:cjeZdZdZddZdZdZdZdZdZ d Z d Z d Z d Z ddZdZdZdZdS) WrappedSocketzAPI-compatibility wrapper for Python OpenSSL's Connection-class. Note: _makefile_refs, _drop() and _reuse() are needed for the garbage collector of pypy. TcL||_||_||_d|_d|_dSNrF) connectionsocketsuppress_ragged_eofs_makefile_refs_closed)selfrwrxrys r __init__zWrappedSocket.__init__s+$ $8! r c4|jSr")rxfilenor|s r rzWrappedSocket.fileno"s{!!###r cv|jdkr|xjdzc_|jr|dSdS)Nr)rzr{closers r _decref_socketioszWrappedSocket._decref_socketios&sI   " "   1 $   <  JJLLLLL  r cr |jj|i|}|S#tjj$r9}|jr|jdkrYd}~dStt|d}~wtjj $r1|j tjj krYdStjj $rPtj|j|jst#d|j|i|cYStjj$r}t'jd|zd}~wwxYw)NzUnexpected EOFr The read operation timed outread error: %r)rwrecvrXSSL SysCallErrorryargs SocketErrorrVZeroReturnError get_shutdownRECEIVED_SHUTDOWN WantReadErrorr wait_for_readrx gettimeoutrErrorsslSSLError)r|rkwargsdatarps r rzWrappedSocket.recv,s` '4?'888D*K){' * * *( *QV7M-M-Msssss!#a&&))){*   ++--1NNNss{( 2 2 2%dk4;3I3I3K3KLL 2<=== ty$1&11111{  5 5 5,/!344 4 5s4D6AAAD6$A!D6D6D11D6cn |jj|i|S#tjj$r9}|jr|jdkrYd}~dStt|d}~wtjj $r1|j tjj krYdStjj $rPtj|j|jst#d|j|i|cYStjj$r}t'jd|zd}~wwxYw)Nrrrr)rw recv_intorXrrryrrrVrrrrrrrxrrrrr)r|rrrps r rzWrappedSocket.recv_intoEsX 5,4?,d=f== ={' * * *( *QV7M-M-Mqqqqq!#a&&))){*   ++--1NNNqq{( 7 7 7%dk4;3I3I3K3KLL 7<===%t~t6v66666{  5 5 5,/!344 4 5s4D4AAAD4"A!D4D4D//D4c6|j|Sr")rx settimeout)r|rs r rzWrappedSocket.settimeout\s{%%g...r cR |j|S#tjj$rBt j|j|jstYqtjj $r!}tt|d}~wwxYwr") rwsendrXrWantWriteErrorrwait_for_writerxrrrrrV)r|rrps r _send_until_donezWrappedSocket._send_until_done_s * *++D111;-   *4; 8N8N8P8PQQ$!))O;+ * * *!#a&&))) *sAB&2B&B!!B&cd}|t|kr?||||tz}||z }|t|k=dSdSNr)rArSSL_WRITE_BLOCKSIZE)r|r total_sentsents r sendallzWrappedSocket.sendalljsk 3t99$$((Z*/B"BBCD $ J 3t99$$$$$$r c8|jdSr")rwshutdownrs r rzWrappedSocket.shutdownrs   """""r c|jdkr< d|_|jS#tjj$rYdSwxYw|xjdzc_dS)NrT)rzr{rwrrXrrrs r rzWrappedSocket.closevss   " " # ,,...;$       1 $    s-AAFc|j}|s|S|r/tjtjj|Sd|jjffft|dS)N commonName)subjectsubjectAltName) rwget_peer_certificaterXrYrZr[ get_subjectCNrr)r| binary_formrs r getpeercertzWrappedSocket.getpeercerts3355 K  W>227>3OQUVV V'(8(8(:(:(=>@B/55   r c4|jSr")rwget_protocol_version_namers r versionzWrappedSocket.versions88:::r c&|xjdz c_dSNr)rzrs r _reusezWrappedSocket._reuses q r ch|jdkr|dS|xjdzc_dSr)rzrrs r _dropzWrappedSocket._drops;   " " JJLLLLL   1 $    r N)T)F)rr r __doc__r}rrrrrrrrrrrrrr r r rtrts $$$ 2555./// * * *###%%%     ;;;!!!%%%%%r rtrcH|xjdz c_t|||dS)NrT)r)rzr)r|modebufsizes r makefilers- q 4wd;;;;r ceZdZdZdZedZejdZedZejdZdZ dZ dd Z dd Z d Z ddZd S)r)z 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. ct||_tj|j|_d|_d|_dSrv)_openssl_versionsprotocolrXrContext_ctx_optionscheck_hostname)r|rs r r}zPyOpenSSLContext.__init__s<)(3 K'' 66  #r c|jSr")rrs r optionszPyOpenSSLContext.optionss }r cH||_|j|dSr")rr set_optionsr|r`s r rzPyOpenSSLContext.optionss%  e$$$$$r cJt|jSr")_openssl_to_stdlib_verifyrget_verify_moders r verify_modezPyOpenSSLContext.verify_modes()B)B)D)DEEr c\|jt|tdSr")r set_verify_stdlib_to_openssl_verify_verify_callbackrs r rzPyOpenSSLContext.verify_modes' 6u=?OPPPPPr c8|jdSr")rset_default_verify_pathsrs r rz)PyOpenSSLContext.set_default_verify_pathss **,,,,,r ct|tjr|d}|j|dS)NrJ) isinstancer text_typerBrset_cipher_list)r|cipherss r set_cipherszPyOpenSSLContext.set_cipherssC gs} - - .nnW--G !!'*****r NcV||d}||d} |j|||)|jt|dSdS#tjj$r}tjd|zd}~wwxYw)NrJz'unable to load trusted certificates: %r) rBrload_verify_locationsrrXrrrr)r|cafilecapathcadatarps r rz&PyOpenSSLContext.load_verify_locationss  ]]7++F  ]]7++F N I + +FF ; ; ;! //@@@@@"!{  N N N,H1LMM M NsAA88B( B##B(c|j|Lttjsd|jfd|j|p|dS)NrJcSr"r )_passwords r z2PyOpenSSLContext.load_cert_chain..sxr )ruse_certificate_chain_filerr binary_typerB set_passwd_cbuse_privatekey_file)r|certfilekeyfilers `r load_cert_chainz PyOpenSSLContext.load_cert_chains ,,X666  h88 4#??733 I # #$7$7$7$7 8 8 8 %%g&9:::::r cNd|D}|j|S)Nc6g|]}tj|Sr )r ensure_binary)r#ps r rTz7PyOpenSSLContext.set_alpn_protocols..s#===aS&q))===r )rset_alpn_protos)r| protocolss r set_alpn_protocolsz#PyOpenSSLContext.set_alpn_protocolss+==9=== y((333r FTcLtj|j|}t |t jr|d}||||  | n~#tjj $r9tj ||stdYctjj$r}t#jd|zd}~wwxYw t'||S)NrJTzselect timed outzbad handshake: %r)rXr ConnectionrrrrrBset_tlsext_host_nameset_connect_state do_handshakerrrrrrrrrt)r|sock server_sidedo_handshake_on_connectryserver_hostnamecnxrps r wrap_socketzPyOpenSSLContext.wrap_sockets&k$$TY55 os} 5 5 >-44W==O  &  $ $_ 5 5 5   <  """";,   )$0A0ABB6!"4555;$ < < <l#6#:;;; < S$'''sBA D#D6D  D)NNN)NN)FTTN)rr r rr}propertyrsetterrrrrrrrr r r r)r)s  $$$ X ^%%^%FFXFQQQ---+++ N N N N;;;;444 $! ((((((r r)c|dkSrr )rrerr_no err_depth return_codes r rrs Q;r )r)Or __future__rr9rX OpenSSL.SSL cryptographyr$cryptography.hazmat.backends.opensslrr]cryptography.x509rr8 Exceptioniorrxrrrrpackages.backports.makefilerloggingrrKwarningsrpackagesr util.ssl_rwarnDeprecationWarning__all__r, PROTOCOL_TLSr SSLv23_METHODPROTOCOL_TLSv1 TLSv1_METHODrrWrrrrr r CERT_NONE VERIFY_NONE CERT_OPTIONAL VERIFY_PEER CERT_REQUIREDVERIFY_FAIL_IF_NO_PEER_CERTrdictitemsrrr0r+r*r/ getLoggerrrerrr(rNrrobjectrtrr)rr r r r&sw..^'&&&&&KKKKKK 6666666        y      ''''''@"""""""@@@K????????@ ++++++  5   !"8 9  w{02 0  73 !!Egggk>&J&JE,3K,Dc() 73"##I =M(N(NI.5k.Hc*+ 73"##I =M(N(NI.5k.Hc*+M7;*w{.w{. k-. !D V V4M4S4S4U4U V V VVVLy+g!! " " "###   4(((V222jD%D%D%D%D%FD%D%D%N!<<<<< !H! [([([([([(v[([([(|s%;;A A('A(