Process a STARTTLS command. Arguments: - context: SSL context to use for the encrypted connection
(self, context=None)
| 991 | |
| 992 | if _have_ssl: |
| 993 | def starttls(self, context=None): |
| 994 | """Process a STARTTLS command. Arguments: |
| 995 | - context: SSL context to use for the encrypted connection |
| 996 | """ |
| 997 | # Per RFC 4642, STARTTLS MUST NOT be sent after authentication or if |
| 998 | # a TLS session already exists. |
| 999 | if self.tls_on: |
| 1000 | raise ValueError("TLS is already enabled.") |
| 1001 | if self.authenticated: |
| 1002 | raise ValueError("TLS cannot be started after authentication.") |
| 1003 | resp = self._shortcmd('STARTTLS') |
| 1004 | if resp.startswith('382'): |
| 1005 | self.file.close() |
| 1006 | self.sock = _encrypt_on(self.sock, context, self.host) |
| 1007 | self.file = self.sock.makefile("rwb") |
| 1008 | self.tls_on = True |
| 1009 | # Capabilities may change after TLS starts up, so ask for them |
| 1010 | # again. |
| 1011 | self._caps = None |
| 1012 | self.getcapabilities() |
| 1013 | else: |
| 1014 | raise NNTPError("TLS failed to start.") |
| 1015 | |
| 1016 | |
| 1017 | if _have_ssl: |
no test coverage detected