[Twisted-Python] transport.getPeerCertificate in connectionMade

Phil Mayers p.mayers at imperial.ac.uk
Mon Aug 20 07:52:04 EDT 2012


All,

It's been my observation that this code:

class MyProto(protocol.Protocol):

   def connectionMade(self):
     print self.transport.getPeerCertificate()
     self.transport.loseConnection()

class MyFactory(protocol.ClientFactory):

   def buildProtocol(self, addr):
     return MyProto()

def main():
   factory = MyFactory()
   ctxfact = ssl.ClientContextFactory()
   reactor.connectSSL(host, port, factory, ctxfact)
   reactor.run()

...will print "None". It seems that connectSSL calls connectionMade at 
TCP connection time, not when SSL has completed. This seems unintuitive 
to me because I've called "connectSSL" not "connectTCP", but I guess may 
be hard to fix given the way the code works?

At the very least, should this be documented?

Or could we have an interface e.g.

class ISSLProtocol(interface):
   def sslReady():
     """called when the SSL layer is ready"""

...and people who are interested can "implements()" it to get the callback?



More information about the Twisted-Python mailing list