Skip to content

Commit 2e39286

Browse files
Merge branch 'wrapped-item-encryptor' into python-poc
2 parents 30aa212 + 736b2fe commit 2e39286

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
include "../Model/AwsCryptographyDynamoDbEncryptionTypesWrapped.dfy"
5+
include "../../../../DynamoDbEncryption/dafny/DynamoDbItemEncryptor/src/Index.dfy"
6+
7+
module {:extern} CreateWrappedItemEncryptor {
8+
import opened Wrappers
9+
import AwsCryptographyDbEncryptionSdkDynamoDbTypes
10+
import ENC = AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorTypes
11+
import DynamoDbItemEncryptor
12+
import Operations = AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations
13+
14+
// The `ensures` clause is copy-pasted from the DynamoDbItemEncryptor client method's `ensures` clause.
15+
method {:extern} CreateWrappedItemEncryptor(config: ENC.DynamoDbItemEncryptorConfig)
16+
returns (output: Result<ENC.IDynamoDbItemEncryptorClient, AwsCryptographyDbEncryptionSdkDynamoDbTypes.Error>)
17+
requires config.keyring.Some? ==>
18+
config.keyring.value.ValidState()
19+
requires config.cmm.Some? ==>
20+
config.cmm.value.ValidState()
21+
requires config.legacyOverride.Some? ==>
22+
config.legacyOverride.value.encryptor.ValidState()
23+
modifies if config.keyring.Some? then
24+
config.keyring.value.Modifies
25+
else {}
26+
modifies if config.cmm.Some? then
27+
config.cmm.value.Modifies
28+
else {}
29+
modifies if config.legacyOverride.Some? then
30+
config.legacyOverride.value.encryptor.Modifies
31+
else {}
32+
ensures output.Success? ==>
33+
&& output.value is DynamoDbItemEncryptor.DynamoDbItemEncryptorClient
34+
&& fresh(output.value)
35+
&& fresh(output.value.History)
36+
&& output.value.ValidState()
37+
&& var rconfig := (output.value as DynamoDbItemEncryptor.DynamoDbItemEncryptorClient).config;
38+
&& fresh(output.value.Modifies - Operations.ModifiesInternalConfig(rconfig))
39+
&& rconfig.logicalTableName == config.logicalTableName
40+
&& rconfig.partitionKeyName == config.partitionKeyName
41+
&& rconfig.sortKeyName == config.sortKeyName
42+
&& rconfig.attributeActionsOnEncrypt == config.attributeActionsOnEncrypt
43+
&& rconfig.allowedUnsignedAttributes == config.allowedUnsignedAttributes
44+
&& rconfig.allowedUnsignedAttributePrefix == config.allowedUnsignedAttributePrefix
45+
&& rconfig.algorithmSuiteId == config.algorithmSuiteId
46+
47+
//= specification/dynamodb-encryption-client/ddb-table-encryption-config.md#attribute-actions
48+
//= type=implication
49+
//# The [Key Action](#key-action)
50+
//# MUST be configured to the partition attribute and, if present, sort attribute.
51+
&& rconfig.version == Operations.VersionFromActions(config.attributeActionsOnEncrypt)
52+
&& config.partitionKeyName in config.attributeActionsOnEncrypt
53+
&& config.attributeActionsOnEncrypt[config.partitionKeyName] == Operations.KeyActionFromVersion(rconfig.version)
54+
&& (config.sortKeyName.Some? ==>
55+
&& config.sortKeyName.value in config.attributeActionsOnEncrypt
56+
&& config.attributeActionsOnEncrypt[config.sortKeyName.value] == Operations.KeyActionFromVersion(rconfig.version))
57+
58+
//= specification/dynamodb-encryption-client/ddb-table-encryption-config.md#plaintext-policy
59+
//# If not specified, encryption and decryption MUST behave according to `FORBID_PLAINTEXT_WRITE_FORBID_PLAINTEXT_READ`.
60+
ensures
61+
&& output.Success?
62+
&& config.plaintextOverride.None?
63+
==>
64+
&& var config := (output.value as DynamoDbItemEncryptor.DynamoDbItemEncryptorClient).config;
65+
&& config.plaintextOverride.FORBID_PLAINTEXT_WRITE_FORBID_PLAINTEXT_READ?
66+
{
67+
var encryptor :- expect DynamoDbItemEncryptor.DynamoDbItemEncryptor(config);
68+
return Success(encryptor);
69+
}
70+
}

TestVectors/dafny/DDBEncryption/src/JsonConfig.dfy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
include "JsonItem.dfy"
55
include "CreateInterceptedDDBClient.dfy"
6+
include "CreateWrappedItemEncryptor.dfy"
67
include "../../../../DynamoDbEncryption/dafny/DynamoDbItemEncryptor/src/Index.dfy"
78

89
module {:options "-functionSyntax:4"} JsonConfig {
@@ -31,6 +32,8 @@ module {:options "-functionSyntax:4"} JsonConfig {
3132
import ParseJsonManifests
3233
import CreateInterceptedDDBClient
3334
import DynamoDbItemEncryptor
35+
import CreateWrappedItemEncryptor
36+
import Operations = AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations
3437

3538

3639
predicate IsValidInt32(x: int) { -0x8000_0000 <= x < 0x8000_0000}
@@ -256,7 +259,7 @@ module {:options "-functionSyntax:4"} JsonConfig {
256259
ensures encryptor.Success? ==>
257260
&& encryptor.value.ValidState()
258261
&& fresh(encryptor.value)
259-
&& fresh(encryptor.value.Modifies)
262+
&& fresh(encryptor.value.Modifies - Operations.ModifiesInternalConfig(encryptor.value.config))
260263
{
261264
:- Need(data.Object?, "A Table Config must be an object.");
262265
var logicalTableName := TableName;
@@ -347,7 +350,8 @@ module {:options "-functionSyntax:4"} JsonConfig {
347350
legacyOverride := legacyOverride,
348351
plaintextOverride := plaintextOverride
349352
);
350-
var enc : ENC.IDynamoDbItemEncryptorClient :- expect DynamoDbItemEncryptor.DynamoDbItemEncryptor(encryptorConfig);
353+
var enc : ENC.IDynamoDbItemEncryptorClient :- expect CreateWrappedItemEncryptor.CreateWrappedItemEncryptor(encryptorConfig);
354+
// var enc : ENC.IDynamoDbItemEncryptorClient :- expect DynamoDbItemEncryptor.DynamoDbItemEncryptor(encryptorConfig);
351355
assert enc is DynamoDbItemEncryptor.DynamoDbItemEncryptorClient;
352356
var encr := enc as DynamoDbItemEncryptor.DynamoDbItemEncryptorClient;
353357
return Success(encr);

0 commit comments

Comments
 (0)