-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Keyring error when persisting key to registry #60049
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
Comments
Looks like the exception is coming from here: aspnetcore/src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs Line 161 in 731c3b7
Have you re-configured aspnetcore/src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs Line 63 in 731c3b7
It seems like one of the two (or both) are returning unexpecting values, causing the addition to go wrong. Getting an idea of what the values going into the addition will help clarify what's going wrong. |
I didn't re-confifured ClockSkew.
|
Spotted the issue callerShouldGenerateNewKey = !allKeys.Any(key =>
key.ActivationDate <= (preferredDefaultKey.ExpirationDate + _maxServerToServerClockSkew)
&& !key.IsExpired(now + _keyPropagationWindow)
&& !key.IsRevoked); Precisely it's this part wich is not working: key.ActivationDate <= (preferredDefaultKey.ExpirationDate + _maxServerToServerClockSkew) it's equal to : key.ActivationDate <= (DateTimeOffset.MaxValue + TimeSpan.FromMinutes(5))); So the value is over DateTimeOffset.MaxValue |
aspnetcore/src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs Lines 101 to 108 in 31d685b
Looks like this is possibly only an issue for .NET 8.0.x as .NET 9.0.x and main don't seem to inspect The code was refactored by #54309 and #57186 during the development of .NET 9. |
@martincostello I seen this. But unfortunately we are on .Net 8 and I can't upgrade to .Net 9 now. |
Unless the team think this is serious enough an issue to fix and backport to the |
@martincostello It's hardcoded: IKeyManagerExtensions.GetKey() Line 24: if(key == null)
key = _keyManager.CreateNewKey(DateTimeOffset.Now, DateTimeOffset.MaxValue); I think a good workaround would be to crete a key before the first call to DataProtection. This way it will bypass the creation of the default key with DateTimeOffset.MaxValue as expiration date. I'll do the PR after my test |
Where is that code? I can't find it. PRs for released versions of .NET have a higher bar to merge so I would suggest getting some input from the ASP.NET Core team first that this is something that has a good chance of being merged or not, to save you spending the time creating a PR that won't get approved. |
My god, it's some extension code someone made internally to override IKeyManager.GetKey() Method. I want to cry .... I will close this issue. |
Is there an existing issue for this?
Describe the bug
I customized DataProtection to save key to windows registry.
When doing this I get this exception:
Here's my code:
Removing PersistKeysToRegistry() makes things working.
Removing ProtectKeysWithDpapi() doesn't change anything.
Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
8.0.404
Anything else?
No response
The text was updated successfully, but these errors were encountered: