Skip to content

Commit 642bb93

Browse files
committed
bpo-44389: Fix deprecation of OP_NO_TLSv1_3
Signed-off-by: Christian Heimes <[email protected]>
1 parent cb7230c commit 642bb93

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
@@ -580,6 +580,54 @@ def test_timeout(self):
580580
with test_wrap_socket(s) as ss:
581581
self.assertEqual(timeout, ss.gettimeout())
582582

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+
583631
@ignore_deprecation
584632
def test_errors_sslwrap(self):
585633
sock = socket.socket()
@@ -3067,7 +3115,7 @@ def test_dual_rsa_ecc(self):
30673115
client_context.load_verify_locations(SIGNING_CA)
30683116
# TODO: fix TLSv1.3 once SSLContext can restrict signature
30693117
# algorithms.
3070-
client_context.options |= ssl.OP_NO_TLSv1_3
3118+
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
30713119
# only ECDSA certs
30723120
client_context.set_ciphers('ECDHE:ECDSA:!NULL:!aRSA')
30733121
hostname = SIGNED_CERTFILE_ECC_HOSTNAME
@@ -3806,7 +3854,7 @@ def test_do_handshake_enotconn(self):
38063854
def test_no_shared_ciphers(self):
38073855
client_context, server_context, hostname = testing_context()
38083856
# 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
38103858
# Force different suites on client and server
38113859
client_context.set_ciphers("AES128")
38123860
server_context.set_ciphers("AES256")
@@ -4021,10 +4069,10 @@ def test_dh_params(self):
40214069
# Check we can get a connection with ephemeral Diffie-Hellman
40224070
client_context, server_context, hostname = testing_context()
40234071
# test scenario needs TLS <= 1.2
4024-
client_context.options |= ssl.OP_NO_TLSv1_3
4072+
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
40254073
server_context.load_dh_params(DHFILE)
40264074
server_context.set_ciphers("kEDH")
4027-
server_context.options |= ssl.OP_NO_TLSv1_3
4075+
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
40284076
stats = server_params_test(client_context, server_context,
40294077
chatty=True, connectionchatty=True,
40304078
sni_name=hostname)
@@ -4270,7 +4318,7 @@ def test_sendfile(self):
42704318
def test_session(self):
42714319
client_context, server_context, hostname = testing_context()
42724320
# 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
42744322

42754323
# first connection without session
42764324
stats = server_params_test(client_context, server_context,
@@ -4329,8 +4377,8 @@ def test_session_handling(self):
43294377
client_context2, _, _ = testing_context()
43304378

43314379
# 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
43344382

43354383
server = ThreadedEchoServer(context=server_context, chatty=False)
43364384
with server:
@@ -4754,7 +4802,7 @@ def msg_cb(conn, direction, version, content_type, msg_type, data):
47544802

47554803
def test_msg_callback_tls12(self):
47564804
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
47584806

47594807
msg = []
47604808

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)