Your IP : 3.147.77.119


Current Path : /opt/alt/python310/lib64/python3.10/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/asyncio/__pycache__/sslproto.cpython-310.opt-2.pyc

o

6��fCk�@s�ddlZddlZzddlZWneydZYnwddlmZddlmZddlmZddlm	Z	dd�Z
d	Zd
ZdZ
dZGd
d�de�ZGdd�dejej�ZGdd�dej�ZdS)�N�)�	constants)�	protocols)�
transports)�loggercCs"|rtd��t��}|sd|_|S)Nz(Server side SSL needs a valid SSLContextF)�
ValueError�sslZcreate_default_contextZcheck_hostname)�server_side�server_hostname�
sslcontext�r�7/opt/alt/python310/lib64/python3.10/asyncio/sslproto.py�_create_transport_contextsrZ	UNWRAPPEDZDO_HANDSHAKEZWRAPPEDZSHUTDOWNc@s|eZdZ	dZddd�Zedd��Zedd��Zed	d
��Zedd��Z	dd
d�Z
ddd�Zdd�Zddd�Z
ddd�ZdS)�_SSLPipeiNcCsJ	||_||_||_t|_t��|_t��|_d|_	d|_
d|_d|_dS�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__cC�	|jS�N)r�rr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_ssldata�r�callback�ssldata�appdatarrr
�do_handshakeis
�z_SSLPipe.do_handshakecCsD	|jtkr
td��|jtkrtd��t|_||_|�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_eof�s
z_SSLPipe.feed_eofFc
Cs�	|jtkr|r|g}g|fSg}g|fSd|_|r |j�|�g}g}zZ|jtkrA|j��t|_|j	r:|�	d�|rA||fWS|jtkrX	|j�
|j�}|�|�|sVnqGn%|jt
krp|j��d|_t|_|jro|��n
|jtkr}|�|j�
��Wn:tjtjfy�}z*t|dd�}|tjtjtjfvr�|jtkr�|j	r�|�	|��|tjk|_WYd}~nd}~ww|jjr�|�|j�
��||fS)NFT�errno)rrrr�writer)rr/r$r�read�max_size�appendr0Zunwraprr�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*�sj
�





�

�
��
��z_SSLPipe.feed_ssldatarc
Cs	|jtkr|t|�kr||d�g}ng}|t|�fSg}t|�}	d|_z|t|�kr9||j�||d��7}Wn5tjyo}z(t	|dd�}|j
dkrTtj}|_|tjtj
tjfvr_�|tjk|_WYd}~nd}~ww|jjr||�|j���|t|�ks�|jr�	||fSq#)NTFr3ZPROTOCOL_IS_SHUTDOWN)rr�len�
memoryviewrrr4rr8r:�reasonr;r3r<r=rr>r7r5)rr?�offsetr-ZviewrArBrrr
�feed_appdata�s@
�
����z_SSLPipe.feed_appdatar )F)r)�__name__�
__module__�__qualname__r6r�propertyrr"r#r%r/r1r2r*rGrrrr
r#s"








Krc@s�eZdZejjZdd�Zd$dd�Zdd�Z	dd	�Z
d
d�Zdd
�Ze
jfdd�Zdd�Zdd�Zdd�Zd%dd�Zdd�Zdd�Zedd��Zdd�Zd d!�Zd"d#�ZdS)&�_SSLProtocolTransportcCs||_||_d|_dSr)�_loop�
_ssl_protocol�_closed)r�loopZssl_protocolrrr
r s
z_SSLProtocolTransport.__init__NcCs	|j�||�Sr )rN�_get_extra_info�r�name�defaultrrr
�get_extra_info&sz$_SSLProtocolTransport.get_extra_infocCs|j�|�dSr )rN�_set_app_protocol)r�protocolr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|_|j��dS�NT)rOrN�_start_shutdownr!rrr
�close3sz_SSLProtocolTransport.closecCs*|js|d|��t|d�|��dSdS)Nzunclosed transport )�source)rO�ResourceWarningr^)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�	|jj��dSr )rNrb�
pause_readingr!rrr
reI�z#_SSLProtocolTransport.pause_readingcCrdr )rNrb�resume_readingr!rrr
rgQrfz$_SSLProtocolTransport.resume_readingcCs	|jj�||�dSr )rNrb�set_write_buffer_limits)rZhighZlowrrr
rhYsz-_SSLProtocolTransport.set_write_buffer_limitscC�	|jj��Sr )rNrb�get_write_buffer_sizer!rrr
rjnsz+_SSLProtocolTransport.get_write_buffer_sizecCrir )rNrb�get_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|tttf�stdt|�j����|sdS|j�|�dS)Nz+data: expecting a bytes-like instance, got )	�
isinstance�bytes�	bytearrayrD�	TypeError�typerHrN�_write_appdata�rr?rrr
r4}s�z_SSLProtocolTransport.writecCs	dSrrr!rrr
�
can_write_eof�sz#_SSLProtocolTransport.can_write_eofcCs	|j��d|_dSr\)rN�_abortrOr!rrr
�abort�s

z_SSLProtocolTransport.abortr )NN)rHrIrJrZ
_SendfileModeZFALLBACKZ_sendfile_compatiblerrUrXrZr[r^�warnings�warnrarcrergrhrjrkrKrlr4rtrvrrrr
rLs(



rLc@s�eZdZ				d+dd�Zdd�Zd,dd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zd,dd�Zdd�Z
dd�Zdd�Zdd�Zd d!�Zd"d#�Zd-d%d&�Zd'd(�Zd)d*�ZdS).�SSLProtocolFNTc		Cs�tdurtd��|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 )rF)rr(rZSSL_HANDSHAKE_TIMEOUTrrrr�_sslcontext�dict�_extra�collections�deque�_write_backlog�_write_buffer_size�_waiterrMrVrL�_app_transport�_sslpipe�_session_established�
_in_handshake�_in_shutdownrb�_call_connection_made�_ssl_handshake_timeout)	rrP�app_protocolrZwaiterr	r
Zcall_connection_madeZssl_handshake_timeoutrrr
r�sB���


zSSLProtocol.__init__cCs||_t|tj�|_dSr )rYrmrZBufferedProtocol�_app_protocol_is_buffer)rr�rrr
rV�s
�zSSLProtocol._set_app_protocolcCsD|jdurdS|j��s|dur|j�|�n|j�d�d|_dSr )r�Z	cancelledZ
set_exceptionZ
set_result�rrArrr
�_wakeup_waiter�s


zSSLProtocol._wakeup_waitercCs(	||_t|j|j|j�|_|��dSr )rbrrzrrr��_start_handshake)r�	transportrrr
�connection_made�s�zSSLProtocol.connection_madecCsp	|jrd|_|j�|jj|�n	|jdurd|j_d|_d|_t|dd�r+|j	�
�|�|�d|_d|_dS)NFT�_handshake_timeout_handle)
r�rM�	call_soonrY�connection_lostr�rOrbr:r��cancelr�r�r�rrr
r��s



zSSLProtocol.connection_lostcC�	|j��dSr )rY�
pause_writingr!rrr
r��zSSLProtocol.pause_writingcCr�r )rY�resume_writingr!rrr
r�r�zSSLProtocol.resume_writingcCs	|jdurdSz
|j�|�\}}Wn"ttfy�ty4}z
|�|d�WYd}~dSd}~ww|D]}|j�|�q7|D]A}|r}z|jrRt	�
|j|�n|j�|�WqBttfyc�ty|}z|�|d�WYd}~dSd}~ww|�
�dSdS)NzSSL error in data receivedz/application protocol failed to receive SSL data)r�r*�
SystemExit�KeyboardInterrupt�
BaseException�_fatal_errorrbr4r�rZ_feed_data_to_buffered_protorY�
data_receivedr])rr?r-r.�er@Zexrrr
r�sF
��������zSSLProtocol.data_receivedcCs~	z7|j��r
t�d|�|�t�|js)|j��}|r1t�	d�W|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_debugr�debugr��ConnectionResetErrorr�rY�eof_receivedZwarningrbr^)rZ	keep_openrrr
r�2s


