a
´iCk ã @ s¸ d dl Z d dlZzd dlZW n ey2 dZY n0 ddlmZ ddlmZ ddlmZ ddlm Z dd„ Z
d Zd
ZdZ
dZG d
d„ deƒZG dd„ dejejƒZG dd„ dejƒZdS )é Né )Ú constants)Ú protocols)Ú
transports)Úloggerc C s" | rt dƒ‚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.9/asyncio/sslproto.pyÚ_create_transport_context s r Z UNWRAPPEDZDO_HANDSHAKEZWRAPPEDZSHUTDOWNc @ s~ e Zd ZdZdZddd„Zedd„ ƒZedd „ ƒZed
d„ ƒZ edd
„ ƒZ
ddd„Zddd„Zdd„ Z
ddd„Zddd„ZdS )Ú_SSLPipea An 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().
i Nc C sH || _ || _|| _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)ÚselfÚcontextr r
r r r
Ú__init__7 s
z_SSLPipe.__init__c C s | j S )z*The SSL context passed to the constructor.)r ©r r r r
r M s z_SSLPipe.contextc C s | j S )z^The internal ssl.SSLObject instance.
Return None if the pipe is not wrapped.
)r r r r r
Ú
ssl_objectR s z_SSLPipe.ssl_objectc C s | j S )zgWhether more record level data is needed to complete a handshake
that is currently in progress.)r r r r r
Úneed_ssldataZ s z_SSLPipe.need_ssldatac C s
| j tkS )zj
Whether a security layer is currently in effect.
Return False during handshake.
)r Ú_WRAPPEDr r r r
Úwrapped` s z_SSLPipe.wrappedc C sb | j tkrtdƒ‚| jj| j| j| j| jd�| _ t
| _ || _| jddd�\}}t
|ƒdks^J ‚|S )aL Start 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_handshaker )r r ÚRuntimeErrorr Zwrap_bior r r r r Ú
_DO_HANDSHAKEr Úfeed_ssldataÚlen©r ÚcallbackÚssldataÚappdatar r r
Údo_handshakei s
ýz_SSLPipe.do_handshakec C sj | j tkrtdƒ‚| j tkr$tdƒ‚| j ttfv s6J ‚t| _ || _| d¡\}}|g ksf|dgksfJ ‚|S )a1 Start 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# )r r r% Ú _SHUTDOWNr! r&