Skip to content

Fix TlsSession's ClientHello peek failure message - #135700

Merged
rzikm merged 2 commits into
dotnet:mainfrom
caraioniurie47:issue-135694
Oct 19, 2026
Merged

rzikm merged 2 commits into
dotnet:mainfrom
caraioniurie47:issue-135694

Conversation

@caraioniurie47

Copy link
Copy Markdown
Contributor

When a server TlsSocketSession on Linux fails to read the ClientHello off the socket (the client closes or resets the connection before a full TLS record arrives, or the record header announces more bytes than the read buffer holds), TlsSession threw IOException(SR.net_ssl_read_bio_failed_error) without SR.Format, so the message was SSL Read BIO failed with OpenSSL error - {0}.

Formatting it would not help: CryptoNative_BioPeekTlsFrame clears the OpenSSL error queue on entry and none of its -1 returns pushes an OpenSSL error, so there is no OpenSSL error to name.

This change throws the same IOException with a new resource without a placeholder, net_ssl_read_client_hello_failed ("The TLS ClientHello could not be read from the socket."). The other uses of net_ssl_read_bio_failed_error, which go through Interop.OpenSsl.CreateSslException, are unchanged.

SocketBoundServerSession_ClientHelloPeekFails_ThrowsIOExceptionWithMessage is a new Linux test with a row for each failure: the client shuts down its sending side, the client resets the connection, and the client sends a handshake record header announcing a 65535-byte fragment. Each row drives Handshake() on the server session, expects an IOException, and asserts that its message contains neither {0} nor OpenSSL. Every row fails on the old code with Assert.DoesNotContain() Failure: Sub-string found and passes with the fix.

The System.Net.Security functional tests passed on Linux x64 with the change (OuterLoop tests not run), apart from NegotiateAuthenticationKerberosTest, whose failures there are the same without the change.

Resolves #135694

Note

AI-generated, written at my direction and reviewed by me before posting.
Source read at dotnet/runtime 90b22d9. Tests ran on Ubuntu 22.04.5 LTS x64 (WSL2) with OpenSSL 3.0.2, against a ./build.sh clr+libs -rc Release build of that commit with System.Net.Security rebuilt with this change (./.dotnet/dotnet build src/libraries/System.Net.Security/src), with ./.dotnet/dotnet build src/libraries/System.Net.Security/tests/FunctionalTests /t:Test. The old-code runs (the new test, and NegotiateAuthenticationKerberosTest) used the same tree with src/libraries/System.Net.Security/src checked out at that commit and rebuilt.

When CryptoNative_BioPeekTlsFrame fails (the peer closes or resets the
connection before a full record arrives, recv fails, or the record
header announces more than the peek buffer holds), TlsSession threw
IOException(SR.net_ssl_read_bio_failed_error) without formatting it,
so the message read "SSL Read BIO failed with OpenSSL error - {0}.".
None of those failures pushes an OpenSSL error, so there is nothing
true to put in the placeholder either.

Throw the IOException with a new placeholder-free resource,
net_ssl_read_client_hello_failed: "The TLS ClientHello could not be
read from the socket."

Fix dotnet#135694

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 13, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@rzikm rzikm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@rzikm

rzikm commented Oct 19, 2026

Copy link
Copy Markdown
Member

/ba-g test failures are unrelated

@rzikm
rzikm merged commit 8b73f02 into dotnet:main Oct 19, 2026
86 of 88 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 20, 2026
@caraioniurie47
caraioniurie47 deleted the issue-135694 branch October 20, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Net.Security community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TlsSocketSession on Linux: a failed ClientHello read throws an IOException whose message contains a literal {0}

2 participants