%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python3.8/asyncio/__pycache__/
Upload File :
Create Path :
Current File : //usr/local/lib/python3.8/asyncio/__pycache__/sslproto.cpython-38.pyc

U

paJj@sddlZddlZzddlZWnek
r4dZYnXddlmZddlmZddlmZddlmZddl	m
Z
dd	Zd
ZdZ
dZd
ZGdddeZGdddejejZGdddejZdS)N)base_events)	constants)	protocols)
transports)loggercCs"|rtdt}|sd|_|S)Nz(Server side SSL needs a valid SSLContextF)
ValueErrorsslZcreate_default_contextZcheck_hostname)server_sideserver_hostname
sslcontextr
,/usr/local/lib/python3.8/asyncio/sslproto.py_create_transport_contextsrZ	UNWRAPPEDZDO_HANDSHAKEZWRAPPEDZSHUTDOWNc@s~eZdZdZdZdddZeddZedd	Zed
dZ	edd
Z
dddZdddZddZ
dddZdddZdS)_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_stater	Z	MemoryBIO	_incoming	_outgoing_sslobj
_need_ssldata
_handshake_cb_shutdown_cb)selfcontextr
rr
r
r__init__8s

z_SSLPipe.__init__cCs|jS)z*The SSL context passed to the constructor.)rrr
r
rrNsz_SSLPipe.contextcCs|jS)z^The internal ssl.SSLObject instance.

        Return None if the pipe is not wrapped.
        )rrr
r
r
ssl_objectSsz_SSLPipe.ssl_objectcCs|jS)zgWhether more record level data is needed to complete a handshake
        that is currently in progress.)rrr
r
rneed_ssldata[sz_SSLPipe.need_ssldatacCs
|jtkS)zj
        Whether a security layer is currently in effect.

        Return False during handshake.
        )r_WRAPPEDrr
r
rwrappedasz_SSLPipe.wrappedcCsb|jtkrtd|jj|j|j|j|jd|_	t
|_||_|jddd\}}t
|dks^t|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
rT)only_handshaker)rrRuntimeErrorrZwrap_biorrrrr
_DO_HANDSHAKErfeed_ssldatalenAssertionErrorrcallbackssldataappdatar
r
rdo_handshakejs	
z_SSLPipe.do_handshakecCsj|jtkrtd|jtkr$td|jttfks6tt|_||_|d\}}|gksf|dgksft|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&	_SHUTDOWNr"r'r*rr(r+r
r
rshutdowns	

z_SSLPipe.shutdowncCs2|j|d\}}|gks.|dgks.tdS)zSend a potentially "ragged" EOF.

        This method will raise an SSL_ERROR_EOF exception if the EOF is
        unexpected.
        r$N)rZ	write_eofr(r*)rr-r.r
r
rfeed_eofs
z_SSLPipe.feed_eofFc
Cs|jtkr"|r|g}ng}g|fSd|_|r8|j|g}g}z|jtkrz|jt|_|j	rl|	d|rz||fWS|jtkr|j
|j}|||sqqnJ|jt
kr|jd|_t|_|jr|n|jtkr||j
Wnztjtjfk
rl}zRt|dd}|tjtjtjfkrP|jtkrN|j	rN|	||tjk|_W5d}~XYnX|jjr||j
||fS)aFeed 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().
        FNerrno)rrrrwriter'rr/r"rreadmax_sizeappendr0Zunwraprr	SSLErrorCertificateErrorgetattrSSL_ERROR_WANT_READSSL_ERROR_WANT_WRITESSL_ERROR_SYSCALLrpending)rdatar%r.r-chunkexc	exc_errnor
r
rr(sZ












z_SSLPipe.feed_ssldatarc
Cs4d|krt|ksnt|jtkrT|t|krD||dg}ng}|t|fSg}t|}d|_z(|t|kr||j||d7}Wnhtj	k
r}zHt
|dd}|jdkrtj}|_
|tjtjtjfkrڂ|tjk|_W5d}~XYnX|jjr||j|t|ks,|jr`q,q`||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.
        rNFr3ZPROTOCOL_IS_SHUTDOWN)r)r*rr
memoryviewrrr4r	r8r:reasonr;r3r<r=rr>r7r5)rr?offsetr-viewrArBr
r
rfeed_appdatas6


z_SSLPipe.feed_appdata)N)N)N)F)r)__name__
__module____qualname____doc__r6rpropertyrr r!r#r/r1r2r(rGr
r
r
rr$s 








