Repository navigation
Description
Summary:
VerifyNamesWithDuplicateAttributes failed with CryptographicException "Keyset does not exist" while retrieving an RSA private key.
Failed in (1):
Console Log: Console Log
Source: runtime-coreclr libraries-jitstress2-jitstressregs / net11.0-windows-Release-x86-jitstress2_jitstressregs0x10-Windows.10.Amd64.Open / System.Security.Cryptography.X509Certificates.Tests.X509CertificateLoaderPkcs12Tests_FromByteSpan.VerifyNamesWithDuplicateAttributes
Failed tests:
- net11.0-windows-Release-x86-jitstress2_jitstressregs0x10-Windows.10.Amd64.Open
- System.Security.Cryptography.X509Certificates.Tests.X509CertificateLoaderPkcs12Tests_FromByteSpan.VerifyNamesWithDuplicateAttributes
Error Message:
System.Security.Cryptography.CryptographicException : Keyset does not exist
Stack Trace:
/_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CapiHelper.Windows.cs(282,0): at System.Security.Cryptography.CapiHelper.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
/_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RSACryptoServiceProvider.Windows.cs(93,0): at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeProvHandle()
/_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RSACryptoServiceProvider.Windows.cs(136,0): at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeKeyHandle()
/_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RSACryptoServiceProvider.Windows.cs(51,0): at System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters)
/_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificatePal.Windows.PrivateKey.cs(26,0): at System.Security.Cryptography.X509Certificates.CertificatePal.<>c.<GetRSAPrivateKey>b__70_0(CspParameters csp)
/_/src/libraries/Common/src/System/Security/Cryptography/X509Certificates/CertificateHelpers.Windows.cs(120,0): at System.Security.Cryptography.X509Certificates.CertificateHelpers.GetPrivateKey[T](CertificatePal certificate, Func`2 createCsp, Func`2 createCng)
/_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificatePal.Windows.PrivateKey.cs(23,0): at System.Security.Cryptography.X509Certificates.CertificatePal.GetRSAPrivateKey()
/_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateExtensionsCommon.cs(61,0): at System.Security.Cryptography.X509Certificates.CertificateExtensionsCommon.GetPrivateKey[T](X509Certificate2 certificate, Predicate`1 matchesConstraints)
/_/src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/X509CertificateLoaderPkcs12Tests.WindowsAttributes.cs(213,0): at System.Security.Cryptography.X509Certificates.Tests.X509CertificateLoaderPkcs12Tests.VerifyNamesWithDuplicateAttributes(Boolean noLimits)
/_/src/coreclr/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.CoreCLR.cs(37,0): at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
/_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs(174,0): at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
Analysis:
The full console log contains a single xUnit failure in System.Security.Cryptography.Tests. Searches by full test name, VerifyNamesWithDuplicateAttributes, Keyset does not exist, and RSACryptoServiceProvider found only product/API discussions or unrelated issues; none matched this specific CI test failure under jitstressregs.
Generated by ci-pipeline-monitor/scripts/update_github.py
Activity
MihuBot commentedon May 11, 2026
I'm a bot. Here are possible related and/or duplicate issues (I may be wrong):
dotnet-policy-service commentedon May 11, 2026
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.
vcsjones commentedon Jul 15, 2026
I think this is because we can in some circumstances have multiple tests operating on
TestData.DuplicateAttributesPfxconcurrently that write keys to disk. This PKCS#12 has named keys - so the keys get written to disk by a test 1, test 2 does the same thing, test 1 is done and cleans up the persisted keys, then test 2 is missing the keys.@bartonjs does the sounds like a reasonable hypothesis? If this is likely the culprit the fix is likely going to be ugly. We would either need to serialize access to the certificate so the tests don't run concurrently, or manufacture PKCS#12 objects on-the-fly so that each test has their own "duplicate" set. This is difficult because we don't have an API that makes manufacturing PKCS#12's with duplicate attribute sets easy.
Pkcs12Buildernormalizes it into a multi-value single attribute.bartonjs commentedon Jul 15, 2026
Yeah, that's both the motivation for the EphemeralKeySet flag and why all of our TestData PFX blobs had their keyname attributes stripped out years ago.
Serializing the loads is probably the best answer.
So my off the cuff answer is "rename it to DuplicateAttributesPfx_LoadUnderLock", and change all the places that load it to lock against that field. The rename will help ensure 100% coverage.
bartonjs commentedon Jul 15, 2026
Only the load has to be locked... Windows does a File.Exists ... File.Create based (anti-) pattern during PFX load, if the name is in use then Windows'll just replace the name with a UUID and move on.
I don't think I added a test that asserts it gets created with the "correct" keyname... so it's not important that the load always see the name available.... just that it avoid the parallel load OS bug.