Skip to content

Commit 58f411e

Browse files
committed
first commit
1 parent 28d06fe commit 58f411e

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

DynamoDbEncryption/dafny/DynamoDbEncryption/src/ConfigToInfo.dfy

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module SearchConfigToInfo {
3333
import SE = AwsCryptographyDbEncryptionSdkStructuredEncryptionTypes
3434
import MPT = AwsCryptographyMaterialProvidersTypes
3535
import Primitives = AtomicPrimitives
36+
import UUID
3637

3738
// convert configured SearchConfig to internal SearchInfo
3839
method Convert(outer : DynamoDbTableEncryptionConfig)
@@ -151,13 +152,35 @@ module SearchConfigToInfo {
151152
cache :- maybeCache.MapFailure(e => AwsCryptographyMaterialProviders(e));
152153
}
153154

155+
var partitionIdBytes : seq<uint8>;
156+
157+
if outer.keyring.Some? {
158+
if outer.keyring.value.partitionId.Some? {
159+
partitionIdBytes :- UTF8.Encode(outer.keyring.value.partitionId.value)
160+
.MapFailure(
161+
e => Error.DynamoDbEncryptionException(
162+
message := "Could not UTF-8 Encode Partition ID: " + e
163+
)
164+
);
165+
}
166+
}
167+
else {
168+
var uuid? := UUID.GenerateUUID();
169+
170+
var uuid :- uuid?
171+
.MapFailure(e => Error.DynamoDbEncryptionException(message := e));
172+
173+
partitionIdBytes :- UUID.ToByteArray(uuid)
174+
.MapFailure(e => Error.DynamoDbEncryptionException(message := e));
175+
}
176+
154177
if config.multi? {
155178
:- Need(0 < config.multi.cacheTTL, E("Beacon Cache TTL must be at least 1."));
156179
var deleteKey :- ShouldDeleteKeyField(outer, config.multi.keyFieldName);
157-
output := Success(I.KeySource(client, keyStore, I.MultiLoc(config.multi.keyFieldName, deleteKey), cache, config.multi.cacheTTL as uint32));
180+
output := Success(I.KeySource(client, keyStore, I.MultiLoc(config.multi.keyFieldName, deleteKey), cache, config.multi.cacheTTL as uint32, partitionIdBytes));
158181
} else {
159182
:- Need(0 < config.single.cacheTTL, E("Beacon Cache TTL must be at least 1."));
160-
output := Success(I.KeySource(client, keyStore, I.SingleLoc(config.single.keyId), cache, config.single.cacheTTL as uint32));
183+
output := Success(I.KeySource(client, keyStore, I.SingleLoc(config.single.keyId), cache, config.single.cacheTTL as uint32, partitionIdBytes));
161184
}
162185
}
163186

