kghTddlZddlZddlZddlmZddlmZdZGddZdS)N)ProxySchemeUnsupported)sixi@ceZdZdZedZ d!dZdZdZdZ d"d Z d#d Z d$d Z d%dZ d%dZ d&dZdZdZd'dZdZdZdZdZdZdZdZdZdZd(dZd ZdS)) SSLTransportaL The SSLTransport wraps an existing socket and establishes an SSL connection. Contrary to Python's implementation of SSLSocket, it allows you to chain multiple TLS connections together. It's particularly useful if you need to implement TLS within TLS. The class supports most of the socket API operations. czt|ds*tjrtdtddS)z Raises a ProxySchemeUnsupported if the provided ssl_context can't be used for TLS in TLS. The only requirement is that the ssl_context provides the 'wrap_bio' methods. wrap_biozKTLS in TLS requires SSLContext.wrap_bio() which isn't supported on Python 2zXTLS in TLS requires SSLContext.wrap_bio() which isn't available on non-native SSLContextN)hasattrrPY2r) ssl_contexts /builddir/build/BUILD/imunify360-venv-2.6.0/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/urllib3/util/ssltransport.py$_validate_ssl_context_for_tls_in_tlsz1SSLTransport._validate_ssl_context_for_tls_in_tlssZ{J// w ,, -9  NTctj|_tj|_||_||_||j|j||_||jj dS)zV Create an SSLTransport around socket using the provided ssl_context. )server_hostnameN) ssl MemoryBIOincomingoutgoingsuppress_ragged_eofssocketr sslobj _ssl_io_loop do_handshake)selfrr rrs r __init__zSSLTransport.__init__,su     $8! !** M4=/+   $+233333rc|SNrs r __enter__zSSLTransport.__enter__?s rc.|dSr)close)r_s r __exit__zSSLTransport.__exit__Bs rc4|jSr)rfilenor s r r'zSSLTransport.filenoE{!!###rc.|||Sr)_wrap_ssl_read)rlenbuffers r readzSSLTransport.readHs""3///rrcV|dkrtd||S)Nrz+non-zero flags not allowed in calls to recv) ValueErrorr+)rr,flagss r recvzSSLTransport.recvKs. A::JKK K""3'''rc|dkrtd|r|t|}n|d}|||S)Nrz0non-zero flags not allowed in calls to recv_intor))r0r,r.)rr-nbytesr1s r recv_intozSSLTransport.recv_intoPsQ A::OPP P  v~[[FF ^Fyy(((rcX|dkrtdd}t|5}|d5}t|}||kr(|||d}||z }||k(dddn #1swxYwYddddS#1swxYwYdS)Nrz.non-zero flags not allowed in calls to sendallB)r0 memoryviewcastr,send)rdatar1countview byte_viewamountvs r sendallzSSLTransport.sendallYs1 A::MNN N    tyy~~ ^^F&..IIi/00 &..                                 s4B>B; BB BB BB#&B#cp|dkrtd||jj|}|S)Nrz+non-zero flags not allowed in calls to send)r0rrwrite)rr;r1responses r r:zSSLTransport.sendcs9 A::JKK K$$T[%6==rrc.t|hdkstd|dd|v}d|vp| }|s|sJd|v}d} |r| dz } |r| dz } tj|| } |jxjdz c_|d }|d kr t j}|d kr|std | S|r|rt j| | |} n1|rt j| |} n|sJt j | |} |r| St j | |||} || _ | S) a Python's httpclient uses makefile and buffered io when reading HTTP messages and we need to support it. This is unfortunately a copy and paste of socket.py makefile with small changes to point to the socket directly. >brEwz invalid mode z (only r, w, b allowed)rHrErGNrz!unbuffered streams must be binary) setr0rSocketIO_io_refsioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrappermode) rrU bufferingencodingerrorsnewlinewritingreadingbinaryrawmoderawr-texts r makefilezSSLTransport.makefileis~4yyOOO++*OPP P++,W!'!!!   sNG   sNGodG,, !  I q==.I >> F !DEEEJ  7w 7&sC;;FF  7&sI66FFNN7&sI66F  M&'BB  rcD||jjdSr)rrunwrapr s r rbzSSLTransport.unwraps! $+,-----rc8|jdSr)rr#r s r r#zSSLTransport.closes rFc6|j|Sr)r getpeercert)r binary_forms r rezSSLTransport.getpeercerts{&&{333rc4|jSr)rversionr s r rhzSSLTransport.versions{""$$$rc4|jSr)rcipherr s r rjzSSLTransport.cipherr(rc4|jSr)rselected_alpn_protocolr s r rlz#SSLTransport.selected_alpn_protocols{11333rc4|jSr)rselected_npn_protocolr s r rnz"SSLTransport.selected_npn_protocols{00222rc4|jSr)rshared_ciphersr s r rpzSSLTransport.shared_cipherss{))+++rc4|jSr)r compressionr s r rrzSSLTransport.compressions{&&(((rc:|j|dSr)r settimeout)rvalues r rtzSSLTransport.settimeouts u%%%%%rc4|jSr)r gettimeoutr s r rwzSSLTransport.gettimeouts{%%'''rc8|jdSr)r_decref_socketiosr s r ryzSSLTransport._decref_socketioss %%'''''rc ||jj||S#tj$r(}|jtjkr |jrYd}~dSd}~wwxYwNr)rrr.rSSLErrorerrno SSL_ERROR_EOFr)rr,r-es r r+zSSLTransport._wrap_ssl_readsm $$T[%5sFCC C|   w#+++0I+qqqqq  s #AAAAcd}d}|rd} ||}nD#tj$r2}|jtjtjfvr||j}Yd}~nd}~wwxYw|j}|j||d}ne|tjkrU|j t}|r|j |n|j ||S)z>Performs an I/O loop between incoming/outgoing and the socket.TNF)rr|r}SSL_ERROR_WANT_READSSL_ERROR_WANT_WRITErr.rrAr2 SSL_BLOCKSIZErrC write_eof)rfuncargs should_loopretr}rbufs r rzSSLTransport._ssl_io_loops  .E dDk<   73#:Crs ////// RRRRRRRRRRr