Krc@seZdZejjZddZd"ddZddZ	dd	Z
d
dZdd
Ze
jfddZddZddZddZd#ddZddZeddZddZddZd d!ZdS)$_SSLProtocolTransportcCs||_||_d|_dS)NF)_loop
_ssl_protocol_closed)rloopZssl_protocolr
r
rr!sz_SSLProtocolTransport.__init__NcCs|j||S)z#Get optional transport information.)rO_get_extra_infornamedefaultr
r
rget_extra_info'sz$_SSLProtocolTransport.get_extra_infocCs|j|dSN)rO_set_app_protocol)rprotocolr
r
rset_protocol+sz"_SSLProtocolTransport.set_protocolcCs|jjSrW)rO
_app_protocolrr
r
rget_protocol.sz"_SSLProtocolTransport.get_protocolcCs|jSrW)rPrr
r
r
is_closing1sz _SSLProtocolTransport.is_closingcCsd|_|jdS)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)rPrO_start_shutdownrr
r
rclose4sz_SSLProtocolTransport.closecCs&|js"|d|t|d|dS)Nzunclosed transport )source)rPResourceWarningr_)r_warnr
r
r__del__?sz_SSLProtocolTransport.__del__cCs |jj}|dkrtd|S)Nz*SSL transport has not been initialized yet)rO
_transportr&
is_reading)rtrr
r
rreDsz _SSLProtocolTransport.is_readingcCs|jjdS)zPause the receiving end.

        No data will be passed to the protocol's data_received()
        method until resume_reading() is called.
        N)rOrd
pause_readingrr
r
rrgJsz#_SSLProtocolTransport.pause_readingcCs|jjdS)zResume the receiving end.

        Data received will once again be passed to the protocol's
        data_received() method.
        N)rOrdresume_readingrr
r
rrhRsz$_SSLProtocolTransport.resume_readingcCs|jj||dS)aSet 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)rOrdset_write_buffer_limits)rhighlowr
r
rriZsz-_SSLProtocolTransport.set_write_buffer_limitscCs|jjS)z,Return the current size of the write buffer.)rOrdget_write_buffer_sizerr
r
rrlosz+_SSLProtocolTransport.get_write_buffer_sizecCs
|jjjSrW)rOrd_protocol_pausedrr
r
rrmssz&_SSLProtocolTransport._protocol_pausedcCs<t|tttfs$tdt|j|s,dS|j|dS)zWrite 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)	
isinstancebytes	bytearrayrC	TypeErrortyperHrO_write_appdatarr?r
r
rr4xs
z_SSLProtocolTransport.writecCsdS)zAReturn True if this transport supports write_eof(), False if not.Fr
rr
r
r
can_write_eofsz#_SSLProtocolTransport.can_write_eofcCs|jd|_dS)zClose 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)rO_abortrPrr
r
raborts
z_SSLProtocolTransport.abort)N)NN)rHrIrJrZ
_SendfileModeZFALLBACKZ_sendfile_compatiblerrVrZr\r]r_warningswarnrcrergrhrirlrLrmr4rurwr
r
r
rrMs$



rMc@seZdZdZd,ddZddZd-d	d
ZddZd
dZddZ	ddZ
ddZddZd.ddZ
ddZddZddZdd Zd!d"Zd#d$Zd/d&d'Zd(d)Zd*d+ZdS)0SSLProtocolzSSL protocol.

    Implementation of SSL on top of a socket using incoming and outgoing
    buffers which are ssl.MemoryBIO objects.
    FNTc		Cstdkrtd|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_sslcontextdict_extracollectionsdeque_write_backlog_write_buffer_size_waiterrNrXrM_app_transport_sslpipe_session_established
_in_handshake_in_shutdownrd_call_connection_made_ssl_handshake_timeout)	rrQapp_protocolrwaiterr
rZcall_connection_madeZssl_handshake_timeoutr
r
rrs@

zSSLProtocol.__init__cCs||_t|tj|_dSrW)r[rnrZBufferedProtocol_app_protocol_is_buffer)rrr
r
rrXs
zSSLProtocol._set_app_protocolcCsD|jdkrdS|js:|dk	r.|j|n|jdd|_dSrW)r	cancelled
set_exception
set_resultrrAr
r
r_wakeup_waiters

zSSLProtocol._wakeup_waitercCs&||_t|j|j|j|_|dS)zXCalled when the low-level connection is made.

        Start the SSL handshake.
        N)rdrr{rrr_start_handshake)r	transportr
