]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128035: Add ssl.HAS_PHA to detect libssl PHA support (GH-128036)
authorWill Childs-Klein <willck93@gmail.com>
Tue, 24 Dec 2024 18:29:27 +0000 (12:29 -0600)
committerGitHub <noreply@github.com>
Tue, 24 Dec 2024 18:29:27 +0000 (18:29 +0000)
* Add ssl.HAS_PHA to detect libssl Post-Handshake-Auth support

Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Doc/library/ssl.rst
Doc/whatsnew/3.14.rst
Lib/ssl.py
Lib/test/test_httplib.py
Lib/test/test_ssl.py
Misc/NEWS.d/next/Core_and_Builtins/2024-12-17-18-20-37.gh-issue-128035.JwqHdB.rst [new file with mode: 0644]
Modules/_ssl.c

index f07d151a885692e6140e050c24392bae7731f4b8..9d7b6aa66cd443fc3a7afc16e7519a00fe771203 100644 (file)
@@ -934,6 +934,12 @@ Constants
 
    .. versionadded:: 3.13
 
+.. data:: HAS_PHA
+
+   Whether the OpenSSL library has built-in support for TLS-PHA.
+
+   .. versionadded:: next
+
 .. data:: CHANNEL_BINDING_TYPES
 
    List of supported TLS channel binding types.  Strings in this list
index 97a37a82f76b9bf47430415ace43ac6ce32806fd..0dcee56b7d233f4c725522564bdaacb6f6d25111 100644 (file)
@@ -584,6 +584,14 @@ pydoc
   (Contributed by Jelle Zijlstra in :gh:`101552`.)
 
 
+ssl
+---
+
+* Indicate through :data:`ssl.HAS_PHA` whether the :mod:`ssl` module supports
+  TLSv1.3 post-handshake client authentication (PHA).
+  (Contributed by Will Childs-Klein in :gh:`128036`.)
+
+
 symtable
 --------
 
index c8703b046cfd4b3bc335062089f0ae2bda76fc62..05df4ad7f0f05cfb987b064eea3fbe236e9ff01c 100644 (file)
@@ -116,7 +116,7 @@ except ImportError:
 
 from _ssl import (
     HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1,
-    HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK
+    HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK, HAS_PHA
 )
 from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION
 
index 9d853d254db7c6b1f41782e40da5b11efc54633d..89963dadeb152b6de4dc5d4222e90a62e3a5efbf 100644 (file)
@@ -2073,8 +2073,8 @@ class HTTPSTest(TestCase):
 
     def test_tls13_pha(self):
         import ssl
-        if not ssl.HAS_TLSv1_3:
-            self.skipTest('TLS 1.3 support required')
+        if not ssl.HAS_TLSv1_3 or not ssl.HAS_PHA:
+            self.skipTest('TLS 1.3 PHA support required')
         # just check status of PHA flag
         h = client.HTTPSConnection('localhost', 443)
         self.assertTrue(h._context.post_handshake_auth)
index 3f6f890bbdc658cffbaea61e0c4fd3bacea8fafa..c16ef3f96f9a21e2ca759f7e412f592a1d979dda 100644 (file)
@@ -4494,7 +4494,8 @@ class ThreadedTests(unittest.TestCase):
                 s.connect((HOST, server.port))
 
 
-@unittest.skipUnless(has_tls_version('TLSv1_3'), "Test needs TLS 1.3")
+@unittest.skipUnless(has_tls_version('TLSv1_3') and ssl.HAS_PHA,
+                     "Test needs TLS 1.3 PHA")
 class TestPostHandshakeAuth(unittest.TestCase):
     def test_pha_setter(self):
         protocols = [
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-12-17-18-20-37.gh-issue-128035.JwqHdB.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-17-18-20-37.gh-issue-128035.JwqHdB.rst
new file mode 100644 (file)
index 0000000..27815d4
--- /dev/null
@@ -0,0 +1 @@
+Indicate through :data:`ssl.HAS_PHA` whether the :mod:`ssl` module supports TLSv1.3 post-handshake client authentication (PHA). Patch by Will Childs-Klein.
index e7df132869fee678ec7fada635851ae94c447683..74cf99957389e2b8363016caf95750e0f9bf53fe 100644 (file)
@@ -6553,6 +6553,12 @@ sslmodule_init_constants(PyObject *m)
     addbool(m, "HAS_PSK", 1);
 #endif
 
+#ifdef SSL_VERIFY_POST_HANDSHAKE
+    addbool(m, "HAS_PHA", 1);
+#else
+    addbool(m, "HAS_PHA", 0);
+#endif
+
 #undef addbool
 #undef ADD_INT_CONST