Module Expr Str ImportFrom alias alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias Import alias Import alias ClassDef bases body FunctionDef arguments args NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Str decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad Return Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body If CompareEq AttributeLoad NameLoad attr Str body Raise Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Slice NameLoad Assign AttributeStore NameLoad attr SubscriptLoad AttributeLoad NameLoad attr Slice NameLoad Return NameLoad decorator_list decorator_list ClassDef bases NameLoad NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body TryExcept body Expr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler type NameLoad name NameStore body Expr Call AttributeLoad NameLoad attr Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body TryExcept body If UnaryOpNot AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad orelse AugAssignAdd AttributeStore AttributeLoad NameLoad attr attr NameLoad While AttributeLoad AttributeLoad NameLoad attr attr body Expr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler type NameLoad name NameStore body Expr Call AttributeLoad NameLoad attr Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body If UnaryOpNot AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body If CompareEq NameLoad Str body Expr Call AttributeLoad NameLoad attr NameLoad orelse Expr Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults kwarg body Assign AttributeStore NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body If UnaryOpNot AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr NameLoad orelse Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body If UnaryOpNot AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad orelse Expr Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body If UnaryOpNot AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad orelse Expr Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad Str attr NameLoad decorator_list decorator_list
N/A N/A TLS Lite + Twisted. twisted.protocols.policies ProtocolWrapper WrappingFactory twisted.python.failure Failure AsyncStateMachine AsyncStateMachine gdata.tlslite.TLSConnection TLSConnection gdata.tlslite.errors * N/A socket N/A errno _FakeSocket N/A N/A __init__ N/A N/A self wrapper N/A N/A N/A N/A self wrapper wrapper N/A N/A self data N/A send N/A N/A self data N/A N/A N/A N/A N/A ProtocolWrapper write N/A self wrapper data N/A N/A len data N/A recv N/A N/A self numBytes N/A N/A N/A N/A N/A self data N/A N/A N/A N/A socket error N/A errno EWOULDBLOCK N/A returnData N/A N/A self data N/A numBytes N/A N/A self data N/A N/A self data N/A numBytes N/A returnData N/A N/A TLSTwistedProtocolWrapper N/A ProtocolWrapper AsyncStateMachine N/A N/A This class can wrap Twisted protocols to add TLS support.

    Below is a complete example of using TLS Lite with a Twisted echo
    server.

    There are two server implementations below.  Echo is the original
    protocol, which is oblivious to TLS.  Echo1 subclasses Echo and
    negotiates TLS when the client connects.  Echo2 subclasses Echo and
    negotiates TLS when the client sends "STARTTLS"::

        from twisted.internet.protocol import Protocol, Factory
        from twisted.internet import reactor
        from twisted.protocols.policies import WrappingFactory
        from twisted.protocols.basic import LineReceiver
        from twisted.python import log
        from twisted.python.failure import Failure
        import sys
        from tlslite.api import *

        s = open("./serverX509Cert.pem").read()
        x509 = X509()
        x509.parse(s)
        certChain = X509CertChain([x509])

        s = open("./serverX509Key.pem").read()
        privateKey = parsePEMKey(s, private=True)

        verifierDB = VerifierDB("verifierDB")
        verifierDB.open()

        class Echo(LineReceiver):
            def connectionMade(self):
                self.transport.write("Welcome to the echo server!\r\n")

            def lineReceived(self, line):
                self.transport.write(line + "\r\n")

        class Echo1(Echo):
            def connectionMade(self):
                if not self.transport.tlsStarted:
                    self.transport.setServerHandshakeOp(certChain=certChain,
                                                        privateKey=privateKey,
                                                        verifierDB=verifierDB)
                else:
                    Echo.connectionMade(self)

            def connectionLost(self, reason):
                pass #Handle any TLS exceptions here

        class Echo2(Echo):
            def lineReceived(self, data):
                if data == "STARTTLS":
                    self.transport.setServerHandshakeOp(certChain=certChain,
                                                        privateKey=privateKey,
                                                        verifierDB=verifierDB)
                else:
                    Echo.lineReceived(self, data)

            def connectionLost(self, reason):
                pass #Handle any TLS exceptions here

        factory = Factory()
        factory.protocol = Echo1
        #factory.protocol = Echo2

        wrappingFactory = WrappingFactory(factory)
        wrappingFactory.protocol = TLSTwistedProtocolWrapper

        log.startLogging(sys.stdout)
        reactor.listenTCP(1079, wrappingFactory)
        reactor.run()

    This class works as follows:

    Data comes in and is given to the AsyncStateMachine for handling.
    AsyncStateMachine will forward events to this class, and we'll
    pass them on to the ProtocolHandler, which will proxy them to the
    wrapped protocol.  The wrapped protocol may then call back into
    this class, and these calls will be proxied into the
    AsyncStateMachine.

    The call graph looks like this:
     - self.dataReceived
       - AsyncStateMachine.inReadEvent
         - self.out(Connect|Close|Read)Event
           - ProtocolWrapper.(connectionMade|loseConnection|dataReceived)
             - self.(loseConnection|write|writeSequence)
               - AsyncStateMachine.(setCloseOp|setWriteOp)
     __init__ N/A N/A self factory wrappedProtocol N/A N/A N/A N/A N/A ProtocolWrapper __init__ self factory wrappedProtocol N/A N/A N/A AsyncStateMachine __init__ self N/A N/A self fakeSocket N/A _FakeSocket self N/A N/A self tlsConnection N/A TLSConnection N/A self fakeSocket N/A N/A self tlsStarted False N/A N/A self connectionLostCalled False N/A connectionMade N/A N/A self N/A N/A N/A N/A N/A N/A N/A ProtocolWrapper connectionMade self N/A N/A N/A TLSError N/A e N/A N/A N/A N/A self connectionLost N/A Failure e N/A N/A N/A ProtocolWrapper loseConnection self N/A dataReceived N/A N/A self data N/A N/A N/A N/A N/A N/A N/A self tlsStarted N/A N/A N/A N/A ProtocolWrapper dataReceived self data N/A N/A N/A N/A self fakeSocket data data N/A N/A N/A self fakeSocket data N/A N/A N/A N/A AsyncStateMachine inReadEvent self N/A N/A N/A TLSError N/A e N/A N/A N/A N/A self connectionLost N/A Failure e N/A N/A N/A ProtocolWrapper loseConnection self N/A connectionLost N/A N/A self reason N/A N/A N/A N/A N/A self connectionLostCalled N/A N/A N/A N/A ProtocolWrapper connectionLost self reason N/A N/A self connectionLostCalled True N/A outConnectEvent N/A N/A self N/A N/A N/A N/A N/A ProtocolWrapper connectionMade self N/A outCloseEvent N/A N/A self N/A N/A N/A N/A N/A ProtocolWrapper loseConnection self N/A outReadEvent N/A N/A self data N/A N/A N/A N/A data N/A N/A N/A N/A ProtocolWrapper loseConnection self N/A N/A N/A N/A ProtocolWrapper dataReceived self data N/A setServerHandshakeOp N/A N/A self N/A args N/A N/A N/A self tlsStarted True N/A N/A N/A AsyncStateMachine setServerHandshakeOp self args N/A loseConnection N/A N/A self N/A N/A N/A N/A N/A self tlsStarted N/A N/A N/A N/A ProtocolWrapper loseConnection self N/A N/A N/A N/A AsyncStateMachine setCloseOp self N/A write N/A N/A self data N/A N/A N/A N/A N/A self tlsStarted N/A N/A N/A N/A ProtocolWrapper write self data N/A N/A N/A N/A AsyncStateMachine setWriteOp self data N/A writeSequence N/A N/A self seq N/A N/A N/A N/A N/A self tlsStarted N/A N/A N/A N/A ProtocolWrapper writeSequence self seq N/A N/A N/A N/A AsyncStateMachine setWriteOp self N/A N/A join seq N/A N/A