copenssl

OpenSSL: Unexpected EOF from www.openssl.org using their own example program


On a Windows 10 machine, I've set up an OpenSSL 3.3 project via vcpkg, and compiled the example program they provided at https://github.com/openssl/openssl/blob/master/demos/guide/tls-client-block.c

I tried to make a HTTPS request to www.openssl.org:443 with this program (full command line: tls-client-block www.openssl.org 443), but the connection failed with the log output:

Failed to connect to the server
2C7C0000:error:0A000126:SSL routines::unexpected eof while reading:ssl\record\rec_layer_s3.c:692:

Consulting the documentation, there is an option you can set to mitigate this, SSL_OP_IGNORE_UNEXPECTED_EOF, but setting that option doesn't resolve the main problem - the connection still fails, only one step later, ending in a SSL_ERROR_ZERO_RETURN.

Attempting the connection with wget https://www.openssl.org:443/ does work; as does the web browser, unsurprisingly. But I'm not sure if either of these are using OpenSSL in the back, since I don't think it's a system library on Windows.

It appears that the server simply rejects the client as configured in the official example and I don't yet know enough about TLS in general, and OpenSSL in particular, to figure out why this happens. I'd be grateful for some pointers.


Solution

  • To probably noone's surprise, this turned out to be an environment configuration problem, not a problem with the example program or the target web server. Company HTTP proxy and whatnot. Switching over to a free network solved this issue and led to another; OpenSSL was unable to load the required certificates, as in Can OpenSSL on Windows use the system certificate store?. Implementing the solution in the accepted answer there solved that problem as well and now I am able to successfully connect and receive the HTTP data.

    Thank you to Matt Caswell for taking the time to answer!