Skip to content

"OpenSSL SSL_read: SSL_ERROR_SYSCALL" with OpenSSL ≥ 3.2 + old servers #17471

Closed
@mkauf

Description

@mkauf

I did this

When using a server that does not shut down the SSL connection properly (no "close notify"), depending on the OpenSSL version, curl reports an error when closing the connection. The problem has started to appear with OpenSSL 3.2.0 and is also present with OpenSSL 3.5.0.

I'm not sure whether this is a bug in curl or in OpenSSL. With git bisect I have found this OpenSSL commit: openssl/openssl@e2d5742

How to reproduce

The server is an openssl s_server 1.1.1 (or 1.0.2, same result). It does not send a "close notify" when closing the connection.

Create a certificate:

openssl genrsa -out server.key.pem 2048
openssl req -new -x509 -key server.key.pem -out server.crt.pem -days 365

Start openssl s_server:

openssl s_server -cert server.crt.pem -key server.key.pem -accept 8443 -www

With OpenSSL 3.0.16 + curl master (or curl 8.13.0, same result):

</BODY></HTML>

* shutting down connection #0

With OpenSSL 3.5.0 + curl master (or curl 8.13.0, same result):

curl -k -v https://localhost:8443/
...
</BODY></HTML>

* OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 0
* closing connection #0
curl: (56) OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 0

So no error is reported with OpenSSL 3.0 but an error is reported with OpenSSL 3.5.

Notes about the flag SSL_OP_IGNORE_UNEXPECTED_EOF

I have tried to set the OpenSSL flag SSL_OP_IGNORE_UNEXPECTED_EOF but the result is the same:

diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
index ffdae2399..f21f6140c 100644
--- a/lib/vtls/openssl.c
+++ b/lib/vtls/openssl.c
@@ -4109,6 +4109,7 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx,
     return CURLE_SSL_CONNECT_ERROR;
   }
 
+  ctx_options |= SSL_OP_IGNORE_UNEXPECTED_EOF;
   SSL_CTX_set_options(octx->ssl_ctx, ctx_options);
 
 #ifdef SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER

For openssl s_client, the flag -ignore_unexpected_eof works:

openssl s_client -crlf -ignore_unexpected_eof -connect localhost:8443
GET / HTTP/1.0
...
closed

It's strange that the flag works for openssl s_client but does not work for curl.

I expected the following

curl should not report an error with OpenSSL 3.5.0 + old servers, or there should be a way to ignore the error, e.g. with the OpenSSL flag SSL_OP_IGNORE_UNEXPECTED_EOF

curl/libcurl version

curl 8.14.0-DEV (x86_64-pc-linux-gnu) libcurl/8.14.0-DEV OpenSSL/3.2.4 zlib/1.3.1.zlib-ng nghttp2/1.64.0
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS HSTS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM SSL threadsafe TLS-SRP UnixSockets

operating system

Fedora Linux 42

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions