mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[3.10] bpo-44389: Fix deprecation of OP_NO_TLSv1_3 (GH-26700) (GH-26705)
Signed-off-by: Christian Heimes <christian@python.org>
(cherry picked from commit bf527277d4
)
Co-authored-by: Christian Heimes <christian@python.org>
Automerge-Triggered-By: GH:tiran
This commit is contained in:
parent
f30f484e96
commit
4becc569a6
3 changed files with 58 additions and 9 deletions
|
@ -584,6 +584,54 @@ class BasicSocketTests(unittest.TestCase):
|
||||||
with test_wrap_socket(s) as ss:
|
with test_wrap_socket(s) as ss:
|
||||||
self.assertEqual(timeout, ss.gettimeout())
|
self.assertEqual(timeout, ss.gettimeout())
|
||||||
|
|
||||||
|
def test_openssl111_deprecations(self):
|
||||||
|
options = [
|
||||||
|
ssl.OP_NO_TLSv1,
|
||||||
|
ssl.OP_NO_TLSv1_1,
|
||||||
|
ssl.OP_NO_TLSv1_2,
|
||||||
|
ssl.OP_NO_TLSv1_3
|
||||||
|
]
|
||||||
|
protocols = [
|
||||||
|
ssl.PROTOCOL_TLSv1,
|
||||||
|
ssl.PROTOCOL_TLSv1_1,
|
||||||
|
ssl.PROTOCOL_TLSv1_2,
|
||||||
|
ssl.PROTOCOL_TLS
|
||||||
|
]
|
||||||
|
versions = [
|
||||||
|
ssl.TLSVersion.SSLv3,
|
||||||
|
ssl.TLSVersion.TLSv1,
|
||||||
|
ssl.TLSVersion.TLSv1_1,
|
||||||
|
]
|
||||||
|
|
||||||
|
for option in options:
|
||||||
|
with self.subTest(option=option):
|
||||||
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
||||||
|
with self.assertWarns(DeprecationWarning) as cm:
|
||||||
|
ctx.options |= option
|
||||||
|
self.assertEqual(
|
||||||
|
'ssl.OP_NO_SSL*/ssl.SSL_NO_TLS* options are deprecated',
|
||||||
|
str(cm.warning)
|
||||||
|
)
|
||||||
|
|
||||||
|
for protocol in protocols:
|
||||||
|
with self.subTest(protocol=protocol):
|
||||||
|
with self.assertWarns(DeprecationWarning) as cm:
|
||||||
|
ssl.SSLContext(protocol)
|
||||||
|
self.assertEqual(
|
||||||
|
f'{protocol!r} is deprecated',
|
||||||
|
str(cm.warning)
|
||||||
|
)
|
||||||
|
|
||||||
|
for version in versions:
|
||||||
|
with self.subTest(version=version):
|
||||||
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
||||||
|
with self.assertWarns(DeprecationWarning) as cm:
|
||||||
|
ctx.minimum_version = version
|
||||||
|
self.assertEqual(
|
||||||
|
f'ssl.{version!r} is deprecated',
|
||||||
|
str(cm.warning)
|
||||||
|
)
|
||||||
|
|
||||||
@ignore_deprecation
|
@ignore_deprecation
|
||||||
def test_errors_sslwrap(self):
|
def test_errors_sslwrap(self):
|
||||||
sock = socket.socket()
|
sock = socket.socket()
|
||||||
|
@ -3071,7 +3119,7 @@ class ThreadedTests(unittest.TestCase):
|
||||||
client_context.load_verify_locations(SIGNING_CA)
|
client_context.load_verify_locations(SIGNING_CA)
|
||||||
# TODO: fix TLSv1.3 once SSLContext can restrict signature
|
# TODO: fix TLSv1.3 once SSLContext can restrict signature
|
||||||
# algorithms.
|
# algorithms.
|
||||||
client_context.options |= ssl.OP_NO_TLSv1_3
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||||
# only ECDSA certs
|
# only ECDSA certs
|
||||||
client_context.set_ciphers('ECDHE:ECDSA:!NULL:!aRSA')
|
client_context.set_ciphers('ECDHE:ECDSA:!NULL:!aRSA')
|
||||||
hostname = SIGNED_CERTFILE_ECC_HOSTNAME
|
hostname = SIGNED_CERTFILE_ECC_HOSTNAME
|
||||||
|
@ -3817,7 +3865,7 @@ class ThreadedTests(unittest.TestCase):
|
||||||
def test_no_shared_ciphers(self):
|
def test_no_shared_ciphers(self):
|
||||||
client_context, server_context, hostname = testing_context()
|
client_context, server_context, hostname = testing_context()
|
||||||
# OpenSSL enables all TLS 1.3 ciphers, enforce TLS 1.2 for test
|
# OpenSSL enables all TLS 1.3 ciphers, enforce TLS 1.2 for test
|
||||||
client_context.options |= ssl.OP_NO_TLSv1_3
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||||
# Force different suites on client and server
|
# Force different suites on client and server
|
||||||
client_context.set_ciphers("AES128")
|
client_context.set_ciphers("AES128")
|
||||||
server_context.set_ciphers("AES256")
|
server_context.set_ciphers("AES256")
|
||||||
|
@ -4032,10 +4080,10 @@ class ThreadedTests(unittest.TestCase):
|
||||||
# Check we can get a connection with ephemeral Diffie-Hellman
|
# Check we can get a connection with ephemeral Diffie-Hellman
|
||||||
client_context, server_context, hostname = testing_context()
|
client_context, server_context, hostname = testing_context()
|
||||||
# test scenario needs TLS <= 1.2
|
# test scenario needs TLS <= 1.2
|
||||||
client_context.options |= ssl.OP_NO_TLSv1_3
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||||
server_context.load_dh_params(DHFILE)
|
server_context.load_dh_params(DHFILE)
|
||||||
server_context.set_ciphers("kEDH")
|
server_context.set_ciphers("kEDH")
|
||||||
server_context.options |= ssl.OP_NO_TLSv1_3
|
server_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||||
stats = server_params_test(client_context, server_context,
|
stats = server_params_test(client_context, server_context,
|
||||||
chatty=True, connectionchatty=True,
|
chatty=True, connectionchatty=True,
|
||||||
sni_name=hostname)
|
sni_name=hostname)
|
||||||
|
@ -4281,7 +4329,7 @@ class ThreadedTests(unittest.TestCase):
|
||||||
def test_session(self):
|
def test_session(self):
|
||||||
client_context, server_context, hostname = testing_context()
|
client_context, server_context, hostname = testing_context()
|
||||||
# TODO: sessions aren't compatible with TLSv1.3 yet
|
# TODO: sessions aren't compatible with TLSv1.3 yet
|
||||||
client_context.options |= ssl.OP_NO_TLSv1_3
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||||
|
|
||||||
# first connection without session
|
# first connection without session
|
||||||
stats = server_params_test(client_context, server_context,
|
stats = server_params_test(client_context, server_context,
|
||||||
|
@ -4340,8 +4388,8 @@ class ThreadedTests(unittest.TestCase):
|
||||||
client_context2, _, _ = testing_context()
|
client_context2, _, _ = testing_context()
|
||||||
|
|
||||||
# TODO: session reuse does not work with TLSv1.3
|
# TODO: session reuse does not work with TLSv1.3
|
||||||
client_context.options |= ssl.OP_NO_TLSv1_3
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||||
client_context2.options |= ssl.OP_NO_TLSv1_3
|
client_context2.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||||
|
|
||||||
server = ThreadedEchoServer(context=server_context, chatty=False)
|
server = ThreadedEchoServer(context=server_context, chatty=False)
|
||||||
with server:
|
with server:
|
||||||
|
@ -4765,7 +4813,7 @@ class TestSSLDebug(unittest.TestCase):
|
||||||
|
|
||||||
def test_msg_callback_tls12(self):
|
def test_msg_callback_tls12(self):
|
||||||
client_context, server_context, hostname = testing_context()
|
client_context, server_context, hostname = testing_context()
|
||||||
client_context.options |= ssl.OP_NO_TLSv1_3
|
client_context.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||||
|
|
||||||
msg = []
|
msg = []
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix deprecation of :data:`ssl.OP_NO_TLSv1_3`
|
|
@ -3587,7 +3587,7 @@ set_options(PySSLContext *self, PyObject *arg, void *c)
|
||||||
long new_opts, opts, set, clear;
|
long new_opts, opts, set, clear;
|
||||||
long opt_no = (
|
long opt_no = (
|
||||||
SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 |
|
SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 |
|
||||||
SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2
|
SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!PyArg_Parse(arg, "l", &new_opts))
|
if (!PyArg_Parse(arg, "l", &new_opts))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue