Your IP : 18.226.187.232


Current Path : /opt/alt/python35/lib64/python3.5/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/asyncio/__pycache__/sslproto.cpython-35.opt-2.pyc



���]]e�
@sddlZddlZyddlZWnek
rBdZYnXddlmZddlmZddlmZddlmZddl	m
Z
dd	�Zd
d�ZdZ
d
ZdZdZGdd�de�ZGdd�dejej�ZGdd�dej�ZdS)�N�)�base_events)�compat)�	protocols)�
transports)�loggercCs�|rtd��ttd�r?tj�}|s�d|_nLtjtj�}|jtjO_|jtj	O_|j
�tj|_|S)Nz(Server side SSL needs a valid SSLContext�create_default_contextF)
�
ValueError�hasattr�sslr�check_hostnameZ
SSLContextZPROTOCOL_SSLv23�optionsZOP_NO_SSLv2ZOP_NO_SSLv3Zset_default_verify_pathsZ
CERT_REQUIRED�verify_mode)�server_side�server_hostname�
sslcontext�r�-/opt/alt/python35/lib64/python3.5/sslproto.py�_create_transport_contexts
rcCs
ttd�S)N�	MemoryBIO)r
rrrrr�_is_sslproto_available%srZ	UNWRAPPEDZDO_HANDSHAKEZWRAPPEDZSHUTDOWNc@s�eZdZdZddd�Zedd��Zedd	��Zed
d��Zedd
��Z	ddd�Z
ddd�Zdd�Zddd�Z
ddd�ZdS)�_SSLPipe�iNcCsj||_||_||_t|_tj�|_tj�|_d|_	d|_
d|_d|_dS)NF)
�_context�_server_side�_server_hostname�
_UNWRAPPED�_staterr�	_incoming�	_outgoing�_sslobj�
_need_ssldata�
_handshake_cb�_shutdown_cb)�self�contextrrrrr�__init__Ds							z_SSLPipe.__init__cCs|jS)N)r)r$rrrr%Zsz_SSLPipe.contextcCs|jS)N)r )r$rrr�
ssl_object_sz_SSLPipe.ssl_objectcCs|jS)N)r!)r$rrr�need_ssldatagsz_SSLPipe.need_ssldatacCs
|jtkS)N)r�_WRAPPED)r$rrr�wrappedmsz_SSLPipe.wrappedcCs||jtkrtd��|jj|j|jd|jd|j�|_	t
|_||_|jddd�\}}|S)Nz"handshake in progress or completedrr��only_handshakeT)
rr�RuntimeErrorrZwrap_biorrrrr �
_DO_HANDSHAKEr"�feed_ssldata)r$�callback�ssldata�appdatarrr�do_handshakevs					z_SSLPipe.do_handshakecCsa|jtkrtd��|jtkr6td��t|_||_|jd�\}}|S)Nzno security layer presentzshutdown in progressr+)rrr-�	_SHUTDOWNr#r/)r$r0r1r2rrr�shutdown�s			z_SSLPipe.shutdowncCs&|jj�|jd�\}}dS)Nr+)rZ	write_eofr/)r$r1r2rrr�feed_eof�s
z_SSLPipe.feed_eofFcCs|jtkr1|r!|g}ng}g|fSd|_|rP|jj|�g}g}y�|jtkr�|jj�t|_|j	r�|j	d�|r�||fS|jtkr�x�|jj
|j�}|j|�|s�Pq�Wni|jt
kr0|jj�d|_t|_|jrU|j�n%|jtkrU|j|jj
��Wn�tjtjfk
r�}zlt|dd�tjtjtjfkr�|jtkr�|j	r�|j	|��|jtjk|_WYdd}~XnX|jjr|j|jj
��||fS)NF�errno)rrr!r�writer.r r3r)r"�read�max_size�appendr4Zunwrapr#r�SSLError�CertificateError�getattr�SSL_ERROR_WANT_READ�SSL_ERROR_WANT_WRITE�SSL_ERROR_SYSCALLr7r�pending)r$�datar,r2r1�chunk�excrrrr/�sV
	
		



			

(z_SSLPipe.feed_ssldatarcCsl|jtkrM|t|�kr7||d�g}ng}|t|�fSg}t|�}xd|_y6|t|�kr�||jj||d��7}Wn|tjk
r}zY|j	dkr�tj
|_|jtj
tjtj
fkr��|jtj
k|_WYdd}~XnX|jjrB|j|jj��|t|�ks]|jrbPqbW||fS)NFZPROTOCOL_IS_SHUTDOWN)rr�len�
memoryviewr!r r8rr<�reasonr?r7r@rArrBr;r9)r$rC�offsetr1�viewrErrr�feed_appdata�s2	$(z_SSLPipe.feed_appdatai)�__name__�
__module__�__qualname__r:r&�propertyr%r'r(r*r3r5r6r/rKrrrrr0s	
Jrc@s�eZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Ze	j
rldd�Zdd�Zdd�Z
dddd�Zdd�Zdd�Zdd�Zdd�ZdS)�_SSLProtocolTransportcCs(||_||_||_d|_dS)NF)�_loop�
_ssl_protocol�
_app_protocol�_closed)r$�loopZssl_protocol�app_protocolrrrr&)s			z_SSLProtocolTransport.__init__NcCs|jj||�S)N)rR�_get_extra_info)r$�name�defaultrrr�get_extra_info0sz$_SSLProtocolTransport.get_extra_infocCs
||_dS)N)rS)r$�protocolrrr�set_protocol4sz"_SSLProtocolTransport.set_protocolcCs|jS)N)rS)r$rrr�get_protocol7sz"_SSLProtocolTransport.get_protocolcCs|jS)N)rT)r$rrr�
is_closing:sz _SSLProtocolTransport.is_closingcCsd|_|jj�dS)NT)rTrR�_start_shutdown)r$rrr�close=s	z_SSLProtocolTransport.closecCs+|js'tjd|t�|j�dS)Nzunclosed transport %r)rT�warnings�warn�ResourceWarningr`)r$rrr�__del__Ls	z_SSLProtocolTransport.__del__cCs|jjj�dS)N)rR�
_transport�
pause_reading)r$rrrrfQsz#_SSLProtocolTransport.pause_readingcCs|jjj�dS)N)rRre�resume_reading)r$rrrrgYsz$_SSLProtocolTransport.resume_readingcCs|jjj||�dS)N)rRre�set_write_buffer_limits)r$�high�lowrrrrhasz-_SSLProtocolTransport.set_write_buffer_limitscCs|jjj�S)N)rRre�get_write_buffer_size)r$rrrrkvsz+_SSLProtocolTransport.get_write_buffer_sizecCsTt|tttf�s6tdjt|�j���|s@dS|jj	|�dS)Nz/data: expecting a bytes-like instance, got {!r})
�
isinstance�bytes�	bytearrayrG�	TypeError�format�typerLrR�_write_appdata)r$rCrrrr8zs	z_SSLProtocolTransport.writecCsdS)NFr)r$rrr�
can_write_eof�sz#_SSLProtocolTransport.can_write_eofcCs|jj�dS)N)rR�_abort)r$rrr�abort�sz_SSLProtocolTransport.abort)rLrMrNr&rZr\r]r^r`rZPY34rdrfrgrhrkr8rsrurrrrrP&s	
rPc@s�eZdZddddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd d!d"�Zd#d$�Zd%d&�ZdS)'�SSLProtocolFNTcCs�tdkrtd��|s-t||�}||_|rO|rO||_n	d|_||_td|�|_tj	�|_
d|_||_||_
||_t|j
||j�|_d|_d|_d|_d|_d|_||_dS)Nzstdlib ssl module not availablerrF)rr-rrr�_sslcontext�dict�_extra�collections�deque�_write_backlog�_write_buffer_size�_waiterrQrSrP�_app_transport�_sslpipe�_session_established�
_in_handshake�_in_shutdownre�_call_connection_made)r$rUrVr�waiterrrZcall_connection_maderrrr&�s.	
												zSSLProtocol.__init__cCs^|jdkrdS|jj�sQ|dk	rA|jj|�n|jjd�d|_dS)N)r~�	cancelled�
set_exception�
set_result)r$rErrr�_wakeup_waiter�szSSLProtocol._wakeup_waitercCs5||_t|j|j|j�|_|j�dS)N)rerrwrrr��_start_handshake)r$�	transportrrr�connection_made�s
		zSSLProtocol.connection_madecCsN|jr+d|_|jj|jj|�d|_d|_|j|�dS)NF)r�rQ�	call_soonrS�connection_lostrerr�)r$rErrrr��s				zSSLProtocol.connection_lostcCs|jj�dS)N)rS�
