Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 320de24

Browse files
committedJan 14, 2025·
fix Duvet
1 parent 453f0fa commit 320de24

File tree

2 files changed

+197
-24
lines changed

2 files changed

+197
-24
lines changed
 

‎DynamoDbEncryption/dafny/DynamoDbEncryption/src/SearchInfo.dfy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ module SearchableEncryptionInfo {
329329
return Failure(AwsCryptographyMaterialProviders(AwsCryptographyMaterialProviders:=getCacheOutput.error));
330330
}
331331

332-
// //= specification/searchable-encryption/search-config.md#<heading>
332+
//= specification/searchable-encryption/search-config.md#get-beacon-key-materials
333333
//# If using a `Shared` cache across multiple Beacon Key Sources,
334-
//# different Key Sources having the same `beaconKey` can have different TTLs.
334+
//# different Beacon Key Sources having the same `branchKey` can have different TTLs.
335335
//# In such a case, the expiry time in the cache is set according to the Beacon Key Source that populated the cache.
336336
//# There MUST be a check (cacheEntryWithinLimits) to make sure that for the cache entry found, who's TTL has NOT expired,
337337
//# `time.now() - cacheEntryCreationTime <= ttlSeconds` is true and

‎specification/searchable-encryption/search-config.md

Lines changed: 195 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
## Version
77

8-
1.0.0
8+
- 1.1.0
9+
- [Update Cache Entry Identifier Formulas to shared cache across multiple Beacon Key Sources](../../changes/2024-09-13_cache-across-hierarchical-keyrings/change.md)
10+
- New optional parameter `Partition ID` used to distinguish Cryptographic Material Providers (i.e: Beacon Key Sources) writing to a cache
11+
- New optional parameter `cache` allowed while creating a `SingleKeyStore`
12+
- 1.0.0
13+
- Initial record
914

1015
### Changelog
1116

@@ -164,10 +169,10 @@ This can also be described as single tenant.
164169

165170
On initialization of a Single Key Store, the caller MUST provide:
166171

