Skip to content

Commit 85b6b0e

Browse files
miss-islingtonWillChilds-Kleinpicnixz
authored
[3.12] gh-131050: skip test_dh_params when TLS library lacks FFDHE ciphersuites (GH-131051) (#131875)
gh-131050: skip `test_dh_params` when TLS library lacks FFDHE ciphersuites (GH-131051) (cherry picked from commit be2d218) Co-authored-by: Will Childs-Klein <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 3cd04d4 commit 85b6b0e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Lib/test/test_ssl.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,14 @@ def try_protocol_combo(server_protocol, client_protocol, expect_success,
27822782
% (expect_success, stats['version']))
27832783

27842784

2785+
def supports_kx_alias(ctx, aliases):
2786+
for cipher in ctx.get_ciphers():
2787+
for alias in aliases:
2788+
if f"Kx={alias}" in cipher['description']:
2789+
return True
2790+
return False
2791+
2792+
27852793
class ThreadedTests(unittest.TestCase):
27862794

27872795
@support.requires_resource('walltime')
@@ -3970,8 +3978,13 @@ def test_no_legacy_server_connect(self):
39703978
sni_name=hostname)
39713979

39723980
def test_dh_params(self):
3973-
# Check we can get a connection with ephemeral Diffie-Hellman
3981+
# Check we can get a connection with ephemeral finite-field
3982+
# Diffie-Hellman (if supported).
39743983
client_context, server_context, hostname = testing_context()
3984+
dhe_aliases = {"ADH", "EDH", "DHE"}
3985+
if not (supports_kx_alias(client_context, dhe_aliases)
3986+
and supports_kx_alias(server_context, dhe_aliases)):
3987+
self.skipTest("libssl doesn't support ephemeral DH")
39753988
# test scenario needs TLS <= 1.2
39763989
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
39773990
try:
@@ -3987,7 +4000,7 @@ def test_dh_params(self):
39874000
sni_name=hostname)
39884001
cipher = stats["cipher"][0]
39894002
parts = cipher.split("-")
3990-
if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts:
4003+
if not dhe_aliases.intersection(parts):
39914004
self.fail("Non-DH key exchange: " + cipher[0])
39924005

39934006
def test_ecdh_curve(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``test_ssl.test_dh_params`` is skipped if the underlying TLS library does not support finite-field ephemeral Diffie-Hellman.

0 commit comments

Comments
 (0)