Skip to content

Commit 3b6a849

Browse files
miss-islingtontiran
authored andcommitted
bpo-43794: OpenSSL 3.0.0: set OP_IGNORE_UNEXPECTED_EOF by default (pythonGH-25309)
Signed-off-by: Christian Heimes <[email protected]> (cherry picked from commit 6f37ebc) Co-authored-by: Christian Heimes <[email protected]>
1 parent c76739a commit 3b6a849

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
@@ -844,6 +844,14 @@ Constants
844844

845845
.. versionadded:: 3.6
846846

847+
.. data:: OP_IGNORE_UNEXPECTED_EOF
848+
849+
Ignore unexpected shutdown of TLS connections.
850+
851+
This option is only available with OpenSSL 3.0.0 and later.
852+
853+
.. versionadded:: 3..6.15-27
854+
847855
.. data:: HAS_ALPN
848856

849857
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
@@ -92,6 +92,7 @@ def data_file(*name):
9292
OP_SINGLE_ECDH_USE = getattr(ssl, "OP_SINGLE_ECDH_USE", 0)
9393
OP_CIPHER_SERVER_PREFERENCE = getattr(ssl, "OP_CIPHER_SERVER_PREFERENCE", 0)
9494
OP_ENABLE_MIDDLEBOX_COMPAT = getattr(ssl, "OP_ENABLE_MIDDLEBOX_COMPAT", 0)
95+
OP_IGNORE_UNEXPECTED_EOF = getattr(ssl, "OP_IGNORE_UNEXPECTED_EOF", 0)
9596

9697

9798
def handle_error(prefix):
@@ -986,7 +987,8 @@ def test_options(self):
986987
# SSLContext also enables these by default
987988
default |= (OP_NO_COMPRESSION | OP_CIPHER_SERVER_PREFERENCE |
988989
OP_SINGLE_DH_USE | OP_SINGLE_ECDH_USE |
989-
OP_ENABLE_MIDDLEBOX_COMPAT)
990+
OP_ENABLE_MIDDLEBOX_COMPAT |
991+
OP_IGNORE_UNEXPECTED_EOF)
990992
self.assertEqual(default, ctx.options)
991993
ctx.options |= ssl.OP_NO_TLSv1
992994
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
@@ -2933,6 +2933,10 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
29332933
#endif
29342934
#ifdef SSL_OP_SINGLE_ECDH_USE
29352935
options |= SSL_OP_SINGLE_ECDH_USE;
2936+
#endif
2937+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
2938+
/* Make OpenSSL 3.0.0 behave like 1.1.1 */
2939+
options |= SSL_OP_IGNORE_UNEXPECTED_EOF;
29362940
#endif
29372941
SSL_CTX_set_options(self->ctx, options);
29382942

@@ -5697,6 +5701,10 @@ PyInit__ssl(void)
56975701
PyModule_AddIntConstant(m, "OP_ENABLE_MIDDLEBOX_COMPAT",
56985702
SSL_OP_ENABLE_MIDDLEBOX_COMPAT);
56995703
#endif
5704+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
5705+
PyModule_AddIntConstant(m, "OP_IGNORE_UNEXPECTED_EOF",
5706+
SSL_OP_IGNORE_UNEXPECTED_EOF);
5707+
#endif
57005708

57015709
#if HAVE_SNI
57025710
r = Py_True;

0 commit comments

Comments
 (0)