Skip to content

Commit 22fdeeb

Browse files
miss-islingtonpukkandanserhiy-storchaka
authored
[3.12] gh-79846: Make ssl.create_default_context() ignore invalid certificates (GH-91740) (#122769)
An error in one certificate should not cause the whole thing to fail. (cherry picked from commit 9e551f9) Co-authored-by: pukkandan <pukkandan.ytdlp@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 9d7209f commit 22fdeeb

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Diff for: Lib/ssl.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -513,18 +513,17 @@ def set_alpn_protocols(self, alpn_protocols):
513513
self._set_alpn_protocols(protos)
514514

515515
def _load_windows_store_certs(self, storename, purpose):
516-
certs = bytearray()
517516
try:
518517
for cert, encoding, trust in enum_certificates(storename):
519518
# CA certs are never PKCS#7 encoded
520519
if encoding == "x509_asn":
521520
if trust is True or purpose.oid in trust:
522-
certs.extend(cert)
521+
try:
522+
self.load_verify_locations(cadata=cert)
523+
except SSLError as exc:
524+
warnings.warn(f"Bad certificate in Windows certificate store: {exc!s}")
523525
except PermissionError:
524526
warnings.warn("unable to enumerate Windows certificate store")
525-
if certs:
526-
self.load_verify_locations(cadata=certs)
527-
return certs
528527

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

0 commit comments

Comments
 (0)