Skip to content

Commit 99125e8

Browse files
committed
Add ssl.OP_LEGACY_SERVER_CONNECT
Fixes #89051
1 parent 4beee0c commit 99125e8

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Doc/library/ssl.rst

+7
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,13 @@ Constants
920920

921921
.. versionadded:: 3.10
922922

923+
.. data:: OP_LEGACY_SERVER_CONNECT
924+
925+
Allow legacy insecure renegotiation between OpenSSL and unpatched servers
926+
only.
927+
928+
.. versionadded:: 3.12
929+
923930
.. data:: HAS_ALPN
924931

925932
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
@@ -1685,6 +1685,8 @@ def _assert_context_options(self, ctx):
16851685
if OP_CIPHER_SERVER_PREFERENCE != 0:
16861686
self.assertEqual(ctx.options & OP_CIPHER_SERVER_PREFERENCE,
16871687
OP_CIPHER_SERVER_PREFERENCE)
1688+
self.assertEqual(ctx.options & ssl.OP_LEGACY_SERVER_CONNECT,
1689+
0 if IS_OPENSSL_3_0_0 else ssl.OP_LEGACY_SERVER_CONNECT)
16881690

16891691
def test_create_default_context(self):
16901692
ctx = ssl.create_default_context()
@@ -4073,6 +4075,20 @@ def test_compression_disabled(self):
40734075
sni_name=hostname)
40744076
self.assertIs(stats['compression'], None)
40754077

4078+
def test_legacy_server_connect(self):
4079+
client_context, server_context, hostname = testing_context()
4080+
client_context.options |= ssl.OP_LEGACY_SERVER_CONNECT
4081+
server_params_test(client_context, server_context,
4082+
chatty=True, connectionchatty=True,
4083+
sni_name=hostname)
4084+
4085+
def test_no_legacy_server_connect(self):
4086+
client_context, server_context, hostname = testing_context()
4087+
client_context.options &= ~ssl.OP_LEGACY_SERVER_CONNECT
4088+
server_params_test(client_context, server_context,
4089+
chatty=True, connectionchatty=True,
4090+
sni_name=hostname)
4091+
40764092
@unittest.skipIf(Py_DEBUG_WIN32, "Avoid mixing debug/release CRT on Windows")
40774093
def test_dh_params(self):
40784094
# Check we can get a connection with ephemeral Diffie-Hellman

Modules/_ssl.c

+2
Original file line numberDiff line numberDiff line change
@@ -5883,6 +5883,8 @@ sslmodule_init_constants(PyObject *m)
58835883
SSL_OP_CIPHER_SERVER_PREFERENCE);
58845884
PyModule_AddIntConstant(m, "OP_SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE);
58855885
PyModule_AddIntConstant(m, "OP_NO_TICKET", SSL_OP_NO_TICKET);
5886+
PyModule_AddIntConstant(m, "OP_LEGACY_SERVER_CONNECT",
5887+
SSL_OP_LEGACY_SERVER_CONNECT);
58865888
#ifdef SSL_OP_SINGLE_ECDH_USE
58875889
PyModule_AddIntConstant(m, "OP_SINGLE_ECDH_USE", SSL_OP_SINGLE_ECDH_USE);
58885890
#endif

0 commit comments

Comments
 (0)