@@ -157,10 +157,13 @@ module SearchableEncryptionInfo {
157
157
partitionIdBytes : seq <uint8 >
158
158
) {
159
159
function Modifies () : set < object > {
160
- client. Modifies + store. Modifies
160
+ client. Modifies + store. Modifies + cache . Modifies
161
161
}
162
162
predicate ValidState () {
163
- client. ValidState () && store. ValidState ()
163
+ && client. ValidState ()
164
+ && store. ValidState ()
165
+ && cache. ValidState ()
166
+ && store. Modifies !! cache. Modifies
164
167
}
165
168
method getKeyMap (stdNames : seq <string >, keyId : MaybeKeyId ) returns (output : Result< MaybeKeyMap, Error> )
166
169
requires Seq. HasNoDuplicates (stdNames)
@@ -170,7 +173,8 @@ module SearchableEncryptionInfo {
170
173
{
171
174
if keyLoc. SingleLoc? {
172
175
:- Need (keyId.DontUseKeyId?, E("KeyID should not be supplied with a SingleKeyStore"));
173
- var theMap :- getKeysCache (stdNames, keyLoc.keyId, cacheTTL as MP.PositiveLong, partitionIdBytes);
176
+ var now := Time. GetCurrent ();
177
+ var theMap :- getKeysCache (stdNames, keyLoc.keyId, cacheTTL as MP.PositiveLong, partitionIdBytes, now as MP.PositiveLong);
174
178
return Success (Keys(theMap));
175
179
} else if keyLoc. LiteralLoc? {
176
180
:- Need (keyId.DontUseKeyId?, E("KeyID should not be supplied with a LiteralKeyStore"));
@@ -180,7 +184,7 @@ module SearchableEncryptionInfo {
180
184
match keyId {
181
185
case DontUseKeyId => return Failure (E("KeyID must not be supplied with a MultiKeyStore"));
182
186
case ShouldHaveKeyId => return Success (ShouldHaveKeys);
183
- case KeyId (id) => var theMap :- getKeysCache (stdNames, id, cacheTTL as MP.PositiveLong, partitionIdBytes); return Success (Keys(theMap));
187
+ case KeyId (id) => var now := Time . GetCurrent (); var theMap :- getKeysCache (stdNames, id, cacheTTL as MP.PositiveLong, partitionIdBytes, now as MP.PositiveLong ); return Success (Keys(theMap));
184
188
}
185
189
}
186
190
}
@@ -213,7 +217,8 @@ module SearchableEncryptionInfo {
213
217
stdNames : seq <string >,
214
218
keyId : string ,
215
219
cacheTTL : MP .PositiveLong,
216
- partitionIdBytes : seq <uint8 >
220
+ partitionIdBytes : seq <uint8 >,
221
+ now : MP .PositiveLong
217
222
)
218
223
returns (output : Result< HmacKeyMap, Error> )
219
224
requires Seq. HasNoDuplicates (stdNames)
@@ -230,23 +235,29 @@ module SearchableEncryptionInfo {
230
235
&& var oldHistory := old (cache. History. GetCacheEntry);
231
236
&& var newHistory := cache. History. GetCacheEntry;
232
237
&& |newHistory| == |oldHistory|+ 1
233
- && Seq. Last (newHistory). output. Success?
234
238
&& var cacheInput := Seq. Last (newHistory). input;
235
239
&& var cacheOutput := Seq. Last (newHistory). output;
236
240
&& UTF8. Encode (keyId). Success?
237
- // TODO - why is this verifying?
238
241
&& cacheInput. identifier == RESOURCE_ID_HIERARCHICAL_KEYRING + NULL_BYTE + SCOPE_ID_SEARCHABLE_ENCRYPTION + NULL_BYTE + partitionIdBytes + NULL_BYTE + UTF8. Encode (keyId). value
239
242
240
243
// = specification/searchable-encryption/search-config.md#get-beacon-key-materials
241
244
// = type=implication
242
245
// # If a [cache entry](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#cache-entry)
243
246
// # exists, get beacon key MUST return the [entry materials](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#materials).
244
- && (cacheOutput. Success? ==>
247
+ && (cacheOutput. Success? && cacheEntryWithinLimits (
248
+ creationTime := cacheOutput.value.creationTime,
249
+ now := now,
250
+ ttlSeconds := cacheTTL
251
+ ) ==>
245
252
&& cacheOutput. value. materials. BeaconKey?
246
253
&& cacheOutput. value. materials. BeaconKey. hmacKeys. Some?
247
254
&& output. value == cacheOutput. value. materials. BeaconKey. hmacKeys. value)
248
255
249
- && (cacheOutput. Failure? ==>
256
+ && (cacheOutput. Failure? || ! cacheEntryWithinLimits (
257
+ creationTime := cacheOutput.value.creationTime,
258
+ now := now,
259
+ ttlSeconds := cacheTTL
260
+ ) ==>
250
261
&& var oldGetHistory := old (store. History. GetBeaconKey);
251
262
&& var newGetHistory := store. History. GetBeaconKey;
252
263
&& |newGetHistory| == |oldGetHistory|+ 1
@@ -263,14 +274,12 @@ module SearchableEncryptionInfo {
263
274
&& var oldPutHistory := old (cache. History. PutCacheEntry);
264
275
&& var newPutHistory := cache. History. PutCacheEntry;
265
276
&& |newPutHistory| == |oldPutHistory|+ 1
266
- && Seq. Last (newPutHistory). output. Success?
267
277
&& var storeInput := Seq. Last (newPutHistory). input;
268
278
&& var storeOutput := Seq. Last (newPutHistory). output;
269
279
// = specification/searchable-encryption/search-config.md#get-beacon-key-materials
270
280
// = type=implication
271
281
// # These cached materials MUST be returned.
272
- && storeInput. materials. BeaconKey. hmacKeys == Some (output.value)
273
-
282
+ && storeInput. materials. BeaconKey? ==> storeInput. materials. BeaconKey. hmacKeys == Some (output.value)
274
283
)
275
284
{
276
285
@@ -290,16 +299,12 @@ module SearchableEncryptionInfo {
290
299
291
300
var getCacheInput := MP. GetCacheEntryInput (identifier := identifier, bytesUsed := None);
292
301
verifyValidStateCache (cache);
293
- assume {:axiom} cache. Modifies == {};
294
302
var getCacheOutput := cache. GetCacheEntry (getCacheInput);
295
-
296
303
// If error is not EntryDoesNotExist, return failure
297
304
if (getCacheOutput. Failure? && ! getCacheOutput. error. EntryDoesNotExist?) {
298
305
return Failure (AwsCryptographyMaterialProviders(AwsCryptographyMaterialProviders:=getCacheOutput.error));
299
306
}
300
307
301
- var now := Time. GetCurrent ();
302
-
303
308
// //= specification/searchable-encryption/search-config.md#<heading>
304
309
// # If using a `Shared` cache across multiple Beacon Key Sources,
305
310
// # different Key Sources having the same `beaconKey` can have different TTLs.
@@ -332,18 +337,20 @@ module SearchableEncryptionInfo {
332
337
// # These materials MUST be put into the associated [Key Store Cache](#key-store-cache)
333
338
// # with an [Expiry Time](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#expiry-time)
334
339
// # equal to now + configured [cacheTTL](#cachettl).
335
- var now := Time. GetCurrent ();
340
+ :- expect Need (
341
+ (now as int + cacheTTL as int) < UInt. INT64_MAX_LIMIT,
342
+ MP. AwsCryptographicMaterialProvidersException (message := "INT64 Overflow when putting cache entry.")
343
+ );
336
344
var putCacheEntryInput:= MP. PutCacheEntryInput (
337
345
identifier := identifier,
338
346
materials := MP.Materials.BeaconKey(beaconKeyMaterials),
339
347
creationTime := now,
340
- expiryTime := now+ cacheTTL as MP . PositiveLong ,
348
+ expiryTime := now + cacheTTL ,
341
349
messagesUsed := None,
342
350
bytesUsed := None
343
351
);
344
352
345
353
verifyValidStateCache (cache);
346
- assume {:axiom} cache. Modifies == {};
347
354
348
355
var putResult := cache. PutCacheEntry (putCacheEntryInput);
349
356
if (putResult. Failure? && ! putResult. error. EntryAlreadyExists?) {
0 commit comments