Start a TLS session on the active connection as specified in RFC 2595. context - a ssl.SSLContext
(self, context=None)
| 393 | |
| 394 | |
| 395 | def stls(self, context=None): |
| 396 | """Start a TLS session on the active connection as specified in RFC 2595. |
| 397 | |
| 398 | context - a ssl.SSLContext |
| 399 | """ |
| 400 | if not HAVE_SSL: |
| 401 | raise error_proto('-ERR TLS support missing') |
| 402 | if self._tls_established: |
| 403 | raise error_proto('-ERR TLS session already established') |
| 404 | caps = self.capa() |
| 405 | if not 'STLS' in caps: |
| 406 | raise error_proto('-ERR STLS not supported by server') |
| 407 | if context is None: |
| 408 | context = ssl._create_stdlib_context() |
| 409 | resp = self._shortcmd('STLS') |
| 410 | self.sock = context.wrap_socket(self.sock, |
| 411 | server_hostname=self.host) |
| 412 | self.file = self.sock.makefile('rb') |
| 413 | self._tls_established = True |
| 414 | return resp |
| 415 | |
| 416 | |
| 417 | if HAVE_SSL: |
nothing calls this directly
no test coverage detected