Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-94172: urllib.request avoids deprecated key_file/cert_file #94232

Merged
merged 1 commit into from
Jun 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1990,9 +1990,17 @@ def http_error_default(self, url, fp, errcode, errmsg, headers):

if _have_ssl:
def _https_connection(self, host):
return http.client.HTTPSConnection(host,
key_file=self.key_file,
cert_file=self.cert_file)
if self.key_file or self.cert_file:
http_version = http.client.HTTPSConnection._http_vsn
context = http.client._create_https_context(http_version)
context.load_cert_chain(self.cert_file, self.key_file)
# cert and key file means the user wants to authenticate.
# enable TLS 1.3 PHA implicitly even for custom contexts.
if context.post_handshake_auth is not None:
context.post_handshake_auth = True
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This post_handshake_auth code is already in _create_https_context(), but I copied Python 3.11 code which also checks again post_handshake_auth after calling load_cert_chain().

else:
context = None
return http.client.HTTPSConnection(host, context=context)

def open_https(self, url, data=None):
"""Use HTTPS protocol."""
Expand Down