Repository navigation
Fix PHA-not-offered check in NegotiateClientCertificateAsync on OpenSSL 1.1 - #134641
Conversation
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]>
|
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. |
|
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones |
rzikm
left a comment
There was a problem hiding this comment.
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]>
|
/ba-g Test failure is unrelated |
Pull request was closed
|
Are there any plans to backport this to release/11.0 ? cc @tmds |
If the area owners want it in 11.0, I can open the backport PR to |
|
/backport to release/11.0 |
|
Started backporting to |
…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]>
SslRenegotiaterecognizes a TLS 1.3 client that didn't offer post-handshake authentication by masking the OpenSSL error code with0X7FFFFF(#128942). That extracts the reason only in OpenSSL 3's layout,lib << 23 | reason. OpenSSL 1.1 packslib << 24 | func << 12 | reason, so on 1.1.1 the error (0x14268117) isn't recognized andNegotiateClientCertificateAsyncthrowsOpenSslCryptographicExceptioninstead of returning.Change.
GetSslLibraryReasondecodes the code with the layout of the loaded OpenSSL (OpenSslVersionNumber() >= 0x3_00_00_00_0, the thresholdOpenSslX509ChainProcessor.GetVersionLookupuses) and returns the reason only for errors fromERR_LIB_SSL. An OpenSSL 3 system error has the top bit set and fails that check. Only aCryptographicException'sHResultis decoded, so anIOExceptioncarrying an errno isn't read as an OpenSSL code.TlsSession.RequestClientCertificateon a socket-bound session reads the same status, so on 1.1.1 it now returnsCompleteinstead of throwingAuthenticationException, 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 whatCryptoNative_SslRenegotiatereturns, for this one caller.Tests
OpenSslErrorTests.GetSslLibraryReason_UsesLayoutOfLoadedOpenSslunit test: the two reasons in each layout, each layout read as the other, reason 279 fromERR_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.DOTNET_OPENSSL_VERSION_OVERRIDE=1.1: without the change,SslStream_NegotiateClientCertificateAsync_Tls13PhaNotOfferedpasses on 3.0.2 and fails on 1.1.1f witherror:14268117; with it, it passes on both.TlsSessionTests.SocketBoundSession_RequestClientCertificate_Tls13PhaNotOffered_Completes(Linux), the same scenario on a socket-boundTlsSession: without the change it passes on 3.0.2 and fails on 1.1.1f withAuthenticationException(innererror:14268117); with it, it passes on both.System.Net.Security.TestsandSystem.Net.Security.Unit.Testson 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 areNegotiateAuthenticationKerberosTest(both versions) and NTLM tests inNegotiateAuthenticationTests(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) ofmainat 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 whichlibsslit loaded. TheERR_GET_REASONvalue comes from a C program compiled against the OpenSSL 3.0.2 headers.