]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-79846: Make ssl.create_default_context() ignore invalid certificates (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 9 Aug 2024 16:55:36 +0000 (18:55 +0200)
committerGitHub <noreply@github.com>
Fri, 9 Aug 2024 16:55:36 +0000 (12:55 -0400)
An error in one certificate should not cause the whole thing to fail.

(cherry picked from commit 9e551f9b351440ebae79e07a02d0e4a1b61d139e)

Co-authored-by: pukkandan <pukkandan.ytdlp@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/ssl.py
Misc/NEWS.d/next/Windows/2022-04-20-18-32-30.gh-issue-79846.Vggv3f.rst [new file with mode: 0644]

index 983c2db6361898db6503bc732b25b74ba4ef9128..42ebb8ed38466d28560e493bb422f66cb7cad3b5 100644 (file)
@@ -513,18 +513,17 @@ class SSLContext(_SSLContext):
         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):
diff --git a/Misc/NEWS.d/next/Windows/2022-04-20-18-32-30.gh-issue-79846.Vggv3f.rst b/Misc/NEWS.d/next/Windows/2022-04-20-18-32-30.gh-issue-79846.Vggv3f.rst
new file mode 100644 (file)
index 0000000..82c2670
--- /dev/null
@@ -0,0 +1,2 @@
+Makes :code:`ssl.create_default_context()` ignore invalid certificates in
+the Windows certificate store