\hB~dZddlmZddlZddlZddlmZddlm Z  ddl m Z dd lmZdd lmZdd lmZ dd lmZddlZddlZddlZddlZd dlmZd dlmZd dl m!Z!ejDde#d ddgZ$dZ%ejLejNjPe!ejNjPejRejNjTiZ+e,edr6e,ejNdr#ejNjZe+ej\<e,edr6e,ejNdr#ejNj^e+ej`<e,edr6e,ejNdr#ejNjbe+ejd<ejfejNjhejjejNjlejnejNjlejNjpziZ9e:de9jwDZej~jZAejeCZDdZEd ZFd!ZGd"ZHd#ZIGd$d%eJZKerd*d&ZLneZLeLeK_LGd'd(eJZMd)ZNy#e $rGddeZ YwxYw#e $r dZd dlmZY~wxYw)+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)UnsupportedExtensionc eZdZy)rN)__name__ __module__ __qualname__h/root/niggaflix-v3/playground/venv/lib/python3.12/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|] \}}||f ywNr ).0kvs r r&vs VDAq!Q Vsi@cttt_ttj_t t_t tj_dt_dtj_y)z7Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.TN)_validate_dependencies_metPyOpenSSLContextr SSLContextssl_HAS_SNI IS_PYOPENSSLr r r rrsD &DO+DIIDLDIID!DIIr ctt_ttj_tt_ttj_dt_dtj_y)z4Undo monkey-patching by :func:`inject_into_urllib3`.FN)orig_util_SSLContextrr*r+orig_util_HAS_SNIr,r-r r r rrs>+DO/DII$DL)DIID"DIIr cddlm}t|dd tdddlm}|}t|dd tdy) 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[ 8z4d;C 0  $ 6DtWd#+ /  ,r cvd}d|vr|S||}|ytjdk\r|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. cddlm} dD]F}|j|s|t|d}|j d|j |zcS|j |S#|j j $rYywxYw)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??6*F .D!==1DKK4EEE F;;t$ $yy""  sA$2A$A$$B?B:N)rutf-8)sys version_infodecode)rErGs r _dnsname_to_stdlibrNsH$ d{ t D |  V #{{7# Kr c t|dr|j}nRtjj tjj |}t j|t} |jjt jj}t)t*|j-t j.Dcgc]}|d|f }}|j1d|j-t j2D|S#t j$rgcYSt jtt j t"f$r"}t$j'd|gcYd}~Sd}~wwxYwcc}w)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 %sNDNSc36K|]}dt|fyw)z IP AddressN)str)r#rEs r r&z$get_subj_alt_name.. s&*s4y!s)hasattrrPOpenSSLcryptodump_certificate FILETYPE_ASN1rload_der_x509_certificateopenssl_backend extensionsr3SubjectAlternativeNamevalueExtensionNotFoundDuplicateExtensionrUnsupportedGeneralNameType UnicodeErrorlogwarningmaprNget_values_for_typeDNSNameextend IPAddress) peer_certcertderexterEnamess r get_subj_alt_namerosH y+,((*nn--gnn.J.JIV--c?Coo55d6Q6QRXX:*C,C,CDLL,QR       E   LL.1.E.Ednn.U LG  ! !   ''    >    . s*13D FE>0,E>E93E>9E>cheZdZdZddZdZdZdZdZdZ dZ d Z d Z d Z dd Zd ZdZdZy) WrappedSocketzAPI-compatibility wrapper for Python OpenSSL's Connection-class. Note: _makefile_refs, _drop() and _reuse() are needed for the garbage collector of pypy. cJ||_||_||_d|_d|_yNrF) connectionsocketsuppress_ragged_eofs_makefile_refs_closed)selfrtrurvs r __init__zWrappedSocket.__init__s'$ $8! r c6|jjSr")rufilenorys r r|zWrappedSocket.fileno"s{{!!##r c|jdkDr|xjdzc_|jr|jyy)Nr)rwrxcloser}s r _decref_socketioszWrappedSocket._decref_socketios&s6    "   1 $  << JJL r c |jj|i|}|S#tjj$r9}|j r|j dk(rYd}~ytt|d}~wtjj$r9|jjtjjk(rYytjj$rXtj|j|jj!s t#d|j|i|cYStjj$$r}t'j(d|zd}~wwxYw)NzUnexpected EOFr The read operation timed outread error: %r)rtrecvrUSSL SysCallErrorrvargs SocketErrorrSZeroReturnError get_shutdownRECEIVED_SHUTDOWN WantReadErrorr wait_for_readru gettimeoutrErrorsslSSLError)ryrkwargsdatarms r rzWrappedSocket.recv,s" '4??''88D*K){{'' *((QVV7M-M!#a&)){{** ++-1N1NN{{(( 2%%dkk4;;3I3I3KL<== tyy$1&11{{   5,,/!34 4 5s4 E5A1A11AE5A2E5<E5E00E5c |jj|i|S#tjj$r9}|j r|j dk(rYd}~ytt|d}~wtjj$r9|jjtjjk(rYytjj$rXtj|j|jj!s t#d|j|i|cYStjj$$r}t'j(d|zd}~wwxYw)Nrrrr)rt recv_intorUrrrvrrrSrrrrrrrurrrrr)ryrrrms r rzWrappedSocket.recv_intoEs 5,4??,,d=f= ={{'' *((QVV7M-M!#a&)){{** ++-1N1NN{{(( 7%%dkk4;;3I3I3KL<==%t~~t6v66{{   5,,/!34 4 5s4E3A/A//AE3A2E3:E3E..E3c8|jj|Sr")ru settimeout)ryrs r rzWrappedSocket.settimeout\s{{%%g..r cn |jj|S#tjj$rEt j |j|jjs tY~tjj$r}tt|d}~wwxYwr") rtsendrUrWantWriteErrorrwait_for_writerurrrrrS)ryrrms r _send_until_donezWrappedSocket._send_until_done_s *++D11;;-- **4;; 8N8N8PQ!)O;;++ *!#a&)) *sAB4?B4B//B4cd}|t|kr0|j|||tz}||z }|t|kr/yyNr)rArSSL_WRITE_BLOCKSIZE)ryr total_sentsents r sendallzWrappedSocket.sendalljsM 3t9$((Z*/B"BCD $ J 3t9$r c8|jjyr")rtshutdownr}s r rzWrappedSocket.shutdownrs   "r c|jdkr" d|_|jjS|xjdzc_y#tj j $rYywxYw)NrT)rwrxrtrrUrrr}s r rzWrappedSocket.closevs`    " # ,,..   1 $ ;;$$  s AA('A(c|jj}|s|S|r8tjj tjj |Sd|j jffft|dS)N commonName)subjectsubjectAltName) rtget_peer_certificaterUrVrWrX get_subjectCNro)ry binary_formrs r getpeercertzWrappedSocket.getpeercertsu335K >>227>>3O3OQUV V'(8(8(8(:(=(=>@B/5  r c6|jjSr")rtget_protocol_version_namer}s r versionzWrappedSocket.versions88::r c.|xjdz c_yNr)rwr}s r _reusezWrappedSocket._reuses q r cn|jdkr|jy|xjdzc_yr)rwrr}s r _dropzWrappedSocket._drops*    " JJL   1 $ r N)T)F)rr r __doc__rzr|rrrrrrrrrrrrr r r rqrqsM $ 25./ *#%  ;!%r rqcJ|xjdz c_t|||dS)NrT)r)rwr)rymodebufsizes r makefilers$ q 4wd;;r ceZdZdZdZedZejdZedZejdZdZ dZ dd Z dd Z d Z dd Zy )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||_tjj |j|_d|_d|_yrs)_openssl_versionsprotocolrUrContext_ctx_optionscheck_hostname)ryrs r rzzPyOpenSSLContext.__init__s7)(3 KK'' 6  #r c|jSr")rr}s r optionszPyOpenSSLContext.optionss }}r cH||_|jj|yr")rr set_optionsryr]s r rzPyOpenSSLContext.optionss  e$r cDt|jjSr")_openssl_to_stdlib_verifyrget_verify_moder}s r verify_modezPyOpenSSLContext.verify_modes()B)B)DEEr cR|jjt|tyr")r set_verify_stdlib_to_openssl_verify_verify_callbackrs r rzPyOpenSSLContext.verify_modes 6u=?OPr c8|jjyr")rset_default_verify_pathsr}s r rz)PyOpenSSLContext.set_default_verify_pathss **,r ct|tjr|jd}|jj |y)NrJ) isinstancer text_typerBrset_cipher_list)rycipherss r set_cipherszPyOpenSSLContext.set_cipherss0 gs}} -nnW-G !!'*r NcR||jd}||jd} |jj|||%|jjt|yy#tj j $r}tjd|zd}~wwxYw)NrJz'unable to load trusted certificates: %r) rBrload_verify_locationsrrUrrrr)rycafilecapathcadatarms r rz&PyOpenSSLContext.load_verify_locationss  ]]7+F  ]]7+F N II + +FF ;! //@"{{   N,,H1LM M NsAA,,B& B!!B&c|jj|Ittjsj d|jj fd|jj|xs|y)NrJcSr"r )_passwords r z2PyOpenSSLContext.load_cert_chain..sxr )ruse_certificate_chain_filerr binary_typerB set_passwd_cbuse_privatekey_file)rycertfilekeyfilers `r load_cert_chainz PyOpenSSLContext.load_cert_chainsa ,,X6  h8#??73 II # #$7 8 %%g&9:r c|Dcgc]}tj|}}|jj|Scc}wr")r ensure_binaryrset_alpn_protos)ry protocolsps r set_alpn_protocolsz#PyOpenSSLContext.set_alpn_protocolss:3<=aS&&q)= =yy((33>s>cDtjj|j|}t |t j r|jd}||j||j |j t'||S#tjj$r2tj||js tdYmtjj $r}t#j$d|zd}~wwxYw)NrJzselect timed outzbad handshake: %r)rUr ConnectionrrrrrBset_tlsext_host_nameset_connect_state do_handshakerrrrrrrrrq)rysock server_sidedo_handshake_on_connectrvserver_hostnamecnxrms r wrap_socketzPyOpenSSLContext.wrap_socketskk$$TYY5 os}} 5-44W=O  &  $ $_ 5  <  " S$'';;,, ))$0AB!"455;;$$ <ll#6#:;; r"s.^'K 6'@"  +  5   !"8 9  w{{0022 00  3 !ggkk>&J,3KK,D,Dc(() 3"# =M(N.5kk.H.Hc**+ 3"# =M(N.5kk.H.Hc**+MM7;;**w{{..w{{.. kk--. ! V4M4S4S4U VVLLyy++g! "# 4(V2jD%FD%N< !H! [(v[(|Y  y  @K??@s"JJ+J('J(+ J<;J<