DynamoDbEncryption/dafny/DynamoDbEncryption/src/SearchInfo.dfy

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module SearchableEncryptionInfo {
2626
import MP = AwsCryptographyMaterialProvidersTypes
2727
import KeyStoreTypes = AwsCryptographyKeyStoreTypes
2828
import SE = AwsCryptographyDbEncryptionSdkStructuredEncryptionTypes
29+
import CacheConstants
2930

3031
//= specification/searchable-encryption/search-config.md#version-number
3132
//= type=implication
@@ -137,7 +138,8 @@ module SearchableEncryptionInfo {
137138
store : ValidStore,
138139
keyLoc : KeyLocation,
139140
cache : MP.ICryptographicMaterialsCache,
140-
cacheTTL : uint32
141+
cacheTTL : uint32,
142+
partitionIdBytes : seq<uint8>
141143
) {
142144
function Modifies() : set<object> {
143145
client.Modifies + store.Modifies
@@ -153,7 +155,7 @@ module SearchableEncryptionInfo {
153155
{
154156
if keyLoc.SingleLoc? {
155157
:- Need(keyId.DontUseKeyId?, E("KeyID should not be supplied with a SingleKeyStore"));
156-
var theMap :- getKeysCache(stdNames, keyLoc.keyId);
158+
var theMap :- getKeysCache(stdNames, keyLoc.keyId, partitionIdBytes);
157159
return Success(Keys(theMap));
158160
} else if keyLoc.LiteralLoc? {
159161
:- Need(keyId.DontUseKeyId?, E("KeyID should not be supplied with a LiteralKeyStore"));
@@ -163,7 +165,7 @@ module SearchableEncryptionInfo {
163165
match keyId {
164166
case DontUseKeyId => return Failure(E("KeyID must not be supplied with a MultiKeyStore"));
165167
case ShouldHaveKeyId => return Success(ShouldHaveKeys);
166-
case KeyId(id) => var theMap :- getKeysCache(stdNames, id); return Success(Keys(theMap));
168+
case KeyId(id) => var theMap :- getKeysCache(stdNames, id, partitionIdBytes); return Success(Keys(theMap));
167169
}
168170
}
169171
}
@@ -182,7 +184,8 @@ module SearchableEncryptionInfo {
182184

183185
method getKeysCache(
184186
stdNames : seq<string>,
185-
keyId : string
187+
keyId : string,
188+
partitionIdBytes : seq<uint8>
186189
)
187190
returns (output : Result<HmacKeyMap, Error>)
188191
requires Seq.HasNoDuplicates(stdNames)
@@ -241,6 +244,11 @@ module SearchableEncryptionInfo {
241244

242245
)
243246
{
247+
248+
// Resource ID: Searchable Encryption [0x02]
249+
// var resourceId : seq<uint8> := RESOURCE_ID_HIERARCHICAL_KEYRING;
250+
251+
244252
var keyIdBytesR := UTF8.Encode(keyId);
245253
var keyIdBytes :- keyIdBytesR.MapFailure(e => E(e));
246254
var getCacheInput := MP.GetCacheEntryInput(identifier := keyIdBytes, bytesUsed := None);
@@ -253,6 +261,7 @@ module SearchableEncryptionInfo {
253261
return Failure(AwsCryptographyMaterialProviders(AwsCryptographyMaterialProviders:=getCacheOutput.error));
254262
}
255263

264+
// TODO: Add cacheEntryWithinLimits
256265
if getCacheOutput.Failure? {
257266
//= specification/searchable-encryption/search-config.md#beacon-keys
258267
//# Beacon keys MUST be obtained from the configured [Beacon Key Source](#beacon-key-source).

DynamoDbEncryption/dafny/DynamoDbEncryption/src/Util.dfy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module DynamoDbEncryptionUtil {
2626
//
2727
// Counterintuitively, DontUseKeys and DontUseKeyId are very different things.
2828
// DontUseKeyId is the usual thing for single tenant, meaning to use the pre-configured
29-
// KeyId, rather than fnd a new one from somewhere.
29+
// KeyId, rather than find a new one from somewhere.
3030
// DontUseKeys means to not hash the values into beacons,
3131
// but to leave them plaintext, which is necessary for the post-query filtering.
3232
datatype MaybeKeyMap =

DynamoDbEncryption/dafny/DynamoDbEncryptionTransforms/src/Index.dfy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ module
150150
var tableName: string := tableNamesSeq[i];
151151

152152
var inputConfig := config.tableEncryptionConfigs[tableName];
153-
:- Need(inputConfig.logicalTableName !in allLogicalTableNames, E("Duplicate logical table maped to multipule physical tables: " + inputConfig.logicalTableName));
153+
:- Need(inputConfig.logicalTableName !in allLogicalTableNames, E("Duplicate logical table mapped to multiple physical tables: " + inputConfig.logicalTableName));
154154

155155
assert SearchConfigToInfo.ValidSearchConfig(inputConfig.search);
156156
SearchInModifies(config, tableName);

0 commit comments

Comments
 (0)