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

Compute dates in DefaultKeyResolver once #60051

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ private bool CanCreateAuthenticatedEncryptor(IKey key, ref int retriesRemaining)
// fallback code below and the hypothetical advantage of making it easier for instances
// to choose the same key in the event of a race (though we never managed to show that
// empirically. See also https://github.com/dotnet/aspnetcore/issues/57137.
var maxActivationDate = now + _maxServerToServerClockSkew;
var preferredDefaultKey = (from key in allKeys
where key.ActivationDate <= now + _maxServerToServerClockSkew
where key.ActivationDate <= maxActivationDate
orderby key.ActivationDate descending, key.KeyId ascending
select key).FirstOrDefault();

Expand Down Expand Up @@ -192,13 +193,14 @@ private bool CanCreateAuthenticatedEncryptor(IKey key, ref int retriesRemaining)
// Unlike for the preferred key, we don't choose a fallback key and then reject it if
// CanCreateAuthenticatedEncryptor is false. We want to end up with *some* key, so we
// keep trying until we find one that works.
var maxCreationDate = now - _keyPropagationWindow;
var unrevokedKeys = allKeys.Where(key => !key.IsRevoked);
fallbackKey = (from key in (from key in unrevokedKeys
where !ReferenceEquals(key, preferredDefaultKey) // Don't reconsider it as a fallback
where key.CreationDate <= now - _keyPropagationWindow
where key.CreationDate <= maxCreationDate
orderby key.CreationDate descending
select key).Concat(from key in unrevokedKeys
where key.CreationDate > now - _keyPropagationWindow
where key.CreationDate > maxCreationDate
orderby key.CreationDate ascending
select key)
where CanCreateAuthenticatedEncryptor(key, ref decryptRetriesRemaining)
Expand Down
Loading