[Twisted-Python] transport.getPeerCertificate in connectionMade
glyph at twistedmatrix.com
Mon Aug 20 13:50:56 EDT 2012
On Aug 20, 2012, at 4:52 AM, Phil Mayers <p.mayers at imperial.ac.uk> wrote:
> It's been my observation that this code:
> class MyProto(protocol.Protocol):
> def connectionMade(self):
> print self.transport.getPeerCertificate()
> class MyFactory(protocol.ClientFactory):
> def buildProtocol(self, addr):
> return MyProto()
> def main():
> factory = MyFactory()
> ctxfact = ssl.ClientContextFactory()
> reactor.connectSSL(host, port, factory, ctxfact)
> ...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?
Yup, it's a bug, reported 3 years ago:
It's definitely a problem. Perhaps worse is the fact that startTLS() doesn't directly give you that notification either. Please feel free to contribute a fix :).
More information about the Twisted-Python