From aaa45846d3dd3bd826284200a693e0cbf3efca0d Mon Sep 17 00:00:00 2001 From: Mathias Ertl Date: Fri, 5 May 2017 16:47:25 +0200 Subject: add function to explicitly get the ssl context --- slixmpp/xmlstream/xmlstream.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index 704a34f1..4ff9fc58 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -488,14 +488,10 @@ class XMLStream(asyncio.BaseProtocol): """ pass - def start_tls(self): - """Perform handshakes for TLS. - - If the handshake is successful, the XML stream will need - to be restarted. + def get_ssl_context(self): + """ + Get SSL context. """ - self.event_when_connected = "tls_success" - if self.ciphers is not None: self.ssl_context.set_ciphers(self.ciphers) if self.keyfile and self.certfile: @@ -510,7 +506,18 @@ class XMLStream(asyncio.BaseProtocol): self.ssl_context.verify_mode = ssl.CERT_REQUIRED self.ssl_context.load_verify_locations(cafile=self.ca_certs) - ssl_connect_routine = self.loop.create_connection(lambda: self, ssl=self.ssl_context, + return self.ssl_context + + def start_tls(self): + """Perform handshakes for TLS. + + If the handshake is successful, the XML stream will need + to be restarted. + """ + self.event_when_connected = "tls_success" + + ssl_context = self.get_ssl_context() + ssl_connect_routine = self.loop.create_connection(lambda: self, ssl=ssl_context, sock=self.socket, server_hostname=self.default_domain) @asyncio.coroutine -- cgit v1.2.3