@@ -584,6 +584,54 @@ def test_timeout(self):
584
584
with test_wrap_socket (s ) as ss :
585
585
self .assertEqual (timeout , ss .gettimeout ())
586
586
587
+ def test_openssl111_deprecations (self ):
588
+ options = [
589
+ ssl .OP_NO_TLSv1 ,
590
+ ssl .OP_NO_TLSv1_1 ,
591
+ ssl .OP_NO_TLSv1_2 ,
592
+ ssl .OP_NO_TLSv1_3
593
+ ]
594
+ protocols = [
595
+ ssl .PROTOCOL_TLSv1 ,
596
+ ssl .PROTOCOL_TLSv1_1 ,
597
+ ssl .PROTOCOL_TLSv1_2 ,
598
+ ssl .PROTOCOL_TLS
599
+ ]
600
+ versions = [
601
+ ssl .TLSVersion .SSLv3 ,
602
+ ssl .TLSVersion .TLSv1 ,
603
+ ssl .TLSVersion .TLSv1_1 ,
604
+ ]
605
+
606
+ for option in options :
607
+ with self .subTest (option = option ):
608
+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
609
+ with self .assertWarns (DeprecationWarning ) as cm :
610
+ ctx .options |= option
611
+ self .assertEqual (
612
+ 'ssl.OP_NO_SSL*/ssl.SSL_NO_TLS* options are deprecated' ,
613
+ str (cm .warning )
614
+ )
615
+
616
+ for protocol in protocols :
617
+ with self .subTest (protocol = protocol ):
618
+ with self .assertWarns (DeprecationWarning ) as cm :
619
+ ssl .SSLContext (protocol )
620
+ self .assertEqual (
621
+ f'{ protocol !r} is deprecated' ,
622
+ str (cm .warning )
623
+ )
624
+
625
+ for version in versions :
626
+ with self .subTest (version = version ):
627
+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
628
+ with self .assertWarns (DeprecationWarning ) as cm :
629
+ ctx .minimum_version = version
630
+ self .assertEqual (
631
+ f'ssl.{ version !r} is deprecated' ,
632
+ str (cm .warning )
633
+ )
634
+
587
635
@ignore_deprecation
588
636
def test_errors_sslwrap (self ):
589
637
sock = socket .socket ()
@@ -3071,7 +3119,7 @@ def test_dual_rsa_ecc(self):
3071
3119
client_context .load_verify_locations (SIGNING_CA )
3072
3120
# TODO: fix TLSv1.3 once SSLContext can restrict signature
3073
3121
# algorithms.
3074
- client_context .options | = ssl .OP_NO_TLSv1_3
3122
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
3075
3123
# only ECDSA certs
3076
3124
client_context .set_ciphers ('ECDHE:ECDSA:!NULL:!aRSA' )
3077
3125
hostname = SIGNED_CERTFILE_ECC_HOSTNAME
@@ -3817,7 +3865,7 @@ def test_do_handshake_enotconn(self):
3817
3865
def test_no_shared_ciphers (self ):
3818
3866
client_context , server_context , hostname = testing_context ()
3819
3867
# OpenSSL enables all TLS 1.3 ciphers, enforce TLS 1.2 for test
3820
- client_context .options | = ssl .OP_NO_TLSv1_3
3868
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
3821
3869
# Force different suites on client and server
3822
3870
client_context .set_ciphers ("AES128" )
3823
3871
server_context .set_ciphers ("AES256" )
@@ -4032,10 +4080,10 @@ def test_dh_params(self):
4032
4080
# Check we can get a connection with ephemeral Diffie-Hellman
4033
4081
client_context , server_context , hostname = testing_context ()
4034
4082
# test scenario needs TLS <= 1.2
4035
- client_context .options | = ssl .OP_NO_TLSv1_3
4083
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
4036
4084
server_context .load_dh_params (DHFILE )
4037
4085
server_context .set_ciphers ("kEDH" )
4038
- server_context .options | = ssl .OP_NO_TLSv1_3
4086
+ server_context .maximum_version = ssl .TLSVersion . TLSv1_2
4039
4087
stats = server_params_test (client_context , server_context ,
4040
4088
chatty = True , connectionchatty = True ,
4041
4089
sni_name = hostname )
@@ -4281,7 +4329,7 @@ def test_sendfile(self):
4281
4329
def test_session (self ):
4282
4330
client_context , server_context , hostname = testing_context ()
4283
4331
# TODO: sessions aren't compatible with TLSv1.3 yet
4284
- client_context .options | = ssl .OP_NO_TLSv1_3
4332
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
4285
4333
4286
4334
# first connection without session
4287
4335
stats = server_params_test (client_context , server_context ,
@@ -4340,8 +4388,8 @@ def test_session_handling(self):
4340
4388
client_context2 , _ , _ = testing_context ()
4341
4389
4342
4390
# TODO: session reuse does not work with TLSv1.3
4343
- client_context .options | = ssl .OP_NO_TLSv1_3
4344
- client_context2 .options | = ssl .OP_NO_TLSv1_3
4391
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
4392
+ client_context2 .maximum_version = ssl .TLSVersion . TLSv1_2
4345
4393
4346
4394
server = ThreadedEchoServer (context = server_context , chatty = False )
4347
4395
with server :
@@ -4765,7 +4813,7 @@ def msg_cb(conn, direction, version, content_type, msg_type, data):
4765
4813
4766
4814
def test_msg_callback_tls12 (self ):
4767
4815
client_context , server_context , hostname = testing_context ()
4768
- client_context .options | = ssl .OP_NO_TLSv1_3
4816
+ client_context .maximum_version = ssl .TLSVersion . TLSv1_2
4769
4817
4770
4818
msg = []
4771
4819
0 commit comments