Skip to content

Commit 9c16ffe

Browse files
committed
bpo-43794: OpenSSL 3.0.0: set OP_IGNORE_UNEXPECTED_EOF by default (pythonGH-25309)
1 parent bcf034f commit 9c16ffe

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Doc/library/ssl.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,12 @@ Constants
760760

761761
.. versionadded:: 2.7.9
762762

763+
.. data:: OP_IGNORE_UNEXPECTED_EOF
764+
765+
Ignore unexpected shutdown of TLS connections.
766+
767+
This option is only available with OpenSSL 3.0.0 and later.
768+
763769
.. data:: HAS_ALPN
764770

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

Lib/test/test_ssl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def data_file(*name):
8484
OP_SINGLE_ECDH_USE = getattr(ssl, "OP_SINGLE_ECDH_USE", 0)
8585
OP_CIPHER_SERVER_PREFERENCE = getattr(ssl, "OP_CIPHER_SERVER_PREFERENCE", 0)
8686
OP_ENABLE_MIDDLEBOX_COMPAT = getattr(ssl, "OP_ENABLE_MIDDLEBOX_COMPAT", 0)
87+
OP_IGNORE_UNEXPECTED_EOF = getattr(ssl, "OP_IGNORE_UNEXPECTED_EOF", 0)
8788

8889

8990
def handle_error(prefix):
@@ -839,7 +840,8 @@ def test_options(self):
839840
# SSLContext also enables these by default
840841
default |= (OP_NO_COMPRESSION | OP_CIPHER_SERVER_PREFERENCE |
841842
OP_SINGLE_DH_USE | OP_SINGLE_ECDH_USE |
842-
OP_ENABLE_MIDDLEBOX_COMPAT)
843+
OP_ENABLE_MIDDLEBOX_COMPAT |
844+
OP_IGNORE_UNEXPECTED_EOF)
843845
self.assertEqual(default, ctx.options)
844846
ctx.options |= ssl.OP_NO_TLSv1
845847
self.assertEqual(default | ssl.OP_NO_TLSv1, ctx.options)

Modules/_ssl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,10 @@ context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
23122312
#endif
23132313
#ifdef SSL_OP_SINGLE_ECDH_USE
23142314
options |= SSL_OP_SINGLE_ECDH_USE;
2315+
#endif
2316+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
2317+
/* Make OpenSSL 3.0.0 behave like 1.1.1 */
2318+
options |= SSL_OP_IGNORE_UNEXPECTED_EOF;
23152319
#endif
23162320
SSL_CTX_set_options(self->ctx, options);
23172321

@@ -4477,6 +4481,10 @@ init_ssl(void)
44774481
PyModule_AddIntConstant(m, "OP_ENABLE_MIDDLEBOX_COMPAT",
44784482
SSL_OP_ENABLE_MIDDLEBOX_COMPAT);
44794483
#endif
4484+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
4485+
PyModule_AddIntConstant(m, "OP_IGNORE_UNEXPECTED_EOF",
4486+
SSL_OP_IGNORE_UNEXPECTED_EOF);
4487+
#endif
44804488

44814489
#if HAVE_SNI
44824490
r = Py_True;

0 commit comments

Comments
 (0)