167-
TODO: Update
168-
169172
- [Beacon Key Id](#beacon-key-id)
170173
- [cacheTTL](#cachettl)
174+
- [cache](#key-store-cache)
175+
- [partition-id](#partition-id)
171176

172177
### Multi Key Store Initialization
173178

@@ -177,11 +182,10 @@ This can also be described as multi tenant.
177182

178183
On initialization of a Multi Key Store, the caller MUST provide:
179184

180-
TODO: Update
181-
182185
- [Beacon Key Field Name](#beacon-key-field-name)
183186
- [cacheTTL](#cachettl)
184-
- [max cache size](#max-cache-size)
187+
- [cache](#key-store-cache)
188+
- [partition-id](#partition-id)
185189

186190
### Field descriptions
187191

@@ -212,28 +216,32 @@ and used to extract a beacon key id from a query.
212216
The [cacheTTL](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#time-to-live-ttl)
213217
for how long a beacon key should exist locally before reauthorization.
214218

215-
#### max cache size
219+
### Key Store Cache
216220

217-
TODO: Remove and add partition ID
221+
For a Beacon Key Source a [CMC](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md)
222+
MUST be created.
223+
For a [Single Key Store](#single-key-store-initialization), either the customer provides a cache, or we create a cache that MUST have [Entry Capacity](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#entry-capacity)
224+
equal to 1.
225+
For a [Multi Key Store](#multi-key-store-initialization), either the customer provides a cache, or we create a cache that MUST have [Entry Capacity](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#entry-capacity)
226+
equal to 1000.
218227

219-
The [max cache size](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/local-cryptographic-materials-cache.md#entry-capacity)
220-
that the [Key Store Cache](#key-store-cache) will be configured to.
228+
The Key Store Cache MUST be shared across different [Beacon Key Sources](#beacon-key-source) if and only if a `Shared` cache is used.
229+
In all other cases, the Key Store Cache MUST be bound to the [Beacon Key Source](#beacon-key-source).
230+
In either case, Cache Identifiers MUST be unique across all key sources.
231+
Cache Identifiers for Searchable Encryption MUST be set as per the section [Searchable Encryption Cache Identifier](#searchable-encryption-cache-identifier).
221232

222-
### Key Store Cache
233+
### Partition ID
223234

224-
TODO: Update
235+
An optional string that uniquely identifies the respective [Beacon Key Source](#beacon-key-source)
236+
and is used to avoid collisions with other [Beacon Key Sources](#beacon-key-source).
225237

226-
For a Beacon Key Source a [CMC](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md)
227-
MUST be created.
228-
For a [Single Key Store](#single-key-store-initialization) the [Entry Capacity](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#entry-capacity)
229-
MUST be 1
230-
For a [Multi Key Store](#multi-key-store-initialization) the [Entry Capacity](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#entry-capacity)
231-
MUST be key store's max cache size.
238+
PartitionId can be a string provided by the user. If provided, it MUST be interpreted as UTF8 bytes.
239+
If the PartitionId is NOT provided by the user, it MUST be set to the 16 byte representation of a v4 UUID.
240+
241+
The Partition ID MUST NOT be changed after initialization.
232242

233-
The Key Store Cache MUST be bound to the Beacon Key Source.
234-
This is currently invariant because we construct the cache for each search config
235-
It is easy for beacon key ids to be unique within a single key source,
236-
this may not be true across all key sources.
243+
Please see [Shared Cache Considerations](#shared-cache-considerations) on how to provide the
244+
Partition ID and Logical Key Store Name while providing a Shared Cache to the [Beacon Key Source](#beacon-key-source).
237245

238246
## Beacon Keys
239247

@@ -328,6 +336,14 @@ These materials MUST be put into the associated [Key Store Cache](#key-store-cac
328336
with an [Expiry Time](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#expiry-time)
329337
equal to now + configured [cacheTTL](#cachettl).
330338

339+
If using a `Shared` cache across multiple [Beacon Key Sources](#beacon-key-source),
340+
different [Beacon Key Sources](#beacon-key-source) having the same `branchKey` can have different TTLs.
341+
In such a case, the expiry time in the cache is set according to the [Beacon Key Source](#beacon-key-source) that populated the cache.
342+
There MUST be a check (cacheEntryWithinLimits) to make sure that for the cache entry found, who's TTL has NOT expired,
343+
`time.now() - cacheEntryCreationTime <= ttlSeconds` is true and
344+
valid for TTL of the [Beacon Key Source](#beacon-key-source) getting the cache entry.
345+
If this is NOT true, then we MUST treat the cache entry as expired.
346+
331347
These cached materials MUST be returned.
332348

333349
### HMAC Key Generation
@@ -340,3 +356,160 @@ using the beacon key retrieved above as the initial key material with no salt.
340356
The `info` MUST be the concatenation of "AWS_DBE_SCAN_BEACON" encoded as UTF8
341357
and the beacon name.
342358
The `expectedLength` MUST be 64 bytes.
359+
360+
## Searchable Encryption Cache Identifier
361+
362+
When accessing the underlying cryptographic materials cache,
363+
Searchable Encryption MUST use the formulas specified in this section
364+
in order to compute the [cache entry identifier](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#cache-identifier).
365+
366+
### Preliminaries
367+
368+
Each of the cache entry identifier formulas includes serialized information related to the branch key,
369+
as defined in the [Key Provider Info](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/structures.md#key-provider-information).
370+
371+
We establish the following definitions for the Cache Entry Identifier formula:
372+
373+
#### Resource Identifier
374+
375+
A Hex value that indicates if an element is from a Caching_CMM, Hierarchical_Keyring, or some other future resource.
376+
377+
```
378+
Caching_CMM : 0x01 (0001)
379+
Hierarchical_Keyring : 0x02 (0010)
380+
```
381+
382+
#### Scope Identifier
383+
384+
A Hex value that indicates if an element is used for Encryption, Decryption, Searchable Encryption, or some other future purpose.
385+
386+
```
387+
Encrypt : 0x01 (0001)
388+
Decrypt : 0x02 (0010)
389+
Searchable Encryption : 0x03 (0011)
390+
```
391+
392+
#### Partition ID
393+
394+
Partition ID is an optional parameter provided to the [Beacon Key Source](#beacon-key-source) input, which distinguishes
395+
Cryptographic Material Providers (i.e: [Beacon Key Sources](#beacon-key-source)) writing to a cache.
396+
It can either be a String provided by the user, which MUST be interpreted as the bytes of
397+
UTF-8 Encoding of the String, or a v4 UUID, which SHOULD be interpreted as the 16 byte representation of the UUID.
398+
399+
Note: The cache will not know if the Partition ID is a String set by the user or the UUID.
400+
The constructor of the [Beacon Key Source](#beacon-key-source) MUST record these bytes at construction time.
401+
402+
Please see [Shared Cache Considerations](#shared-cache-considerations) on how to provide the
403+
Partition ID and Logical Key Store Name of the [beacon versions](#beacon-version-initialization)
404+
while providing a Shared Cache to the [Beacon Key Source](#beacon-key-source).
405+
406+
#### Resource Suffix
407+
408+
The resource suffixes for the Searchable Encryption is as follows:
409+
410+
```
411+
logicalKeyStoreName + NULL_BYTE + UTF8Encode(branchKeyId)
412+
```
413+
414+
The aforementioned 4 definitions ([Resource Identifier](#resource-identifier),
415+
[Scope Identifier](#scope-identifier), [Partition ID](#partition-id-1), and
416+
[Resource Suffix](#resource-suffix)) MUST be appended together with the null byte, 0x00,
417+
and the SHA384 of the result should be taken as the final cache identifier.
418+
419+
When the [Beacon Key Source](#beacon-key-source) receives a `getKeyMap` request,
420+
the cache entry identifier MUST be calculated as the
421+
SHA-384 hash of the following byte strings, in the order listed:
422+
423+
- MUST be the Resource ID for the Hierarchical Keyring (0x02)
424+
- MUST be the Scope ID for Searchable Encryption (0x03)
425+
- MUST be the Partition ID for the [Beacon Key Source](#beacon-key-source)
426+
- Resource Suffix
427+
- MUST be the UTF8 encoded Logical Key Store Name of the keystore for the [beacon versions](#beacon-version-initialization)
428+
- MUST be the UTF8 encoded branch-key-id
429+
430+
All the above fields must be separated by a single NULL_BYTE `0x00`.
431+
432+
| Field | Length (bytes) | Interpreted as |
433+
| ---------------------- | -------------- | ------------------- |
434+
| Resource ID | 1 | bytes |
435+
| Null Byte | 1 | `0x00` |
436+
| Scope ID | 1 | bytes |
437+
| Null Byte | 1 | `0x00` |
438+
| Partition ID | Variable | bytes |
439+
| Null Byte | 1 | `0x00` |
440+
| Logical Key Store Name | Variable | UTF-8 Encoded Bytes |
441+
| Null Byte | 1 | `0x00` |
442+
| Branch Key ID | Variable | UTF-8 Encoded Bytes |
443+
444+
As a formula:
445+
446+
```
447+
resource-id = [0x02]
448+
scope-id = [0x03]
449+
logical-key-store-name = UTF8Encode(beaconVersion.keystore.LogicalKeyStoreName)
450+
branch-key-id = UTF8Encode(BranchKeyIdentifier)
451+
NULL_BYTE = [0x00]
452+
453+
ENTRY_ID = SHA384(
454+
resource-id
455+
+ NULL_BYTE
456+
+ scope-id
457+
+ NULL_BYTE
458+
+ partition-id
459+
+ NULL_BYTE
460+
+ logical-key-store-name
461+
+ NULL_BYTE
462+
+ branch-key-id
463+
)
464+
```
465+
466+
## Shared Cache Considerations
467+
468+
If a user has two or more [beacon versions](#beacon-version-initialization) with:
469+
470+
- Same Partition ID
471+
- Same Logical Key Store Name of the Key Store
472+
- Same Branch Key ID
473+
474+
then they WILL share the cache entries in the `Shared` Cache.
475+
476+
Any keyring that has access to the `Shared` cache MAY be able to use materials
477+
that it MAY or MAY NOT have direct access to.
478+
479+
Users MUST make sure that all of Partition ID, Logical Key Store Name of the Key Store
480+
and Branch Key ID are set to be the same for two [beacon versions](#beacon-version-initialization) if and only they want the keyrings to share
481+
cache entries.
482+
483+
Therefore, there are two important parameters that users need to carefully set while providing the shared cache:
484+
485+
### Partition ID
486+
487+
Partition ID is an optional parameter provided to the [Beacon Key Source](#beacon-key-source) input,
488+
which distinguishes Cryptographic Material Providers (i.e: [Beacon Key Sources](#beacon-key-source)) writing to a cache.
489+
490+
- (Default) A a random 16-byte UUID, which makes
491+
it unique for every [Beacon Key Source](#beacon-key-source). In this case, two [Beacon Key Sources](#beacon-key-source) (or another Material Provider)
492+
CANNOT share the same cache entries in the cache.
493+
- If the Partition ID is set by the user and is the same for two [Beacon Key Sources](#beacon-key-source) (or another Material Provider),
494+
they CAN share the same cache entries in the cache.
495+
- If the Partition ID is set by the user and is different for two [Beacon Key Sources](#beacon-key-source) (or another Material Provider),
496+
they CANNOT share the same cache entries in the cache.
497+
498+
### Logical Key Store Name
499+
500+
> Note: Users MUST NEVER have two different physical Key Stores with the same Logical Key Store Name.
501+
502+
Logical Key Store Name is set by the user when configuring the Key Store for
503+
the [beacon versions](#beacon-version-initialization). This is a logical name for the key store.
504+
Logical Key Store Name MUST be converted to UTF8 Bytes to be used in
505+
the cache identifiers.
506+
507+
Suppose there's a physical Key Store on DynamoDB (K). Two Key Store clients of K (K1 and K2) are created.
508+
Now, two [beacon versions](#beacon-version-initialization) (BV1 and BV2) are created with these Key Store clients (K1 and K2 respectively).
509+
510+
- If we want to share cache entries across these two BeaconVersions BV1 and BV2, the Logical Key Store Names
511+
for both the Key Store clients (K1 and K2) should be set to be the same.
512+
- If we set the Logical Key Store Names for K1 and K2 to be different, BV1 (which uses Key Store client K1)
513+
and BV2 (which uses Key Store client K2) will NOT be able to share cache entries.
514+
515+
Notice that both K1 and K2 are clients for the same physical Key Store (K).

0 commit comments

Comments
 (0)
Please sign in to comment.