Skip to content

Fix PHA-not-offered check in NegotiateClientCertificateAsync on OpenSSL 1.1 - #134641

Merged
rzikm merged 2 commits into
dotnet:mainfrom
caraioniurie47:pha-openssl111
Oct 1, 2026
Merged

rzikm merged 2 commits into
dotnet:mainfrom
caraioniurie47:pha-openssl111

Conversation

@caraioniurie47

Copy link
Copy Markdown
Contributor

SslRenegotiate recognizes a TLS 1.3 client that didn't offer post-handshake authentication by masking the OpenSSL error code with 0X7FFFFF (#128942). That extracts the reason only in OpenSSL 3's layout, lib << 23 | reason. OpenSSL 1.1 packs lib << 24 | func << 12 | reason, so on 1.1.1 the error (0x14268117) isn't recognized and NegotiateClientCertificateAsync throws OpenSslCryptographicException instead of returning.

Change. GetSslLibraryReason decodes the code with the layout of the loaded OpenSSL (OpenSslVersionNumber() >= 0x3_00_00_00_0, the threshold OpenSslX509ChainProcessor.GetVersionLookup uses) and returns the reason only for errors from ERR_LIB_SSL. An OpenSSL 3 system error has the top bit set and fails that check. Only a CryptographicException's HResult is decoded, so an IOException carrying an errno isn't read as an OpenSSL code. TlsSession.RequestClientCertificate on a socket-bound session reads the same status, so on 1.1.1 it now returns Complete instead of throwing AuthenticationException, as it already did on OpenSSL 3. On OpenSSL 3 the only difference from before is that reasons 279 and 339 from another library no longer count as "not offered".

Why not in the shim. ERR_GET_REASON's layout is the one of the headers the shim is compiled against: compiled against OpenSSL 3.0.2 headers, ERR_GET_REASON(0x14268117) is 2523415. Doing it natively would need the same run-time version check in C and a change to what CryptoNative_SslRenegotiate returns, for this one caller.

Tests

  • New OpenSslErrorTests.GetSslLibraryReason_UsesLayoutOfLoadedOpenSsl unit test: the two reasons in each layout, each layout read as the other, reason 279 from ERR_LIB_EVP, and an OpenSSL 3 system error. It takes the layout as a parameter, so both layouts are covered whichever OpenSSL the test machine has.
  • On Linux x64 (Ubuntu 22.04), with the system OpenSSL 3.0.2 and with Ubuntu 20.04's OpenSSL 1.1.1f selected through DOTNET_OPENSSL_VERSION_OVERRIDE=1.1: without the change, SslStream_NegotiateClientCertificateAsync_Tls13PhaNotOffered passes on 3.0.2 and fails on 1.1.1f with error:14268117; with it, it passes on both.
  • New TlsSessionTests.SocketBoundSession_RequestClientCertificate_Tls13PhaNotOffered_Completes (Linux), the same scenario on a socket-bound TlsSession: without the change it passes on 3.0.2 and fails on 1.1.1f with AuthenticationException (inner error:14268117); with it, it passes on both.
  • System.Net.Security.Tests and System.Net.Security.Unit.Tests on both OpenSSL versions, compared by test name with and without the change: apart from the tests above, the results are identical. The failures present with and without the change are NegotiateAuthenticationKerberosTest (both versions) and NTLM tests in NegotiateAuthenticationTests (1.1.1f only).

Resolves #134640

Note

AI-generated, written at my direction and reviewed by me before posting. The tests ran on a local Release build (clr+libs -rc release -lc release) of main at 99f3a67, with and without this commit, on Ubuntu 22.04 x64; for each full-suite run the test process's memory map was checked to confirm which libssl it loaded. The ERR_GET_REASON value comes from a C program compiled against the OpenSSL 3.0.2 headers.

NegotiateClientCertificateAsync, and RequestClientCertificate on a
socket-bound TlsSession, are meant to return without a certificate on
a TLS 1.3 connection whose client did not offer post-handshake
authentication. SslRenegotiate recognized that case by masking the
OpenSSL error code with 0x7FFFFF, which extracts the reason only in the
OpenSSL 3 layout. OpenSSL 1.1 packs lib << 24 | func << 12 | reason, so
error 0x14268117 (SSL_R_EXTENSION_NOT_RECEIVED) was not recognized and
both calls threw.

Decode the reason with the layout of the loaded OpenSSL, and only for
errors raised by the SSL library.

Fix dotnet#134640

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 25, 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.

I am not sure if we still plan to support OpenSSL 1.1 in .NET 12, but I think it's okay to take this change.

@wfurt

wfurt commented Sep 30, 2026

Copy link
Copy Markdown
Member

I am not sure if we still plan to support OpenSSL 1.1 in .NET 12, but I think it's okay to take this change.

agree. I would still take community contributions if reasonable. This one seems to meet my bar.

On Linux, a socket-bound server's RequestClientCertificate() returns
Complete without sending a request when the TLS 1.3 client did not offer
post-handshake authentication. Say so in the method's remarks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 1, 2026

Copy link
Copy Markdown
Member

/ba-g Test failure is unrelated

@rzikm
rzikm enabled auto-merge (squash) October 1, 2026 10:09
auto-merge was automatically disabled October 1, 2026 13:55

Pull request was closed

@rzikm
rzikm merged commit ced3e57 into dotnet:main Oct 1, 2026
82 of 84 checks passed
@caraioniurie47
caraioniurie47 deleted the pha-openssl111 branch October 1, 2026 13:56
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 2, 2026
@omajid

omajid commented Oct 22, 2026

Copy link
Copy Markdown
Member

Are there any plans to backport this to release/11.0 ?

cc @tmds

@caraioniurie47

Copy link
Copy Markdown
Contributor Author

Are there any plans to backport this to release/11.0 ?

If the area owners want it in 11.0, I can open the backport PR to release/11.0.

@rzikm

rzikm commented Oct 22, 2026

Copy link
Copy Markdown
Member

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

svick pushed a commit that referenced this pull request Nov 5, 2026
…teAsync` on OpenSSL 1.1 (#136279)

Backport of #134641 to release/11.0

/cc @rzikm @caraioniurie47

## Customer Impact

#128942 removed unexpected
exception in a corner case, but the fix worked only when running with
OpenSSL 3+ (what we run in CI). When running on systems with OpenSSL
1.1.1, the unexpected exception still surfaced.

## Regression

No, we changed the behavior in 11.0 via
#128942 to not throw to avoid
cryptic exceptions.

## Testing

CI verifies that OpenSSL 3+ is unaffected, OpenSSL 1.1.1 tested
manually.

## Risk

Low, change is small and contained.

Co-authored-by: Iurie Caraion <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

NegotiateClientCertificateAsync throws on OpenSSL 1.1.1 when the client doesn't offer post-handshake auth

4 participants