Issue #19782: imaplib now supports SSLContext.check_hostname and server name

indication for TLS/SSL connections.
This commit is contained in:
Christian Heimes 2013-12-02 20:01:29 +01:00
parent 0c924b83ee
commit 48aae57996
4 changed files with 43 additions and 4 deletions

View file

@ -745,7 +745,9 @@ class IMAP4:
ssl_context = ssl._create_stdlib_context()
typ, dat = self._simple_command(name)
if typ == 'OK':
self.sock = ssl_context.wrap_socket(self.sock)
server_hostname = self.host if ssl.HAS_SNI else None
self.sock = ssl_context.wrap_socket(self.sock,
server_hostname=server_hostname)
self.file = self.sock.makefile('rb')
self._tls_established = True
self._get_capabilities()
@ -1216,7 +1218,9 @@ if HAVE_SSL:
def _create_socket(self):
sock = IMAP4._create_socket(self)
return self.ssl_context.wrap_socket(sock)
server_hostname = self.host if ssl.HAS_SNI else None
return self.ssl_context.wrap_socket(sock,
server_hostname=server_hostname)
def open(self, host='', port=IMAP4_SSL_PORT):
"""Setup connection to remote server on "host:port".