mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
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().
This commit is contained in:
parent
32eddc1bbc
commit
67986f9431
11 changed files with 100 additions and 55 deletions
|
|
@ -664,10 +664,10 @@ class SMTP:
|
|||
if context is not None and certfile is not None:
|
||||
raise ValueError("context and certfile arguments are mutually "
|
||||
"exclusive")
|
||||
if context is not None:
|
||||
self.sock = context.wrap_socket(self.sock)
|
||||
else:
|
||||
self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
|
||||
if context is None:
|
||||
context = ssl._create_stdlib_context(certfile=certfile,
|
||||
keyfile=keyfile)
|
||||
self.sock = context.wrap_socket(self.sock)
|
||||
self.file = None
|
||||
# RFC 3207:
|
||||
# The client MUST discard any knowledge obtained from
|
||||
|
|
@ -880,6 +880,9 @@ if _have_ssl:
|
|||
"exclusive")
|
||||
self.keyfile = keyfile
|
||||
self.certfile = certfile
|
||||
if context is None:
|
||||
context = ssl._create_stdlib_context(certfile=certfile,
|
||||
keyfile=keyfile)
|
||||
self.context = context
|
||||
SMTP.__init__(self, host, port, local_hostname, timeout,
|
||||
source_address)
|
||||
|
|
@ -889,10 +892,7 @@ if _have_ssl:
|
|||
print('connect:', (host, port), file=stderr)
|
||||
new_socket = socket.create_connection((host, port), timeout,
|
||||
self.source_address)
|
||||
if self.context is not None:
|
||||
new_socket = self.context.wrap_socket(new_socket)
|
||||
else:
|
||||
new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
|
||||
new_socket = self.context.wrap_socket(new_socket)
|
||||
return new_socket
|
||||
|
||||
__all__.append("SMTP_SSL")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue