@@ -1326,10 +1326,14 @@ def test_load_verify_cadata(self):
13261326 with self .assertRaises (ssl .SSLError ):
13271327 ctx .load_verify_locations (cadata = cacert_der + b"A" )
13281328
1329- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
13301329 def test_load_dh_params (self ):
13311330 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
1332- ctx .load_dh_params (DHFILE )
1331+ try :
1332+ ctx .load_dh_params (DHFILE )
1333+ except RuntimeError :
1334+ if Py_DEBUG_WIN32 :
1335+ self .skipTest ("not supported on Win32 debug build" )
1336+ raise
13331337 if os .name != 'nt' :
13341338 ctx .load_dh_params (BYTES_DHFILE )
13351339 self .assertRaises (TypeError , ctx .load_dh_params )
@@ -1650,12 +1654,17 @@ def test_str(self):
16501654 self .assertEqual (str (e ), "foo" )
16511655 self .assertEqual (e .errno , 1 )
16521656
1653- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
16541657 def test_lib_reason (self ):
16551658 # Test the library and reason attributes
16561659 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
1657- with self .assertRaises (ssl .SSLError ) as cm :
1658- ctx .load_dh_params (CERTFILE )
1660+ try :
1661+ with self .assertRaises (ssl .SSLError ) as cm :
1662+ ctx .load_dh_params (CERTFILE )
1663+ except RuntimeError :
1664+ if Py_DEBUG_WIN32 :
1665+ self .skipTest ("not supported on Win32 debug build" )
1666+ raise
1667+
16591668 self .assertEqual (cm .exception .library , 'PEM' )
16601669 regex = "(NO_START_LINE|UNSUPPORTED_PUBLIC_KEY_TYPE)"
16611670 self .assertRegex (cm .exception .reason , regex )
@@ -2773,6 +2782,14 @@ def try_protocol_combo(server_protocol, client_protocol, expect_success,
27732782 % (expect_success , stats ['version' ]))
27742783
27752784
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+
27762793class ThreadedTests (unittest .TestCase ):
27772794
27782795 @support .requires_resource ('walltime' )
@@ -3960,21 +3977,30 @@ def test_no_legacy_server_connect(self):
39603977 chatty = True , connectionchatty = True ,
39613978 sni_name = hostname )
39623979
3963- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
39643980 def test_dh_params (self ):
3965- # 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).
39663983 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" )
39673988 # test scenario needs TLS <= 1.2
39683989 client_context .maximum_version = ssl .TLSVersion .TLSv1_2
3969- server_context .load_dh_params (DHFILE )
3990+ try :
3991+ server_context .load_dh_params (DHFILE )
3992+ except RuntimeError :
3993+ if Py_DEBUG_WIN32 :
3994+ self .skipTest ("not supported on Win32 debug build" )
3995+ raise
39703996 server_context .set_ciphers ("kEDH" )
39713997 server_context .maximum_version = ssl .TLSVersion .TLSv1_2
39723998 stats = server_params_test (client_context , server_context ,
39733999 chatty = True , connectionchatty = True ,
39744000 sni_name = hostname )
39754001 cipher = stats ["cipher" ][0 ]
39764002 parts = cipher .split ("-" )
3977- if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts :
4003+ if not dhe_aliases . intersection ( parts ) :
39784004 self .fail ("Non-DH key exchange: " + cipher [0 ])
39794005
39804006 def test_ecdh_curve (self ):
@@ -4607,14 +4633,18 @@ def keylog_lines(self, fname=os_helper.TESTFN):
46074633 return len (list (f ))
46084634
46094635 @requires_keylog
4610- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
46114636 def test_keylog_defaults (self ):
46124637 self .addCleanup (os_helper .unlink , os_helper .TESTFN )
46134638 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
46144639 self .assertEqual (ctx .keylog_filename , None )
46154640
46164641 self .assertFalse (os .path .isfile (os_helper .TESTFN ))
4617- ctx .keylog_filename = os_helper .TESTFN
4642+ try :
4643+ ctx .keylog_filename = os_helper .TESTFN
4644+ except RuntimeError :
4645+ if Py_DEBUG_WIN32 :
4646+ self .skipTest ("not supported on Win32 debug build" )
4647+ raise
46184648 self .assertEqual (ctx .keylog_filename , os_helper .TESTFN )
46194649 self .assertTrue (os .path .isfile (os_helper .TESTFN ))
46204650 self .assertEqual (self .keylog_lines (), 1 )
@@ -4631,12 +4661,17 @@ def test_keylog_defaults(self):
46314661 ctx .keylog_filename = 1
46324662
46334663 @requires_keylog
4634- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
46354664 def test_keylog_filename (self ):
46364665 self .addCleanup (os_helper .unlink , os_helper .TESTFN )
46374666 client_context , server_context , hostname = testing_context ()
46384667
4639- client_context .keylog_filename = os_helper .TESTFN
4668+ try :
4669+ client_context .keylog_filename = os_helper .TESTFN
4670+ except RuntimeError :
4671+ if Py_DEBUG_WIN32 :
4672+ self .skipTest ("not supported on Win32 debug build" )
4673+ raise
4674+
46404675 server = ThreadedEchoServer (context = server_context , chatty = False )
46414676 with server :
46424677 with client_context .wrap_socket (socket .socket (),
@@ -4669,7 +4704,6 @@ def test_keylog_filename(self):
46694704 @requires_keylog
46704705 @unittest .skipIf (sys .flags .ignore_environment ,
46714706 "test is not compatible with ignore_environment" )
4672- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
46734707 def test_keylog_env (self ):
46744708 self .addCleanup (os_helper .unlink , os_helper .TESTFN )
46754709 with unittest .mock .patch .dict (os .environ ):
@@ -4679,7 +4713,12 @@ def test_keylog_env(self):
46794713 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
46804714 self .assertEqual (ctx .keylog_filename , None )
46814715
4682- ctx = ssl .create_default_context ()
4716+ try :
4717+ ctx = ssl .create_default_context ()
4718+ except RuntimeError :
4719+ if Py_DEBUG_WIN32 :
4720+ self .skipTest ("not supported on Win32 debug build" )
4721+ raise
46834722 self .assertEqual (ctx .keylog_filename , os_helper .TESTFN )
46844723
46854724 ctx = ssl ._create_stdlib_context ()
0 commit comments