Skip to content

Commit 6f37ebc

Browse files
authored
bpo-43794: OpenSSL 3.0.0: set OP_IGNORE_UNEXPECTED_EOF by default (GH-25309)
Signed-off-by: Christian Heimes <[email protected]>
1 parent 507a574 commit 6f37ebc

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

Doc/library/ssl.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,14 @@ Constants
893893

894894
.. versionadded:: 3.6
895895

896+
.. data:: OP_IGNORE_UNEXPECTED_EOF
897+
898+
Ignore unexpected shutdown of TLS connections.
899+
900+
This option is only available with OpenSSL 3.0.0 and later.
901+
902+
.. versionadded:: 3.10
903+
896904
.. data:: HAS_ALPN
897905

898906
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
@@ -151,6 +151,7 @@ def data_file(*name):
151151
OP_SINGLE_ECDH_USE = getattr(ssl, "OP_SINGLE_ECDH_USE", 0)
152152
OP_CIPHER_SERVER_PREFERENCE = getattr(ssl, "OP_CIPHER_SERVER_PREFERENCE", 0)
153153
OP_ENABLE_MIDDLEBOX_COMPAT = getattr(ssl, "OP_ENABLE_MIDDLEBOX_COMPAT", 0)
154+
OP_IGNORE_UNEXPECTED_EOF = getattr(ssl, "OP_IGNORE_UNEXPECTED_EOF", 0)
154155

155156
# Ubuntu has patched OpenSSL and changed behavior of security level 2
156157
# see https://bugs.python.org/issue41561#msg389003
@@ -1168,7 +1169,8 @@ def test_options(self):
11681169
# SSLContext also enables these by default
11691170
default |= (OP_NO_COMPRESSION | OP_CIPHER_SERVER_PREFERENCE |
11701171
OP_SINGLE_DH_USE | OP_SINGLE_ECDH_USE |
1171-
OP_ENABLE_MIDDLEBOX_COMPAT)
1172+
OP_ENABLE_MIDDLEBOX_COMPAT |
1173+
OP_IGNORE_UNEXPECTED_EOF)
11721174
self.assertEqual(default, ctx.options)
11731175
ctx.options |= ssl.OP_NO_TLSv1
11741176
self.assertEqual(default | ssl.OP_NO_TLSv1, ctx.options)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add :data:`ssl.OP_IGNORE_UNEXPECTED_EOF` constants (OpenSSL 3.0.0)

Modules/_ssl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,10 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
32023202
#endif
32033203
#ifdef SSL_OP_SINGLE_ECDH_USE
32043204
options |= SSL_OP_SINGLE_ECDH_USE;
3205+
#endif
3206+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
3207+
/* Make OpenSSL 3.0.0 behave like 1.1.1 */
3208+
options |= SSL_OP_IGNORE_UNEXPECTED_EOF;
32053209
#endif
32063210
SSL_CTX_set_options(self->ctx, options);
32073211

@@ -6313,6 +6317,10 @@ sslmodule_init_constants(PyObject *m)
63136317
PyModule_AddIntConstant(m, "OP_NO_RENEGOTIATION",
63146318
SSL_OP_NO_RENEGOTIATION);
63156319
#endif
6320+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
6321+
PyModule_AddIntConstant(m, "OP_IGNORE_UNEXPECTED_EOF",
6322+
SSL_OP_IGNORE_UNEXPECTED_EOF);
6323+
#endif
63166324

63176325
#ifdef X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT
63186326
PyModule_AddIntConstant(m, "HOSTFLAG_ALWAYS_CHECK_SUBJECT",

0 commit comments

Comments
 (0)