diff options
-rw-r--r-- | slixmpp/xmlstream/xmlstream.py | 23 |
1 files 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 |