Skip to content

Commit 5c2c817

Browse files
miss-islingtonWillChilds-Kleinpicnixz
authored
[3.13] gh-131050: skip test_dh_params when TLS library lacks FFDHE ciphersuites (GH-131051) (#131874)
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 <willck93@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 9ffa80f commit 5c2c817

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
@@ -2810,6 +2810,14 @@ def try_protocol_combo(server_protocol, client_protocol, expect_success,
28102810
% (expect_success, stats['version']))
28112811

28122812

2813+
def supports_kx_alias(ctx, aliases):
2814+
for cipher in ctx.get_ciphers():
2815+
for alias in aliases:
2816+
if f"Kx={alias}" in cipher['description']:
2817+
return True
2818+
return False
2819+
2820+
28132821
class ThreadedTests(unittest.TestCase):
28142822

28152823
@support.requires_resource('walltime')
@@ -4070,8 +4078,13 @@ def test_no_legacy_server_connect(self):
40704078
sni_name=hostname)
40714079

40724080
def test_dh_params(self):
4073-
# Check we can get a connection with ephemeral Diffie-Hellman
4081+
# Check we can get a connection with ephemeral finite-field
4082+
# Diffie-Hellman (if supported).
40744083
client_context, server_context, hostname = testing_context()
4084+
dhe_aliases = {"ADH", "EDH", "DHE"}
4085+
if not (supports_kx_alias(client_context, dhe_aliases)
4086+
and supports_kx_alias(server_context, dhe_aliases)):
4087+
self.skipTest("libssl doesn't support ephemeral DH")
40754088
# test scenario needs TLS <= 1.2
40764089
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
40774090
try:
@@ -4087,7 +4100,7 @@ def test_dh_params(self):
40874100
sni_name=hostname)
40884101
cipher = stats["cipher"][0]
40894102
parts = cipher.split("-")
4090-
if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts:
4103+
if not dhe_aliases.intersection(parts):
40914104
self.fail("Non-DH key exchange: " + cipher[0])
40924105

40934106
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)