@@ -143,6 +143,27 @@ def data_file(*name):
143
143
OP_CIPHER_SERVER_PREFERENCE = getattr (ssl , "OP_CIPHER_SERVER_PREFERENCE" , 0 )
144
144
OP_ENABLE_MIDDLEBOX_COMPAT = getattr (ssl , "OP_ENABLE_MIDDLEBOX_COMPAT" , 0 )
145
145
146
+ # Ubuntu has patched OpenSSL and changed behavior of security level 2
147
+ # see https://bugs.python.org/issue41561#msg389003
148
+ def is_ubuntu ():
149
+ try :
150
+ # Assume that any references of "ubuntu" implies Ubuntu-like distro
151
+ # The workaround is not required for 18.04, but doesn't hurt either.
152
+ with open ("/etc/os-release" , encoding = "utf-8" ) as f :
153
+ return "ubuntu" in f .read ()
154
+ except FileNotFoundError :
155
+ return False
156
+
157
+ if is_ubuntu ():
158
+ def seclevel_workaround (* ctxs ):
159
+ """"Lower security level to '1' and allow all ciphers for TLS 1.0/1"""
160
+ for ctx in ctxs :
161
+ if ctx .minimum_version <= ssl .TLSVersion .TLSv1_1 :
162
+ ctx .set_ciphers ("@SECLEVEL=1:ALL" )
163
+ else :
164
+ def seclevel_workaround (* ctxs ):
165
+ pass
166
+
146
167
147
168
def has_tls_protocol (protocol ):
148
169
"""Check if a TLS protocol is available and enabled
@@ -2772,6 +2793,8 @@ def try_protocol_combo(server_protocol, client_protocol, expect_success,
2772
2793
if client_context .protocol == ssl .PROTOCOL_TLS :
2773
2794
client_context .set_ciphers ("ALL" )
2774
2795
2796
+ seclevel_workaround (server_context , client_context )
2797
+
2775
2798
for ctx in (client_context , server_context ):
2776
2799
ctx .verify_mode = certsreqs
2777
2800
ctx .load_cert_chain (SIGNED_CERTFILE )
@@ -2813,6 +2836,7 @@ def test_echo(self):
2813
2836
with self .subTest (protocol = ssl ._PROTOCOL_NAMES [protocol ]):
2814
2837
context = ssl .SSLContext (protocol )
2815
2838
context .load_cert_chain (CERTFILE )
2839
+ seclevel_workaround (context )
2816
2840
server_params_test (context , context ,
2817
2841
chatty = True , connectionchatty = True )
2818
2842
@@ -3817,6 +3841,7 @@ def test_min_max_version_tlsv1_1(self):
3817
3841
client_context .maximum_version = ssl .TLSVersion .TLSv1_2
3818
3842
server_context .minimum_version = ssl .TLSVersion .TLSv1
3819
3843
server_context .maximum_version = ssl .TLSVersion .TLSv1_1
3844
+ seclevel_workaround (client_context , server_context )
3820
3845
3821
3846
with ThreadedEchoServer (context = server_context ) as server :
3822
3847
with client_context .wrap_socket (socket .socket (),
@@ -3834,6 +3859,8 @@ def test_min_max_version_mismatch(self):
3834
3859
server_context .minimum_version = ssl .TLSVersion .TLSv1_2
3835
3860
client_context .maximum_version = ssl .TLSVersion .TLSv1
3836
3861
client_context .minimum_version = ssl .TLSVersion .TLSv1
3862
+ seclevel_workaround (client_context , server_context )
3863
+
3837
3864
with ThreadedEchoServer (context = server_context ) as server :
3838
3865
with client_context .wrap_socket (socket .socket (),
3839
3866
server_hostname = hostname ) as s :
@@ -3848,6 +3875,8 @@ def test_min_max_version_sslv3(self):
3848
3875
server_context .minimum_version = ssl .TLSVersion .SSLv3
3849
3876
client_context .minimum_version = ssl .TLSVersion .SSLv3
3850
3877
client_context .maximum_version = ssl .TLSVersion .SSLv3
3878
+ seclevel_workaround (client_context , server_context )
3879
+
3851
3880
with ThreadedEchoServer (context = server_context ) as server :
3852
3881
with client_context .wrap_socket (socket .socket (),
3853
3882
server_hostname = hostname ) as s :
0 commit comments