@@ -20,7 +20,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
20
20
{ {} }
21
21
22
22
datatype Config = Config (
23
- )
23
+ )
24
24
25
25
type InternalConfig = Config
26
26
@@ -32,33 +32,33 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
32
32
input: CreateDynamoDbEncryptionBranchKeyIdSupplierInput
33
33
) returns (output: Result< CreateDynamoDbEncryptionBranchKeyIdSupplierOutput, Error> ) {
34
34
var supplier := new DynamoDbEncryptionBranchKeyIdSupplier. DynamoDbEncryptionBranchKeyIdSupplier (
35
- input.ddbKeyBranchKeyIdSupplier
35
+ input.ddbKeyBranchKeyIdSupplier
36
36
);
37
37
return Success (
38
38
CreateDynamoDbEncryptionBranchKeyIdSupplierOutput(
39
39
branchKeyIdSupplier := supplier
40
40
)
41
- );
41
+ );
42
42
}
43
43
predicate GetEncryptedDataKeyDescriptionEnsuresPublicly (input: GetEncryptedDataKeyDescriptionInput , output: Result <GetEncryptedDataKeyDescriptionOutput , Error>)
44
44
{true }
45
45
46
46
method GetEncryptedDataKeyDescription (config: InternalConfig , input: GetEncryptedDataKeyDescriptionInput )
47
47
returns (output: Result< GetEncryptedDataKeyDescriptionOutput, Error> )
48
48
ensures GetEncryptedDataKeyDescriptionEnsuresPublicly (input, output)
49
- ensures output. Success? ==> (
50
- match input. input {
51
- case plaintextItem (item) =>
52
- DynamoToStruct. ItemToStructured (item). Success?
53
- && var extracted := DynamoToStruct. ItemToStructured (item). Extract ();
54
- && var keys := extracted. Keys;
55
- && "aws_dbe_head" in DynamoToStruct. ItemToStructured (item). Extract ()
56
- && var header := DynamoToStruct. ItemToStructured (item). Extract ()["aws_dbe_head"]. content. Terminal. value;
57
- && Header. PartialDeserialize (header). Success?
58
- case header (header) =>
59
- Header. PartialDeserialize (header). Success?
60
- }
61
- )
49
+ ensures output. Success? ==> (
50
+ match input. input {
51
+ case plaintextItem (item) =>
52
+ DynamoToStruct. ItemToStructured (item). Success?
53
+ && var extracted := DynamoToStruct. ItemToStructured (item). Extract ();
54
+ && var keys := extracted. Keys;
55
+ && "aws_dbe_head" in DynamoToStruct. ItemToStructured (item). Extract ()
56
+ && var header := DynamoToStruct. ItemToStructured (item). Extract ()["aws_dbe_head"]. content. Terminal. value;
57
+ && Header. PartialDeserialize (header). Success?
58
+ case header (header) =>
59
+ Header. PartialDeserialize (header). Success?
60
+ }
61
+ )
62
62
{
63
63
var header;
64
64
match input. input
@@ -74,7 +74,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
74
74
:- Need (Header.PartialDeserialize(header). Success?, E ("Failed to deserialize header."));
75
75
var deserializedHeader := Header. PartialDeserialize (header);
76
76
var algorithmSuite;
77
-
77
+
78
78
if deserializedHeader. Extract (). flavor == 0{
79
79
algorithmSuite := AlgorithmSuites. DBE_ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY_SYMSIG_HMAC_SHA384;
80
80
} else {
@@ -85,7 +85,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
85
85
var list : EncryptedDataKeyDescriptionList := [];
86
86
for i := 0 to |datakeys| {
87
87
var singleDataKeyOutput : EncryptedDataKeyDescriptionOutput;
88
-
88
+
89
89
:- Need (UTF8.Decode(datakeys[i].keyProviderId). Success?, E ("Failed to extract keyProviderId."));
90
90
:- Need (UTF8.Decode(datakeys[i].keyProviderInfo). Success?, E ("Failed to extract keyProviderInfo."));
91
91
@@ -95,48 +95,48 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
95
95
if |extractedKeyProviderId| < 7 || extractedKeyProviderId[0.. 7] != "aws- kms" {
96
96
singleDataKeyOutput := EncryptedDataKeyDescriptionOutput (
97
97
keyProviderId := extractedKeyProviderId,
98
- keyProviderInfo := None,
98
+ keyProviderInfo := None,
99
99
branchKeyId := None,
100
100
branchKeyVersion := None
101
101
);
102
102
}
103
103
if extractedKeyProviderId == "aws- kms- hierarchy" {
104
104
:- Need (EdkWrapping.GetProviderWrappedMaterial(datakeys[i].ciphertext, algorithmSuite). Success?, E ("Failed to get provider wrapped material."));
105
-
105
+
106
106
var providerWrappedMaterial := EdkWrapping. GetProviderWrappedMaterial (datakeys[i].ciphertext, algorithmSuite). Extract ();
107
107
108
108
// The ciphertext structure in the hierarchy keyring contains Salt and IV before Version.
109
109
// The length of Salt is 16 and IV is 12 bytes. The length of Version is 16 bytes.
110
110
// https://github.com/awslabs/aws-encryption-sdk-specification/blob/master/framework/aws-kms/aws-kms-hierarchical-keyring.md#ciphertext
111
-
111
+
112
112
var EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX := 12 + 16;
113
113
var EDK_CIPHERTEXT_VERSION_INDEX := EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX + 16;
114
114
115
115
:- Need (EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX < EDK_CIPHERTEXT_VERSION_INDEX, E("Wrong branch key version index."));
116
116
:- Need (|providerWrappedMaterial| >= EDK_CIPHERTEXT_VERSION_INDEX, E("Incorrect ciphertext structure length."));
117
117
var branchKeyVersionUuid := providerWrappedMaterial[EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX .. EDK_CIPHERTEXT_VERSION_INDEX];
118
-
118
+
119
119
:- Need (UUID.FromByteArray(branchKeyVersionUuid). Success?, E ("Failed to convert UUID from byte array."));
120
120
var expectedBranchKeyVersion := UUID. FromByteArray (branchKeyVersionUuid). Extract ();
121
121
122
122
singleDataKeyOutput := EncryptedDataKeyDescriptionOutput (
123
123
keyProviderId := extractedKeyProviderId,
124
- keyProviderInfo := Some(extractedKeyProviderIdInfo),
124
+ keyProviderInfo := Some(extractedKeyProviderIdInfo),
125
125
branchKeyId := Some (extractedKeyProviderIdInfo),
126
126
branchKeyVersion := Some (expectedBranchKeyVersion)
127
127
);
128
128
}
129
129
else {
130
130
singleDataKeyOutput := EncryptedDataKeyDescriptionOutput (
131
131
keyProviderId := extractedKeyProviderId,
132
- keyProviderInfo := Some(extractedKeyProviderIdInfo),
132
+ keyProviderInfo := Some(extractedKeyProviderIdInfo),
133
133
branchKeyId := None,
134
134
branchKeyVersion := None
135
135
);
136
136
}
137
137
list := list + [singleDataKeyOutput];
138
138
}
139
-
139
+
140
140
output := Success (GetEncryptedDataKeyDescriptionOutput(
141
141
EncryptedDataKeyDescriptionOutput := list
142
142
));
0 commit comments