@@ -551,7 +551,7 @@ def test_openssl_version(self):
551
551
else :
552
552
openssl_ver = f"OpenSSL { major :d} .{ minor :d} .{ fix :d} "
553
553
self .assertTrue (
554
- s .startswith ((openssl_ver , libressl_ver )),
554
+ s .startswith ((openssl_ver , libressl_ver , "AWS-LC" )),
555
555
(s , t , hex (n ))
556
556
)
557
557
@@ -1169,24 +1169,30 @@ def test_load_cert_chain(self):
1169
1169
with self .assertRaises (OSError ) as cm :
1170
1170
ctx .load_cert_chain (NONEXISTINGCERT )
1171
1171
self .assertEqual (cm .exception .errno , errno .ENOENT )
1172
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1172
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1173
1173
ctx .load_cert_chain (BADCERT )
1174
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1174
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1175
1175
ctx .load_cert_chain (EMPTYCERT )
1176
1176
# Separate key and cert
1177
1177
ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
1178
1178
ctx .load_cert_chain (ONLYCERT , ONLYKEY )
1179
1179
ctx .load_cert_chain (certfile = ONLYCERT , keyfile = ONLYKEY )
1180
1180
ctx .load_cert_chain (certfile = BYTES_ONLYCERT , keyfile = BYTES_ONLYKEY )
1181
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1181
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1182
1182
ctx .load_cert_chain (ONLYCERT )
1183
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1183
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1184
1184
ctx .load_cert_chain (ONLYKEY )
1185
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1185
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1186
1186
ctx .load_cert_chain (certfile = ONLYKEY , keyfile = ONLYCERT )
1187
1187
# Mismatching key and cert
1188
1188
ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
1189
- with self .assertRaisesRegex (ssl .SSLError , "key values mismatch" ):
1189
+ # Allow for flexible libssl error messages.
1190
+ regex = re .compile (r"""(
1191
+ key values mismatch # OpenSSL
1192
+ |
1193
+ KEY_VALUES_MISMATCH # AWS-LC
1194
+ )""" , re .X )
1195
+ with self .assertRaisesRegex (ssl .SSLError , regex ):
1190
1196
ctx .load_cert_chain (CAFILE_CACERT , ONLYKEY )
1191
1197
# Password protected key and cert
1192
1198
ctx .load_cert_chain (CERTFILE_PROTECTED , password = KEY_PASSWORD )
@@ -1254,7 +1260,7 @@ def test_load_verify_locations(self):
1254
1260
with self .assertRaises (OSError ) as cm :
1255
1261
ctx .load_verify_locations (NONEXISTINGCERT )
1256
1262
self .assertEqual (cm .exception .errno , errno .ENOENT )
1257
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1263
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1258
1264
ctx .load_verify_locations (BADCERT )
1259
1265
ctx .load_verify_locations (CERTFILE , CAPATH )
1260
1266
ctx .load_verify_locations (CERTFILE , capath = BYTES_CAPATH )
@@ -1662,9 +1668,10 @@ def test_lib_reason(self):
1662
1668
with self .assertRaises (ssl .SSLError ) as cm :
1663
1669
ctx .load_dh_params (CERTFILE )
1664
1670
self .assertEqual (cm .exception .library , 'PEM' )
1665
- self .assertEqual (cm .exception .reason , 'NO_START_LINE' )
1671
+ regex = "(NO_START_LINE|UNSUPPORTED_PUBLIC_KEY_TYPE)"
1672
+ self .assertRegex (cm .exception .reason , regex )
1666
1673
s = str (cm .exception )
1667
- self .assertTrue (s . startswith ( "[PEM: NO_START_LINE] no start line" ) , s )
1674
+ self .assertTrue (" NO_START_LINE" in s , s )
1668
1675
1669
1676
def test_subclass (self ):
1670
1677
# Check that the appropriate SSLError subclass is raised
@@ -1844,7 +1851,13 @@ def test_connect_fail(self):
1844
1851
s = test_wrap_socket (socket .socket (socket .AF_INET ),
1845
1852
cert_reqs = ssl .CERT_REQUIRED )
1846
1853
self .addCleanup (s .close )
1847
- self .assertRaisesRegex (ssl .SSLError , "certificate verify failed" ,
1854
+ # Allow for flexible libssl error messages.
1855
+ regex = re .compile (r"""(
1856
+ certificate verify failed # OpenSSL
1857
+ |
1858
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
1859
+ )""" , re .X )
1860
+ self .assertRaisesRegex (ssl .SSLError , regex ,
1848
1861
s .connect , self .server_addr )
1849
1862
1850
1863
def test_connect_ex (self ):
@@ -1912,7 +1925,13 @@ def test_connect_with_context_fail(self):
1912
1925
server_hostname = SIGNED_CERTFILE_HOSTNAME
1913
1926
)
1914
1927
self .addCleanup (s .close )
1915
- self .assertRaisesRegex (ssl .SSLError , "certificate verify failed" ,
1928
+ # Allow for flexible libssl error messages.
1929
+ regex = re .compile (r"""(
1930
+ certificate verify failed # OpenSSL
1931
+ |
1932
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
1933
+ )""" , re .X )
1934
+ self .assertRaisesRegex (ssl .SSLError , regex ,
1916
1935
s .connect , self .server_addr )
1917
1936
1918
1937
def test_connect_capath (self ):
@@ -2129,14 +2148,16 @@ def test_bio_handshake(self):
2129
2148
self .assertIsNone (sslobj .version ())
2130
2149
self .assertIsNone (sslobj .shared_ciphers ())
2131
2150
self .assertRaises (ValueError , sslobj .getpeercert )
2132
- if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES :
2151
+ # tls-unique is not defined for TLSv1.3
2152
+ # https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
2153
+ if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES and sslobj .version () != "TLSv1.3" :
2133
2154
self .assertIsNone (sslobj .get_channel_binding ('tls-unique' ))
2134
2155
self .ssl_io_loop (sock , incoming , outgoing , sslobj .do_handshake )
2135
2156
self .assertTrue (sslobj .cipher ())
2136
2157
self .assertIsNone (sslobj .shared_ciphers ())
2137
2158
self .assertIsNotNone (sslobj .version ())
2138
2159
self .assertTrue (sslobj .getpeercert ())
2139
- if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES :
2160
+ if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES and sslobj . version () != "TLSv1.3" :
2140
2161
self .assertTrue (sslobj .get_channel_binding ('tls-unique' ))
2141
2162
try :
2142
2163
self .ssl_io_loop (sock , incoming , outgoing , sslobj .unwrap )
@@ -2861,11 +2882,16 @@ def test_crl_check(self):
2861
2882
client_context .verify_flags |= ssl .VERIFY_CRL_CHECK_LEAF
2862
2883
2863
2884
server = ThreadedEchoServer (context = server_context , chatty = True )
2885
+ # Allow for flexible libssl error messages.
2886
+ regex = re .compile (r"""(
2887
+ certificate verify failed # OpenSSL
2888
+ |
2889
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
2890
+ )""" , re .X )
2864
2891
with server :
2865
2892
with client_context .wrap_socket (socket .socket (),
2866
2893
server_hostname = hostname ) as s :
2867
- with self .assertRaisesRegex (ssl .SSLError ,
2868
- "certificate verify failed" ):
2894
+ with self .assertRaisesRegex (ssl .SSLError , regex ):
2869
2895
s .connect ((HOST , server .port ))
2870
2896
2871
2897
# now load a CRL file. The CRL file is signed by the CA.
@@ -2896,12 +2922,16 @@ def test_check_hostname(self):
2896
2922
2897
2923
# incorrect hostname should raise an exception
2898
2924
server = ThreadedEchoServer (context = server_context , chatty = True )
2925
+ # Allow for flexible libssl error messages.
2926
+ regex = re .compile (r"""(
2927
+ certificate verify failed # OpenSSL
2928
+ |
2929
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
2930
+ )""" , re .X )
2899
2931
with server :
2900
2932
with client_context .wrap_socket (socket .socket (),
2901
2933
server_hostname = "invalid" ) as s :
2902
- with self .assertRaisesRegex (
2903
- ssl .CertificateError ,
2904
- "Hostname mismatch, certificate is not valid for 'invalid'." ):
2934
+ with self .assertRaisesRegex (ssl .CertificateError , regex ):
2905
2935
s .connect ((HOST , server .port ))
2906
2936
2907
2937
# missing server_hostname arg should cause an exception, too
@@ -3137,7 +3167,7 @@ def test_wrong_cert_tls13(self):
3137
3167
s .connect ((HOST , server .port ))
3138
3168
with self .assertRaisesRegex (
3139
3169
ssl .SSLError ,
3140
- 'alert unknown ca|EOF occurred'
3170
+ 'alert unknown ca|EOF occurred|TLSV1_ALERT_UNKNOWN_CA '
3141
3171
):
3142
3172
# TLS 1.3 perform client cert exchange after handshake
3143
3173
s .write (b'data' )
@@ -3201,13 +3231,21 @@ def test_ssl_cert_verify_error(self):
3201
3231
server_hostname = SIGNED_CERTFILE_HOSTNAME ) as s :
3202
3232
try :
3203
3233
s .connect ((HOST , server .port ))
3234
+ self .fail ("Expected connection failure" )
3204
3235
except ssl .SSLError as e :
3205
3236
msg = 'unable to get local issuer certificate'
3206
3237
self .assertIsInstance (e , ssl .SSLCertVerificationError )
3207
3238
self .assertEqual (e .verify_code , 20 )
3208
3239
self .assertEqual (e .verify_message , msg )
3209
- self .assertIn (msg , repr (e ))
3210
- self .assertIn ('certificate verify failed' , repr (e ))
3240
+ # Allow for flexible libssl error messages.
3241
+ regex = f"({ msg } |CERTIFICATE_VERIFY_FAILED)"
3242
+ self .assertRegex (repr (e ), regex )
3243
+ regex = re .compile (r"""(
3244
+ certificate verify failed # OpenSSL
3245
+ |
3246
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
3247
+ )""" , re .X )
3248
+ self .assertRegex (repr (e ), regex )
3211
3249
3212
3250
def test_PROTOCOL_TLS (self ):
3213
3251
"""Connecting to an SSLv23 server with various client options"""
@@ -3739,7 +3777,7 @@ def test_no_shared_ciphers(self):
3739
3777
server_hostname = hostname ) as s :
3740
3778
with self .assertRaises (OSError ):
3741
3779
s .connect ((HOST , server .port ))
3742
- self .assertIn ("no shared cipher " , server .conn_errors [0 ])
3780
+ self .assertIn ("NO_SHARED_CIPHER " , server .conn_errors [0 ])
3743
3781
3744
3782
def test_version_basic (self ):
3745
3783
"""
@@ -3827,7 +3865,7 @@ def test_min_max_version_mismatch(self):
3827
3865
server_hostname = hostname ) as s :
3828
3866
with self .assertRaises (ssl .SSLError ) as e :
3829
3867
s .connect ((HOST , server .port ))
3830
- self .assertIn ( " alert" , str (e .exception ))
3868
+ self .assertRegex ( "( alert|ALERT) " , str (e .exception ))
3831
3869
3832
3870
@requires_tls_version ('SSLv3' )
3833
3871
def test_min_max_version_sslv3 (self ):
@@ -3869,6 +3907,10 @@ def test_tls_unique_channel_binding(self):
3869
3907
3870
3908
client_context , server_context , hostname = testing_context ()
3871
3909
3910
+ # tls-unique is not defined for TLSv1.3
3911
+ # https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
3912
+ client_context .maximum_version = ssl .TLSVersion .TLSv1_2
3913
+
3872
3914
server = ThreadedEchoServer (context = server_context ,
3873
3915
chatty = True ,
3874
3916
connectionchatty = False )
@@ -3969,7 +4011,7 @@ def test_dh_params(self):
3969
4011
cipher = stats ["cipher" ][0 ]
3970
4012
parts = cipher .split ("-" )
3971
4013
if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts :
3972
- self .fail ("Non-DH cipher : " + cipher [0 ])
4014
+ self .fail ("Non-DH key exchange : " + cipher [0 ])
3973
4015
3974
4016
def test_ecdh_curve (self ):
3975
4017
# server secp384r1, client auto
@@ -4136,8 +4178,9 @@ def cb_raising(ssl_sock, server_name, initial_context):
4136
4178
chatty = False ,
4137
4179
sni_name = 'supermessage' )
4138
4180
4139
- self .assertEqual (cm .exception .reason ,
4140
- 'SSLV3_ALERT_HANDSHAKE_FAILURE' )
4181
+ # Allow for flexible libssl error messages.
4182
+ regex = "(SSLV3_ALERT_HANDSHAKE_FAILURE|NO_PRIVATE_VALUE)"
4183
+ self .assertRegex (regex , cm .exception .reason )
4141
4184
self .assertEqual (catch .unraisable .exc_type , ZeroDivisionError )
4142
4185
4143
4186
def test_sni_callback_wrong_return_type (self ):
0 commit comments