Skip to content

Commit b731a04

Browse files
Detect DHE support in test_ssl.py test
1 parent bd3d31f commit b731a04

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
@@ -4002,19 +4002,29 @@ def test_no_legacy_server_connect(self):
40024002

40034003
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
40044004
def test_dh_params(self):
4005-
# Check we can get a connection with ephemeral Diffie-Hellman
4005+
# Check we can get a connection with ephemeral finite-field Diffie-
4006+
# Hellman (if supported).
40064007
client_context, server_context, hostname = testing_context()
4008+
dhe_aliases = ["ADH", "EDH", "DHE"]
4009+
def supports_dhe(ctx, aliases) -> bool:
4010+
for cipher in ctx.get_ciphers():
4011+
for alias in aliases:
4012+
if alias in cipher:
4013+
return True
4014+
return False
4015+
if not (supports_dhe(client_context, dhe_aliases) and
4016+
supports_dhe(server_context, dhe_aliases)):
4017+
self.skipTest("ssl doesn't support FFDHE")
40074018
# test scenario needs TLS <= 1.2
40084019
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
4009-
server_context.load_dh_params(DHFILE)
40104020
server_context.set_ciphers("kEDH")
40114021
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
40124022
stats = server_params_test(client_context, server_context,
40134023
chatty=True, connectionchatty=True,
40144024
sni_name=hostname)
40154025
cipher = stats["cipher"][0]
40164026
parts = cipher.split("-")
4017-
if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts:
4027+
if all(a not in parts for a in aliases):
40184028
self.fail("Non-DH key exchange: " + cipher[0])
40194029

40204030
def test_ecdh_curve(self):

0 commit comments

Comments
 (0)