Skip to content

Commit 4becc56

Browse files
[3.10] bpo-44389: Fix deprecation of OP_NO_TLSv1_3 (GH-26700) (GH-26705)
Signed-off-by: Christian Heimes <[email protected]> (cherry picked from commit bf52727) Co-authored-by: Christian Heimes <[email protected]> Automerge-Triggered-By: GH:tiran
1 parent f30f484 commit 4becc56

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

Lib/test/test_ssl.py

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,54 @@ def test_timeout(self):
584584
with test_wrap_socket(s) as ss:
585585
self.assertEqual(timeout, ss.gettimeout())
586586

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+
587635
@ignore_deprecation
588636
def test_errors_sslwrap(self):
589637
sock = socket.socket()
@@ -3071,7 +3119,7 @@ def test_dual_rsa_ecc(self):
30713119
client_context.load_verify_locations(SIGNING_CA)
30723120
# TODO: fix TLSv1.3 once SSLContext can restrict signature
30733121
# algorithms.
3074-
client_context.options |= ssl.OP_NO_TLSv1_3
3122+
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
30753123
# only ECDSA certs
30763124
client_context.set_ciphers('ECDHE:ECDSA:!NULL:!aRSA')
30773125
hostname = SIGNED_CERTFILE_ECC_HOSTNAME
@@ -3817,7 +3865,7 @@ def test_do_handshake_enotconn(self):
38173865
def test_no_shared_ciphers(self):
38183866
client_context, server_context, hostname = testing_context()
38193867
# 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
38213869
# Force different suites on client and server
38223870
client_context.set_ciphers("AES128")
38233871
server_context.set_ciphers("AES256")
@@ -4032,10 +4080,10 @@ def test_dh_params(self):
40324080
# Check we can get a connection with ephemeral Diffie-Hellman
40334081
client_context, server_context, hostname = testing_context()
40344082
# test scenario needs TLS <= 1.2
4035-
client_context.options |= ssl.OP_NO_TLSv1_3
4083+
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
40364084
server_context.load_dh_params(DHFILE)
40374085
server_context.set_ciphers("kEDH")
4038-
server_context.options |= ssl.OP_NO_TLSv1_3
4086+
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
40394087
stats = server_params_test(client_context, server_context,
40404088
chatty=True, connectionchatty=True,
40414089
sni_name=hostname)
@@ -4281,7 +4329,7 @@ def test_sendfile(self):
42814329
def test_session(self):
42824330
client_context, server_context, hostname = testing_context()
42834331
# 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
42854333

42864334
# first connection without session
42874335
stats = server_params_test(client_context, server_context,
@@ -4340,8 +4388,8 @@ def test_session_handling(self):
43404388
client_context2, _, _ = testing_context()
43414389

43424390
# 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
43454393

43464394
server = ThreadedEchoServer(context=server_context, chatty=False)
43474395
with server:
@@ -4765,7 +4813,7 @@ def msg_cb(conn, direction, version, content_type, msg_type, data):
47654813

47664814
def test_msg_callback_tls12(self):
47674815
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
47694817

47704818
msg = []
47714819

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix deprecation of :data:`ssl.OP_NO_TLSv1_3`

Modules/_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3587,7 +3587,7 @@ set_options(PySSLContext *self, PyObject *arg, void *c)
35873587
long new_opts, opts, set, clear;
35883588
long opt_no = (
35893589
SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 |
3590-
SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2
3590+
SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3
35913591
);
35923592

35933593
if (!PyArg_Parse(arg, "l", &new_opts))

0 commit comments

Comments
 (0)