[3.10] GH-95494: Fix transport EOF handling in OpenSSL 3.0 (GH-95495)… · python/cpython@b5bf6c1 · GitHub
Skip to content

Commit b5bf6c1

Browse files
[3.10] GH-95494: Fix transport EOF handling in OpenSSL 3.0 (GH-95495) (#103007)
GH-25309 enabled SSL_OP_IGNORE_UNEXPECTED_EOF by default, with a comment that it restores OpenSSL 1.1.1 behavior, but this wasn't quite right. That option causes OpenSSL to treat transport EOF as the same as close_notify (i.e. SSL_ERROR_ZERO_RETURN), whereas Python actually has distinct SSLEOFError and SSLZeroReturnError exceptions. (The latter is usually mapped to a zero return from read.) In OpenSSL 1.1.1, the ssl module would raise them for transport EOF and close_notify, respectively. In OpenSSL 3.0, both act like close_notify. Fix this by, instead, just detecting SSL_R_UNEXPECTED_EOF_WHILE_READING and mapping that to the other exception type. There doesn't seem to have been any unit test of this error, so fill in the missing one. This had to be done with the BIO path because it's actually slightly tricky to simulate a transport EOF with Python's fd based APIs. (If you instruct the server to close the socket, it gets confused, probably because the server's SSL object is still referencing the now dead fd?) (cherry picked from commit 420bbb7) Co-authored-by: David Benjamin <davidben@google.com>
1 parent ae8a721 commit b5bf6c1

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

Lib/test/test_ssl.py

Lines changed: 15 additions & 3 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
When built against OpenSSL 3.0, the :mod:`ssl` module had a bug where it
2+
reported unauthenticated EOFs (i.e. without close_notify) as a clean TLS-level
3+
EOF. It now raises :exc:`~ssl.SSLEOFError`, matching the behavior in previous
4+
versions of OpenSSL. The :attr:`~ssl.SSLContext.options` attribute on
5+
:class:`~ssl.SSLContext` also no longer includes
6+
:data:`~ssl.OP_IGNORE_UNEXPECTED_EOF` by default. This option may be set to
7+
specify the previous OpenSSL 3.0 behavior.

Modules/_ssl.c

Lines changed: 10 additions & 4 deletions

0 commit comments

Comments
 (0)