Skip to content

Commit 89eb30e

Browse files
committed
Merge branch 'main' of github.com:aws/aws-database-encryption-sdk-dynamodb-java into robin-aws/use-smithy-dafny-makefile
# Conflicts: # DynamoDbEncryption/dafny/DynamoDbEncryption/Model/AwsCryptographyDbEncryptionSdkDynamoDbTypes.dfy # DynamoDbEncryption/dafny/DynamoDbEncryption/src/Index.dfy # DynamoDbEncryption/dafny/DynamoDbEncryptionTransforms/Model/AwsCryptographyDbEncryptionSdkDynamoDbTransformsTypes.dfy # DynamoDbEncryption/dafny/DynamoDbEncryptionTransforms/src/Index.dfy # DynamoDbEncryption/dafny/DynamoDbEncryptionTransforms/test/TestFixtures.dfy # DynamoDbEncryption/dafny/DynamoDbItemEncryptor/Model/AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorTypes.dfy # DynamoDbEncryption/dafny/DynamoDbItemEncryptor/src/Index.dfy # DynamoDbEncryption/dafny/StructuredEncryption/Model/AwsCryptographyDbEncryptionSdkStructuredEncryptionTypes.dfy # DynamoDbEncryption/dafny/StructuredEncryption/src/AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations.dfy # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/dynamodb/DynamoDbEncryption.java # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/dynamodb/itemencryptor/DynamoDbItemEncryptor.java # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/dynamodb/itemencryptor/ToDafny.java # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/dynamodb/itemencryptor/ToNative.java # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/dynamodb/itemencryptor/model/ParsedHeader.java # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/dynamodb/transforms/DynamoDbEncryptionTransforms.java # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/structuredencryption/StructuredEncryption.java # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/structuredencryption/ToDafny.java # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/structuredencryption/ToNative.java # DynamoDbEncryption/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/dbencryptionsdk/structuredencryption/model/ParsedHeader.java # DynamoDbEncryption/runtimes/net/Generated/DynamoDbEncryption/TypeConversion.cs # DynamoDbEncryption/runtimes/net/Generated/DynamoDbEncryptionTransforms/TypeConversion.cs # DynamoDbEncryption/runtimes/net/Generated/DynamoDbItemEncryptor/TypeConversion.cs # SharedMakefile.mk # TestVectors/dafny/DDBEncryption/src/JsonConfig.dfy
2 parents 3deea78 + 56f1cd1 commit 89eb30e

File tree

89 files changed

+7737
-5598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+7737
-5598
lines changed

.github/workflows/ci_test_net.yml

+9
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,12 @@ jobs:
113113
else
114114
make test_net FRAMEWORK=net6.0
115115
fi
116+
117+
- name: Test Build and Pack ${{ matrix.library}}
118+
shell: bash
119+
if: matrix.os != 'windows-latest'
120+
working-directory: ./${{ matrix.library }}
121+
run: |
122+
dotnet build runtimes/net /p:Configuration=Release -nowarn:CS0162,CS0168
123+
dotnet pack runtimes/net/DynamoDbEncryption.csproj --no-build /p:Configuration=Release --output build
124+

