Skip to content

feat: add virtual fields #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Mar 22, 2023
Merged
2 changes: 2 additions & 0 deletions DynamoDbEncryptionMiddlewareInternal/src/DDBSupport.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module DynamoDBMiddlewareSupport {
import opened StandardLibrary.UInt
import opened BS = DynamoDBSupport
import opened DdbMiddlewareConfig
import AwsCryptographyDynamoDbItemEncryptorOperations

// IsWritable examines an AttributeMap and fails if it is unsuitable for writing.
// Generally this means that no attribute names starts with "aws_dbe_"
Expand Down Expand Up @@ -62,6 +63,7 @@ module DynamoDBMiddlewareSupport {
// returning a replacement AttributeMap.
function method {:opaque} AddBeacons(config : ValidTableConfig, item : DDB.AttributeMap)
: Result<DDB.AttributeMap, Error>
requires AwsCryptographyDynamoDbItemEncryptorOperations.ValidInternalConfig?(config.itemEncryptor.config)
{
BS.AddBeacons(config.itemEncryptor.config, item)
.MapFailure(e => E(e))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ module TransactWriteItemsTransform {
ensures output.Success? ==> |output.value.transformedInput.TransactItems| == |input.sdkInput.TransactItems|

//= specification/dynamodb-encryption-client/ddb-sdk-integration.md#encrypt-before-transactwriteitems
//= type=implication
//# To protect against a possible fifth field being added to the TransactWriteItem structure in the future,
//# the client MUST fail if none of the `Update`, `ConditionCheck`, `Delete` and `Put` fields are set.
ensures output.Success? ==>
forall item <- input.sdkInput.TransactItems :: IsValid(item)
{
:- Need(forall item <- input.sdkInput.TransactItems :: IsValid(item), E("Each item in TransactWriteItems must specify at least one operation"));
:- Need(forall item <- input.sdkInput.TransactItems :: IsValid(item), E("Each item in TransactWriteItems must specify at least one supported operation"));
var result : seq<DDB.TransactWriteItem> := [];
for x := 0 to |input.sdkInput.TransactItems|
invariant |result| == x
Expand Down Expand Up @@ -110,7 +109,8 @@ module TransactWriteItemsTransform {
//# the result [Encrypted DynamoDB Item](./encrypt-item.md#encrypted-dynamodb-item)
//# calculated above.
var put := Some(item.Put.value.(Item := encrypted.encryptedItem));
result := result + [item.(Put := put)];
var newItem := item.(Put := put);
result := result + [newItem];
} else {
//= specification/dynamodb-encryption-client/ddb-sdk-integration.md#encrypt-before-transactwriteitems
//# Any actions other than `Put, MUST be unchanged.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module TransactWriteItemsTransformTest {
sdkInput := input
)
);
ExpectFailure(transformed, "Each item in TransactWriteItems must specify at least one operation");
ExpectFailure(transformed, "Each item in TransactWriteItems must specify at least one supported operation");
}

method {:test} TestTransactWriteItemsOutputTransform() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
include "../Model/AwsCryptographyDynamoDbItemEncryptorTypes.dfy"
include "../../private-aws-encryption-sdk-dafny-staging/AwsCryptographicMaterialProviders/src/CMMs/ExpectedEncryptionContextCMM.dfy"
include "DynamoToStruct.dfy"
include "../../StructuredEncryption/src/SearchInfo.dfy"

module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptographyDynamoDbItemEncryptorOperations {
import opened StructuredEncryptionUtil
Expand All @@ -18,6 +19,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
import SE = StructuredEncryptionUtil
import MaterialProviders
import ExpectedEncryptionContextCMM
import opened SearchableEncryptionInfo

datatype Config = Config(
nameonly cmpClient : MaterialProviders.MaterialProvidersClient,
Expand All @@ -29,7 +31,8 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
nameonly allowedUnauthenticatedAttributes: Option<ComAmazonawsDynamodbTypes.AttributeNameList>,
nameonly allowedUnauthenticatedAttributePrefix: Option<string>,
nameonly algorithmSuiteId: Option<CMP.DBEAlgorithmSuiteId>,
nameonly structuredEncryption: StructuredEncryption.StructuredEncryptionClient
nameonly structuredEncryption: StructuredEncryption.StructuredEncryptionClient,
nameonly beacons : Option<SearchInfo>
// TODO legacy encryptor
// TODO legacy schema
)
Expand Down Expand Up @@ -266,6 +269,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
&& (forall attribute <- config.attributeActions.Keys ::
!(SE.ReservedPrefix <= attribute))

&& (config.beacons.Some? ==> config.beacons.value.ValidState())
}

function ModifiesInternalConfig(config: InternalConfig) : set<object>
Expand Down
Loading