File: //usr/lib/python3/dist-packages/twisted/internet/__pycache__/_newtls.cpython-38.pyc
U
W[t$ � @ s� d Z ddlmZmZ ddlmZ ddlmZ ddlmZm Z ddl
mZ ddlm
Z
mZ G dd � d e�Zd
d� Zee�G dd
� d
e��ZG dd� de�ZG dd� de�ZdS )z�
This module implements memory BIO based TLS support. It is the preferred
implementation and will be used whenever pyOpenSSL 0.10 or newer is installed
(whenever L{twisted.protocols.tls} is importable).
@since: 11.1
� )�division�absolute_import)�implementer)�directlyProvides)�
ITLSTransport�
ISSLTransport)�FileDescriptor)�TLSMemoryBIOFactory�TLSMemoryBIOProtocolc @ sH e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dS )�
_BypassTLSa
L{_BypassTLS} is used as the transport object for the TLS protocol object
used to implement C{startTLS}. Its methods skip any TLS logic which
C{startTLS} enables.
@ivar _base: A transport class L{_BypassTLS} has been mixed in with to which
methods will be forwarded. This class is only responsible for sending
bytes over the connection, not doing TLS.
@ivar _connection: A L{Connection} which TLS has been started on which will
be proxied to by this object. Any method which has its behavior
altered after C{startTLS} will be skipped in favor of the base class's
implementation. This allows the TLS protocol object to have direct
access to the transport, necessary to actually implement TLS.
c C s || _ || _d S )N)�_base�_connection)�self�baseZ
connection� r �:/usr/lib/python3/dist-packages/twisted/internet/_newtls.py�__init__( s z_BypassTLS.__init__c C s t | j|�S )z�
Forward any extra attribute access to the original transport object.
For example, this exposes C{getHost}, the behavior of which does not
change after TLS is enabled.
)�getattrr
)r �namer r r �__getattr__- s z_BypassTLS.__getattr__c C s | j �| j|�S )z>
Write some bytes directly to the connection.
)r �writer
)r �datar r r r 6 s z_BypassTLS.writec C s | j �| j|�S )z@
Write a some bytes directly to the connection.
)r �
writeSequencer
�r Ziovecr r r r = s z_BypassTLS.writeSequencec O s | j j| jf|�|�S )z2
Close the underlying connection.
)r �loseConnectionr
)r �args�kwargsr r r r D s z_BypassTLS.loseConnectionc C s | j �| j||�S )zE
Register a producer with the underlying connection.
)r �registerProducerr
�r �producer� streamingr r r r K s z_BypassTLS.registerProducerc C s | j �| j�S )zG
Unregister a producer with the underlying connection.
)r �unregisterProducerr
�r r r r r! R s z_BypassTLS.unregisterProducerN)�__name__�
__module__�__qualname__�__doc__r r r r r r r! r r r r r s r c C s� |r| j }n| j }d\}}| jdk r<| j| j }}| �� t||d�}t|| jd�}|| _|j| _|j| _t | t
� d| _| j�t
|| �� |r�| �||� dS )a_
Add a layer of SSL to a transport.
@param transport: The transport which will be modified. This can either by
a L{FileDescriptor<twisted.internet.abstract.FileDescriptor>} or a
L{FileHandle<twisted.internet.iocpreactor.abstract.FileHandle>}. The
actual requirements of this instance are that it have:
- a C{_tlsClientDefault} attribute indicating whether the transport is
a client (C{True}) or a server (C{False})
- a settable C{TLS} attribute which can be used to mark the fact
that SSL has been started
- settable C{getHandle} and C{getPeerCertificate} attributes so
these L{ISSLTransport} methods can be added to it
- a C{protocol} attribute referring to the L{IProtocol} currently
connected to the transport, which can also be set to a new
L{IProtocol} for the transport to deliver data to
@param contextFactory: An SSL context factory defining SSL parameters for
the new SSL layer.
@type contextFactory: L{twisted.internet.interfaces.IOpenSSLContextFactory}
@param normal: A flag indicating whether SSL will go in the same direction
as the underlying transport goes. That is, if the SSL client will be
the underlying client and the SSL server will be the underlying server.
C{True} means it is the same, C{False} means they are switched.
@type param: L{bool}
@param bypass: A transport base class to call methods on to bypass the new
SSL layer (so that the SSL layer itself can send its bytes).
@type bypass: L{type}
)NNNFT)�_tlsClientDefaultr ZstreamingProducerr! r r
�protocolZ getHandleZgetPeerCertificater r �TLSZmakeConnectionr r ) Z transportZcontextFactory�normalZbypassZclientr r Z
tlsFactoryZtlsProtocolr r r �startTLSZ s"