Repository navigation
[release/11.0] Fix PHA-not-offered check in NegotiateClientCertificateAsync on OpenSSL 1.1 - #136279
Merged
Merged
Conversation
…nSSL 1.1 (#134641) `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. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
|
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. |
Contributor
|
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones |
wfurt
approved these changes
Oct 22, 2026
Member
|
/ba-g test failure is unrelated |
Member
|
Approved by Jeff Schwartz over email |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.