Skip to content

gh-79846: Make ssl.create_default_context() ignore invalid certificates #91740

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

Merged
merged 6 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions Lib/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,18 +513,17 @@ def set_alpn_protocols(self, alpn_protocols):
self._set_alpn_protocols(protos)

def _load_windows_store_certs(self, storename, purpose):
certs = bytearray()
try:
for cert, encoding, trust in enum_certificates(storename):
# CA certs are never PKCS#7 encoded
if encoding == "x509_asn":
if trust is True or purpose.oid in trust:
certs.extend(cert)
try:
self.load_verify_locations(cadata=cert)
except SSLError as exc:
warnings.warn(f"Bad certificate in Windows certificate store: {exc!s}")
except PermissionError:
warnings.warn("unable to enumerate Windows certificate store")
if certs:
self.load_verify_locations(cadata=certs)
return certs

def load_default_certs(self, purpose=Purpose.SERVER_AUTH):
if not isinstance(purpose, _ASN1Object):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Makes :code:`ssl.create_default_context()` ignore invalid certificates in
the Windows certificate store
Loading