[Twisted-Python] Twisted + tlslite
Trevor Perrin
trevp at trevp.net
Thu Mar 11 02:38:22 EST 2004
At 05:40 AM 3/7/2004 +0000, exarkun at divmod.com wrote:
>On Fri, 05 Mar 2004 22:33:48 -0800, Trevor Perrin <trevp at trevp.net> wrote:
> > [...]
> > I recently wrote an SSL library in python [1] and got it working with
> > asyncore. I'd like to make it useable with Twisted too.[...]
>[...]
> One tip: don't try to integrate with the existing SSL code. The
> implementation is very much a result of the API limitations of
> PyOpenSSL. Preferably, a new implementation will provide SSL support as
> a protocol instead of a transport. For examples of how this can be done,
> see twisted.protocols.policies.
Hi JP,
thanks for the tip! I've got a first-draft done and it seems to work
pretty well.
One thing I'm not sure about is exception handling. When TLS Lite throws
an exception, is there anywhere I can plug-in a handler or something?
The code is at http://trevp.net/tlslite/, if anyone's curious. Below is an
example of using it. Echo1 does a TLS handshake when the client connects,
and Echo2 does a handshake when the client sends "STARTTLS".
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)
else:
Echo.connectionMade(self)
class Echo2(Echo):
def lineReceived(self, data):
if data == "STARTTLS":
self.transport.setServerHandshakeOp(certChain=certChain,
privateKey=privateKey)
else:
Echo.lineReceived(self, data)
factory = Factory()
factory.protocol = Echo1
#factory.protocol = Echo2
wrappingFactory = WrappingFactory(factory)
wrappingFactory.protocol = tlslite.TLSTwistedProtocolWrapper
Trevor
More information about the Twisted-Python
mailing list