Your IP : 3.145.43.200


Current Path : /lib64/python3.8/asyncio/__pycache__/
Upload File :
Current File : //lib64/python3.8/asyncio/__pycache__/sslproto.cpython-38.opt-2.pyc

U

e5dJj�@s�ddlZddlZzddlZWnek
r4dZYnXddlmZddlmZddlmZddlmZddl	m
Z
dd	�Zd
ZdZ
dZd
ZGdd�de�ZGdd�dejej�ZGdd�dej�ZdS)�N�)�base_events)�	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.8/asyncio/sslproto.py�_create_transport_contextsrZ	UNWRAPPEDZDO_HANDSHAKEZWRAPPEDZSHUTDOWNc@szeZdZdZddd�Zedd��Zedd��Zed	d
��Zedd��Z	dd
d�Z
ddd�Zdd�Zddd�Z
ddd�ZdS)�_SSLPipeiNcCsH||_||_||_t|_t��|_t��|_d|_	d|_
d|_d|_dS�NF)
�_context�_server_side�_server_hostname�
_UNWRAPPED�_stater	Z	MemoryBIO�	_incoming�	_outgoing�_sslobj�
_need_ssldata�
_handshake_cb�_shutdown_cb)�self�contextr
rr
r
r�__init__8s

z_SSLPipe.__init__cCs|jS�N)r�rr
r
rrNsz_SSLPipe.contextcCs|jSr )rr!r
r
r�
ssl_objectSsz_SSLPipe.ssl_objectcCs|jSr )rr!r
r
r�need_ssldata[sz_SSLPipe.need_ssldatacCs
|jtkSr )r�_WRAPPEDr!r
r
r�wrappedasz_SSLPipe.wrappedcCsR|jtkrtd��|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_handshakejs	
�z_SSLPipe.do_handshakecCsB|jtkrtd��|jtkr$td��t|_||_|�d�\}}|S)Nzno security layer presentzshutdown in progressr&)rrr(�	_SHUTDOWNrr*r+r
r
r�shutdowns	

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}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�
��Wnztjtjfk
�rl}zRt|dd�}|tjtjtjfk�rP|jtk�rN|j	�rN|�	|��|tjk|_W5d}~XYnX|jj�r�|�|j�
��||fS)NF�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
rr*�sZ










�

z_SSLPipe.feed_ssldatarc
Cs|jtkr6|t|�kr&||d�g}ng}|t|�fSg}t|�}d|_z(|t|�krn||j�||d��7}Wnhtjk
r�}zHt	|dd�}|j
dkr�tj}|_|tjtj
tjfkr��|tjk|_W5d}~XYnX|jjr�|�|j���|t|�k�s|jrB�qqB||fS)NFr3ZPROTOCOL_IS_SHUTDOWN)rr�len�
memoryviewrrr4r	r8r:�reasonr;r3r<r=rr>r7r5)rr?�offsetr-ZviewrArBr
r
r�feed_appdata�s4

�z_SSLPipe.feed_appdata)N)N)N)F)r)�__name__�
__module__�__qualname__r6r�propertyrr"r#r%r/r1r2r*rGr
r
r
rr$s








Krc@s�eZdZejjZdd�Zd"dd�Zdd�Z	dd	�Z
d
d�Zdd
�Ze
jfdd�Zdd�Zdd�Zdd�Zd#dd�Zdd�Zedd��Zdd�Zdd�Zd d!�ZdS)$�_SSLProtocolTransportcCs||_||_d|_dSr)�_loop�
_ssl_protocol�_closed)r�loopZssl_protocolr
r
rr!sz_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_closing1sz _SSLProtocolTransport.is_closingcCsd|_|j��dS�NT)rOrN�_start_shutdownr!r
r
r�close4sz_SSLProtocolTransport.closecCs&|js"|d|��t|d�|��dS)Nzunclosed transport )�source)rO�ResourceWarningr^)rZ_warnr
r
r�__del__?sz_SSLProtocolTransport.__del__cCs |jj}|dkrtd��|��S)Nz*SSL transport has not been initialized yet)rN�
_transportr(�
is_reading)rZtrr
r
rrcDsz _SSLProtocolTransport.is_readingcCs|jj��dSr )rNrb�
pause_readingr!r
r
rrdJsz#_SSLProtocolTransport.pause_readingcCs|jj��dSr )rNrb�resume_readingr!r
r
rreRsz$_SSLProtocolTransport.resume_readingcCs|jj�||�dSr )rNrb�set_write_buffer_limits)rZhighZlowr
r
rrfZsz-_SSLProtocolTransport.set_write_buffer_limitscCs|jj��Sr )rNrb�get_write_buffer_sizer!r
r
rrgosz+_SSLProtocolTransport.get_write_buffer_sizecCs
|jjjSr )rNrb�_protocol_pausedr!r
r
rrhssz&_SSLProtocolTransport._protocol_pausedcCs<t|tttf�s$tdt|�j����|s,dS|j�|�dS)Nz+data: expecting a bytes-like instance, got )	�
isinstance�bytes�	bytearrayrD�	TypeError�typerHrN�_write_appdata�rr?r
r
rr4xs
z_SSLProtocolTransport.writecCsdSrr
r!r
r
r�
can_write_eof�sz#_SSLProtocolTransport.can_write_eofcCs|j��d|_dSr\)rN�_abortrOr!r
r
r�abort�s
z_SSLProtocolTransport.abort)N)NN)rHrIrJrZ
_SendfileModeZFALLBACKZ_sendfile_compatiblerrUrXrZr[r^�warnings�warnrarcrdrerfrgrKrhr4rprrr
r
r
rrLs$



rLc@s�eZdZd+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�tdkrtd��|dkr 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)r	r(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_protocolrZwaiterr
rZcall_connection_madeZssl_handshake_timeoutr
r
rr�s@��

zSSLProtocol.__init__cCs||_t|tj�|_dSr )rYrirZBufferedProtocol�_app_protocol_is_buffer)rr�r
r
rrV�s
�zSSLProtocol._set_app_protocolcCsD|jdkrdS|j��s:|dk	r.|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 )rbrrvrrr�_start_handshake)r�	transportr
r
r�connection_made�s�zSSLProtocol.connection_madecCsn|jr d|_|j�|jj|�n|jdk	r2d|j_d|_d|_t|dd�rT|j	�
�|�|�d|_d|_dS)NFT�_handshake_timeout_handle)
r�rM�	call_soonrY�connection_lostr~rOrbr:r��cancelr�rr�r
r
rr��s


