Repository navigation
Keep OpenSSL 3.0.0-3.0.5 from reporting a rejected issuer's error - #137099
caraioniurie47 wants to merge 1 commit into
Conversation
OpenSSL 3.0.0 through 3.0.5 record why check_issued rejected a candidate issuer as the verify context's error, and when no issuer is accepted they report that error as the chain's final error instead of X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY. A trust anchor whose extended key usage extension doesn't decode gives X509_V_ERR_UNSPECIFIED, and one whose subject key identifier doesn't match the authority key identifier of the certificate it would issue gives X509_V_ERR_AKID_SKID_MISMATCH. Neither is mapped, so X509Chain.Build throws instead of reporting PartialChain. OpenSSL 3.0.6 stopped recording the error (openssl/openssl a58afad99640c51c756ac0aa26988a67fccb6dae). On those versions, give the stores the shim builds X509Chain chains against a check_issued that calls OpenSSL's default one and restores the context's error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Azure Pipelines: Successfully started running 3 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: @bartonjs, @vcsjones, @dotnet/area-system-security |
|
This is an awful lot of code for handling libraries that are between 22 and 17 versions out of date. What distro(s) is(/are) running an affected version of OpenSSL as part of their best-available patches? |
Ah, I see that was more clearly stated in the issue that was opened concurrently with the fix (I'm not quite a fan of that, by the way, since it splits the conversation), as Ubuntu 22.04. Ubuntu 22.04 was a supported OS for .NET 10, and the current tip openssl package is 3.0.2-0ubuntu1.30. So, if the behavior is present there, it's something we should fix. |
It is present there: the issue's program output is from Ubuntu 22.04's |
On Linux with OpenSSL 3.0.0 through 3.0.5,
X509Chain.BuildthrowsMapOpenSsl30Code reported unhandled error code '1'(or'30') for the issue's two chains, whose trust anchor OpenSSL rejects as an issuer, because those versions report why the defaultcheck_issuedrejected a candidate as the chain's final error instead ofX509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY. OpenSSL 3.0.6 stopped doing that (openssl/openssl@a58afad).The change: the shim gives the stores it verifies chains against, in
CryptoNative_X509ChainNewandCryptoNative_X509StoreCtxResetForSignatureError, acheck_issuedthat calls OpenSSL's default one and restores the context's error. Like the HMAC workaround inpal_hmac.c, it is installed only whenOpenSSL_version_num()is in the affected range. The two new imports,X509_STORE_CTX_get_check_issuedandX509_STORE_set_check_issued, exist since OpenSSL 1.1.0; the callback's parameters useOSSL4CONSTfor the OpenSSL 4.0 headers.With it, the issue's program reports
PartialChainfor both chains with Ubuntu's 3.0.2.Mapping codes 1 and 30 in managed code instead was not taken: it would stop the exception, but the first build would still end with 1 or 30, which
IsCompleteChaintreats as a complete chain, so the AIA download would be skipped.Tests:
DynamicChainTests.MismatchKeyIdentifiersAtTrustAnchoris new: a trust anchor whose subject key identifier doesn't match the intermediate's authority key identifier, expectingPartialChain. Like the existingCorruptPoliciesChainTests.CorruptEku*(level: 4)cases, without the change it fails where OpenSSL 3.0.0-3.0.5 is loaded; none of the Linux x64 Helix queues ineng/pipelines/helix-platforms.ymlis Ubuntu 22.04.Performance: BenchmarkDotNet 0.15.2,
X509Chain.Buildof a valid three-certificate chain and of a partial one (no intermediate), Release runtime and libraries, Ubuntu's 3.0.2. Two comparisons ran in order baseline, changed, changed, baseline, in-process with default iteration selection and outlier filtering (mean ± StdDev):The valid-chain mean increased by 4.29 us (4.0%) in the first pair and 0.30 us (0.3%) in the second; the partial-chain gaps are 0.76 us slower and 0.07 us faster. Reported managed allocations are unchanged.
Resolves #137098
Note
AI-generated, written at my direction and reviewed by me before posting. Verified on Ubuntu 22.04 x64, Debug libraries: the new test and
CorruptPoliciesChainTestswith Ubuntu's OpenSSL 3.0.2, OpenSSL 3.0.1, 3.0.3-3.0.7 and 1.1.1f;System.Security.Cryptography.Testswith Ubuntu's 3.0.2 and 1.1.1f. With this change, the issue's program ran on the Release libraries testhost built for the benchmark, with Ubuntu's 3.0.2.