Skip to content

Commit 79ccc03

Browse files
authored
gh-89051: Add ssl.OP_LEGACY_SERVER_CONNECT (#93927)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Christian Heimes <christian@python.org> Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Fixes #89051
1 parent 36a0b1d commit 79ccc03

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

Doc/library/ssl.rst

+7
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,13 @@ Constants
823823

824824
.. versionadded:: 3.12
825825

826+
.. data:: OP_LEGACY_SERVER_CONNECT
827+
828+
Allow legacy insecure renegotiation between OpenSSL and unpatched servers
829+
only.
830+
831+
.. versionadded:: 3.12
832+
826833
.. data:: HAS_ALPN
827834

828835
Whether the OpenSSL library has built-in support for the *Application-Layer

Lib/test/test_ssl.py

+16
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,8 @@ def _assert_context_options(self, ctx):
14611461
if OP_CIPHER_SERVER_PREFERENCE != 0:
14621462
self.assertEqual(ctx.options & OP_CIPHER_SERVER_PREFERENCE,
14631463
OP_CIPHER_SERVER_PREFERENCE)
1464+
self.assertEqual(ctx.options & ssl.OP_LEGACY_SERVER_CONNECT,
1465+
0 if IS_OPENSSL_3_0_0 else ssl.OP_LEGACY_SERVER_CONNECT)
14641466

14651467
def test_create_default_context(self):
14661468
ctx = ssl.create_default_context()
@@ -3815,6 +3817,20 @@ def test_compression_disabled(self):
38153817
sni_name=hostname)
38163818
self.assertIs(stats['compression'], None)
38173819

3820+
def test_legacy_server_connect(self):
3821+
client_context, server_context, hostname = testing_context()
3822+
client_context.options |= ssl.OP_LEGACY_SERVER_CONNECT
3823+
server_params_test(client_context, server_context,
3824+
chatty=True, connectionchatty=True,
3825+
sni_name=hostname)
3826+
3827+
def test_no_legacy_server_connect(self):
3828+
client_context, server_context, hostname = testing_context()
3829+
client_context.options &= ~ssl.OP_LEGACY_SERVER_CONNECT
3830+
server_params_test(client_context, server_context,
3831+
chatty=True, connectionchatty=True,
3832+
sni_name=hostname)
3833+
38183834
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
38193835
def test_dh_params(self):
38203836
# Check we can get a connection with ephemeral Diffie-Hellman
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add :data:`ssl.OP_LEGACY_SERVER_CONNECT`

Modules/_ssl.c

+2
Original file line numberDiff line numberDiff line change
@@ -5845,6 +5845,8 @@ sslmodule_init_constants(PyObject *m)
58455845
SSL_OP_CIPHER_SERVER_PREFERENCE);
58465846
PyModule_AddIntConstant(m, "OP_SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE);
58475847
PyModule_AddIntConstant(m, "OP_NO_TICKET", SSL_OP_NO_TICKET);
5848+
PyModule_AddIntConstant(m, "OP_LEGACY_SERVER_CONNECT",
5849+
SSL_OP_LEGACY_SERVER_CONNECT);
58485850
#ifdef SSL_OP_SINGLE_ECDH_USE
58495851
PyModule_AddIntConstant(m, "OP_SINGLE_ECDH_USE", SSL_OP_SINGLE_ECDH_USE);
58505852
#endif

0 commit comments

Comments
 (0)