Skip to content

Commit 9d82567

Browse files
author
Lucas McDonald
committed
m
1 parent 8ca2883 commit 9d82567

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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, ENC.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+
}

TestVectors/dafny/DDBEncryption/src/JsonConfig.dfy

Lines changed: 5 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
const abc : UTF8.ValidUTF8Bytes :=
@@ -261,7 +264,7 @@ module {:options "-functionSyntax:4"} JsonConfig {
261264
ensures encryptor.Success? ==>
262265
&& encryptor.value.ValidState()
263266
&& fresh(encryptor.value)
264-
&& fresh(encryptor.value.Modifies)
267+
&& fresh(encryptor.value.Modifies - Operations.ModifiesInternalConfig(encryptor.value.config))
265268
{
266269
:- Need(data.Object?, "A Table Config must be an object.");
267270
var logicalTableName := TableName;
@@ -352,7 +355,7 @@ module {:options "-functionSyntax:4"} JsonConfig {
352355
legacyOverride := legacyOverride,
353356
plaintextOverride := plaintextOverride
354357
);
355-
var enc : ENC.IDynamoDbItemEncryptorClient :- expect DynamoDbItemEncryptor.DynamoDbItemEncryptor(encryptorConfig);
358+
var enc : ENC.IDynamoDbItemEncryptorClient :- expect CreateWrappedItemEncryptor.CreateWrappedItemEncryptor(encryptorConfig);
356359
assert enc is DynamoDbItemEncryptor.DynamoDbItemEncryptorClient;
357360
var encr := enc as DynamoDbItemEncryptor.DynamoDbItemEncryptorClient;
358361
return Success(encr);

0 commit comments

Comments
 (0)