]> granicus.if.org Git - python/commitdiff
enable X509_V_FLAG_TRUSTED_FIRST when possible (closes #23476)
authorBenjamin Peterson <benjamin@python.org>
Thu, 5 Mar 2015 03:11:12 +0000 (22:11 -0500)
committerBenjamin Peterson <benjamin@python.org>
Thu, 5 Mar 2015 03:11:12 +0000 (22:11 -0500)
Misc/NEWS
Modules/_ssl.c

index 129843472f98b1557c48eb7f4646137654c742cd..29c62144962c5cd4de1991e91fd0ea16410f031b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #23476: In the ssl module, enable OpenSSL's X509_V_FLAG_TRUSTED_FIRST
+  flag on certificate stores when it is available.
+
 - Issue #23576: Avoid stalling in SSL reads when EOF has been reached in the
   SSL layer but the underlying connection hasn't been closed.
 
index e7ba5839491080f06d2a4c43367489e7e4872169..a5b94eb4b00b90e2922ad1620065e3046f579ef6 100644 (file)
@@ -2063,6 +2063,15 @@ context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                                    sizeof(SID_CTX));
 #undef SID_CTX
 
+#ifdef X509_V_FLAG_TRUSTED_FIRST
+    {
+        /* Improve trust chain building when cross-signed intermediate
+           certificates are present. See https://bugs.python.org/issue23476. */
+        X509_STORE *store = SSL_CTX_get_cert_store(self->ctx);
+        X509_STORE_set_flags(store, X509_V_FLAG_TRUSTED_FIRST);
+    }
+#endif
+
     return (PyObject *)self;
 }