Part of twisted.protocols View Source
Implementation of a TLS transport (
IProtocol layered on top of any
implementation, based on OpenSSL's memory BIO features.
WrappingFactorywhich wraps protocols created by the factory it wraps with
TLSMemoryBIOProtocolintercedes 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()Because the reactor's SSL and TLS APIs are likely implemented in a more efficient way, it is more common to use them (see
ITLSTransport). However, this API offers somewhat more flexibility; for example, a
TLSMemoryBIOProtocolinstance can use another instance of
TLSMemoryBIOProtocolas its transport, yielding TLS over TLS - useful to implement onion routing. Or it can be used to run TLS over a UNIX socket, or over stdio to a child process.