.github/workflows/ci_test_vector_net.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- name: Test TestVectors on .NET 6.0
5959
working-directory: ./TestVectors/runtimes/net
6060
run: |
61-
cp ../java/decrypt_java.json ../java/decrypt_dotnet.json .
61+
cp ../java/decrypt_java_*.json ../java/decrypt_dotnet_*.json .
6262
dotnet run
6363
cp ../java/*.json .
6464
dotnet run --framework net6.0

CHANGELOG.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 3.2.0 2024-03-20
4+
5+
### Features
6+
7+
- A fourth Crypto Action will be made available : `SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT`, to join the existing `DO_NOTHING`, `SIGN_ONLY` and `ENCRYPT_AND_SIGN`. `SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT` behaves like `SIGN_ONLY`, but also includes the value in the encryption context, making it available to the branch key selector.
8+
- The Parsed Header, returned from EncryptItem and DecryptItem, now returns two more fields
9+
- encryptionContext : the full encryption context used for encryption
10+
- selectorContext : the encryption context as presented to the branch key selector
11+
- The Java Enhanced Client now supports Single Table Design. When using the DynamoDbEnhancedTableEncryptionConfig builder, one can now specify `schemaOnEncrypt` multiple times, once for each class being modeled in the table.
12+
- There was a hard limit of 100 on the size of maps and lists in Items to be encrypted. This limit has been removed.
13+
314
## 3.2.0 2024-01-16
415

516
### Features
@@ -15,7 +26,7 @@
1526
- New APIs : ResolveAttributes and GetVirtualFields to assist in development and debugging.
1627

1728
### Fix
18-
- String compare for client side filtering of Scan and Query results could somtimes produce the wrong result for certain characters.
29+
- String compare for client side filtering of Scan and Query results could sometimes produce the wrong result for certain characters.
1930

2031

2132
## 3.1.2 2023-11-13

DynamoDbEncryption/codebuild/release-staging.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ phases:
6363
- dotnet add runtimes/net/DbEsdkTestVectors.csproj package AWS.Cryptography.DbEncryptionSDK.DynamoDb --version $VERSION
6464
- make transpile_net
6565
- cd runtimes/net
66-
- cp ../java/decrypt_java.json ../java/decrypt_dotnet.json .
66+
- cp ../java/decrypt_java_*.json ../java/decrypt_dotnet_*.json .
6767
- dotnet run --framework net6.0

DynamoDbEncryption/codebuild/test-prod.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ phases:
3939
- dotnet add runtimes/net/DbEsdkTestVectors.csproj package AWS.Cryptography.DbEncryptionSDK.DynamoDb --version $VERSION
4040
- make transpile_net
4141
- cd runtimes/net
42-
- cp ../java/decrypt_java.json ../java/decrypt_dotnet.json .
42+
- cp ../java/decrypt_java_*.json ../java/decrypt_dotnet_*.json .
4343
- dotnet run --framework net6.0

DynamoDbEncryption/dafny/DynamoDbEncryption/Model/AwsCryptographyDbEncryptionSdkDynamoDbTypes.dfy

+531-531
Large diffs are not rendered by default.

DynamoDbEncryption/dafny/DynamoDbEncryption/Model/DynamoDbEncryption.smithy

+15
Original file line numberDiff line numberDiff line change
@@ -762,33 +762,48 @@ operation GetBranchKeyIdFromDdbKey {
762762
output: GetBranchKeyIdFromDdbKeyOutput
763763
}
764764

765+
//= specification/dynamodb-encryption-client/ddb-encryption-branch-key-id-supplier.md#dynamodbkeybranchkeyidsupplier
766+
//= type=implication
767+
//# This operation MUST take in a DDB `Key` structure (and attribute map containing the partition and sort attributes) as input.
765768
@javadoc("Inputs for getting the Branch Key that should be used for wrapping and unwrapping data keys.")
766769
structure GetBranchKeyIdFromDdbKeyInput {
767770
@required
768771
@javadoc("The partition and sort (if it exists) attributes on the item being read or written.")
769772
ddbKey: Key
770773
}
771774

775+
//= specification/dynamodb-encryption-client/ddb-encryption-branch-key-id-supplier.md#dynamodbkeybranchkeyidsupplier
776+
//= type=implication
777+
//# This operation MUST return a branch key id (string) as output.
772778
@javadoc("Outputs for getting the Branch Key that should be used for wrapping and unwrapping data keys.")
773779
structure GetBranchKeyIdFromDdbKeyOutput {
774780
@required
775781
@javadoc("The ID of the Branch Key that should be used to wrap and unwrap data keys for this item.")
776782
branchKeyId: String
777783
}
778784

785+
//= specification/dynamodb-encryption-client/ddb-encryption-branch-key-id-supplier.md#operation
786+
//= type=implication
787+
//# The `CreateDynamoDbEncryptionBranchKeyIdSupplier` is an operation that MUST be vended alongside the DynamoDb Item Encryptor.
779788
@javadoc("Create a Branch Key Supplier for use with the Hierarchical Keyring that decides what Branch Key to use based on the primary key of the DynamoDB item being read or written.")
780789
operation CreateDynamoDbEncryptionBranchKeyIdSupplier {
781790
input: CreateDynamoDbEncryptionBranchKeyIdSupplierInput,
782791
output: CreateDynamoDbEncryptionBranchKeyIdSupplierOutput
783792
}
784793

794+
//= specification/dynamodb-encryption-client/ddb-encryption-branch-key-id-supplier.md#input
795+
//= type=implication
796+
//# This operation MUST take in a [DynamoDbKeyBranchKeyIdSupplier](#dynamodb-key-branch-key-id-supplier) as input.
785797
@javadoc("Inputs for creating a Branch Key Supplier from a DynamoDB Key Branch Key Id Supplier")
786798
structure CreateDynamoDbEncryptionBranchKeyIdSupplierInput {
787799
@required
788800
@javadoc("An implementation of the DynamoDbKeyBranchKeyIdSupplier interface, which determines what Branch Key to use for data key wrapping/unwrapping based on the DynamoDB item being written/read.")
789801
ddbKeyBranchKeyIdSupplier: DynamoDbKeyBranchKeyIdSupplierReference,
790802
}
791803

804+
//= specification/dynamodb-encryption-client/ddb-encryption-branch-key-id-supplier.md#output
805+
//= type=implication
806+
//# This operation MUST output a BranchKeyIdSupplierReference.
792807
@javadoc("Outputs for creating a Branch Key Supplier from a DynamoDB Key Branch Key Id Supplier")
793808
structure CreateDynamoDbEncryptionBranchKeyIdSupplierOutput {
794809
@required

DynamoDbEncryption/dafny/DynamoDbEncryption/src/ConfigToInfo.dfy

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ module SearchConfigToInfo {
8989
match outer.attributeActionsOnEncrypt[keyFieldName] {
9090
case DO_NOTHING => Success(true)
9191
case SIGN_ONLY => Success(false)
92+
case SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT => Success(false)
9293
case ENCRYPT_AND_SIGN => Failure(E("Beacon key field name " + keyFieldName + " is configured as ENCRYPT_AND_SIGN which is not allowed."))
9394
}
9495
}
@@ -267,7 +268,10 @@ module SearchConfigToInfo {
267268
{
268269
&& var name := loc[0].key;
269270
&& name in outer.attributeActionsOnEncrypt
270-
&& outer.attributeActionsOnEncrypt[name] == SE.SIGN_ONLY
271+
&& (
272+
|| outer.attributeActionsOnEncrypt[name] == SE.SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT
273+
|| outer.attributeActionsOnEncrypt[name] == SE.SIGN_ONLY
274+
)
271275
}
272276

273277
// is this terminal location encrypted

DynamoDbEncryption/dafny/DynamoDbEncryption/src/DynamoDbEncryptionBranchKeyIdSupplier.dfy

+13-67
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
include "DynamoToStruct.dfy"
5-
include "Util.dfy"
4+
include "../../DynamoDbItemEncryptor/src/Util.dfy"
65

76
module DynamoDbEncryptionBranchKeyIdSupplier {
87
import opened AwsCryptographyDbEncryptionSdkDynamoDbTypes
9-
import MPL = AwsCryptographyMaterialProvidersTypes
10-
import DDB = ComAmazonawsDynamodbTypes
11-
import opened Seq
128
import opened Wrappers
13-
import opened StandardLibrary.UInt
14-
import DynamoToStruct
15-
import Base64
16-
import DynamoDbEncryptionUtil
17-
18-
const MPL_EC_PARTITION_NAME: UTF8.ValidUTF8Bytes := UTF8.EncodeAscii("aws-crypto-partition-name")
19-
const MPL_EC_SORT_NAME: UTF8.ValidUTF8Bytes := UTF8.EncodeAscii("aws-crypto-sort-name")
9+
import MPL = AwsCryptographyMaterialProvidersTypes
10+
import DynamoDbItemEncryptorUtil
2011

2112
class DynamoDbEncryptionBranchKeyIdSupplier
2213
extends MPL.IBranchKeyIdSupplier
23-
{
14+
{
2415
const ddbKeyBranchKeyIdSupplier: IDynamoDbKeyBranchKeyIdSupplier
2516

2617
predicate ValidState()
@@ -48,76 +39,31 @@ module DynamoDbEncryptionBranchKeyIdSupplier {
4839
{true}
4940

5041
method GetBranchKeyId'(input: MPL.GetBranchKeyIdInput)
51-
returns (output: Result<MPL.GetBranchKeyIdOutput, MPL.Error>)
42+
returns (output: Result<MPL.GetBranchKeyIdOutput, MPL.Error>)
5243
requires ValidState()
5344
modifies Modifies - {History}
5445
decreases Modifies - {History}
5546
ensures ValidState()
5647
ensures GetBranchKeyIdEnsuresPublicly(input, output)
5748
ensures unchanged(History)
5849
{
59-
var context := input.encryptionContext;
60-
var attrMap: DDB.AttributeMap := map[];
50+
var attrMapR := DynamoDbItemEncryptorUtil.ConvertContextForSelector(input.encryptionContext);
51+
var attrMap :- attrMapR.MapFailure(e => MPL.AwsCryptographicMaterialProvidersException(message:=e));
6152

62-
// Add partition key to map
63-
:- Need(MPL_EC_PARTITION_NAME in context.Keys,
64-
MPL.AwsCryptographicMaterialProvidersException(
65-
message := "Invalid encryption context: Missing partition name"));
66-
var partitionName := context[MPL_EC_PARTITION_NAME];
67-
var partitionValueKey := DynamoDbEncryptionUtil.DDBEC_EC_ATTR_PREFIX + partitionName;
68-
:- Need(partitionValueKey in context.Keys,
69-
MPL.AwsCryptographicMaterialProvidersException(
70-
message := "Invalid encryption context: Missing partition value"));
71-
attrMap :- AddAttributeToMap(partitionValueKey, context[partitionValueKey], attrMap);
72-
73-
if MPL_EC_SORT_NAME in context.Keys {
74-
var sortName := context[MPL_EC_SORT_NAME];
75-
var sortValueKey := DynamoDbEncryptionUtil.DDBEC_EC_ATTR_PREFIX + sortName;
76-
:- Need(sortValueKey in context.Keys,
77-
MPL.AwsCryptographicMaterialProvidersException(
78-
message := "Invalid encryption context: Missing sort value"));
79-
attrMap :- AddAttributeToMap(sortValueKey, context[sortValueKey], attrMap);
80-
}
81-
8253
// Get branch key id from these DDB attributes
8354
var branchKeyIdR := ddbKeyBranchKeyIdSupplier.GetBranchKeyIdFromDdbKey(
84-
GetBranchKeyIdFromDdbKeyInput(ddbKey := attrMap)
85-
);
55+
GetBranchKeyIdFromDdbKeyInput(ddbKey := attrMap)
56+
);
57+
//= specification/dynamodb-encryption-client/ddb-encryption-branch-key-id-supplier.md#behavior
58+
//# - Otherwise, this operation MUST fail.
8659
var branchKeyIdOut :- branchKeyIdR.MapFailure(ConvertToMplError);
8760

61+
//= specification/dynamodb-encryption-client/ddb-encryption-branch-key-id-supplier.md#behavior
62+
//# - If successful, the resulting string MUST be outputted by this operation.
8863
return Success(MPL.GetBranchKeyIdOutput(branchKeyId:=branchKeyIdOut.branchKeyId));
8964
}
9065
}
9166

92-
function method AddAttributeToMap(ddbAttrKey: seq<uint8>, encodedAttrValue: seq<uint8>, attrMap: DDB.AttributeMap)
93-
: (res: Result<DDB.AttributeMap, MPL.Error>)
94-
requires |ddbAttrKey| >= |DynamoDbEncryptionUtil.DDBEC_EC_ATTR_PREFIX|
95-
{
96-
// Obtain attribute name from EC kvPair key
97-
var ddbAttrNameBytes := ddbAttrKey[|DynamoDbEncryptionUtil.DDBEC_EC_ATTR_PREFIX|..];
98-
var ddbAttrName :- UTF8.Decode(ddbAttrNameBytes)
99-
.MapFailure(e => MPL.AwsCryptographicMaterialProvidersException(message:=e));
100-
:- Need(DDB.IsValid_AttributeName(ddbAttrName),
101-
MPL.AwsCryptographicMaterialProvidersException(
102-
message := "Invalid serialization of DDB Attribute in encryption context."));
103-
104-
// Obtain attribute value from EC kvPair value
105-
var utf8DecodedVal :- UTF8.Decode(encodedAttrValue)
106-
.MapFailure(e => MPL.AwsCryptographicMaterialProvidersException(message:=e));
107-
var base64DecodedVal :- Base64.Decode(utf8DecodedVal)
108-
.MapFailure(e => MPL.AwsCryptographicMaterialProvidersException(message:=e));
109-
:- Need(|base64DecodedVal| >= 2,
110-
MPL.AwsCryptographicMaterialProvidersException(
111-
message := "Invalid serialization of DDB Attribute in encryption context."));
112-
var typeId := base64DecodedVal[..2];
113-
var serializedValue := base64DecodedVal[2..];
114-
var ddbAttrValue :- DynamoToStruct.BytesToAttr(serializedValue, typeId, false)
115-
.MapFailure(e => MPL.AwsCryptographicMaterialProvidersException(message:=e));
116-
117-
// Add to our AttributeMap
118-
Success(attrMap[ddbAttrName := ddbAttrValue.val])
119-
}
120-
12167
function method ConvertToMplError(err: Error)
12268
:(ret: MPL.Error)
12369
{

0 commit comments

Comments
 (0)