From 5b41fb98deee0be688d1b733023051821cabb29c Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 30 Oct 2014 19:51:30 +0100 Subject: Add the ssl_cert and ssl_invalid_chain back - hack the stdlib to get the peercert, remove that hack when http://bugs.python.org/issue22768 gets fixed --- slixmpp/xmlstream/xmlstream.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index 16e1aa22..f4f0b87e 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -453,7 +453,19 @@ class XMLStream(object): ssl_connect_routine = loop.create_connection(lambda: self, ssl=self.ssl_context, sock=self.socket, server_hostname=self.address[0]) - asyncio.async(ssl_connect_routine) + def ssl_coro(): + try: + transp, prot = yield from ssl_connect_routine + except ssl.SSLError: + import traceback + log.debug('SSL: Unable to connect:\n%s', exc_info=True) + self.event('ssl_invalid_chain', direct=True) + else: + der_cert = transp._sock.getpeercert(True) + pem_cert = ssl.DER_cert_to_PEM_cert(der_cert) + self.event('ssl_cert', pem_cert) + + asyncio.async(ssl_coro()) def _start_keepalive(self, event): """Begin sending whitespace periodically to keep the connection alive. -- cgit v1.2.3