]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
expose X509_V_FLAG_TRUSTED_FIRST
authorBenjamin Peterson <benjamin@python.org>
Thu, 5 Mar 2015 03:49:41 +0000 (22:49 -0500)
committerBenjamin Peterson <benjamin@python.org>
Thu, 5 Mar 2015 03:49:41 +0000 (22:49 -0500)
Doc/library/ssl.rst
Lib/test/test_ssl.py
Modules/_ssl.c

index b261eee93297e8b923c4b051ed966ba81661604f..d328c2bad68f26262ff36173177e64cc4aec9d73 100644 (file)
@@ -482,9 +482,9 @@ Constants
 
 .. data:: VERIFY_DEFAULT
 
-   Possible value for :attr:`SSLContext.verify_flags`. In this mode,
-   certificate revocation lists (CRLs) are not checked. By default OpenSSL
-   does neither require nor verify CRLs.
+   Possible value for :attr:`SSLContext.verify_flags`. In this mode, certificate
+   revocation lists (CRLs) are not checked. By default OpenSSL does neither
+   require nor verify CRLs.
 
    .. versionadded:: 2.7.9
 
@@ -512,6 +512,14 @@ Constants
 
    .. versionadded:: 2.7.9
 
+.. data:: VERIFY_X509_TRUSTED_FIRST
+
+   Possible value for :attr:`SSLContext.verify_flags`. It instructs OpenSSL to
+   prefer trusted certificates when building the trust chain to validate a
+   certificate. This flag is enabled by default.
+
+   .. versionadded:: 2.7.10
+
 .. data:: PROTOCOL_SSLv23
 
    Selects the highest protocol version that both the client and server support.
index e9e80ee9ced3a9c52b92b70a690bf57f9549324d..b2d57cf874787ce6701f00b4908a1d44bb1aa235 100644 (file)
@@ -749,8 +749,9 @@ class ContextTests(unittest.TestCase):
                          "verify_flags need OpenSSL > 0.9.8")
     def test_verify_flags(self):
         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
-        # default value by OpenSSL
-        self.assertEqual(ctx.verify_flags, ssl.VERIFY_DEFAULT)
+        # default value
+        tf = getattr(ssl, "VERIFY_X509_TRUSTED_FIRST", 0)
+        self.assertEqual(ctx.verify_flags, ssl.VERIFY_DEFAULT | tf)
         ctx.verify_flags = ssl.VERIFY_CRL_CHECK_LEAF
         self.assertEqual(ctx.verify_flags, ssl.VERIFY_CRL_CHECK_LEAF)
         ctx.verify_flags = ssl.VERIFY_CRL_CHECK_CHAIN
index 309d00bf783caeaaa76dec8a0ce5f089cc76f574..8515c0fd1191b9a1639594c96d6cf03419e7a3ad 100644 (file)
@@ -4052,6 +4052,10 @@ init_ssl(void)
                             X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL);
     PyModule_AddIntConstant(m, "VERIFY_X509_STRICT",
                             X509_V_FLAG_X509_STRICT);
+#ifdef X509_V_FLAG_TRUSTED_FIRST
+    PyModule_AddIntConstant(m, "VERIFY_X509_TRUSTED_FIRST",
+                            X509_V_FLAG_TRUSTED_FIRST);
+#endif
 
     /* Alert Descriptions from ssl.h */
     /* note RESERVED constants no longer intended for use have been removed */