@@ -580,6 +580,54 @@ def test_timeout(self):
580
580
with test_wrap_socket (s ) as ss :
581
581
self .assertEqual (timeout , ss .gettimeout ())
582
582
583
+ def test_openssl111_deprecations (self ):
584
+ options = [
585
+ ssl .OP_NO_TLSv1 ,
586
+ ssl .OP_NO_TLSv1_1 ,
587
+ ssl .OP_NO_TLSv1_2 ,
588
+ ssl .OP_NO_TLSv1_3
589
+ ]
590
+ protocols = [
591
+ ssl .PROTOCOL_TLSv1 ,
592
+ ssl .PROTOCOL_TLSv1_1 ,
593
+ ssl .PROTOCOL_TLSv1_2 ,
594
+ ssl .PROTOCOL_TLS
595
+ ]
596
+ versions = [
597
+ ssl .TLSVersion .SSLv3 ,
598
+ ssl .TLSVersion .TLSv1 ,
599
+ ssl .TLSVersion .TLSv1_1 ,
600
+ ]
601
+
602
+ for option in options :
603
+ with self .subTest (option = option ):
604
+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
605
+ with self .assertWarns (DeprecationWarning ) as cm :
606
+ ctx .options |= option
607
+ self .assertEqual (
608
+ 'ssl.OP_NO_SSL*/ssl.SSL_NO_TLS* options are deprecated' ,
609
+ str (cm .warning )
610
+ )
611
+
612
+ for protocol in protocols :
613
+ with self .subTest (protocol = protocol ):
614
+ with self .assertWarns (DeprecationWarning ) as cm :
615
+ ssl .SSLContext (protocol )
616
+ self .assertEqual (
617
+ f'{ protocol !r} is deprecated' ,
618
+ str (cm .warning )
619
+ )
620
+
621
+ for version in versions :
622
+ with self .subTest (version = version ):
623
+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
624
+ with self .assertWarns (DeprecationWarning ) as cm :
625
+ ctx .minimum_version = version
626
+ self .assertEqual (
627
+ f'ssl.{ version !r} is deprecated' ,
628
+ str (cm .warning )
629
+ )
630
+
583
631
@ignore_deprecation
584
632
def test_errors_sslwrap (self ):
585
633
sock = socket .socket ()
@@ -3067,7 +3115,7 @@ def test_dual_rsa_ecc(self):
3067
3115
client_context .load_verify_locations (SIGNING_CA )
3068
3116
# TODO: fix TLSv1.3 once SSLContext can restrict signature
3069
3117
# algorithms.
3070
- client_context .options | = ssl .OP_NO_TLSv1_3
3118
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
3071
3119
# only ECDSA certs
3072
3120
client_context .set_ciphers ('ECDHE:ECDSA:!NULL:!aRSA' )
3073
3121
hostname = SIGNED_CERTFILE_ECC_HOSTNAME
@@ -3806,7 +3854,7 @@ def test_do_handshake_enotconn(self):
3806
3854
def test_no_shared_ciphers (self ):
3807
3855
client_context , server_context , hostname = testing_context ()
3808
3856
# OpenSSL enables all TLS 1.3 ciphers, enforce TLS 1.2 for test
3809
- client_context .options | = ssl .OP_NO_TLSv1_3
3857
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
3810
3858
# Force different suites on client and server
3811
3859
client_context .set_ciphers ("AES128" )
3812
3860
server_context .set_ciphers ("AES256" )
@@ -4021,10 +4069,10 @@ def test_dh_params(self):
4021
4069
# Check we can get a connection with ephemeral Diffie-Hellman
4022
4070
client_context , server_context , hostname = testing_context ()
4023
4071
# test scenario needs TLS <= 1.2
4024
- client_context .options | = ssl .OP_NO_TLSv1_3
4072
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
4025
4073
server_context .load_dh_params (DHFILE )
4026
4074
server_context .set_ciphers ("kEDH" )
4027
- server_context .options | = ssl .OP_NO_TLSv1_3
4075
+ server_context .maximum_version = ssl .TLSVersion . TLSv1_2
4028
4076
stats = server_params_test (client_context , server_context ,
4029
4077
chatty = True , connectionchatty = True ,
4030
4078
sni_name = hostname )
@@ -4270,7 +4318,7 @@ def test_sendfile(self):
4270
4318
def test_session (self ):
4271
4319
client_context , server_context , hostname = testing_context ()
4272
4320
# TODO: sessions aren't compatible with TLSv1.3 yet
4273
- client_context .options | = ssl .OP_NO_TLSv1_3
4321
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
4274
4322
4275
4323
# first connection without session
4276
4324
stats = server_params_test (client_context , server_context ,
@@ -4329,8 +4377,8 @@ def test_session_handling(self):
4329
4377
client_context2 , _ , _ = testing_context ()
4330
4378
4331
4379
# TODO: session reuse does not work with TLSv1.3
4332
- client_context .options | = ssl .OP_NO_TLSv1_3
4333
- client_context2 .options | = ssl .OP_NO_TLSv1_3
4380
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
4381
+ client_context2 .maximum_version = ssl .TLSVersion . TLSv1_2
4334
4382
4335
4383
server = ThreadedEchoServer (context = server_context , chatty = False )
4336
4384
with server :
@@ -4754,7 +4802,7 @@ def msg_cb(conn, direction, version, content_type, msg_type, data):
4754
4802
4755
4803
def test_msg_callback_tls12 (self ):
4756
4804
client_context , server_context , hostname = testing_context ()
4757
- client_context .options | = ssl .OP_NO_TLSv1_3
4805
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
4758
4806
4759
4807
msg = []
4760
4808
0 commit comments