grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a ´iCkã@s¸ddlZddlZz ddlZWney2dZYn0ddlmZddlmZddlmZddlm Z dd„Z d Z d Z d Z d ZGd d„deƒZGdd„dejejƒZGdd„dejƒZdS)éNé)Ú constants)Ú protocols)Ú transports)ÚloggercCs"|r tdƒ‚t ¡}|sd|_|S)Nz(Server side SSL needs a valid SSLContextF)Ú ValueErrorÚsslZcreate_default_contextZcheck_hostname)Ú server_sideÚserver_hostnameÚ sslcontext©r ú(/usr/lib64/python3.9/asyncio/sslproto.pyÚ_create_transport_contexts rZ UNWRAPPEDZ DO_HANDSHAKEZWRAPPEDZSHUTDOWNc@s~eZdZdZdZddd„Zedd„ƒZedd „ƒZed d „ƒZ ed d „ƒZ ddd„Z ddd„Z dd„Z ddd„Zddd„ZdS)Ú_SSLPipeaAn SSL "Pipe". An SSL pipe allows you to communicate with an SSL/TLS protocol instance through memory buffers. It can be used to implement a security layer for an existing connection where you don't have access to the connection's file descriptor, or for some reason you don't want to use it. An SSL pipe can be in "wrapped" and "unwrapped" mode. In unwrapped mode, data is passed through untransformed. In wrapped mode, application level data is encrypted to SSL record level data and vice versa. The SSL record level is the lowest level in the SSL protocol suite and is what travels as-is over the wire. An SslPipe initially is in "unwrapped" mode. To start SSL, call do_handshake(). To shutdown SSL again, call unwrap(). iNcCsH||_||_||_t|_t ¡|_t ¡|_d|_ d|_ d|_ d|_ dS)a• The *context* argument specifies the ssl.SSLContext to use. The *server_side* argument indicates whether this is a server side or client side transport. The optional *server_hostname* argument can be used to specify the hostname you are connecting to. You may only specify this parameter if the _ssl module supports Server Name Indication (SNI). NF) Ú_contextÚ _server_sideÚ_server_hostnameÚ _UNWRAPPEDÚ_staterZ MemoryBIOÚ _incomingÚ _outgoingÚ_sslobjÚ _need_ssldataÚ _handshake_cbÚ _shutdown_cb)ÚselfÚcontextr r r r r Ú__init__7s   z_SSLPipe.__init__cCs|jS)z*The SSL context passed to the constructor.)r©rr r r rMsz_SSLPipe.contextcCs|jS)z^The internal ssl.SSLObject instance. Return None if the pipe is not wrapped. )rrr r r Ú ssl_objectRsz_SSLPipe.ssl_objectcCs|jS)zgWhether more record level data is needed to complete a handshake that is currently in progress.)rrr r r Ú need_ssldataZsz_SSLPipe.need_ssldatacCs |jtkS)zj Whether a security layer is currently in effect. Return False during handshake. )rÚ_WRAPPEDrr r r Úwrapped`sz_SSLPipe.wrappedcCsb|jtkrtdƒ‚|jj|j|j|j|jd�|_ t |_||_ |j ddd�\}}t |ƒdks^J‚|S)aLStart the SSL handshake. Return a list of ssldata. A ssldata element is a list of buffers The optional *callback* argument can be used to install a callback that will be called when the handshake is complete. The callback will be called with None if successful, else an exception instance. z"handshake in progress or completed)r r óT)Úonly_handshaker)rrÚ RuntimeErrorrZwrap_biorrrrrÚ _DO_HANDSHAKErÚ feed_ssldataÚlen©rÚcallbackÚssldataÚappdatar r r Ú do_handshakeis ýz_SSLPipe.do_handshakecCsj|jtkrtdƒ‚|jtkr$tdƒ‚|jttfvs6J‚t|_||_| d¡\}}|gksf|dgksfJ‚|S)a1Start the SSL shutdown sequence. Return a list of ssldata. A ssldata element is a list of buffers The optional *callback* argument can be used to install a callback that will be called when the shutdown is complete. The callback will be called without arguments. zno security layer presentzshutdown in progressr#)rrr%Ú _SHUTDOWNr!r&rr'r)r r r Úshutdown~s  z_SSLPipe.shutdowncCs2|j ¡| d¡\}}|gks.|dgks.J‚dS)z†Send a potentially "ragged" EOF. This method will raise an SSL_ERROR_EOF exception if the EOF is unexpected. r#N)rZ write_eofr')rr+r,r r r Úfeed_eof’s z_SSLPipe.feed_eofFc Cs’|jtkr"|r|g}ng}g|fSd|_|r8|j |¡g}g}z²|jtkrz|j ¡t|_|j rl|  d¡|rz||fWS|jtkr¦|j  |j ¡}|  |¡|s„qðq„nJ|jt krÖ|j ¡d|_t|_|jrð| ¡n|jtkrð|  |j  ¡¡Wn|tjtjf�yn}zZt|ddƒ}|tjtjtjfv�rN|jtk�rL|j �rL|  |¡‚|tjk|_WYd}~n d}~00|jj�rŠ|  |j  ¡¡||fS)a�Feed SSL record level data into the pipe. The data must be a bytes instance. It is OK to send an empty bytes instance. This can be used to get ssldata for a handshake initiated by this endpoint. Return a (ssldata, appdata) tuple. The ssldata element is a list of buffers containing SSL data that needs to be sent to the remote SSL. The appdata element is a list of buffers containing plaintext data that needs to be forwarded to the application. The appdata list may contain an empty buffer indicating an SSL "close_notify" alert. This alert must be acknowledged by calling shutdown(). FNÚerrno)rrrrÚwriter&rr-r!rÚreadÚmax_sizeÚappendr.ÚunwraprrÚSSLErrorÚCertificateErrorÚgetattrÚSSL_ERROR_WANT_READÚSSL_ERROR_WANT_WRITEÚSSL_ERROR_SYSCALLrÚpending)rÚdatar$r,r+ÚchunkÚexcÚ exc_errnor r r r'œsX             þ " z_SSLPipe.feed_ssldatarc Cs6d|krt|ƒksnJ‚|jtkrT|t|ƒkrD||d…g}ng}|t|ƒfSg}t|ƒ}d|_z(|t|ƒkrŒ||j ||d…¡7}Wnjtjyø}zPt |ddƒ}|j dkrÂtj }|_ |tj tj tjfvrØ‚|tj k|_WYd}~n d}~00|jj�r| |j ¡¡|t|ƒk�s.|jr`�q.q`||fS)a Feed plaintext data into the pipe. Return an (ssldata, offset) tuple. The ssldata element is a list of buffers containing record level data that needs to be sent to the remote SSL instance. The offset is the number of plaintext bytes that were processed, which may be less than the length of data. NOTE: In case of short writes, this call MUST be retried with the SAME buffer passed into the *data* argument (i.e. the id() must be the same). This is an OpenSSL requirement. A further particularity is that a short write will always have offset == 0, because the _ssl module does not enable partial writes. And even though the offset is zero, there will still be encrypted data in ssldata. rNFr1ZPROTOCOL_IS_SHUTDOWN)r(rrÚ memoryviewrrr2rr7r9Úreasonr:r1r;r<rr=r5r3)rr>Úoffsetr+Úviewr@rAr r r Ú feed_appdataçs6       þ" z_SSLPipe.feed_appdata)N)N)N)F)r)Ú__name__Ú __module__Ú __qualname__Ú__doc__r4rÚpropertyrrr r"r-r/r0r'rFr r r r r#s         Krc@sªeZdZejjZdd„Zd$dd„Zdd„Z dd „Z d d „Z d d „Z e jfdd„Zdd„Zdd„Zdd„Zd%dd„Zdd„Zdd„Zedd„ƒZdd„Zd d!„Zd"d#„ZdS)&Ú_SSLProtocolTransportcCs||_||_d|_dS)NF)Ú_loopÚ _ssl_protocolÚ_closed)rÚloopZ ssl_protocolr r r r sz_SSLProtocolTransport.__init__NcCs|j ||¡S)z#Get optional transport information.)rNÚ_get_extra_info©rÚnameÚdefaultr r r Úget_extra_info&sz$_SSLProtocolTransport.get_extra_infocCs|j |¡dS©N)rNÚ_set_app_protocol)rÚprotocolr r r Ú set_protocol*sz"_SSLProtocolTransport.set_protocolcCs|jjSrV)rNÚ _app_protocolrr r r Ú get_protocol-sz"_SSLProtocolTransport.get_protocolcCs|jSrV)rOrr r r Ú is_closing0sz _SSLProtocolTransport.is_closingcCsd|_|j ¡dS)a Close the transport. Buffered data will be flushed asynchronously. No more data will be received. After all buffered data is flushed, the protocol's connection_lost() method will (eventually) called with None as its argument. TN)rOrNÚ_start_shutdownrr r r Úclose3sz_SSLProtocolTransport.closecCs&|js"|d|›�t|d�| ¡dS)Nzunclosed transport )Úsource)rOÚResourceWarningr^)rÚ_warnr r r Ú__del__>sz_SSLProtocolTransport.__del__cCs |jj}|durtdƒ‚| ¡S)Nz*SSL transport has not been initialized yet)rNÚ _transportr%Ú is_reading)rÚtrr r r rdCsz _SSLProtocolTransport.is_readingcCs|jj ¡dS)z”Pause the receiving end. No data will be passed to the protocol's data_received() method until resume_reading() is called. N)rNrcÚ pause_readingrr r r rfIsz#_SSLProtocolTransport.pause_readingcCs|jj ¡dS)z…Resume the receiving end. Data received will once again be passed to the protocol's data_received() method. N)rNrcÚresume_readingrr r r rgQsz$_SSLProtocolTransport.resume_readingcCs|jj ||¡dS)a¦Set the high- and low-water limits for write flow control. These two values control when to call the protocol's pause_writing() and resume_writing() methods. If specified, the low-water limit must be less than or equal to the high-water limit. Neither value can be negative. The defaults are implementation-specific. If only the high-water limit is given, the low-water limit defaults to an implementation-specific value less than or equal to the high-water limit. Setting high to zero forces low to zero as well, and causes pause_writing() to be called whenever the buffer becomes non-empty. Setting low to zero causes resume_writing() to be called only once the buffer is empty. Use of zero for either limit is generally sub-optimal as it reduces opportunities for doing I/O and computation concurrently. N)rNrcÚset_write_buffer_limits)rÚhighÚlowr r r rhYsz-_SSLProtocolTransport.set_write_buffer_limitscCs |jj ¡S)z,Return the current size of the write buffer.)rNrcÚget_write_buffer_sizerr r r rknsz+_SSLProtocolTransport.get_write_buffer_sizecCs |jj ¡S)z•Get the high and low watermarks for write flow control. Return a tuple (low, high) where low and high are positive number of bytes.)rNrcÚget_write_buffer_limitsrr r r rlrsz-_SSLProtocolTransport.get_write_buffer_limitscCs |jjjSrV)rNrcÚ_protocol_pausedrr r r rmxsz&_SSLProtocolTransport._protocol_pausedcCs<t|tttfƒs$tdt|ƒj›�ƒ‚|s,dS|j |¡dS)z�Write some data bytes to the transport. This does not block; it buffers the data and arranges for it to be sent out asynchronously. z+data: expecting a bytes-like instance, got N) Ú isinstanceÚbytesÚ bytearrayrBÚ TypeErrorÚtyperGrNÚ_write_appdata©rr>r r r r2}sÿz_SSLProtocolTransport.writecCsdS)zAReturn True if this transport supports write_eof(), False if not.Fr rr r r Ú can_write_eofŠsz#_SSLProtocolTransport.can_write_eofcCs|j ¡d|_dS)zÝClose the transport immediately. Buffered data will be lost. No more data will be received. The protocol's connection_lost() method will (eventually) be called with None as its argument. TN)rNÚ_abortrOrr r r ÚabortŽs z_SSLProtocolTransport.abort)N)NN)rGrHrIrZ _SendfileModeZFALLBACKZ_sendfile_compatiblerrUrYr[r\r^ÚwarningsÚwarnrbrdrfrgrhrkrlrKrmr2rurwr r r r rLs&     rLc@s°eZdZdZd,dd„Zdd„Zd-d d „Zd d „Zd d„Zdd„Z dd„Z dd„Z dd„Z d.dd„Z dd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd/d&d'„Zd(d)„Zd*d+„ZdS)0Ú SSLProtocolz‰SSL protocol. Implementation of SSL on top of a socket using incoming and outgoing buffers which are ssl.MemoryBIO objects. FNTc CsÔtdurtdƒ‚|dur tj}n|dkr6td|›�ƒ‚|sDt||ƒ}||_|rZ|sZ||_nd|_||_t |d�|_ t   ¡|_ d|_||_||_| |¡t|j|ƒ|_d|_d|_d|_d|_d|_||_||_dS)Nzstdlib ssl module not availablerz7ssl_handshake_timeout should be a positive number, got )r F)rr%rZSSL_HANDSHAKE_TIMEOUTrrrrÚ _sslcontextÚdictÚ_extraÚ collectionsÚdequeÚ_write_backlogÚ_write_buffer_sizeÚ_waiterrMrWrLÚ_app_transportÚ_sslpipeÚ_session_establishedÚ _in_handshakeÚ _in_shutdownrcÚ_call_connection_madeÚ_ssl_handshake_timeout) rrPÚ app_protocolr Úwaiterr r Zcall_connection_madeZssl_handshake_timeoutr r r r sBÿÿÿ   zSSLProtocol.__init__cCs||_t|tjƒ|_dSrV)rZrnrZBufferedProtocolÚ_app_protocol_is_buffer)rrŠr r r rWÎs ÿzSSLProtocol._set_app_protocolcCsD|jdurdS|j ¡s:|dur.|j |¡n |j d¡d|_dSrV)r‚Ú cancelledÚ set_exceptionÚ set_result©rr@r r r Ú_wakeup_waiterÓs   zSSLProtocol._wakeup_waitercCs&||_t|j|j|jƒ|_| ¡dS)zXCalled when the low-level connection is made. Start the SSL handshake. N)rcrr{rrr„Ú_start_handshake)rÚ transportr r r Úconnection_madeÝs þzSSLProtocol.connection_madecCsn|jr d|_|j |jj|¡n|jdur2d|j_d|_d|_t|ddƒrT|j   ¡|  |¡d|_d|_ dS)zÝCalled when the low-level connection is lost or closed. The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed). FNTÚ_handshake_timeout_handle) r…rMÚ call_soonrZÚconnection_lostrƒrOrcr9r•Úcancelr‘r„r�r r r r—ès    zSSLProtocol.connection_lostcCs|j ¡dS)z\Called when the low-level transport's buffer goes over the high-water mark. N)rZÚ pause_writingrr r r r™szSSLProtocol.pause_writingcCs|j ¡dS)z^Called when the low-level transport's buffer drains below the low-water mark. N)rZÚresume_writingrr r r ršszSSLProtocol.resume_writingc Cs|jdurdSz|j |¡\}}WnHttfy:‚Yn2tyj}z| |d¡WYd}~dSd}~00|D]}|j |¡qp|D]Ž}|�rz&|jr¨t   |j |¡n |j   |¡WnLttfy΂Yn6t�y}z| |d¡WYd}~dSd}~00q†|  ¡�qq†dS)zXCalled when some SSL data is received. The argument is a bytes object. NzSSL error in data receivedz/application protocol failed to receive SSL data)r„r'Ú SystemExitÚKeyboardInterruptÚ BaseExceptionÚ _fatal_errorrcr2rŒrZ_feed_data_to_buffered_protorZÚ data_receivedr])rr>r+r,Úer?Úexr r r rŸ s8  ÿÿzSSLProtocol.data_receivedcCs^zL|j ¡rt d|¡| t¡|js@|j ¡}|r@t  d¡W|j   ¡n |j   ¡0dS)aCalled when the other end of the low-level stream is half-closed. If this returns a false value (including None), the transport will close itself. If it returns a true value, closing the transport is up to the protocol. z%r received EOFz?returning true from eof_received() has no effect when using sslN) rMÚ get_debugrÚdebugr‘ÚConnectionResetErrorr†rZÚ eof_receivedÚwarningrcr^)rZ keep_openr r r r¥2s     zSSLProtocol.eof_receivedcCs4||jvr|j|S|jdur,|j ||¡S|SdSrV)r}rcrUrRr r r rQHs    zSSLProtocol._get_extra_infocCs.|jr dS|jr| ¡nd|_| d¡dS)NTr#)r‡r†rvrsrr r r r]Ps  zSSLProtocol._start_shutdowncCs.|j |df¡|jt|ƒ7_| ¡dS)Nr)r€r5r�r(Ú_process_write_backlogrtr r r rsYszSSLProtocol._write_appdatacCs\|j ¡r$t d|¡|j ¡|_nd|_d|_|j d¡|j  |j |j ¡|_ |  ¡dS)Nz%r starts SSL handshakeT)r#r)rMr¢rr£ÚtimeÚ_handshake_start_timer†r€r5Z call_laterr‰Ú_check_handshake_timeoutr•r§rr r r r’^s    ÿÿzSSLProtocol._start_handshakecCs*|jdur&d|j›d�}| t|ƒ¡dS)NTz$SSL handshake is taking longer than z! seconds: aborting the connection)r†r‰ržÚConnectionAbortedError)rÚmsgr r r rªms  ÿÿz$SSLProtocol._check_handshake_timeoutc Cs d|_|j ¡|jj}z|dur&|‚| ¡}Wn^ttfyH‚YnHtyŽ}z0t |t j ƒrhd}nd}|  ||¡WYd}~dSd}~00|j  ¡r¼|j  ¡|j}t d||d¡|jj|| ¡| ¡|d�|jrì|j |j¡| ¡d|_|j  |j¡dS)NFz1SSL handshake failed on verifying the certificatezSSL handshake failedz%r: SSL handshake took %.1f msg@�@)ÚpeercertÚcipherÚ compressionrT)r†r•r˜r„rZ getpeercertr›rœr�rnrr8ržrMr¢r¨r©rr£r}Úupdater®r¯rˆrZr”rƒr‘r…r–r§)rZ handshake_excZsslobjr­r@r¬Zdtr r r Ú_on_handshake_completevs8     ýz"SSLProtocol._on_handshake_completec CsP|jdus|jdurdSzÔtt|jƒƒD]À}|jd\}}|rR|j ||¡\}}n*|rj|j |j¡}d}n|j |j ¡}d}|D]}|j  |¡q€|t|ƒkrÎ||f|jd<|jj s¸J‚|jj rÊ|j  ¡qê|jd=|jt|ƒ8_q(Wn^ttf�y‚YnFt�yJ}z,|j�r*| |¡n | |d¡WYd}~n d}~00dS)NrrzFatal error on SSL transport)rcr„Úranger(r€rFr-r±r/Ú _finalizer2r Z_pausedrgr�r›rœr�r†rž)rÚir>rDr+r?r@r r r r§Ÿs<ÿ    z"SSLProtocol._process_write_backlogúFatal error on transportcCsVt|tƒr(|j ¡r@tjd||dd�n|j |||j|dœ¡|jrR|j |¡dS)Nz%r: %sT)Úexc_info)ÚmessageÚ exceptionr“rX) rnÚOSErrorrMr¢rr£Zcall_exception_handlerrcZ _force_close)rr@r·r r r ržÊs  üzSSLProtocol._fatal_errorcCsd|_|jdur|j ¡dSrV)r„rcr^rr r r r³Øs zSSLProtocol._finalizecCs0z |jdur|j ¡W| ¡n | ¡0dSrV)rcrwr³rr r r rvÞs  zSSLProtocol._abort)FNTN)N)N)rµ)rGrHrIrJrrWr‘r”r—r™ršrŸr¥rQr]rsr’rªr±r§ržr³rvr r r r rz™s.ý .  &   )+ rz)r~rxrÚ ImportErrorÚrrrÚlogrrrr&r!r.ÚobjectrZ_FlowControlMixinZ TransportrLÚProtocolrzr r r r Ús(       yÿ~