]> granicus.if.org Git - python/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 015e0dbb7dd2b84ea383d1e67d86ada10fddb456..bb30d0fad15be0726cf41e4de12fef1c9aaa2e45 100644 (file)
@@ -499,9 +499,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:: 3.4
 
@@ -529,6 +529,14 @@ Constants
 
    .. versionadded:: 3.4
 
+.. 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:: 3.4.5
+
 .. data:: PROTOCOL_SSLv23
 
    Selects the highest protocol version that both the client and server support.
index dc82475a9d02a2ebf6c3779c2f9598f12a0a7d92..6353e230d605e21ac0755b9578a28152b42f0e1e 100644 (file)
@@ -710,8 +710,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 a5b94eb4b00b90e2922ad1620065e3046f579ef6..9bd07764bc08efc54a0b5a6d762ff04d3a290e7f 100644 (file)
@@ -4004,6 +4004,10 @@ PyInit__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 */