Skip to content

Commit e545cbe

Browse files
committed
feat: index support for beacons (#73)
* feat: index support for beacons
1 parent 8928637 commit e545cbe

File tree

10 files changed

+534
-42
lines changed

10 files changed

+534
-42
lines changed

DynamoDbEncryptionMiddlewareInternal/src/DdbMiddlewareConfig.dfy

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module DdbMiddlewareConfig {
1919
var encryptorConfig := config.itemEncryptor.config;
2020
&& config.partitionKeyName == encryptorConfig.partitionKeyName
2121
&& config.sortKeyName == encryptorConfig.sortKeyName
22+
&& config.itemEncryptor.ValidState()
2223
}
2324

2425
type ValidTableConfig = c: TableConfig | ValidTableConfig?(c) witness *

DynamoDbItemEncryptor/src/AwsCryptographyDynamoDbItemEncryptorOperations.dfy

+27-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
include "../Model/AwsCryptographyDynamoDbItemEncryptorTypes.dfy"
44
include "../../private-aws-encryption-sdk-dafny-staging/AwsCryptographicMaterialProviders/src/CMMs/ExpectedEncryptionContextCMM.dfy"
55
include "DynamoToStruct.dfy"
6+
include "Util.dfy"
67
include "../../StructuredEncryption/src/SearchInfo.dfy"
78
include "InternalLegacyConfig.dfy"
89

910
module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptographyDynamoDbItemEncryptorOperations {
10-
import opened StructuredEncryptionUtil
1111
import ComAmazonawsDynamodbTypes
12+
import opened DynamoDbItemEncryptorUtil
1213
import CMP = AwsCryptographyMaterialProvidersTypes
1314
import StructuredEncryption
1415
import DynamoToStruct
@@ -22,6 +23,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
2223
import MaterialProviders
2324
import ExpectedEncryptionContextCMM
2425
import opened SearchableEncryptionInfo
26+
import SET = AwsCryptographyStructuredEncryptionTypes
2527

2628
datatype Config = Config(
2729
nameonly cmpClient : MaterialProviders.MaterialProvidersClient,
@@ -39,6 +41,24 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
3941
)
4042

4143
type InternalConfig = Config
44+
type ValidConfig = x : Config | ValidInternalConfig?(x) witness *
45+
46+
predicate method IsEncrypted(config : ValidConfig, attr : string)
47+
{
48+
&& attr in config.attributeActions
49+
&& config.attributeActions[attr] == SET.ENCRYPT_AND_SIGN
50+
}
51+
52+
predicate method IsSigned(config : ValidConfig, attr : string)
53+
{
54+
&& attr in config.attributeActions
55+
&& config.attributeActions[attr] != SET.DO_NOTHING
56+
}
57+
58+
const DoNotSign :=
59+
CSE.AuthenticateSchema(content := CSE.AuthenticateSchemaContent.Action(CSE.AuthenticateAction.DO_NOT_SIGN), attributes := None)
60+
const DoSign :=
61+
CSE.AuthenticateSchema(content := CSE.AuthenticateSchemaContent.Action(CSE.AuthenticateAction.SIGN), attributes := None)
4262

4363
// constant attribute names for the encryption context
4464
const TABLE_NAME : seq<uint8> := UTF8.EncodeAscii("aws-crypto-table-name");
@@ -53,7 +73,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
5373
{
5474
|| (unauthenticatedAttributes.Some? && attr in unauthenticatedAttributes.value)
5575
|| (unauthenticatedPrefix.Some? && unauthenticatedPrefix.value <= attr)
56-
|| SE.ReservedPrefix <= attr
76+
|| ReservedPrefix <= attr
5777
// Attributes with the reserved prefix are "allowed unauthenticated" in that
5878
// they are not specified as signed within attributeActions.
5979
// These attributes MAY still be authenticated via other methods,
@@ -106,7 +126,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
106126
else if unauthenticatedPrefix.Some? && unauthenticatedPrefix.value <= attr then
107127
"it also begins with the unauthenticatedPrefix."
108128
else
109-
assert SE.ReservedPrefix <= attr;
129+
assert ReservedPrefix <= attr;
110130
"it also begins with the reserved prefix."
111131
}
112132

@@ -299,7 +319,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
299319

300320
// It is forbidden to explicitly configure an attribute with the reserved prefix
301321
&& (forall attribute <- config.attributeActions.Keys ::
302-
!(SE.ReservedPrefix <= attribute))
322+
!(ReservedPrefix <= attribute))
303323

304324
&& (config.beacons.Some? ==> config.beacons.value.ValidState())
305325
}
@@ -356,13 +376,13 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
356376
//= type=implication
357377
//# Otherwise, Attributes MUST be considered as within the signature scope.
358378
ensures ret.Success? ==>
359-
((ret.value == SE.DoNotSign) <==> !InSignatureScope(config, attr))
379+
((ret.value == DoNotSign) <==> !InSignatureScope(config, attr))
360380
{
361381
:- Need(!UnknownAttribute(config, attr), "Attribute " + attr + " is not configured");
362382
if InSignatureScope(config, attr) then
363-
Success(SE.DoSign)
383+
Success(DoSign)
364384
else
365-
Success(SE.DoNotSign)
385+
Success(DoNotSign)
366386
}
367387

368388
// get CryptoSchema for this item

0 commit comments

Comments
 (0)