Skip to content

Commit 8233b4b

Browse files
Set OPENSSL_NO_EXTERNAL_PSK_TLS13 to indicate lack of TLS 1.3 PSK (#2399)
Due to [security concerns][1] neither AWS-LC [nor BoringSSL][2] support external (i.e. non-session-resumption, established out of band) PSKs in TLS 1.3. This PR proposes a "configuration" flag to indicate this limitation to consumers, much as we did with `OPENSSL_NO_TLS_PHA` in 0aebf17. [1]: https://www.rfc-editor.org/rfc/rfc9258.html#section-1 [2]: https://issues.chromium.org/issues/369963041
1 parent a614f97 commit 8233b4b

2 files changed

Lines changed: 45 additions & 20 deletions

File tree

include/openssl/opensslconf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ extern "C" {
5353
#define OPENSSL_NO_MD2
5454
#define OPENSSL_NO_MDC2
5555
#define OPENSSL_NO_OCB
56+
// OPENSSL_NO_EXTERNAL_PSK_TLS13 indicates lack of support for external
57+
// PSK authentication in TLS >= 1.3. AWS-LC intentionally omits support
58+
// for this due to security conerns outlined in RFC 9258.
59+
#define OPENSSL_NO_EXTERNAL_PSK_TLS13
5660
#define OPENSSL_NO_RC2
5761
#define OPENSSL_NO_RC5
5862
#define OPENSSL_NO_RFC3779
Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1+
diff --git a/Lib/ssl.py b/Lib/ssl.py
2+
index 05df4ad..7e3c4cb 100644
3+
--- a/Lib/ssl.py
4+
+++ b/Lib/ssl.py
5+
@@ -116,7 +116,7 @@
6+
7+
from _ssl import (
8+
HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1,
9+
- HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK, HAS_PHA
10+
+ HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK, HAS_PSK_TLS13, HAS_PHA
11+
)
12+
from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION
13+
114
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
2-
index 0e50d09..f4b7b3c 100644
15+
index 395b2ef..c168224 100644
316
--- a/Lib/test/test_ssl.py
417
+++ b/Lib/test/test_ssl.py
5-
@@ -4443,14 +4445,14 @@ def server_callback(identity):
6-
self.assertEqual(identity, client_identity)
7-
return psk
8-
9-
- client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
10-
+ client_context, server_context, _ = testing_context()
11-
+
12-
client_context.check_hostname = False
13-
client_context.verify_mode = ssl.CERT_NONE
14-
client_context.minimum_version = ssl.TLSVersion.TLSv1_3
15-
client_context.set_ciphers('PSK')
16-
client_context.set_psk_client_callback(client_callback)
17-
18-
- server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
19-
server_context.minimum_version = ssl.TLSVersion.TLSv1_3
20-
server_context.set_ciphers('PSK')
21-
server_context.set_psk_server_callback(server_callback, identity_hint)
18+
@@ -4488,6 +4488,7 @@ def server_callback(identity):
19+
20+
@requires_tls_version('TLSv1_3')
21+
@unittest.skipUnless(ssl.HAS_PSK, 'TLS-PSK disabled on this OpenSSL build')
22+
+ @unittest.skipUnless(ssl.HAS_PSK_TLS13, 'TLS 1.3 PSK disabled on this OpenSSL build')
23+
def test_psk_tls1_3(self):
24+
psk = bytes.fromhex('deadbeef')
25+
identity_hint = 'identity-hint'
2226
diff --git a/Modules/Setup b/Modules/Setup
23-
index cd1cf24..53bcc4c 100644
27+
index a066982..3d7fbc3 100644
2428
--- a/Modules/Setup
2529
+++ b/Modules/Setup
26-
@@ -208,11 +208,11 @@ PYTHONPATH=$(COREPYTHONPATH)
30+
@@ -213,11 +213,11 @@ PYTHONPATH=$(COREPYTHONPATH)
2731
#_hashlib _hashopenssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) -lcrypto
2832

2933
# To statically link OpenSSL:
@@ -40,3 +44,20 @@ index cd1cf24..53bcc4c 100644
4044

4145
# The _tkinter module.
4246
#
47+
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
48+
index 97a29f4..3f2f55e 100644
49+
--- a/Modules/_ssl.c
50+
+++ b/Modules/_ssl.c
51+
@@ -6626,6 +6626,12 @@ sslmodule_init_constants(PyObject *m)
52+
addbool(m, "HAS_PSK", 1);
53+
#endif
54+
55+
+#ifdef OPENSSL_NO_EXTERNAL_PSK_TLS13
56+
+ addbool(m, "HAS_PSK_TLS13", 0);
57+
+#else
58+
+ addbool(m, "HAS_PSK_TLS13", 1);
59+
+#endif
60+
+
61+
#ifdef SSL_VERIFY_POST_HANDSHAKE
62+
addbool(m, "HAS_PHA", 1);
63+
#else

0 commit comments

Comments
 (0)