Skip to content

Commit 7afbecf

Browse files
committed
Merge branch 'main' of github.com:awslabs/aws-dynamodb-encryption-dafny into refactor
2 parents 8a5c94a + 7a570d6 commit 7afbecf

File tree

10 files changed

+533
-43
lines changed

10 files changed

+533
-43
lines changed

DynamoDbEncryption/src/DynamoDbEncryption/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 *

DynamoDbEncryption/src/DynamoDbItemEncryptor/AwsCryptographyDynamoDbItemEncryptorOperations.dfy

+27-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ include "../../Model/AwsCryptographyDynamoDbItemEncryptorTypes.dfy"
44
include "../../../submodules/MaterialProviders/AwsCryptographicMaterialProviders/src/CMMs/ExpectedEncryptionContextCMM.dfy"
55
include "DynamoToStruct.dfy"
66
include "../StructuredEncryption/SearchInfo.dfy"
7+
include "Util.dfy"
78

89
module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptographyDynamoDbItemEncryptorOperations {
9-
import opened StructuredEncryptionUtil
1010
import ComAmazonawsDynamodbTypes
11+
import opened DynamoDbItemEncryptorUtil
1112
import CMP = AwsCryptographyMaterialProvidersTypes
1213
import StructuredEncryption
1314
import DynamoToStruct
@@ -16,10 +17,10 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
1617
import opened StandardLibrary
1718
import Seq
1819
import CSE = AwsCryptographyStructuredEncryptionTypes
19-
import SE = StructuredEncryptionUtil
2020
import MaterialProviders
2121
import ExpectedEncryptionContextCMM
2222
import opened SearchableEncryptionInfo
23+
import SET = AwsCryptographyStructuredEncryptionTypes
2324

2425
datatype Config = Config(
2526
nameonly cmpClient : MaterialProviders.MaterialProvidersClient,
@@ -38,6 +39,24 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
3839
)
3940

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

4261
// constant attribute names for the encryption context
4362
const TABLE_NAME : seq<uint8> := UTF8.EncodeAscii("aws-crypto-table-name");
@@ -52,7 +71,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
5271
{
5372
|| (unauthenticatedAttributes.Some? && attr in unauthenticatedAttributes.value)
5473
|| (unauthenticatedPrefix.Some? && unauthenticatedPrefix.value <= attr)
55-
|| SE.ReservedPrefix <= attr
74+
|| ReservedPrefix <= attr
5675
// Attributes with the reserved prefix are "allowed unauthenticated" in that
5776
// they are not specified as signed within attributeActions.
5877
// These attributes MAY still be authenticated via other methods,
@@ -105,7 +124,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
105124
else if unauthenticatedPrefix.Some? && unauthenticatedPrefix.value <= attr then
106125
"it also begins with the unauthenticatedPrefix."
107126
else
108-
assert SE.ReservedPrefix <= attr;
127+
assert ReservedPrefix <= attr;
109128
"it also begins with the reserved prefix."
110129
}
111130

@@ -298,7 +317,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
298317

299318
// It is forbidden to explicitly configure an attribute with the reserved prefix
300319
&& (forall attribute <- config.attributeActions.Keys ::
301-
!(SE.ReservedPrefix <= attribute))
320+
!(ReservedPrefix <= attribute))
302321

303322
&& (config.beacons.Some? ==> config.beacons.value.ValidState())
304323
}
@@ -355,13 +374,13 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
355374
//= type=implication
356375
//# Otherwise, Attributes MUST be considered as within the signature scope.
357376
ensures ret.Success? ==>
358-
((ret.value == SE.DoNotSign) <==> !InSignatureScope(config, attr))
377+
((ret.value == DoNotSign) <==> !InSignatureScope(config, attr))
359378
{
360379
:- Need(!UnknownAttribute(config, attr), "Attribute " + attr + " is not configured");
361380
if InSignatureScope(config, attr) then
362-
Success(SE.DoSign)
381+
Success(DoSign)
363382
else
364-
Success(SE.DoNotSign)
383+
Success(DoNotSign)
365384
}
366385

367386
// get CryptoSchema for this item

0 commit comments

Comments
 (0)