Skip to content

Commit dd21351

Browse files
graingerthugovk
authored andcommitted
pythongh-89051: Add ssl.OP_LEGACY_SERVER_CONNECT (python#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 python#89051 (cherry picked from commit 79ccc03)
1 parent cfa78ec commit dd21351

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
@@ -918,6 +918,13 @@ Constants
918918

919919
.. versionadded:: 3.10
920920

921+
.. data:: OP_LEGACY_SERVER_CONNECT
922+
923+
Allow legacy insecure renegotiation between OpenSSL and unpatched servers
924+
only.
925+
926+
.. versionadded:: 3.11.2
927+
921928
.. data:: HAS_ALPN
922929

923930
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
@@ -1702,6 +1702,8 @@ def _assert_context_options(self, ctx):
17021702
if OP_CIPHER_SERVER_PREFERENCE != 0:
17031703
self.assertEqual(ctx.options & OP_CIPHER_SERVER_PREFERENCE,
17041704
OP_CIPHER_SERVER_PREFERENCE)
1705+
self.assertEqual(ctx.options & ssl.OP_LEGACY_SERVER_CONNECT,
1706+
0 if IS_OPENSSL_3_0_0 else ssl.OP_LEGACY_SERVER_CONNECT)
17051707

17061708
def test_create_default_context(self):
17071709
ctx = ssl.create_default_context()
@@ -4094,6 +4096,20 @@ def test_compression_disabled(self):
40944096
sni_name=hostname)
40954097
self.assertIs(stats['compression'], None)
40964098

4099+
def test_legacy_server_connect(self):
4100+
client_context, server_context, hostname = testing_context()
4101+
client_context.options |= ssl.OP_LEGACY_SERVER_CONNECT
4102+
server_params_test(client_context, server_context,
4103+
chatty=True, connectionchatty=True,
4104+
sni_name=hostname)
4105+
4106+
def test_no_legacy_server_connect(self):
4107+
client_context, server_context, hostname = testing_context()
4108+
client_context.options &= ~ssl.OP_LEGACY_SERVER_CONNECT
4109+
server_params_test(client_context, server_context,
4110+
chatty=True, connectionchatty=True,
4111+
sni_name=hostname)
4112+
40974113
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
40984114
def test_dh_params(self):
40994115
# 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
@@ -5888,6 +5888,8 @@ sslmodule_init_constants(PyObject *m)
58885888
SSL_OP_CIPHER_SERVER_PREFERENCE);
58895889
PyModule_AddIntConstant(m, "OP_SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE);
58905890
PyModule_AddIntConstant(m, "OP_NO_TICKET", SSL_OP_NO_TICKET);
5891+
PyModule_AddIntConstant(m, "OP_LEGACY_SERVER_CONNECT",
5892+
SSL_OP_LEGACY_SERVER_CONNECT);
58915893
#ifdef SSL_OP_SINGLE_ECDH_USE
58925894
PyModule_AddIntConstant(m, "OP_SINGLE_ECDH_USE", SSL_OP_SINGLE_ECDH_USE);
58935895
#endif

0 commit comments

Comments
 (0)