Hacked By AnonymousFox

Current Path : /opt/alt/python39/lib64/python3.9/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/asyncio/__pycache__/sslproto.cpython-39.opt-1.pyc

a

���eCk�@s�ddlZddlZzddlZWney2dZYn0ddlmZddlmZddlmZddlm	Z	dd�Z
d	Zd
ZdZ
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�5/opt/alt/python39/lib64/python3.9/asyncio/sslproto.py�_create_transport_contextsrZ	UNWRAPPEDZDO_HANDSHAKEZWRAPPEDZSHUTDOWNc@s~eZdZdZdZddd�Zedd��Zedd	��Zed
d��Z	edd
��Z
ddd�Zddd�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.wrappedcCsR|jtkrtd��|jj|j|j|j|jd�|_	t
|_||_|jddd�\}}|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_handshake)
rr�RuntimeErrorrZwrap_biorrrrr�
_DO_HANDSHAKEr�feed_ssldata�r�callback�ssldata�appdatarrr
�do_handshakeis	
�z_SSLPipe.do_handshakecCsB|jtkrtd��|jtkr$td��t|_||_|�d�\}}|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%�	_SHUTDOWNrr'r(rrr
�shutdown~s	

z_SSLPipe.shutdowncCs|j��|�d�\}}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-Zunwraprr�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
Cs|jtkr6|t|�kr&||d�g}ng}|t|�fSg}t|�}d|_z(|t|�krn||j�||d��7}Wnjtjy�}zPt	|dd�}|j
dkr�tj}|_|tjtj
tjfvr��|tjk|_WYd}~n
d}~00|jjr�|�|j���|t|�k�s|jrB�qqB||fS)aFeed 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.
        NFr0ZPROTOCOL_IS_SHUTDOWN)rr�len�
memoryviewrrr1rr5r7�reasonr8r0r9r:rr;r4r2)rr<�offsetr*Zviewr>r?rrr
�feed_appdata�s4

�"z_SSLPipe.feed_appdata)N)N)N)F)r)�__name__�
__module__�__qualname__�__doc__r3r�propertyrrr r"r,r.r/r'rDr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|_dS)NF)�_loop�
_ssl_protocol�_closed)r�loopZssl_protocolrrr
r sz_SSLProtocolTransport.__init__NcCs|j�||�S)z#Get optional transport information.)rL�_get_extra_info�r�name�defaultrrr
�get_extra_info&sz$_SSLProtocolTransport.get_extra_infocCs|j�|�dS�N)rL�_set_app_protocol)r�protocolrrr
�set_protocol*sz"_SSLProtocolTransport.set_protocolcCs|jjSrT)rL�
_app_protocolrrrr
�get_protocol-sz"_SSLProtocolTransport.get_protocolcCs|jSrT)rMrr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)rMrL�_start_shutdownrrrr
�close3sz_SSLProtocolTransport.closecCs&|js"|d|��t|d�|��dS)Nzunclosed transport )�source)rM�ResourceWarningr\)rZ_warnrrr
�__del__>sz_SSLProtocolTransport.__del__cCs |jj}|durtd��|��S)Nz*SSL transport has not been initialized yet)rL�
_transportr%�
is_reading)rZtrrrr
raCsz _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)rLr`�
pause_readingrrrr
rbIsz#_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)rLr`�resume_readingrrrr
rcQsz$_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)rLr`�set_write_buffer_limits)rZhighZlowrrr
rdYsz-_SSLProtocolTransport.set_write_buffer_limitscCs|jj��S)z,Return the current size of the write buffer.)rLr`�get_write_buffer_sizerrrr
rensz+_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.)rLr`�get_write_buffer_limitsrrrr
rfrsz-_SSLProtocolTransport.get_write_buffer_limitscCs
|jjjSrT)rLr`�_protocol_pausedrrrr
rgxsz&_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�	bytearrayrA�	TypeError�typerErL�_write_appdata�rr<rrr
r1}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)rL�_abortrMrrrr
�abort�s
z_SSLProtocolTransport.abort)N)NN)rErFrGrZ
_SendfileModeZFALLBACKZ_sendfile_compatiblerrSrWrYrZr\�warnings�warnr_rarbrcrdrerfrIrgr1rorqrrrr
rJs&