pause_writing)r$rrrr��szSSLProtocol.pause_writingcCs|jj�dS)N)rS�resume_writing)r$rrrr��szSSLProtocol.resume_writingcCs�y|jj|�\}}Wnatjk
r}z>|jj�r_tjd||j|j	�|j
�dSWYdd}~XnXx|D]}|jj|�q�Wx2|D]*}|r�|j
j|�q�|j�Pq�WdS)Nz%r: SSL error %s (reason %s))r�r/rr<rQ�	get_debugr�warningr7rHrtrer8rS�
data_receivedr_)r$rCr1r2�erDrrrr��s	



zSSLProtocol.data_receivedc
Cspz[|jj�r"tjd|�|jt�|jsZ|jj�}|rZtj	d�Wd|j
j�XdS)Nz%r received EOFz?returning true from eof_received() has no effect when using ssl)rQr�r�debugr��ConnectionResetErrorr�rS�eof_receivedr�rer`)r$Z	keep_openrrrr�s
	zSSLProtocol.eof_receivedcCsD||jkr|j|S|jdk	r<|jj||�S|SdS)N)ryrerZ)r$rXrYrrrrWs
zSSLProtocol._get_extra_infocCs=|jr
dS|jr#|j�nd|_|jd�dS)NTr+)r�r�rtrr)r$rrrr_&s		
	zSSLProtocol._start_shutdowncCs9|jj|df�|jt|�7_|j�dS)Nr)r|r;r}rF�_process_write_backlog)r$rCrrrrr/szSSLProtocol._write_appdatacCsm|jj�r4tjd|�|jj�|_n	d|_d|_|jjd�|jj	|j
�dS)Nz%r starts SSL handshakeTr+r)r+r)rQr�rr��time�_handshake_start_timer�r|r;r�r�)r$rrrr�4s		zSSLProtocol._start_handshakecCs�d|_|jj}ye|dk	r*|�|j�}t|jd�sy|jry|jjtj	krytj
||j�Wn�tk
r!}z�|jj
�r�t|tj�r�tjd|dd�ntjd|dd�|jj�t|t�r|j|�dS�WYdd}~XnX|jj
�r^|jj�|j}tjd||d�|jjd	|d
|j�d|j�d|�|jr�|jj|j �|j�d|_!|jj"|j#�dS)
NFrz5%r: SSL handshake failed on verifying the certificate�exc_infoTz%r: SSL handshake failedz%r: SSL handshake took %.1f msg@�@�peercert�cipher�compressionr')$r�r�r'Zgetpeercertr
rwrrrZ	CERT_NONEZmatch_hostname�
BaseExceptionrQr�rlr=rr�rer`�	Exceptionr�r�r�r�ry�updater�r�r�rSr�rr�r�r�)r$Z
handshake_excZsslobjr�rEZdtrrr�_on_handshake_complete@sD				


	
	z"SSLProtocol._on_handshake_completecCs�|jdkrdSyxtt|j��D]�}|jd\}}|ri|jj||�\}}n?|r�|jj|j�}d}n|jj|j	�}d}x|D]}|jj
|�q�W|t|�kr||f|jd<|jjr|jj�P|jd=|j
t|�8_
q,WWn`tk
r�}z@|jrZ|j|�n|j|d�t|t�s|�WYdd}~XnXdS)NrrzFatal error on SSL transport)re�rangerFr|r�rKr3r�r5�	_finalizer8Z_pausedrgr}r�r��_fatal_errorrlr�)r$�irCrIr1rDrErrrr�ts8		


	z"SSLProtocol._process_write_backlogzFatal error on transportc	Cs�t|tj�r=|jj�rhtjd||dd�n+|jjd|d|d|jd|i�|jr�|jj	|�dS)Nz%r: %sr�T�message�	exceptionr�r[)
rlrZ_FATAL_ERROR_IGNORErQr�rr�Zcall_exception_handlerreZ_force_close)r$rEr�rrrr��s		
	zSSLProtocol._fatal_errorcCs)d|_|jdk	r%|jj�dS)N)r�rer`)r$rrrr��s	zSSLProtocol._finalizec
Cs2z |jdk	r|jj�Wd|j�XdS)N)rerur�)r$rrrrt�szSSLProtocol._abort)rLrMrNr&r�r�r�r�r�r�r�rWr_rrr�r�r�r�r�rtrrrrrv�s$#
	4,rv)rzrar�ImportError�rrrr�logrrrrr.r)r4�objectrZ_FlowControlMixinZ	TransportrPZProtocolrvrrrr�<module>s(
�n

?>