@@ -544,7 +544,7 @@ def test_openssl_version(self):
544
544
else :
545
545
openssl_ver = f"OpenSSL { major :d} .{ minor :d} .{ fix :d} "
546
546
self .assertTrue (
547
- s .startswith ((openssl_ver , libressl_ver )),
547
+ s .startswith ((openssl_ver , libressl_ver , "AWS-LC" )),
548
548
(s , t , hex (n ))
549
549
)
550
550
@@ -1162,24 +1162,30 @@ def test_load_cert_chain(self):
1162
1162
with self .assertRaises (OSError ) as cm :
1163
1163
ctx .load_cert_chain (NONEXISTINGCERT )
1164
1164
self .assertEqual (cm .exception .errno , errno .ENOENT )
1165
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1165
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1166
1166
ctx .load_cert_chain (BADCERT )
1167
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1167
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1168
1168
ctx .load_cert_chain (EMPTYCERT )
1169
1169
# Separate key and cert
1170
1170
ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
1171
1171
ctx .load_cert_chain (ONLYCERT , ONLYKEY )
1172
1172
ctx .load_cert_chain (certfile = ONLYCERT , keyfile = ONLYKEY )
1173
1173
ctx .load_cert_chain (certfile = BYTES_ONLYCERT , keyfile = BYTES_ONLYKEY )
1174
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1174
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1175
1175
ctx .load_cert_chain (ONLYCERT )
1176
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1176
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1177
1177
ctx .load_cert_chain (ONLYKEY )
1178
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1178
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1179
1179
ctx .load_cert_chain (certfile = ONLYKEY , keyfile = ONLYCERT )
1180
1180
# Mismatching key and cert
1181
1181
ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
1182
- with self .assertRaisesRegex (ssl .SSLError , "key values mismatch" ):
1182
+ # Allow for flexible libssl error messages.
1183
+ regex = "("
1184
+ regex += "key values mismatch" # OpenSSL
1185
+ regex += "|"
1186
+ regex += "KEY_VALUES_MISMATCH" # AWS-LC/BoringSSL
1187
+ regex += ")"
1188
+ with self .assertRaisesRegex (ssl .SSLError , regex ):
1183
1189
ctx .load_cert_chain (CAFILE_CACERT , ONLYKEY )
1184
1190
# Password protected key and cert
1185
1191
ctx .load_cert_chain (CERTFILE_PROTECTED , password = KEY_PASSWORD )
@@ -1247,7 +1253,7 @@ def test_load_verify_locations(self):
1247
1253
with self .assertRaises (OSError ) as cm :
1248
1254
ctx .load_verify_locations (NONEXISTINGCERT )
1249
1255
self .assertEqual (cm .exception .errno , errno .ENOENT )
1250
- with self .assertRaisesRegex (ssl .SSLError , "PEM lib" ):
1256
+ with self .assertRaisesRegex (ssl .SSLError , "PEM ( lib|routines) " ):
1251
1257
ctx .load_verify_locations (BADCERT )
1252
1258
ctx .load_verify_locations (CERTFILE , CAPATH )
1253
1259
ctx .load_verify_locations (CERTFILE , capath = BYTES_CAPATH )
@@ -1651,9 +1657,10 @@ def test_lib_reason(self):
1651
1657
with self .assertRaises (ssl .SSLError ) as cm :
1652
1658
ctx .load_dh_params (CERTFILE )
1653
1659
self .assertEqual (cm .exception .library , 'PEM' )
1654
- self .assertEqual (cm .exception .reason , 'NO_START_LINE' )
1660
+ regex = "(NO_START_LINE|UNSUPPORTED_PUBLIC_KEY_TYPE)"
1661
+ self .assertRegex (cm .exception .reason , regex )
1655
1662
s = str (cm .exception )
1656
- self .assertTrue (s . startswith ( "[PEM: NO_START_LINE] no start line" ) , s )
1663
+ self .assertTrue (" NO_START_LINE" in s , s )
1657
1664
1658
1665
def test_subclass (self ):
1659
1666
# Check that the appropriate SSLError subclass is raised
@@ -1833,7 +1840,13 @@ def test_connect_fail(self):
1833
1840
s = test_wrap_socket (socket .socket (socket .AF_INET ),
1834
1841
cert_reqs = ssl .CERT_REQUIRED )
1835
1842
self .addCleanup (s .close )
1836
- self .assertRaisesRegex (ssl .SSLError , "certificate verify failed" ,
1843
+ # Allow for flexible libssl error messages.
1844
+ regex = "("
1845
+ regex += "certificate verify failed" # OpenSSL
1846
+ regex += "|"
1847
+ regex += "CERTIFICATE_VERIFY_FAILED" # AWS-LC/BoringSSL
1848
+ regex += ")"
1849
+ self .assertRaisesRegex (ssl .SSLError , regex ,
1837
1850
s .connect , self .server_addr )
1838
1851
1839
1852
def test_connect_ex (self ):
@@ -1901,7 +1914,13 @@ def test_connect_with_context_fail(self):
1901
1914
server_hostname = SIGNED_CERTFILE_HOSTNAME
1902
1915
)
1903
1916
self .addCleanup (s .close )
1904
- self .assertRaisesRegex (ssl .SSLError , "certificate verify failed" ,
1917
+ # Allow for flexible libssl error messages.
1918
+ regex = "("
1919
+ regex += "certificate verify failed" # OpenSSL
1920
+ regex += "|"
1921
+ regex += "CERTIFICATE_VERIFY_FAILED" # AWS-LC/BoringSSL
1922
+ regex += ")"
1923
+ self .assertRaisesRegex (ssl .SSLError , regex ,
1905
1924
s .connect , self .server_addr )
1906
1925
1907
1926
def test_connect_capath (self ):
@@ -2118,14 +2137,16 @@ def test_bio_handshake(self):
2118
2137
self .assertIsNone (sslobj .version ())
2119
2138
self .assertIsNone (sslobj .shared_ciphers ())
2120
2139
self .assertRaises (ValueError , sslobj .getpeercert )
2121
- if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES :
2140
+ # tls-unique is not defined for TLSv1.3
2141
+ # https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
2142
+ if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES and sslobj .version () != "TLSv1.3" :
2122
2143
self .assertIsNone (sslobj .get_channel_binding ('tls-unique' ))
2123
2144
self .ssl_io_loop (sock , incoming , outgoing , sslobj .do_handshake )
2124
2145
self .assertTrue (sslobj .cipher ())
2125
2146
self .assertIsNone (sslobj .shared_ciphers ())
2126
2147
self .assertIsNotNone (sslobj .version ())
2127
2148
self .assertTrue (sslobj .getpeercert ())
2128
- if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES :
2149
+ if 'tls-unique' in ssl .CHANNEL_BINDING_TYPES and sslobj . version () != "TLSv1.3" :
2129
2150
self .assertTrue (sslobj .get_channel_binding ('tls-unique' ))
2130
2151
try :
2131
2152
self .ssl_io_loop (sock , incoming , outgoing , sslobj .unwrap )
@@ -2850,11 +2871,16 @@ def test_crl_check(self):
2850
2871
client_context .verify_flags |= ssl .VERIFY_CRL_CHECK_LEAF
2851
2872
2852
2873
server = ThreadedEchoServer (context = server_context , chatty = True )
2874
+ # Allow for flexible libssl error messages.
2875
+ regex = "("
2876
+ regex += "certificate verify failed" # OpenSSL
2877
+ regex += "|"
2878
+ regex += "CERTIFICATE_VERIFY_FAILED" # AWS-LC/BoringSSL
2879
+ regex += ")"
2853
2880
with server :
2854
2881
with client_context .wrap_socket (socket .socket (),
2855
2882
server_hostname = hostname ) as s :
2856
- with self .assertRaisesRegex (ssl .SSLError ,
2857
- "certificate verify failed" ):
2883
+ with self .assertRaisesRegex (ssl .SSLError , regex ):
2858
2884
s .connect ((HOST , server .port ))
2859
2885
2860
2886
# now load a CRL file. The CRL file is signed by the CA.
@@ -2885,12 +2911,16 @@ def test_check_hostname(self):
2885
2911
2886
2912
# incorrect hostname should raise an exception
2887
2913
server = ThreadedEchoServer (context = server_context , chatty = True )
2914
+ # Allow for flexible libssl error messages.
2915
+ regex = "("
2916
+ regex += "Hostname mismatch, certificate is not valid" # OpenSSL
2917
+ regex += "|"
2918
+ regex += "CERTIFICATE_VERIFY_FAILED" # AWS-LC/BoringSSL
2919
+ regex += ")"
2888
2920
with server :
2889
2921
with client_context .wrap_socket (socket .socket (),
2890
2922
server_hostname = "invalid" ) as s :
2891
- with self .assertRaisesRegex (
2892
- ssl .CertificateError ,
2893
- "Hostname mismatch, certificate is not valid for 'invalid'." ):
2923
+ with self .assertRaisesRegex (ssl .CertificateError , regex ):
2894
2924
s .connect ((HOST , server .port ))
2895
2925
2896
2926
# missing server_hostname arg should cause an exception, too
@@ -3094,7 +3124,7 @@ def test_wrong_cert_tls13(self):
3094
3124
s .connect ((HOST , server .port ))
3095
3125
with self .assertRaisesRegex (
3096
3126
ssl .SSLError ,
3097
- 'alert unknown ca|EOF occurred'
3127
+ 'alert unknown ca|EOF occurred|TLSV1_ALERT_UNKNOWN_CA '
3098
3128
):
3099
3129
# TLS 1.3 perform client cert exchange after handshake
3100
3130
s .write (b'data' )
@@ -3158,13 +3188,21 @@ def test_ssl_cert_verify_error(self):
3158
3188
server_hostname = SIGNED_CERTFILE_HOSTNAME ) as s :
3159
3189
try :
3160
3190
s .connect ((HOST , server .port ))
3191
+ self .fail ("Expected connection failure" )
3161
3192
except ssl .SSLError as e :
3162
3193
msg = 'unable to get local issuer certificate'
3163
3194
self .assertIsInstance (e , ssl .SSLCertVerificationError )
3164
3195
self .assertEqual (e .verify_code , 20 )
3165
3196
self .assertEqual (e .verify_message , msg )
3166
- self .assertIn (msg , repr (e ))
3167
- self .assertIn ('certificate verify failed' , repr (e ))
3197
+ # Allow for flexible libssl error messages.
3198
+ regex = "(" + msg + "|CERTIFICATE_VERIFY_FAILED)"
3199
+ self .assertRegex (repr (e ), regex )
3200
+ regex = "("
3201
+ regex += "certificate verify failed" # OpenSSL
3202
+ regex += "|"
3203
+ regex += "CERTIFICATE_VERIFY_FAILED" # AWS-LC/BoringSSL
3204
+ regex += ")"
3205
+ self .assertRegex (repr (e ), regex )
3168
3206
3169
3207
def test_PROTOCOL_TLS (self ):
3170
3208
"""Connecting to an SSLv23 server with various client options"""
@@ -3696,7 +3734,7 @@ def test_no_shared_ciphers(self):
3696
3734
server_hostname = hostname ) as s :
3697
3735
with self .assertRaises (OSError ):
3698
3736
s .connect ((HOST , server .port ))
3699
- self .assertIn ("no shared cipher " , server .conn_errors [0 ])
3737
+ self .assertIn ("NO_SHARED_CIPHER " , server .conn_errors [0 ])
3700
3738
3701
3739
def test_version_basic (self ):
3702
3740
"""
@@ -3784,7 +3822,7 @@ def test_min_max_version_mismatch(self):
3784
3822
server_hostname = hostname ) as s :
3785
3823
with self .assertRaises (ssl .SSLError ) as e :
3786
3824
s .connect ((HOST , server .port ))
3787
- self .assertIn ( " alert" , str (e .exception ))
3825
+ self .assertRegex ( "( alert|ALERT) " , str (e .exception ))
3788
3826
3789
3827
@requires_tls_version ('SSLv3' )
3790
3828
def test_min_max_version_sslv3 (self ):
@@ -3826,6 +3864,10 @@ def test_tls_unique_channel_binding(self):
3826
3864
3827
3865
client_context , server_context , hostname = testing_context ()
3828
3866
3867
+ # tls-unique is not defined for TLSv1.3
3868
+ # https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
3869
+ client_context .maximum_version = ssl .TLSVersion .TLSv1_2
3870
+
3829
3871
server = ThreadedEchoServer (context = server_context ,
3830
3872
chatty = True ,
3831
3873
connectionchatty = False )
@@ -3926,7 +3968,7 @@ def test_dh_params(self):
3926
3968
cipher = stats ["cipher" ][0 ]
3927
3969
parts = cipher .split ("-" )
3928
3970
if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts :
3929
- self .fail ("Non-DH cipher : " + cipher [0 ])
3971
+ self .fail ("Non-DH key exchange : " + cipher [0 ])
3930
3972
3931
3973
def test_ecdh_curve (self ):
3932
3974
# server secp384r1, client auto
@@ -4093,8 +4135,9 @@ def cb_raising(ssl_sock, server_name, initial_context):
4093
4135
chatty = False ,
4094
4136
sni_name = 'supermessage' )
4095
4137
4096
- self .assertEqual (cm .exception .reason ,
4097
- 'SSLV3_ALERT_HANDSHAKE_FAILURE' )
4138
+ # Allow for flexible libssl error messages.
4139
+ regex = "(SSLV3_ALERT_HANDSHAKE_FAILURE|NO_PRIVATE_VALUE)"
4140
+ self .assertRegex (regex , cm .exception .reason )
4098
4141
self .assertEqual (catch .unraisable .exc_type , ZeroDivisionError )
4099
4142
4100
4143
def test_sni_callback_wrong_return_type (self ):
0 commit comments