Repository navigation
Description
SSL3 for OpenVMS V3.0(8) Apr 10 2023 (Library: SSL3 for OpenVMS V3.0(8) Apr 10 2023)
(problem exhibited also when build against OpenSSL 1.1.1t)
The server, for TLSv1.2, uses renegotiation for requesting a client certificate be provided (for authentication/authorisation).
I have been chasing the the reason for the above error and it appears to be related to the server certificate in use! A current Let's Encrypt issued server cert results in the above error very early in the renegotiation. A self-signed server cert does not. I have no third alternative to try.
Using the s_client to make the request:
$ openssl s_client -cert clientl.pem -tls1_2 -state -nbio -connect host-name:443
8< snip 8<
New, TLSv1.2, Cipher is ECDHE-RSA-AES128-SHA256
Server public key is 4096 bit
Secure Renegotiation IS supported
8< snip 8<
SSL_connect:SSL negotiation finished successfully
SSL_connect:SSL negotiation finished successfully
SSL_connect:SSLv3/TLS read hello request
SSL_connect:SSLv3/TLS write client hello
SSL_connect:error in SSLv3/TLS write client hello
read R BLOCK
SSL_connect:SSLv3/TLS write client hello
SSL3 alert write:fatal:decode error
SSL_connect:error in error
80CEBC7B00000000:error:0A000126:SSL routines:(unknown function):unexpected eof while reading:rec_layer_s3.c;1:321:
and the server reports:
8< snip 8<
|09:11:39.11 SESOLANE 0249 000002 SSL BEGIN TLSv1.2|
|09:11:39.11 SESOLA 3570 000002 SSL START handshake|
8< snip 8<
|09:11:40.14 SESOLA 3717 000002 SSL SESSION hit:no protocol:TLSv1.2 cipher:ECDHE-RSA-AES128-SHA256 keysize:128/128 X509:no|
8< snip 8<
|09:11:51.23 SESOLACL 1229 000002 SSL X509 client certificate VERIFY:REQUIRED|
|09:11:51.23 SESOLA 3570 000002 SSL START handshake|
8< snip 8<
|09:11:51.24 SESOLACL 1281 000002 SSL STATE 1 "SSLOK" SSL negotiation finished successfully cert:FALSE|
|09:11:51.24 SESOLA 3652 000002 SSL READ 528/528 (complete)|
|09:11:51.24 SESOLA 3570 000002 SSL START handshake|
|09:11:51.24 SESOLA 3666 000002 SSL CTRL 6 0|
|09:11:51.24 SESOLA 3512 000002 SSL LOOP SSL negotiation finished successfully|
|09:11:51.24 SESOLA 3512 000002 SSL LOOP SSL negotiation finished successfully|
|09:11:51.24 SESOLA 3512 000002 SSL LOOP SSLv3/TLS read client hello|
|09:11:51.24 SESOLA 3512 000002 SSL LOOP SSLv3/TLS write server hello|
|09:11:51.24 SESOLA 3657 000002 SSL WRITE 4096/0 (outstanding)|
|09:11:51.24 SESOLA 3657 000002 SSL WRITE 4096/0 (outstanding)|
|09:11:51.24 SESOLA 3522 000002 SSL EXIT error/blocking in error|
|09:11:51.24 SESOLACL 1270 000002 SSL SSL_do_handshake() -1 1|
|09:11:51.24 SESOLA 3768 000002 SSL SSL routines internal error (s3_enc.c:354)|
|09:11:51.24 SESOLACL 1281 000002 SSL STATE 23 "SSLERR" error cert:FALSE|
I have sought a way to reproduce this using s_server (to make the investigation platform-neutral) but cannot seem to trigger the renegotiation to include the client cert.
Just to repeat, this works with no other change than the server cert from LE to self-signed.
TLSv1.3 also works without issue with both server certs but of course that is via the entirely separate PHA mechanism.
Activity
mattcaswell commentedon Jul 11, 2023
That error is a fundamental very low-level "should not happen" failure:
openssl/ssl/s3_enc.c
Lines 352 to 356 in 31157bc
s->s3.handshake_bufferhere is just a mem BIO which should just automatically expand if it runs out of space. Opportunities for thisBIO_writeto fail are somewhat limited. Possibilities that spring to mind could be:lenis unexpectedly very large (which would ultimately cause memory allocation failure above)len != (int)len, i.e. iflenis so large that(int)lenis negative (this shouldn't ever happen in practice)I don't know if you are able to do some debugging to figure out what is causing it to fail?
mgdaniel commentedon Jul 11, 2023
Sure. Server is mine. Just provide some direction. Thanks.
mattcaswell commentedon Jul 11, 2023
Let's start with some simple checks. If you can set a breakpoint on the SSLfatal line above and discover the value of
retandlenat that point, also confirming thathandshake_bufferandbufare non-NULL (or just use some "printf's" at that point if its easier than using the debugger).mgdaniel commentedon Jul 11, 2023
Matt, this is pre- built and packaged OpenVMS release of OpenSSL. Such requests are difficult (but not entirely impossible) for me. This one needs to be considered accessible from the outside if at all possible. I could at a pinch obtain the appropriate OpenSSL tarball and build from scratch but it will be a long and drawn-out process on a 20 year old architecture.
The code reporting
|09:11:51.24 SESOLA 3768 000002 SSL SSL routines internal error (s3_enc.c:354)|is from a callback that is expressed
If the error could be detected in there and the relevant measurement initiated from there, that would be eminently doable. Note: that underlying bio is essentially used an a (convoluted) asynch mode.
The above report example is itself called from
so the underlying pointer to SSL struct is available for access (1) and use (2).
mgdaniel commentedon Jul 11, 2023
OK, I have obtained the 3.0.8 tarball (equivalent to original reported issue release) and built local libraries, adding the debug statement:
and issued the previously documented s_client request
with the corresponding output in the server log
I am now in a position to add debug statements as requested.
mattcaswell commentedon Jul 12, 2023
Hmmm....and you still see the
SSL routines internal error (s3_enc.c:354)error in the server log? Because, if so, that's quite perplexing. The condition for theifon that line isret <= 0 || ret != (int)len- but as you can see all lines of output show a positiveretvalue that is equal to thelenvalue!mgdaniel commentedon Jul 12, 2023
Here's a fresh one, just generated Matt.
with associated log entries
What does this one represent then?
mattcaswell commentedon Jul 12, 2023
Ah...sorry. Somehow I missed that important line. The 0 len/ret value does look suspicious
Does the debugging log output correspond to exactly one handshake?
mattcaswell commentedon Jul 12, 2023
Please also add this additional logging:
mgdaniel commentedon Jul 12, 2023
mattcaswell commentedon Jul 12, 2023
Please could you try applying the patch below?
mgdaniel commentedon Jul 12, 2023
BINGO!!
Fix ssl3_do_write() to correct handle retries
Fix ssl3_do_write() to correctly handle retries
Fix ssl3_do_write() to correctly handle retries
mattcaswell commentedon Jul 12, 2023
PR to fix this in #21434 (master) and #21435 (3.1/3.0).
I was able to reproduce this problem locally after a bit of experimentation. It turns out to be quite tricky to hit. The scenario where I could get this to happen was:
There might be other scenarios where this occurs but this was the only one I found.
In the end I went with a slightly different fix to the one I originally proposed above.
mgdaniel commentedon Jul 12, 2023
It was noted in opening the issue, "(problem exhibited also when build against OpenSSL 1.1.1t)", but I see mention of "3.1/3.0 only (master is not affected)", nothing of the 1.1.1 branch. I know it's reaching EOL but with LTS. Just a thought.
mattcaswell commentedon Jul 13, 2023
In the last year of LTS support we only typically accept security fixes. Since this isn't a security fix it isn't eligible for backport to 1.1.1.
Fix ssl3_do_write() to correctly handle retries
Fix ssl3_do_write() to correctly handle retries
Fix ssl3_do_write() to correctly handle retries
Fix ssl3_do_write() to correctly handle retries
Fix ssl3_do_write() to correctly handle retries
Fix ssl3_do_write() to correctly handle retries
Fix ssl3_do_write() to correctly handle retries
Fix ssl3_do_write() to correctly handle retries