��zSSLProtocol.eof_receivedcCs0||jvr
|j|S|jdur|j�||�S|Sr )r|rbrUrRrrr
rQHs



zSSLProtocol._get_extra_infocCs0|jrdS|jr|��dSd|_|�d�dS)NTr&)r�r�rurrr!rrr
r]PszSSLProtocol._start_shutdowncCs.|j�|df�|jt|�7_|��dS)Nr)rr7r�rC�_process_write_backlogrsrrr
rrYszSSLProtocol._write_appdatacCs\|j��rt�d|�|j��|_nd|_d|_|j�d�|j�	|j
|j�|_|�
�dS)Nz%r starts SSL handshakeT)r&r)rMr�rr��time�_handshake_start_timer�rr7Z
call_laterr��_check_handshake_timeoutr�r�r!rrr
r�^s

��zSSLProtocol._start_handshakecCs.|jdurd|j�d�}|�t|��dSdS)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
Csd|_|j��|jj}z|dur|�|��}Wn-ttfy"�tyE}zt	|t
j�r2d}nd}|�||�WYd}~dSd}~ww|j
��r\|j
��|j}t�d||d�|jj||��|��|d�|jrt|j�|j�|��d|_|j
�|j�dS)NFz1SSL handshake failed on verifying the certificatezSSL handshake failedz%r: SSL handshake took %.1f msg@�@)�peercert�cipher�compressionr"T)r�r�r�r�r"Zgetpeercertr�r�r�rmrr9r�rMr�r�r�rr�r|�updater�r�r�rYr�r�r�r�r�r�)rZ
handshake_excZsslobjr�rAr�Zdtrrr
�_on_handshake_completevs<
��
�z"SSLProtocol._on_handshake_completec
CsL|jdus
|jdurdSzgtt|j��D]\}|jd\}}|r)|j�||�\}}n|r5|j�|j�}d}n	|j�|j	�}d}|D]}|j�
|�q@|t|�krc||f|jd<|jjr_|j��WdS|jd=|j
t|�8_
qWdSttfy}�ty�}z|jr�|�|�n
|�|d�WYd}~dSWYd}~dSd}~ww)NrrzFatal error on SSL transport)rbr��rangerCrrGr/r�r1�	_finalizer4Z_pausedrgr�r�r�r�r�r�)r�ir?rFr-r@rArrr
r��sB�
����z"SSLProtocol._process_write_backlog�Fatal error on transportcCsZt|t�r|j��rtjd||dd�n|j�|||j|d��|jr+|j�|�dSdS)Nz%r: %sT)�exc_info)�messageZ	exceptionr�rW)	rm�OSErrorrMr�rr�Zcall_exception_handlerrbZ_force_close)rrAr�rrr
r��s

���zSSLProtocol._fatal_errorcCs"d|_|jdur|j��dSdSr )r�rbr^r!rrr
r��s
�zSSLProtocol._finalizecCs<z|jdur|j��W|��dSW|��dS|��wr )rbrvr�r!rrr
ru�s
�zSSLProtocol._abort)FNTNr )r�)rHrIrJrrVr�r�r�r�r�r�r�rQr]rrr�r�r�r�r�r�rurrrr
ry�s0
�.

&
		)
+ry)r}rwr�ImportError�rrr�logrrrr)r$r0�objectrZ_FlowControlMixinZ	TransportrLZProtocolryrrrr
�<module>s,�y�~

?>