mfTddlZddlZddlZddlmZddlmZdZGddZdS)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 P/opt/imunify360/venv/lib64/python3.11/site-packages/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_eofssocketrsslobj _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)rfilenors 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()r/r+r-)rr,nbytesr0s 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)r/ memoryviewcastr+send)rdatar0countview 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)r/rrwrite)rr:r0responses r r9zSSLTransport.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. >brDwz invalid mode z (only r, w, b allowed)rGrDrFNrz!unbuffered streams must be binary) setr/rSocketIO_io_refsioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrappermode) rrT 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)rrunwraprs r razSSLTransport.unwraps! $+,-----rc8|jdSr)rr"rs r r"zSSLTransport.closes rFc6|j|Sr)r getpeercert)r binary_forms r rdzSSLTransport.getpeercerts{&&{333rc4|jSr)rversionrs r rgzSSLTransport.versions{""$$$rc4|jSr)rcipherrs r rizSSLTransport.cipherr'rc4|jSr)rselected_alpn_protocolrs r rkz#SSLTransport.selected_alpn_protocols{11333rc4|jSr)rselected_npn_protocolrs r rmz"SSLTransport.selected_npn_protocols{00222rc4|jSr)rshared_ciphersrs r rozSSLTransport.shared_cipherss{))+++rc4|jSr)r compressionrs r rqzSSLTransport.compressions{&&(((rc:|j|dSr)r settimeout)rvalues r rszSSLTransport.settimeouts u%%%%%rc4|jSr)r gettimeoutrs r rvzSSLTransport.gettimeouts{%%'''rc8|jdSr)r_decref_socketiosrs r rxzSSLTransport._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-rr@r1 SSL_BLOCKSIZErrB write_eof)rfuncargs should_loopretr|r~bufs r rzSSLTransport._ssl_io_loops  .E dDk<   73#:Crs 555555  RRRRRRRRRRr