Skip to content

Commit 3a9bce0

Browse files
Add ssl.HAS_PHA to detect libssl PHA support
1 parent bd3d31f commit 3a9bce0

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-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 post-handshake auth (PHA).
940+
941+
.. versionadded:: 3.14
942+
937943
.. data:: CHANNEL_BINDING_TYPES
938944

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

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 post-handshake auth (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
@@ -4461,7 +4461,8 @@ def server_callback(identity):
44614461
s.connect((HOST, server.port))
44624462

44634463

4464-
@unittest.skipUnless(has_tls_version('TLSv1_3'), "Test needs TLS 1.3")
4464+
@unittest.skipUnless(has_tls_version('TLSv1_3') and ssl.HAS_PHA,
4465+
"Test needs TLS 1.3 PHA")
44654466
class TestPostHandshakeAuth(unittest.TestCase):
44664467
def test_pha_setter(self):
44674468
protocols = [

Modules/_ssl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6318,6 +6318,12 @@ sslmodule_init_constants(PyObject *m)
63186318
addbool(m, "HAS_PSK", 1);
63196319
#endif
63206320

6321+
#ifdef SSL_VERIFY_POST_HANDSHAKE
6322+
addbool(m, "HAS_PHA", 1);
6323+
#else
6324+
addbool(m, "HAS_PHA", 0);
6325+
#endif
6326+
63216327
#undef addbool
63226328
#undef ADD_INT_CONST
63236329

0 commit comments

Comments
 (0)