Skip to content

Commit 80e7fd8

Browse files
Detect DHE support in test_ssl.py test
1 parent 4192ce1 commit 80e7fd8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Lib/test/test_ssl.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,19 +4034,29 @@ def test_no_legacy_server_connect(self):
40344034

40354035
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
40364036
def test_dh_params(self):
4037-
# Check we can get a connection with ephemeral Diffie-Hellman
4037+
# Check we can get a connection with ephemeral finite-field Diffie-
4038+
# Hellman (if supported).
40384039
client_context, server_context, hostname = testing_context()
4040+
dhe_aliases = ["ADH", "EDH", "DHE"]
4041+
def supports_dhe(ctx, aliases) -> bool:
4042+
for cipher in ctx.get_ciphers():
4043+
for alias in aliases:
4044+
if alias in cipher:
4045+
return True
4046+
return False
4047+
if not (supports_dhe(client_context, dhe_aliases) and
4048+
supports_dhe(server_context, dhe_aliases)):
4049+
self.skipTest("ssl doesn't support FFDHE")
40394050
# test scenario needs TLS <= 1.2
40404051
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
4041-
server_context.load_dh_params(DHFILE)
40424052
server_context.set_ciphers("kEDH")
40434053
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
40444054
stats = server_params_test(client_context, server_context,
40454055
chatty=True, connectionchatty=True,
40464056
sni_name=hostname)
40474057
cipher = stats["cipher"][0]
40484058
parts = cipher.split("-")
4049-
if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts:
4059+
if all(a not in parts for a in aliases):
40504060
self.fail("Non-DH key exchange: " + cipher[0])
40514061

40524062
def test_ecdh_curve(self):

0 commit comments

Comments
 (0)