Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
I was trying to figure out how UnprotectKeysWithAnyCertificate
worked, but I did not manage any code without it to fail when trying to unprotect an old secret created by a another certificate than the one provided in ProtectKeysWithCertificate
.
While trying to figure out why we have a UnprotectKeysWithAnyCertificate
(which in my point at the time seem quite useless) I wrote the dotnet/AspNetCore.Docs#28213 issue. And after I got answer on that I realized that the problem was the fact that even though I hadn't referenced any relationships to the Windows user certificate store, the data protection key certificate logic still tries to search the certificate store on Windows operating systems. And if it finds the thumbprint there it uses that which gave me a great amount of wasted time trying to understand the usage of UnprotectKeysWithAnyCertificate
.
Describe the solution you'd like
While (as the previous mentioned issue states) it can be documented better how the certificate key protection works and how it differs between operating environments, it would be nice if the logic is consistent in the fact that the certificate store isn't used unless defined to be doing this by the application.
I can see a couple of different ways that this could be done:
- By not using the windows certificate store if the
ProtectKeysWithCertificate
is used with aX509Certificate2
, only when a thumbnail is provided. - By having a another extension method called something like e.g.
ProtectKeysWithCertificateStore
that takes a thumbnail (and optional aX509Store
if the user wants to override the store to be used) and let theProtectKeysWithCertificate
only accept aX509Certificate2
and thus not using certificate store at all. - Remove (or obsolete) the
ProtectKeysWithCertificate
version that takes aX509Certificate2
and create an extension method called something likeProtectKeysWithExplicitCertificate
which make the certificate key protection ignore any certificate stores.
Either of these ways will (while will be breaking changes except for option 3 with obsoleting the method) make the certificate key protection a bit clearer how they work.
Also, note, as mentioned in option 2, it would be nice if you gave us the opportunity to somehow specify a X509Store
for certificate retrieval.
Additional context
No response