Start a TLS session on the active connection as specified in RFC 2595. context - a ssl.SSLContext
(self, context=None)
| 406 | |
| 407 | |
| 408 | def stls(self, context=None): |
| 409 | """Start a TLS session on the active connection as specified in RFC 2595. |
| 410 | |
| 411 | context - a ssl.SSLContext |
| 412 | """ |
| 413 | if not HAVE_SSL: |
| 414 | raise error_proto('-ERR TLS support missing') |
| 415 | if self._tls_established: |
| 416 | raise error_proto('-ERR TLS session already established') |
| 417 | caps = self.capa() |
| 418 | if not 'STLS' in caps: |
| 419 | raise error_proto('-ERR STLS not supported by server') |
| 420 | if context is None: |
| 421 | context = ssl._create_stdlib_context() |
| 422 | resp = self._shortcmd('STLS') |
| 423 | self.sock = context.wrap_socket(self.sock, |
| 424 | server_hostname=self.host) |
| 425 | self.file = self.sock.makefile('rb') |
| 426 | self._tls_established = True |
| 427 | return resp |
| 428 | |
| 429 | |
| 430 | if HAVE_SSL: |