r
rconnection_madeszSSLProtocol.connection_madecCsn|jr d|_|j|jj|n|jdk	r2d|j_d|_d|_t|ddrT|j	
||d|_d|_dS)zCalled 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)
rrN	call_soonr[connection_lostrrPrdr:rcancelrrrr
r
rrs


zSSLProtocol.connection_lostcCs|jdS)z\Called when the low-level transport's buffer goes over
        the high-water mark.
        N)r[
pause_writingrr
r
rrszSSLProtocol.pause_writingcCs|jdS)z^Called when the low-level transport's buffer drains below
        the low-water mark.
        N)r[resume_writingrr
r
rrszSSLProtocol.resume_writingcCs"|jdkrdSz|j|\}}WnLttfk
r<Yn4tk
rn}z||dWYdSd}~XYnX|D]}|j|qt|D]}|rz&|jrt	
|j|n|j|WnPttfk
rYn8tk
r
}z||dWYdSd}~XYnXq|
qqdS)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)rr(
SystemExitKeyboardInterrupt
BaseException_fatal_errorrdr4rrZ_feed_data_to_buffered_protor[
data_receivedr^)rr?r-r.er@exr
r
rrs<
zSSLProtocol.data_receivedcCsTzB|jrtd||t|js@|j	
}|r@tdW5|jXdS)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)rdr_rN	get_debugrdebugrConnectionResetErrorrr[eof_receivedwarning)rZ	keep_openr
r
rr-s


zSSLProtocol.eof_receivedcCs4||jkr|j|S|jdk	r,|j||S|SdSrW)r}rdrVrSr
r
rrRCs



zSSLProtocol._get_extra_infocCs.|jr
dS|jr|nd|_|ddS)NTr$)rrrvrsrr
r
rr^Ks
zSSLProtocol._start_shutdowncCs.|j|df|jt|7_|dS)Nr)rr7rr)_process_write_backlogrtr
r
rrsTszSSLProtocol._write_appdatacCs\|jr$td||j|_nd|_d|_|jd|j	|j
|j|_|
dS)Nz%r starts SSL handshakeT)r$r)rNrrrtime_handshake_start_timerrr7Z
call_laterr_check_handshake_timeoutrrrr
r
rrYs

zSSLProtocol._start_handshakecCs*|jdkr&d|jd}|t|dS)NTz$SSL handshake is taking longer than z! seconds: aborting the connection)rrrConnectionAbortedError)rmsgr
r
rrhs
z$SSLProtocol._check_handshake_timeoutc
Csd|_|j|jj}z|dk	r&||}Wnbttfk
rJYnJtk
r}z,t	|t
jrld}nd}|||WYdSd}~XYnX|j
r|j
|j}td||d|jj||||d|jr|j|j|d|_|j
|jdS)NFz1SSL handshake failed on verifying the certificatezSSL handshake failedz%r: SSL handshake took %.1f msg@@)peercertciphercompressionr T)rrrrr Zgetpeercertrrrrnr	r9rrNrrrrrr}updaterrrr[rrrrrr)rZ
handshake_excZsslobjrrArZdtr
r
r_on_handshake_completeqs8

z"SSLProtocol._on_handshake_completec
CsP|jdks|jdkrdSztt|jD]}|jd\}}|rR|j||\}}n*|rj|j|j}d}n|j|j	}d}|D]}|j
|q|t|kr||f|jd<|jjst|jj
r|jq|jd=|jt|8_q(Wn^ttfk
rYnDtk
rJ}z$|jr.||n||dW5d}~XYnXdS)NrrzFatal error on SSL transport)rdrranger)rrGr/rr1	_finalizer4r!r*Z_pausedrhrrrrrr)rir?rEr-r@rAr
r
rrs<
z"SSLProtocol._process_write_backlogFatal error on transportcCsVt|tr(|jr@tjd||ddn|j|||j|d|jrR|j|dS)Nz%r: %sT)exc_info)message	exceptionrrY)	rnOSErrorrNrrrZcall_exception_handlerrdZ_force_close)rrArr
r
rrs

zSSLProtocol._fatal_errorcCsd|_|jdk	r|jdSrW)rrdr_rr
r
rrs
zSSLProtocol._finalizecCs(z|jdk	r|jW5|XdSrW)rrdrwrr
r
rrvs
zSSLProtocol._abort)FNTN)N)N)r)rHrIrJrKrrXrrrrrrrrRr^rsrrrrrrrvr
r
r
rrzs0
.

&
		)+
rz)r~rxr	ImportErrorrrrrlogrrrr'r"r0objectrZ_FlowControlMixinZ	TransportrMZProtocolrzr
r
r
r<module>s*
yx

Zerion Mini Shell 1.0