Skip to content

Commit 8ad4e87

Browse files
WillChilds-Kleintomasr8picnixz
authored andcommitted
pythongh-128035: Add ssl.HAS_PHA to detect libssl PHA support (pythonGH-128036)
* Add ssl.HAS_PHA to detect libssl Post-Handshake-Auth support Co-authored-by: Tomas R. <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 1801d45 commit 8ad4e87

File tree

7 files changed

+26
-4
lines changed

7 files changed

+26
-4
lines changed

Doc/library/ssl.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,12 @@ Constants
934934

935935
.. versionadded:: 3.13
936936

937+
.. data:: HAS_PHA
938+
939+
Whether the OpenSSL library has built-in support for TLS-PHA.
940+
941+
.. versionadded:: next
942+
937943
.. data:: CHANNEL_BINDING_TYPES
938944

939945
List of supported TLS channel binding types. Strings in this list

Doc/whatsnew/3.14.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,14 @@ pydoc
584584
(Contributed by Jelle Zijlstra in :gh:`101552`.)
585585

586586

587+
ssl
588+
---
589+
590+
* Indicate through :data:`ssl.HAS_PHA` whether the :mod:`ssl` module supports
591+
TLSv1.3 post-handshake client authentication (PHA).
592+
(Contributed by Will Childs-Klein in :gh:`128036`.)
593+
594+
587595
symtable
588596
--------
589597

Lib/ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116

117117
from _ssl import (
118118
HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1,
119-
HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK
119+
HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK, HAS_PHA
120120
)
121121
from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION
122122

Lib/test/test_httplib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,8 +2073,8 @@ def test_host_port(self):
20732073

20742074
def test_tls13_pha(self):
20752075
import ssl
2076-
if not ssl.HAS_TLSv1_3:
2077-
self.skipTest('TLS 1.3 support required')
2076+
if not ssl.HAS_TLSv1_3 or not ssl.HAS_PHA:
2077+
self.skipTest('TLS 1.3 PHA support required')
20782078
# just check status of PHA flag
20792079
h = client.HTTPSConnection('localhost', 443)
20802080
self.assertTrue(h._context.post_handshake_auth)

Lib/test/test_ssl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4494,7 +4494,8 @@ def server_callback(identity):
44944494
s.connect((HOST, server.port))
44954495

44964496

4497-
@unittest.skipUnless(has_tls_version('TLSv1_3'), "Test needs TLS 1.3")
4497+
@unittest.skipUnless(has_tls_version('TLSv1_3') and ssl.HAS_PHA,
4498+
"Test needs TLS 1.3 PHA")
44984499
class TestPostHandshakeAuth(unittest.TestCase):
44994500
def test_pha_setter(self):
45004501
protocols = [
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

Modules/_ssl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6553,6 +6553,12 @@ sslmodule_init_constants(PyObject *m)
65536553
addbool(m, "HAS_PSK", 1);
65546554
#endif
65556555

6556+
#ifdef SSL_VERIFY_POST_HANDSHAKE
6557+
addbool(m, "HAS_PHA", 1);
6558+
#else
6559+
addbool(m, "HAS_PHA", 0);
6560+
#endif
6561+
65566562
#undef addbool
65576563
#undef ADD_INT_CONST
65586564

0 commit comments

Comments
 (0)