summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Childs-Klein <willck93@gmail.com>2024-12-24 18:29:27 (GMT)
committerGitHub <noreply@github.com>2024-12-24 18:29:27 (GMT)
commit418114c139666f33abff937e40ccbbbdce15bc39 (patch)
tree97db70de47e6bb97168b9aeaf6f03b9cb3905443
parent7985d460c731b2c48419a33fc1820f9512bb6f21 (diff)
downloadcpython-418114c139666f33abff937e40ccbbbdce15bc39.zip
cpython-418114c139666f33abff937e40ccbbbdce15bc39.tar.gz
cpython-418114c139666f33abff937e40ccbbbdce15bc39.tar.bz2
gh-128035: Add ssl.HAS_PHA to detect libssl PHA support (GH-128036)
* 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>
-rw-r--r--Doc/library/ssl.rst6
-rw-r--r--Doc/whatsnew/3.14.rst8
-rw-r--r--Lib/ssl.py2
-rw-r--r--Lib/test/test_httplib.py4
-rw-r--r--Lib/test/test_ssl.py3
-rw-r--r--Misc/NEWS.d/next/Core_and_Builtins/2024-12-17-18-20-37.gh-issue-128035.JwqHdB.rst1
-rw-r--r--Modules/_ssl.c6
7 files changed, 26 insertions, 4 deletions
diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst
index f07d151..9d7b6aa 100644
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -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
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index 97a37a8..0dcee56 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -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
--------
diff --git a/Lib/ssl.py b/Lib/ssl.py
index c8703b0..05df4ad 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -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
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 9d853d2..89963da 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -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)
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 3f6f890..c16ef3f 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -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
index 0000000..27815d4
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-17-18-20-37.gh-issue-128035.JwqHdB.rst
@@ -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.
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index e7df132..74cf999 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -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