8000 bpo-43794: OpenSSL 3.0.0: set OP_IGNORE_UNEXPECTED_EOF by default (GH… · python/cpython@54d89a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 54d89a3

Browse files
bpo-43794: OpenSSL 3.0.0: set OP_IGNORE_UNEXPECTED_EOF by default (GH-25309)
Signed-off-by: Christian Heimes <christian@python.org> (cherry picked from commit 6f37ebc) Co-authored-by: Christian Heimes <christian@python.org>
1 parent 4a5c101 commit 54d89a3

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
@@ -886,6 +886,14 @@ Constants
886886

887887
.. versionadded:: 3.6
888888

889+
.. data:: OP_IGNORE_UNEXPECTED_EOF
890+
891+
Ignore unexpected shutdown of TLS connections.
892+
893+
This option is only available with OpenSSL 3.0.0 and later.
894+
895+
.. versionadded:: 3.10
896+
889897
.. data:: HAS_ALPN
890898

891899
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
@@ -147,6 +147,7 @@ def data_file(*name):
147147
OP_SINGLE_ECDH_USE = getattr(ssl, "OP_SINGLE_ECDH_USE", 0)
148148
OP_CIPHER_SERVER_PREFERENCE = getattr(ssl, "OP_CIPHER_SERVER_PREFERENCE", 0)
149149
OP_ENABLE_MIDDLEBOX_COMPAT = getattr(ssl, "OP_ENABLE_MIDDLEBOX_COMPAT", 0)
150+
OP_IGNORE_UNEXPECTED_EOF = getattr(ssl, "OP_IGNORE_UNEXPECTED_EOF", 0)
150151

151152
# Ubuntu has patched OpenSSL and changed behavior of security level 2
152153
# see https://bugs.python.org/issue41561#msg389003
@@ -1164,7 +1165,8 @@ def test_options(self):
11641165
# SSLContext also enables these by default
11651166
default |= (OP_NO_COMPRESSION | OP_CIPHER_SERVER_PREFERENCE |
11661167
OP_SINGLE_DH_USE | OP_SINGLE_ECDH_USE |
1167-
OP_ENABLE_MIDDLEBOX_COMPAT)
1168+
OP_ENABLE_MIDDLEBOX_COMPAT |
1169+
OP_IGNORE_UNEXPECTED_EOF)
11681170
self.assertEqual(default, ctx.options)
11691171
ctx.options |= ssl.OP_NO_TLSv1
11701172
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
@@ -3212,6 +3212,10 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version)
32123212
#endif
32133213
#ifdef SSL_OP_SINGLE_ECDH_USE
32143214
options |= SSL_OP_SINGLE_ECDH_USE;
3215+
#endif
3216+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
3217+
/* Make OpenSSL 3.0.0 behave like 1.1.1 */
3218+
options |= SSL_OP_IGNORE_UNEXPECTED_EOF;
32153219
#endif
32163220
SSL_CTX_set_options(self->ctx, options);
32173221

@@ -6270,6 +6274,10 @@ PyInit__ssl(void)
62706274
PyModule_AddIntConstant(m, "OP_NO_RENEGOTIATION",
62716275
SSL_OP_NO_RENEGOTIATION);
62726276
#endif
6277+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
6278+
PyModule_AddIntConstant(m, "OP_IGNORE_UNEXPECTED_EOF",
6279+
SSL_OP_IGNORE_UNEXPECTED_EOF);
6280+
#endif
62736281

62746282
#ifdef X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT
62756283
PyModule_AddIntConstant(m, "HOSTFLAG_ALWAYS_CHECK_SUBJECT",

0 commit comments

Comments
 (0)
0