File: //proc/self/root/usr/lib/python3/dist-packages/twisted/protocols/__pycache__/tls.cpython-38.pyc
U
W[l �
@ s| d Z ddlmZmZ ddlmZmZmZ ddlmZm Z m
Z
ze
e e�d� W n8 ek
r� Z ze
e�dkrn� ed��W 5 dZ[X Y nX ddlmZmZmZ dd lmZ dd
lmZ ddlmZmZmZmZmZmZmZmZ ddl m!Z! dd
l"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ee�G dd� de+��Z,eee�G dd� de)��Z-eee�G dd� de+��Z.G dd� de*�Z/dS )a�
Implementation of a TLS transport (L{ISSLTransport}) as an
L{IProtocol<twisted.internet.interfaces.IProtocol>} layered on top of any
L{ITransport<twisted.internet.interfaces.ITransport>} implementation, based on
U{OpenSSL<http://www.openssl.org>}'s memory BIO features.
L{TLSMemoryBIOFactory} is a L{WrappingFactory} which wraps protocols created by
the factory it wraps with L{TLSMemoryBIOProtocol}. L{TLSMemoryBIOProtocol}
intercedes between the underlying transport and the wrapped protocol to
implement SSL and TLS. Typical usage of this module looks like this::
from twisted.protocols.tls import TLSMemoryBIOFactory
from twisted.internet.protocol import ServerFactory
from twisted.internet.ssl import PrivateCertificate
from twisted.internet import reactor
from someapplication import ApplicationProtocol
serverFactory = ServerFactory()
serverFactory.protocol = ApplicationProtocol
certificate = PrivateCertificate.loadPEM(certPEMData)
contextFactory = certificate.options()
tlsFactory = TLSMemoryBIOFactory(contextFactory, False, serverFactory)
reactor.listenTCP(12345, tlsFactory)
reactor.run()
This API offers somewhat more flexibility than
L{twisted.internet.interfaces.IReactorSSL}; for example, a
L{TLSMemoryBIOProtocol} instance can use another instance of
L{TLSMemoryBIOProtocol} as its transport, yielding TLS over TLS - useful to
implement onion routing. It can also be used to run TLS over unusual
transports, such as UNIX sockets and stdio.
� )�division�absolute_import)�Error�ZeroReturnError�
WantReadError)�TLSv1_METHOD�Context�
ConnectionNz3argument must be an int, or have a fileno() method.z7twisted.protocols.tls requires pyOpenSSL 0.10 or newer.)�implementer�
providedBy�directlyProvides)�unicode)�Failure)�
ISystemHandle�INegotiated�
IPushProducer�ILoggingContext�IOpenSSLServerConnectionCreator�IOpenSSLClientConnectionCreator�IProtocolNegotiationFactory�IHandshakeListener)�CONNECTION_LOST)�_PullToPush)�Protocol)�_setAcceptableProtocols)�ProtocolWrapper�WrappingFactoryc @ s4 e Zd ZdZdZdd� Zdd� Zdd� Zd d
� ZdS )�_ProducerMembranea
Stand-in for producer registered with a L{TLSMemoryBIOProtocol} transport.
Ensures that producer pause/resume events from the undelying transport are
coordinated with pause/resume events from the TLS layer.
@ivar _producer: The application-layer producer.
Fc C s
|| _ d S �N)� _producer)�self�producer� r"