-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Reuse known keys in XmlKeyManager #54490
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
Conversation
We weren't actually using polymorphism and this makes cloning easier.
Keys read from the IXmlRepository (as opposed to created) use deferred decryption but may still be decrypted multiple times. Since they're immutable (other than revocation), keep track of the keys we've seen and reuse them next time they're returned from the IXmlRepository. In the absence of deletion support, we don't expect the list of keys to ever shrink, so there's no reason to prune the cache. While this is likely a perf win, it's a small perf win and only once a day, so it would probably not be worthwhile on that basis alone. However, this should also reduce the number of calls to `IXmlDecryptor.Decrypt` (which may, e.g., make an Azure KeyVault request). Each time the key ring is refreshed, it requests all keys from the key manager, clobbering all keys that may have already been decrypted (at least the default key will have been). In the single app-instance case, for example, there should be no need to call Decrypt at all for any key created during the current execution of the app (old keys will have to be decrypted the first time they're used). This shouldn't affect security because (a) the key ring already stores all the `IKeys` all the time and (b) `IKey` wraps the actual data in an `ISecret`. It would have been nice to pass the key ring's list of known keys to the key manager, rather than having it store its own cache, but the key ring's storage format would require abstraction violations that would work poorly with our public extension points.
@@ -3,30 +3,156 @@ | |||
|
|||
using System; | |||
using System.Collections.Generic; | |||
using System.Xml.Linq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would have been more sensible to treat KeyBase
as the diff baseline, but I don't think I can alter that. Basically, Key
and DeferredKey
were just constructors, so I moved those two constructors into the base and made the existing constructor private.
IsRevoked = true; | ||
} | ||
|
||
internal Key Clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is new.
/// <summary> | ||
/// The basic implementation of <see cref="IKey"/>, where the <see cref="IAuthenticatedEncryptorDescriptor"/> | ||
/// has already been created. | ||
/// </summary> | ||
public Key( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be persuaded that the constructors should be private and there should be Eager
and Deferred
factory methods.
This did a very good job of mitigating simulated IXmlDecryptor (e.g. AKV) errors. |
Keys read from the IXmlRepository (as opposed to created) use deferred decryption but may still be decrypted multiple times. Since they're immutable (other than revocation), keep track of the keys we've seen and reuse them next time they're returned from the IXmlRepository.
In the absence of deletion support, we don't expect the list of keys to ever shrink, so there's no reason to prune the cache.
While this is likely a perf win, it's a small perf win and only once a day, so it would probably not be worthwhile on that basis alone. However, this should also reduce the number of calls to
IXmlDecryptor.Decrypt
(which may, e.g., make an Azure KeyVault request). Each time the key ring is refreshed, it requests all keys from the key manager, clobbering all keys that may have already been decrypted (at least the default key will have been). In the single app-instance case, for example, there should be no need to call Decrypt at all for any key created during the current execution of the app (old keys will have to be decrypted the first time they're used).This shouldn't affect security because (a) the key ring already stores all the
IKeys
all the time and (b)IKey
wraps the actual data in anISecret
.It would have been nice to pass the key ring's list of known keys to the key manager, rather than having it store its own cache, but the key ring's storage format would require abstraction violations that would work poorly with our public extension points.