Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Net.Security.Tests assertion failure: !newKey.IsInvalid #105715

Closed
elinor-fung opened this issue Jul 30, 2024 · 8 comments
Closed

System.Net.Security.Tests assertion failure: !newKey.IsInvalid #105715

elinor-fung opened this issue Jul 30, 2024 · 8 comments
Labels
area-System.Security Known Build Error Use this to report build issues in the .NET Helix tab
Milestone

Comments

@elinor-fung
Copy link
Member

elinor-fung commented Jul 30, 2024

From log:

Process terminated. Assertion failed.
!newKey.IsInvalid
   at System.Security.Cryptography.RSAOpenSsl.SetKey(SafeEvpPKeyHandle newKey) in /_/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs:line 657
   at System.Security.Cryptography.RSAOpenSsl..ctor(SafeEvpPKeyHandle pkeyHandle) in /_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RSAOpenSsl.cs:line 83
   at System.Security.Cryptography.X509Certificates.OpenSslX509CertificateReader.GetRSAPrivateKey() in /_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509CertificateReader.cs:line 558
   at System.Security.Cryptography.X509Certificates.CertificateExtensionsCommon.GetPrivateKey[T](X509Certificate2 certificate, Predicate`1 matchesConstraints) in /_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateExtensionsCommon.cs:line 61
   at System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPrivateKey(X509Certificate2 certificate) in /_/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/RSACertificateExtensions.cs:line 27
   at System.Security.Cryptography.X509Certificates.Tests.Common.CertificateAuthority.BuildOcspResponse(ReadOnlyMemory`1 certId, ReadOnlyMemory`1 nonceExtension) in /_/src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/CertificateAuthority.cs:line 639
   at System.Security.Cryptography.X509Certificates.Tests.Common.RevocationResponder.HandleRequest(HttpListenerContext context, Boolean& responded) in /_/src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/RevocationResponder.cs:line 256
   at System.Security.Cryptography.X509Certificates.Tests.Common.RevocationResponder.HandleRequest(HttpListenerContext context) in /_/src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/RevocationResponder.cs:line 138
   at System.Security.Cryptography.X509Certificates.Tests.Common.RevocationResponder.<HandleRequest>b__29_0(HttpListenerContext state) in /_/src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/RevocationResponder.cs:line 105
   at System.Threading.ThreadPoolWorkQueue.Dispatch() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 1096
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:line 128

Build Information

Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=759922
Build error leg or test failing: System.Net.Security.Tests.WorkItemExecution
Pull request: #105673

Error Message

Fill the error message using step by step known issues guidance.

{
  "ErrorMessage": ["System.Net.Security.Tests", "Assertion failed", "!newKey.IsInvalid"],
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=759922
Error message validated: [System.Net.Security.Tests Assertion failed !newKey.IsInvalid]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 7/30/2024 5:34:02 PM UTC

Report

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
0 0 0
@elinor-fung elinor-fung added area-System.Net.Security blocking-clean-ci Blocking PR or rolling runs of 'runtime' or 'runtime-extra-platforms' Known Build Error Use this to report build issues in the .NET Helix tab labels Jul 30, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jul 30, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@vcsjones
Copy link
Member

@bartonjs possible race with GetRSAPrivateKey and Dispose with the new cert loader?

@bartonjs
Copy link
Member

A race in the loader would be exceedingly weird, since anything it disposes would be before returning, and things wouldn't finalize if they were returned out. But taking a quick gander.

@bartonjs
Copy link
Member

bartonjs commented Jul 30, 2024

The workhorse for this is undoubtedly BuildPrivatePki (as nothing else instantiates RevocationResponder). It doesn't use PFX loading, just X.509-DER loading (after CertificateRequest does X.509-DER building) and cert.CopyWithPrivateKey(). So, I don't think loader changes could really be relevant.

System.Net.Security tests do call new X509Certificate2(cert.Export(Pfx)), but only on the EE cert, which wouldn't be answering revocation prompts.

The places that I see all have all of the objects well-captured in a using... but, this is networking... and that means it's possible that a request got fired off and was being handled on the "server side" concurrent with the test giving up and disposing the certificate and responder it made up for the request.

So... we can remove the assert; but otherwise I think that this is just an inherent state with the nature of asynchronous operations.

@jeffhandley jeffhandley added this to the 9.0.0 milestone Jul 31, 2024
@vcsjones
Copy link
Member

vcsjones commented Jul 31, 2024

We have removed asserts in the past (e.g. #86503) where we have checked if a Handle is valid or not. The validity of the handle may not be what we expected in a multi-threaded scenario.

As long as we interact with the handle safely (marshaller or addref + release) we can probably just get rid of the assert and let the handle do its thing by throwing an ObjectDisposedException.

@jeffhandley
Copy link
Member

@bartonjs clarified for me that this is unchanged in .NET 9, so I'm moving it to Future.

@jeffhandley jeffhandley modified the milestones: 9.0.0, Future Jul 31, 2024
@jeffhandley jeffhandley removed untriaged New issue has not been triaged by the area owner blocking-clean-ci Blocking PR or rolling runs of 'runtime' or 'runtime-extra-platforms' labels Jul 31, 2024
@vcsjones
Copy link
Member

Fixed in main by #107932.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Security Known Build Error Use this to report build issues in the .NET Helix tab
Projects
None yet
Development

No branches or pull requests

4 participants