zSSLProtocol.connection_lostcCs|j��dSr )rY�
pause_writingr!r
r
rr��szSSLProtocol.pause_writingcCs|j��dSr )rY�resume_writingr!r
r
rr�szSSLProtocol.resume_writingcCs"|jdkrdSz|j�|�\}}WnLttfk
r<�Yn4tk
rn}z|�|d�WY�dSd}~XYnX|D]}|j�|�qt|D]�}|�rz&|jr�t	�
|j|�n|j�|�WnPttfk
r��Yn8tk
�r
}z|�|d�WY�dSd}~XYnXq�|�
��qq�dS)NzSSL error in data receivedz/application protocol failed to receive SSL data)rr*�
SystemExit�KeyboardInterrupt�
BaseException�_fatal_errorrbr4r�rZ_feed_data_to_buffered_protorY�
data_receivedr])rr?r-r.�er@Zexr
r
rr�s<
��zSSLProtocol.data_receivedcCsTzB|j��rt�d|�|�t�|js@|j	�
�}|r@t�d�W5|j��XdS)Nz%r received EOFz?returning true from eof_received() has no effect when using ssl)rbr^rM�	get_debugr�debugr��ConnectionResetErrorr�rY�eof_receivedZwarning)rZ	keep_openr
r
rr�-s


zSSLProtocol.eof_receivedcCs4||jkr|j|S|jdk	r,|j�||�S|SdSr )rxrbrUrRr
r
rrQCs



zSSLProtocol._get_extra_infocCs.|jr
dS|jr|��nd|_|�d�dS)NTr&)r�r�rqrnr!r
r
rr]Ks
zSSLProtocol._start_shutdowncCs.|j�|df�|jt|�7_|��dS)Nr)r{r7r|rC�_process_write_backlogror
r
rrnTszSSLProtocol._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{r7Z
call_laterr��_check_handshake_timeoutr�r�r!r
r
rr�Ys

��zSSLProtocol._start_handshakecCs*|jdkr&d|j�d�}|�t|��dS)NTz$SSL handshake is taking longer than z! seconds: aborting the connection)r�r�r��ConnectionAbortedError)r�msgr
r
rr�hs
�z$SSLProtocol._check_handshake_timeoutc
Csd|_|j��|jj}z|dk	r&|�|��}Wnbttfk
rJ�YnJtk
r�}z,t	|t
j�rld}nd}|�||�WY�dSd}~XYnX|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�compressionr"T)r�r�r�rr"Zgetpeercertr�r�r�rir	r9r�rMr�r�r�rr�rx�updater�r�r�rYr�r~r�r�r�r�)rZ
handshake_excZsslobjr�rAr�Zdtr
r
r�_on_handshake_completeqs8

�z"SSLProtocol._on_handshake_completec
CsB|jdks|jdkrdSz�tt|j��D]�}|jd\}}|rR|j�||�\}}n*|rj|j�|j�}d}n|j�|j	�}d}|D]}|j�
|�q�|t|�kr�||f|jd<|jjr�|j��q�|jd=|j
t|�8_
q(Wn\ttfk
r��YnDtk
�r<}z$|j�r |�|�n|�|d�W5d}~XYnXdS)NrrzFatal error on SSL transport)rbr�rangerCr{rGr/r�r1�	_finalizer4Z_pausedrer|r�r�r�r�r�)r�ir?rFr-r@rAr
r
rr��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)�messageZ	exceptionr�rW)	ri�OSErrorrMr�rr�Zcall_exception_handlerrbZ_force_close)rrAr�r
r
rr��s

�zSSLProtocol._fatal_errorcCsd|_|jdk	r|j��dSr )rrbr^r!r
r
rr��s
zSSLProtocol._finalizecCs(z|jdk	r|j��W5|��XdSr )r�rbrrr!r
r
rrq�s
zSSLProtocol._abort)FNTN)N)N)r�)rHrIrJrrVr�r�r�r�r�r�r�rQr]rnr�r�r�r�r�r�rqr
r
r
rru�s.�
.

&
		)+
ru)ryrsr	�ImportError�rrrr�logrrrr)r$r0�objectrZ_FlowControlMixinZ	TransportrLZProtocolrur
r
r
r�<module>s*
y�x

?>