diff options
author | Christian Heimes <christian@cheimes.de> | 2013-11-23 22:43:47 +0100 |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2013-11-23 22:43:47 +0100 |
commit | e0d6d1e2e84489a2cbfa6e82150f50e9f397d1ac (patch) | |
tree | 76c7a7965ae53d707569cccacfc1656564a0e4a2 /Lib/imaplib.py | |
parent | be38458d38f80ff5c8ba6a822dea6979b04307ac (diff) | |
download | cpython-e0d6d1e2e84489a2cbfa6e82150f50e9f397d1ac.tar.gz |
Issue #19735: Implement private function ssl._create_stdlib_context() to
create SSLContext objects in Python's stdlib module. It provides a single
configuration point and makes use of SSLContext.load_default_certs().
Diffstat (limited to 'Lib/imaplib.py')
-rw-r--r-- | Lib/imaplib.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py index b29487acdd..dabf161b87 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -742,9 +742,7 @@ class IMAP4: raise self.abort('TLS not supported by server') # Generate a default SSL context if none was passed. if ssl_context is None: - ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) - # SSLv2 considered harmful. - ssl_context.options |= ssl.OP_NO_SSLv2 + ssl_context = ssl._create_stdlib_context() typ, dat = self._simple_command(name) if typ == 'OK': self.sock = ssl_context.wrap_socket(self.sock) @@ -1210,15 +1208,15 @@ if HAVE_SSL: self.keyfile = keyfile self.certfile = certfile + if ssl_context is None: + ssl_context = ssl._create_stdlib_context(certfile=certfile, + keyfile=keyfile) self.ssl_context = ssl_context IMAP4.__init__(self, host, port) def _create_socket(self): sock = IMAP4._create_socket(self) - if self.ssl_context: - return self.ssl_context.wrap_socket(sock) - else: - return ssl.wrap_socket(sock, self.keyfile, self.certfile) + return self.ssl_context.wrap_socket(sock) def open(self, host='', port=IMAP4_SSL_PORT): """Setup connection to remote server on "host:port". |