o ?OgCk@sddlZddlZzddlZWn eydZYnwddlmZddlmZddlmZddlm Z ddZ d Z d Z d Z d ZGd ddeZGdddejejZGdddejZdS)N) constants) protocols) transports)loggercCs"|rtdt}|sd|_|S)Nz(Server side SSL needs a valid SSLContextF) ValueErrorsslZcreate_default_contextZcheck_hostname) server_sideserver_hostname sslcontextr 7/opt/alt/python310/lib64/python3.10/asyncio/sslproto.py_create_transport_contexts rZ UNWRAPPEDZ DO_HANDSHAKEZWRAPPEDZSHUTDOWNc@s|eZdZ dZdddZeddZeddZed d Zed d Z dd dZ dddZ ddZ dddZ dddZdS)_SSLPipeiNcCsJ ||_||_||_t|_t|_t|_d|_ d|_ d|_ d|_ dSNF) _context _server_side_server_hostname _UNWRAPPED_staterZ MemoryBIO _incoming _outgoing_sslobj _need_ssldata _handshake_cb _shutdown_cb)selfcontextr r r r r __init__7s    z_SSLPipe.__init__cC |jSN)rrr r r rMsz_SSLPipe.contextcCrr )rr!r r r ssl_objectRsz_SSLPipe.ssl_objectcCrr )rr!r r r need_ssldataZsz_SSLPipe.need_ssldatacCs |jtkSr )r_WRAPPEDr!r r r wrapped`s z_SSLPipe.wrappedcCsT |jtkr td|jj|j|j|j|jd|_ t |_||_ |j ddd\}}|S)Nz"handshake in progress or completed)r r T)only_handshake) rr RuntimeErrorrZwrap_biorrrrr _DO_HANDSHAKEr feed_ssldatarcallbackssldataappdatar r r do_handshakeis z_SSLPipe.do_handshakecCsD |jtkr td|jtkrtdt|_||_|d\}}|S)Nzno security layer presentzshutdown in progressr&)rrr( _SHUTDOWNrr*r+r r r shutdown~s  z_SSLPipe.shutdowncCs |j|d\}}dS)Nr&)rZ write_eofr*)rr-r.r r r feed_eofs z_SSLPipe.feed_eofFc Cs |jtkr|r|g}g|fSg}g|fSd|_|r |j|g}g}zZ|jtkrA|jt|_|j r:| d|rA||fWS|jtkrX |j |j }| ||sVnqGn%|jt krp|jd|_t|_|jro|n |jtkr}| |j Wn:tjtjfy}z*t|dd}|tjtjtjfvr|jtkr|j r| ||tjk|_WYd}~nd}~ww|jjr| |j ||fS)NFTerrno)rrrrwriter)rr/r$rreadmax_sizeappendr0ZunwraprrSSLErrorCertificateErrorgetattrSSL_ERROR_WANT_READSSL_ERROR_WANT_WRITESSL_ERROR_SYSCALLrpending)rdatar'r.r-chunkexc exc_errnor r r r*sj              z_SSLPipe.feed_ssldatarc Cs |jtkr|t|kr||dg}ng}|t|fSg}t|} d|_z|t|kr9||j||d7}Wn5tjyo}z(t |dd}|j dkrTtj }|_ |tj tj tjfvr_|tj k|_WYd}~nd}~ww|jjr|||j|t|ks|jr ||fSq#)NTFr3ZPROTOCOL_IS_SHUTDOWN)rrlen memoryviewrrr4rr8r:reasonr;r3r<r=rr>r7r5)rr?offsetr-ZviewrArBr r r feed_appdatas@       z_SSLPipe.feed_appdatar )F)r)__name__ __module__ __qualname__r6rpropertyrr"r#r%r/r1r2r*rGr r r r r#s"        Krc@seZdZejjZddZd$ddZddZ dd Z d d Z d d Z e jfddZddZddZddZd%ddZddZddZeddZddZd d!Zd"d#ZdS)&_SSLProtocolTransportcCs||_||_d|_dSr)_loop _ssl_protocol_closed)rloopZ ssl_protocolr r r r s z_SSLProtocolTransport.__init__NcCs |j||Sr )rN_get_extra_infornamedefaultr r r get_extra_info&sz$_SSLProtocolTransport.get_extra_infocCs|j|dSr )rN_set_app_protocol)rprotocolr r r set_protocol*sz"_SSLProtocolTransport.set_protocolcCs|jjSr )rN _app_protocolr!r r r get_protocol-sz"_SSLProtocolTransport.get_protocolcCs|jSr )rOr!r r r is_closing0sz _SSLProtocolTransport.is_closingcCs d|_|jdSNT)rOrN_start_shutdownr!r r r close3sz_SSLProtocolTransport.closecCs*|js|d|t|d|dSdS)Nzunclosed transport )source)rOResourceWarningr^)rZ_warnr r r __del__>s z_SSLProtocolTransport.__del__cCs |jj}|dur td|S)Nz*SSL transport has not been initialized yet)rN _transportr( is_reading)rZtrr r r rcCsz _SSLProtocolTransport.is_readingcC |jjdSr )rNrb pause_readingr!r r r reIz#_SSLProtocolTransport.pause_readingcCrdr )rNrbresume_readingr!r r r rgQrfz$_SSLProtocolTransport.resume_readingcCs |jj||dSr )rNrbset_write_buffer_limits)rZhighZlowr r r rhYsz-_SSLProtocolTransport.set_write_buffer_limitscC |jjSr )rNrbget_write_buffer_sizer!r r r rjns z+_SSLProtocolTransport.get_write_buffer_sizecCrir )rNrbget_write_buffer_limitsr!r r r rkrs z-_SSLProtocolTransport.get_write_buffer_limitscCs |jjjSr )rNrb_protocol_pausedr!r r r rlxs z&_SSLProtocolTransport._protocol_pausedcCs> t|tttfstdt|j|sdS|j|dS)Nz+data: expecting a bytes-like instance, got ) isinstancebytes bytearrayrD TypeErrortyperHrN_write_appdatarr?r r r r4}sz_SSLProtocolTransport.writecCs dSrr r!r r r can_write_eofsz#_SSLProtocolTransport.can_write_eofcCs |jd|_dSr\)rN_abortrOr!r r r aborts  z_SSLProtocolTransport.abortr )NN)rHrIrJrZ _SendfileModeZFALLBACKZ_sendfile_compatiblerrUrXrZr[r^warningswarnrarcrergrhrjrkrKrlr4rtrvr r r r rLs(     rLc@seZdZ   d+ddZddZd,dd Zd d Zd d ZddZddZ ddZ ddZ d,ddZ ddZ ddZddZddZd d!Zd"d#Zd-d%d&Zd'd(Zd)d*ZdS). SSLProtocolFNTc Cstdurtd|durtj}n |dkrtd||s"t||}||_|r-|s-||_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 _sslcontextdict_extra collectionsdeque_write_backlog_write_buffer_size_waiterrMrVrL_app_transport_sslpipe_session_established _in_handshake _in_shutdownrb_call_connection_made_ssl_handshake_timeout) rrP app_protocolr Zwaiterr r Zcall_connection_madeZssl_handshake_timeoutr r r rsB    zSSLProtocol.__init__cCs||_t|tj|_dSr )rYrmrZBufferedProtocol_app_protocol_is_buffer)rrr r r rVs zSSLProtocol._set_app_protocolcCsD|jdurdS|js|dur|j|n|jdd|_dSr )rZ cancelledZ set_exceptionZ set_resultrrAr r r _wakeup_waiters    zSSLProtocol._wakeup_waitercCs( ||_t|j|j|j|_|dSr )rbrrzrrr_start_handshake)r transportr r r connection_mades zSSLProtocol.connection_madecCsp |jrd|_|j|jj|n |jdurd|j_d|_d|_t|ddr+|j | |d|_d|_ dS)NFT_handshake_timeout_handle) rrM call_soonrYconnection_lostrrOrbr:rcancelrrrr r r rs     zSSLProtocol.connection_lostcC |jdSr )rY pause_writingr!r r r rzSSLProtocol.pause_writingcCrr )rYresume_writingr!r r r rrzSSLProtocol.resume_writingc Cs  |jdurdSz |j|\}}Wn"ttfyty4}z ||dWYd}~dSd}~ww|D]}|j|q7|D]A}|r}z|jrRt |j |n|j |WqBttfycty|}z||dWYd}~dSd}~ww| dSdS)NzSSL error in data receivedz/application protocol failed to receive SSL data)rr* SystemExitKeyboardInterrupt BaseException _fatal_errorrbr4rrZ_feed_data_to_buffered_protorY data_receivedr])rr?r-r.er@Zexr r r r sF   zSSLProtocol.data_receivedcCs~ z7|jr td||t|js)|j}|r1t dW|j dSW|j dSW|j dS|j w)Nz%r received EOFz?returning true from eof_received() has no effect when using ssl) rM get_debugrdebugrConnectionResetErrorrrY eof_receivedZwarningrbr^)rZ keep_openr r r r2s     zSSLProtocol.eof_receivedcCs0||jvr |j|S|jdur|j||S|Sr )r|rbrUrRr r r rQHs   zSSLProtocol._get_extra_infocCs0|jrdS|jr|dSd|_|ddS)NTr&)rrrurrr!r r r r]Ps  zSSLProtocol._start_shutdowncCs.|j|df|jt|7_|dS)Nr)rr7rrC_process_write_backlogrsr r r rrYs zSSLProtocol._write_appdatacCs\|jrtd||j|_nd|_d|_|jd|j |j |j |_ | dS)Nz%r starts SSL handshakeT)r&r)rMrrrtime_handshake_start_timerrr7Z call_laterr_check_handshake_timeoutrrr!r r r r^s     zSSLProtocol._start_handshakecCs.|jdurd|jd}|t|dSdS)NTz$SSL handshake is taking longer than z! seconds: aborting the connection)rrrConnectionAbortedError)rmsgr r r rms z$SSLProtocol._check_handshake_timeoutc Csd|_|j|jj}z |dur||}Wn-ttfy"tyE}zt |t j r2d}nd}| ||WYd}~dSd}~ww|j r\|j |j}td||d|jj||||d|jrt|j|j|d|_|j |jdS)NFz1SSL handshake failed on verifying the certificatezSSL handshake failedz%r: SSL handshake took %.1f msg@@)peercertcipher compressionr"T)rrrrr"Z getpeercertrrrrmrr9rrMrrrrrr|updaterrrrYrrrrrr)rZ handshake_excZsslobjrrArZdtr r r _on_handshake_completevs<     z"SSLProtocol._on_handshake_completec CsL|jdus |jdur dSzgtt|jD]\}|jd\}}|r)|j||\}}n|r5|j|j}d}n |j|j }d}|D]}|j |q@|t|krc||f|jd<|jj r_|j WdS|jd=|j t|8_ qWdSttfy}ty}z|jr||n ||dWYd}~dSWYd}~dSd}~ww)NrrzFatal error on SSL transport)rbrrangerCrrGr/rr1 _finalizer4Z_pausedrgrrrrrr)rir?rFr-r@rAr r r rsB   z"SSLProtocol._process_write_backlogFatal error on transportcCsZt|tr|jrtjd||ddn |j|||j|d|jr+|j|dSdS)Nz%r: %sT)exc_info)messageZ exceptionrrW) rmOSErrorrMrrrZcall_exception_handlerrbZ _force_close)rrArr r r rs  zSSLProtocol._fatal_errorcCs"d|_|jdur|jdSdSr )rrbr^r!r r r rs zSSLProtocol._finalizecCs<z|jdur|jW|dSW|dS|wr )rbrvrr!r r r rus    zSSLProtocol._abort)FNTNr )r)rHrIrJrrVrrrrrrrrQr]rrrrrrrrrur r r r rys0 .   &   ) + ry)r}rwr ImportErrorrrrlogrrrr)r$r0objectrZ_FlowControlMixinZ TransportrLZProtocolryr r r r s,      y~