@@ -157,8 +157,9 @@ private bool CanCreateAuthenticatedEncryptor(IKey key, ref int retriesRemaining)
157
157
// fallback code below and the hypothetical advantage of making it easier for instances
158
158
// to choose the same key in the event of a race (though we never managed to show that
159
159
// empirically. See also https://github.com/dotnet/aspnetcore/issues/57137.
160
+ var maxActivationDate = now + _maxServerToServerClockSkew ;
160
161
var preferredDefaultKey = ( from key in allKeys
161
- where key . ActivationDate <= now + _maxServerToServerClockSkew
162
+ where key . ActivationDate <= maxActivationDate
162
163
orderby key . ActivationDate descending, key . KeyId ascending
163
164
select key ) . FirstOrDefault ( ) ;
164
165
@@ -192,13 +193,14 @@ private bool CanCreateAuthenticatedEncryptor(IKey key, ref int retriesRemaining)
192
193
// Unlike for the preferred key, we don't choose a fallback key and then reject it if
193
194
// CanCreateAuthenticatedEncryptor is false. We want to end up with *some* key, so we
194
195
// keep trying until we find one that works.
196
+ var maxCreationDate = now - _keyPropagationWindow ;
195
197
var unrevokedKeys = allKeys . Where ( key => ! key . IsRevoked ) ;
196
198
fallbackKey = ( from key in ( from key in unrevokedKeys
197
199
where ! ReferenceEquals ( key , preferredDefaultKey ) // Don't reconsider it as a fallback
198
- where key . CreationDate <= now - _keyPropagationWindow
200
+ where key . CreationDate <= maxCreationDate
199
201
orderby key . CreationDate descending
200
202
select key ) . Concat ( from key in unrevokedKeys
201
- where key . CreationDate > now - _keyPropagationWindow
203
+ where key . CreationDate > maxCreationDate
202
204
orderby key . CreationDate ascending
203
205
select key )
204
206
where CanCreateAuthenticatedEncryptor ( key , ref decryptRetriesRemaining )
0 commit comments