@@ -557,7 +557,7 @@ def test_openssl_version(self):
557
557
else :
558
558
openssl_ver = f"OpenSSL { major :d} .{ minor :d} .{ fix :d} "
559
559
self .assertTrue (
560
- s .startswith ((openssl_ver , libressl_ver )),
560
+ s .startswith ((openssl_ver , libressl_ver , "AWS-LC" )),
561
561
(s , t , hex (n ))
562
562
)
563
563
@@ -1404,24 +1404,30 @@ def test_load_cert_chain(self):
1404
1404
with self .assertRaises (OSError ) as cm :
1405
1405
ctx .load_cert_chain (NONEXISTINGCERT )
1406
1406
self .assertEqual (cm .exception .errno , errno .ENOENT )
1407
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1407
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1408
1408
ctx .load_cert_chain (BADCERT )
1409
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1409
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1410
1410
ctx .load_cert_chain (EMPTYCERT )
1411
1411
# Separate key and cert
1412
1412
ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
1413
1413
ctx .load_cert_chain (ONLYCERT , ONLYKEY )
1414
1414
ctx .load_cert_chain (certfile = ONLYCERT , keyfile = ONLYKEY )
1415
1415
ctx .load_cert_chain (certfile = BYTES_ONLYCERT , keyfile = BYTES_ONLYKEY )
1416
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1416
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1417
1417
ctx .load_cert_chain (ONLYCERT )
1418
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1418
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1419
1419
ctx .load_cert_chain (ONLYKEY )
1420
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1420
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1421
1421
ctx .load_cert_chain (certfile = ONLYKEY , keyfile = ONLYCERT )
1422
1422
# Mismatching key and cert
1423
1423
ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
1424
- with self .assertRaisesRegex (ssl .SSLError , "key values mismatch" ):
1424
+ # Allow for flexible libssl error messages.
1425
+ regex = re .compile (r"""(
1426
+ key values mismatch # OpenSSL
1427
+ |
1428
+ KEY_VALUES_MISMATCH # AWS-LC
1429
+ )""" , re .X )
1430
+ with self .assertRaisesRegex (ssl .SSLError , regex ):
1425
1431
ctx .load_cert_chain (CAFILE_CACERT , ONLYKEY )
1426
1432
# Password protected key and cert
1427
1433
ctx .load_cert_chain (CERTFILE_PROTECTED , password = KEY_PASSWORD )
@@ -1489,7 +1495,7 @@ def test_load_verify_locations(self):
1489
1495
with self .assertRaises (OSError ) as cm :
1490
1496
ctx .load_verify_locations (NONEXISTINGCERT )
1491
1497
self .assertEqual (cm .exception .errno , errno .ENOENT )
1492
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1498
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1493
1499
ctx .load_verify_locations (BADCERT )
1494
1500
ctx .load_verify_locations (CERTFILE , CAPATH )
1495
1501
ctx .load_verify_locations (CERTFILE , capath = BYTES_CAPATH )
@@ -1888,9 +1894,10 @@ def test_lib_reason(self):
1888
1894
with self .assertRaises (ssl .SSLError ) as cm :
1889
1895
ctx .load_dh_params (CERTFILE )
1890
1896
self .assertEqual (cm .exception .library , 'PEM' )
1891
- self .assertEqual (cm .exception .reason , 'NO_START_LINE' )
1897
+ regex = "(NO_START_LINE|UNSUPPORTED_PUBLIC_KEY_TYPE)"
1898
+ self .assertRegex (cm .exception .reason , regex )
1892
1899
s = str (cm .exception )
1893
- self .assertTrue (s . startswith ( "[PEM: NO_START_LINE] no start line" ) , s )
1900
+ self .assertTrue (" NO_START_LINE" in s , s )
1894
1901
1895
1902
def test_subclass (self ):
1896
1903
# Check that the appropriate SSLError subclass is raised
@@ -2070,7 +2077,13 @@ def test_connect_fail(self):
2070
2077
s = test_wrap_socket (socket .socket (socket .AF_INET ),
2071
2078
cert_reqs = ssl .CERT_REQUIRED )
2072
2079
self .addCleanup (s .close )
2073
- self .assertRaisesRegex (ssl .SSLError , "certificate verify failed" ,
2080
+ # Allow for flexible libssl error messages.
2081
+ regex = re .compile (r"""(
2082
+ certificate verify failed # OpenSSL
2083
+ |
2084
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
2085
+ )""" , re .X )
2086
+ self .assertRaisesRegex (ssl .SSLError , regex ,
2074
2087
s .connect , self .server_addr )
2075
2088
2076
2089
def test_connect_ex (self ):
@@ -2138,7 +2151,13 @@ def test_connect_with_context_fail(self):
2138
2151
server_hostname = SIGNED_CERTFILE_HOSTNAME
2139
2152
)
2140
2153
self .addCleanup (s .close )
2141
- self .assertRaisesRegex (ssl .SSLError , "certificate verify failed" ,
2154
+ # Allow for flexible libssl error messages.
2155
+ regex = re .compile (r"""(
2156
+ certificate verify failed # OpenSSL
2157
+ |
2158
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
2159
+ )""" , re .X )
2160
+ self .assertRaisesRegex (ssl .SSLError , regex ,
2142
2161
s .connect , self .server_addr )
2143
2162
2144
2163
def test_connect_capath (self ):
@@ -2355,14 +2374,16 @@ def test_bio_handshake(self):
2355
2374
self .assertIsNone (sslobj .version ())
2356
2375
self .assertIsNone (sslobj .shared_ciphers ())
2357
2376
self .assertRaises (ValueError , sslobj .getpeercert )
2358
- if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES :
2377
+ # tls-unique is not defined for TLSv1.3
2378
+ # https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
2379
+ if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES and sslobj .version () != "TLSv1.3" :
2359
2380
self .assertIsNone (sslobj .get_channel_binding ('tls-unique' ))
2360
2381
self .ssl_io_loop (sock , incoming , outgoing , sslobj .do_handshake )
2361
2382
self .assertTrue (sslobj .cipher ())
2362
2383
self .assertIsNone (sslobj .shared_ciphers ())
2363
2384
self .assertIsNotNone (sslobj .version ())
2364
2385
self .assertTrue (sslobj .getpeercert ())
2365
- if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES :
2386
+ if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES and sslobj . version () != "TLSv1.3" :
2366
2387
self .assertTrue (sslobj .get_channel_binding ('tls-unique' ))
2367
2388
try :
2368
2389
self .ssl_io_loop (sock , incoming , outgoing , sslobj .unwrap )
@@ -3087,11 +3108,16 @@ def test_crl_check(self):
3087
3108
client_context .verify_flags |= ssl .VERIFY_CRL_CHECK_LEAF
3088
3109
3089
3110
server = ThreadedEchoServer (context = server_context , chatty = True )
3111
+ # Allow for flexible libssl error messages.
3112
+ regex = re .compile (r"""(
3113
+ certificate verify failed # OpenSSL
3114
+ |
3115
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
3116
+ )""" , re .X )
3090
3117
with server :
3091
3118
with client_context .wrap_socket (socket .socket (),
3092
3119
server_hostname = hostname ) as s :
3093
- with self .assertRaisesRegex (ssl .SSLError ,
3094
- "certificate verify failed" ):
3120
+ with self .assertRaisesRegex (ssl .SSLError , regex ):
3095
3121
s .connect ((HOST , server .port ))
3096
3122
3097
3123
# now load a CRL file. The CRL file is signed by the CA.
@@ -3122,12 +3148,16 @@ def test_check_hostname(self):
3122
3148
3123
3149
# incorrect hostname should raise an exception
3124
3150
server = ThreadedEchoServer (context = server_context , chatty = True )
3151
+ # Allow for flexible libssl error messages.
3152
+ regex = re .compile (r"""(
3153
+ certificate verify failed # OpenSSL
3154
+ |
3155
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
3156
+ )""" , re .X )
3125
3157
with server :
3126
3158
with client_context .wrap_socket (socket .socket (),
3127
3159
server_hostname = "invalid" ) as s :
3128
- with self .assertRaisesRegex (
3129
- ssl .CertificateError ,
3130
- "Hostname mismatch, certificate is not valid for 'invalid'." ):
3160
+ with self .assertRaisesRegex (ssl .CertificateError , regex ):
3131
3161
s .connect ((HOST , server .port ))
3132
3162
3133
3163
# missing server_hostname arg should cause an exception, too
@@ -3331,7 +3361,7 @@ def test_wrong_cert_tls13(self):
3331
3361
s .connect ((HOST , server .port ))
3332
3362
with self .assertRaisesRegex (
3333
3363
ssl .SSLError ,
3334
- 'alert unknown ca|EOF occurred'
3364
+ 'alert unknown ca|EOF occurred|TLSV1_ALERT_UNKNOWN_CA '
3335
3365
):
3336
3366
# TLS 1.3 perform client cert exchange after handshake
3337
3367
s .write (b'data' )
@@ -3395,13 +3425,21 @@ def test_ssl_cert_verify_error(self):
3395
3425
server_hostname = SIGNED_CERTFILE_HOSTNAME ) as s :
3396
3426
try :
3397
3427
s .connect ((HOST , server .port ))
3428
+ self .fail ("Expected connection failure" )
3398
3429
except ssl .SSLError as e :
3399
3430
msg = 'unable to get local issuer certificate'
3400
3431
self .assertIsInstance (e , ssl .SSLCertVerificationError )
3401
3432
self .assertEqual (e .verify_code , 20 )
3402
3433
self .assertEqual (e .verify_message , msg )
3403
- self .assertIn (msg , repr (e ))
3404
- self .assertIn ('certificate verify failed' , repr (e ))
3434
+ # Allow for flexible libssl error messages.
3435
+ regex = f"({ msg } |CERTIFICATE_VERIFY_FAILED)"
3436
+ self .assertRegex (repr (e ), regex )
3437
+ regex = re .compile (r"""(
3438
+ certificate verify failed # OpenSSL
3439
+ |
3440
+ CERTIFICATE_VERIFY_FAILED # AWS-LC
3441
+ )""" , re .X )
3442
+ self .assertRegex (repr (e ), regex )
3405
3443
3406
3444
@requires_tls_version ('SSLv2' )
3407
3445
def test_protocol_sslv2 (self ):
@@ -3968,7 +4006,7 @@ def test_no_shared_ciphers(self):
3968
4006
server_hostname = hostname ) as s :
3969
4007
with self .assertRaises (OSError ):
3970
4008
s .connect ((HOST , server .port ))
3971
- self .assertIn ("no shared cipher " , server .conn_errors [0 ])
4009
+ self .assertIn ("NO_SHARED_CIPHER " , server .conn_errors [0 ])
3972
4010
3973
4011
def test_version_basic (self ):
3974
4012
"""
@@ -4056,7 +4094,7 @@ def test_min_max_version_mismatch(self):
4056
4094
server_hostname = hostname ) as s :
4057
4095
with self .assertRaises (ssl .SSLError ) as e :
4058
4096
s .connect ((HOST , server .port ))
4059
- self .assertIn ( " alert" , str (e .exception ))
4097
+ self .assertRegex ( "( alert|ALERT) " , str (e .exception ))
4060
4098
4061
4099
@requires_tls_version ('SSLv3' )
4062
4100
def test_min_max_version_sslv3 (self ):
@@ -4098,6 +4136,10 @@ def test_tls_unique_channel_binding(self):
4098
4136
4099
4137
client_context , server_context , hostname = testing_context ()
4100
4138
4139
+ # tls-unique is not defined for TLSv1.3
4140
+ # https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
4141
+ client_context .maximum_version = ssl .TLSVersion .TLSv1_2
4142
+
4101
4143
server = ThreadedEchoServer (context = server_context ,
4102
4144
chatty = True ,
4103
4145
connectionchatty = False )
@@ -4184,7 +4226,7 @@ def test_dh_params(self):
4184
4226
cipher = stats ["cipher" ][0 ]
4185
4227
parts = cipher .split ("-" )
4186
4228
if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts :
4187
- self .fail ("Non-DH cipher : " + cipher [0 ])
4229
+ self .fail ("Non-DH key exchange : " + cipher [0 ])
4188
4230
4189
4231
def test_ecdh_curve (self ):
4190
4232
# server secp384r1, client auto
@@ -4351,8 +4393,9 @@ def cb_raising(ssl_sock, server_name, initial_context):
4351
4393
chatty = False ,
4352
4394
sni_name = 'supermessage' )
4353
4395
4354
- self .assertEqual (cm .exception .reason ,
4355
- 'SSLV3_ALERT_HANDSHAKE_FAILURE' )
4396
+ # Allow for flexible libssl error messages.
4397
+ regex = "(SSLV3_ALERT_HANDSHAKE_FAILURE|NO_PRIVATE_VALUE)"
4398
+ self .assertRegex (regex , cm .exception .reason )
4356
4399
self .assertEqual (catch .unraisable .exc_type , ZeroDivisionError )
4357
4400
4358
4401
def test_sni_callback_wrong_return_type (self ):
0 commit comments