@@ -1321,10 +1321,14 @@ def test_load_verify_cadata(self):
13211321 with self .assertRaises (ssl .SSLError ):
13221322 ctx .load_verify_locations (cadata = cacert_der + b"A" )
13231323
1324- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
13251324 def test_load_dh_params (self ):
13261325 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
1327- ctx .load_dh_params (DHFILE )
1326+ try :
1327+ ctx .load_dh_params (DHFILE )
1328+ except RuntimeError :
1329+ if Py_DEBUG_WIN32 :
1330+ self .skipTest ("not supported on Win32 debug build" )
1331+ raise
13281332 ctx .load_dh_params (BYTES_DHFILE )
13291333 self .assertRaises (TypeError , ctx .load_dh_params )
13301334 self .assertRaises (TypeError , ctx .load_dh_params , None )
@@ -1648,12 +1652,17 @@ def test_str(self):
16481652 self .assertEqual (str (e ), "foo" )
16491653 self .assertEqual (e .errno , 1 )
16501654
1651- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
16521655 def test_lib_reason (self ):
16531656 # Test the library and reason attributes
16541657 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
1655- with self .assertRaises (ssl .SSLError ) as cm :
1656- ctx .load_dh_params (CERTFILE )
1658+ try :
1659+ with self .assertRaises (ssl .SSLError ) as cm :
1660+ ctx .load_dh_params (CERTFILE )
1661+ except RuntimeError :
1662+ if Py_DEBUG_WIN32 :
1663+ self .skipTest ("not supported on Win32 debug build" )
1664+ raise
1665+
16571666 self .assertEqual (cm .exception .library , 'PEM' )
16581667 regex = "(NO_START_LINE|UNSUPPORTED_PUBLIC_KEY_TYPE)"
16591668 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' )
@@ -4032,21 +4049,30 @@ def test_no_legacy_server_connect(self):
40324049 chatty = True , connectionchatty = True ,
40334050 sni_name = hostname )
40344051
4035- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
40364052 def test_dh_params (self ):
4037- # Check we can get a connection with ephemeral Diffie-Hellman
4053+ # Check we can get a connection with ephemeral finite-field
4054+ # Diffie-Hellman (if supported).
40384055 client_context , server_context , hostname = testing_context ()
4056+ dhe_aliases = {"ADH" , "EDH" , "DHE" }
4057+ if not (supports_kx_alias (client_context , dhe_aliases )
4058+ and supports_kx_alias (server_context , dhe_aliases )):
4059+ self .skipTest ("libssl doesn't support ephemeral DH" )
40394060 # test scenario needs TLS <= 1.2
40404061 client_context .maximum_version = ssl .TLSVersion .TLSv1_2
4041- server_context .load_dh_params (DHFILE )
4062+ try :
4063+ server_context .load_dh_params (DHFILE )
4064+ except RuntimeError :
4065+ if Py_DEBUG_WIN32 :
4066+ self .skipTest ("not supported on Win32 debug build" )
4067+ raise
40424068 server_context .set_ciphers ("kEDH" )
40434069 server_context .maximum_version = ssl .TLSVersion .TLSv1_2
40444070 stats = server_params_test (client_context , server_context ,
40454071 chatty = True , connectionchatty = True ,
40464072 sni_name = hostname )
40474073 cipher = stats ["cipher" ][0 ]
40484074 parts = cipher .split ("-" )
4049- if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts :
4075+ if not dhe_aliases . intersection ( parts ) :
40504076 self .fail ("Non-DH key exchange: " + cipher [0 ])
40514077
40524078 def test_ecdh_curve (self ):
@@ -4819,14 +4845,18 @@ def keylog_lines(self, fname=os_helper.TESTFN):
48194845 return len (list (f ))
48204846
48214847 @requires_keylog
4822- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
48234848 def test_keylog_defaults (self ):
48244849 self .addCleanup (os_helper .unlink , os_helper .TESTFN )
48254850 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
48264851 self .assertEqual (ctx .keylog_filename , None )
48274852
48284853 self .assertFalse (os .path .isfile (os_helper .TESTFN ))
4829- ctx .keylog_filename = os_helper .TESTFN
4854+ try :
4855+ ctx .keylog_filename = os_helper .TESTFN
4856+ except RuntimeError :
4857+ if Py_DEBUG_WIN32 :
4858+ self .skipTest ("not supported on Win32 debug build" )
4859+ raise
48304860 self .assertEqual (ctx .keylog_filename , os_helper .TESTFN )
48314861 self .assertTrue (os .path .isfile (os_helper .TESTFN ))
48324862 self .assertEqual (self .keylog_lines (), 1 )
@@ -4843,12 +4873,17 @@ def test_keylog_defaults(self):
48434873 ctx .keylog_filename = 1
48444874
48454875 @requires_keylog
4846- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
48474876 def test_keylog_filename (self ):
48484877 self .addCleanup (os_helper .unlink , os_helper .TESTFN )
48494878 client_context , server_context , hostname = testing_context ()
48504879
4851- client_context .keylog_filename = os_helper .TESTFN
4880+ try :
4881+ client_context .keylog_filename = os_helper .TESTFN
4882+ except RuntimeError :
4883+ if Py_DEBUG_WIN32 :
4884+ self .skipTest ("not supported on Win32 debug build" )
4885+ raise
4886+
48524887 server = ThreadedEchoServer (context = server_context , chatty = False )
48534888 with server :
48544889 with client_context .wrap_socket (socket .socket (),
@@ -4881,7 +4916,6 @@ def test_keylog_filename(self):
48814916 @requires_keylog
48824917 @unittest .skipIf (sys .flags .ignore_environment ,
48834918 "test is not compatible with ignore_environment" )
4884- @unittest .skipIf (Py_DEBUG_WIN32 , "Avoid mixing debug/release CRT on Windows" )
48854919 def test_keylog_env (self ):
48864920 self .addCleanup (os_helper .unlink , os_helper .TESTFN )
48874921 with unittest .mock .patch .dict (os .environ ):
@@ -4891,7 +4925,12 @@ def test_keylog_env(self):
48914925 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
48924926 self .assertEqual (ctx .keylog_filename , None )
48934927
4894- ctx = ssl .create_default_context ()
4928+ try :
4929+ ctx = ssl .create_default_context ()
4930+ except RuntimeError :
4931+ if Py_DEBUG_WIN32 :
4932+ self .skipTest ("not supported on Win32 debug build" )
4933+ raise
48954934 self .assertEqual (ctx .keylog_filename , os_helper .TESTFN )
48964935
48974936 ctx = ssl ._create_stdlib_context ()
0 commit comments