rJc@s�eZdZdZd,dd�Zdd�Zd-d	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�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 )rF)rr%rZSSL_HANDSHAKE_TIMEOUTrrrr�_sslcontext�dict�_extra�collections�deque�_write_backlog�_write_buffer_size�_waiterrKrUrJ�_app_transport�_sslpipe�_session_established�
_in_handshake�_in_shutdownr`�_call_connection_made�_ssl_handshake_timeout)	rrN�app_protocolrZwaiterr	r
Zcall_connection_madeZssl_handshake_timeoutrrr
r�sB���

zSSLProtocol.__init__cCs||_t|tj�|_dSrT)rXrhrZBufferedProtocol�_app_protocol_is_buffer)rr�rrr
rU�s
�zSSLProtocol._set_app_protocolcCsD|jdurdS|j��s:|dur.|j�|�n|j�d�d|_dSrT)r|Z	cancelledZ
set_exceptionZ
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)r`rrurrr~�_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)
rrK�	call_soonrX�connection_lostr}rMr`r7r��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)rX�
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)rX�resume_writingrrrr
r�szSSLProtocol.resume_writingcCs|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_errorr`r1r�rZ_feed_data_to_buffered_protorX�
data_receivedr[)rr<r*r+�er=Zexr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)rK�	get_debugr�debugr��ConnectionResetErrorr�rX�eof_receivedZwarningr`r\)rZ	keep_openrrr
r�2s


zSSLProtocol.eof_receivedcCs4||jvr|j|S|jdur,|j�||�S|SdSrT)rwr`rSrPrrr
rOHs



zSSLProtocol._get_extra_infocCs.|jr
dS|jr|��nd|_|�d�dS)NTr#)r�r�rprmrrrr
r[Ps
zSSLProtocol._start_shutdowncCs.|j�|df�|jt|�7_|��dS)Nr)rzr4r{r@�_process_write_backlogrnrrr
rmYszSSLProtocol._write_appdatacCs\|j��r$t�d|�|j��|_nd|_d|_|j�d�|j�	|j
|j�|_|�
�dS)Nz%r starts SSL handshakeT)r#r)rKr�rr��time�_handshake_start_timer�rzr4Z
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~rZgetpeercertr�r�r�rhrr6r�rKr�r�r�rr�rw�updater�r�r�rXr�r}r�rr�r�)rZ
handshake_excZsslobjr�r>r�Zdtrrr
�_on_handshake_completevs8

�z"SSLProtocol._on_handshake_completec
CsB|jdus|jdurdSz�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\ttfy��YnFt�y<}z,|j�r|�|�n|�|d�WYd}~n
d}~00dS)NrrzFatal error on SSL transport)r`r~�ranger@rzrDr,r�r.�	_finalizer1Z_pausedrcr{r�r�r�r�r�)r�ir<rCr*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)�messageZ	exceptionr�rV)	rh�OSErrorrKr�rr�Zcall_exception_handlerr`Z_force_close)rr>r�rrr
r��s

�zSSLProtocol._fatal_errorcCsd|_|jdur|j��dSrT)r~r`r\rrrr
r��s
zSSLProtocol._finalizecCs0z |jdur|j��W|��n
|��0dSrT)r`rqr�rrrr
rp�s
zSSLProtocol._abort)FNTN)N)N)r�)rErFrGrHrrUr�r�r�r�r�r�r�rOr[rmr�r�r�r�r�r�rprrrr
rt�s.�
.

&
		)+
rt)rxrrr�ImportError�rrr�logrrrr&r!r-�objectrZ_FlowControlMixinZ	TransportrJ�Protocolrtrrrr
�<module>s(
y�~

Hacked By AnonymousFox1.0, Coded By AnonymousFox