diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java index 7d75d2f9b2..1922791908 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java @@ -49,7 +49,9 @@ public static void ClientSupplierPutItemGetItem( String ddbTableName, String keyArn, List accountIds, - List regions + List regions, + String partitionKeyValue, + String sortKeyValue ) { // 1. Create a single MRK multi-keyring. // This can be either a single-region KMS key or an MRK. @@ -166,9 +168,9 @@ public static void ClientSupplierPutItemGetItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("clientSupplierItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -191,9 +193,9 @@ public static void ClientSupplierPutItemGetItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("clientSupplierItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -289,11 +291,11 @@ public static void ClientSupplierPutItemGetItem( new HashMap<>(); onlyReplicaKeyKeyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); onlyReplicaKeyKeyToGet.put( "sort_key", - AttributeValue.builder().n("0").build() + AttributeValue.builder().n(sortKeyValue).build() ); final GetItemRequest onlyReplicaKeyGetRequest = GetItemRequest @@ -347,6 +349,6 @@ public static void main(final String[] args) { ) { regions.add(args[i]); } - ClientSupplierPutItemGetItem(ddbTableName, keyArn, accounts, regions); + ClientSupplierPutItemGetItem(ddbTableName, keyArn, accounts, regions, "clientSupplierItem", "0"); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java index 3474b3094b..1e107480cb 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java @@ -38,7 +38,7 @@ and uses the high level putItem() and getItem() APIs to demonstrate */ public class EnhancedPutGetExample { - public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { + public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String partitionKeyValue, int sortKeyValue) { // 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data. // For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use. // We will use the `CreateMrkMultiKeyring` method to create this keyring, @@ -153,8 +153,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // The item will be encrypted client-side according to your // configuration above before it is sent to DynamoDb. final SimpleClass4 item = new SimpleClass4(); - item.setPartitionKey("EnhancedPutGetExample"); - item.setSortKey(0); + item.setPartitionKey(partitionKeyValue); + item.setSortKey(sortKeyValue); item.setAttribute1("encrypt and sign me!"); item.setAttribute2("sign me!"); item.setAttribute3("ignore me!"); @@ -167,8 +167,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // original item. final Key key = Key .builder() - .partitionValue("EnhancedPutGetExample") - .sortValue(0) + .partitionValue(partitionKeyValue) + .sortValue(sortKeyValue) .build(); final SimpleClass4 result = @@ -181,7 +181,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // retrieve the same record via a Query PageIterable items = table.query( - QueryConditional.keyEqualTo(k -> k.partitionValue("EnhancedPutGetExample") + QueryConditional.keyEqualTo(k -> k.partitionValue(partitionKeyValue) ) ); List itemList = new ArrayList(); @@ -199,6 +199,6 @@ public static void main(final String[] args) { } final String kmsKeyId = args[0]; final String ddbTableName = args[1]; - PutItemGetItem(kmsKeyId, ddbTableName); + PutItemGetItem(kmsKeyId, ddbTableName, "EnhancedPutGetExample", 0); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java index 4eff731ad1..f412f37f94 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java @@ -48,7 +48,7 @@ and uses the high level putItem() and getItem() APIs to demonstrate */ public class LombokPutGetExample { - public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { + public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String partitionKeyValue, int sortKeyValue) { // 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data. // For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use. // We will use the `CreateMrkMultiKeyring` method to create this keyring, @@ -163,8 +163,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // configuration above before it is sent to DynamoDb. final SimpleViaLombok.SimpleViaLombokBuilder itemBuilder = SimpleViaLombok.builder(); - itemBuilder.partitionKey("LombokPutGetExample"); - itemBuilder.sortKey(0); + itemBuilder.partitionKey(partitionKeyValue); + itemBuilder.sortKey(sortKeyValue); itemBuilder.attribute1("encrypt and sign me!"); itemBuilder.attribute2("sign me!"); itemBuilder.attribute3("ignore me!"); @@ -176,8 +176,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // original item. final Key key = Key .builder() - .partitionValue("LombokPutGetExample") - .sortValue(0) + .partitionValue(partitionKeyValue) + .sortValue(sortKeyValue) .build(); final SimpleViaLombok decrypted = @@ -252,6 +252,6 @@ public static void main(final String[] args) { } final String kmsKeyId = args[0]; final String ddbTableName = args[1]; - PutItemGetItem(kmsKeyId, ddbTableName); + PutItemGetItem(kmsKeyId, ddbTableName, "LombokPutGetExample", 0); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java index c0657017c0..d0469b3e86 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java @@ -37,7 +37,7 @@ and uses the high level putItem() and getItem() APIs to demonstrate */ public class SingleTableExample { - public static void TransactWriteItems(String kmsKeyId, String ddbTableName) { + public static void TransactWriteItems(String kmsKeyId, String ddbTableName, String partitionKeyPrefix, int sortKeyValue) { // 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data. // For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use. // We will use the `CreateMrkMultiKeyring` method to create this keyring, @@ -168,22 +168,22 @@ public static void TransactWriteItems(String kmsKeyId, String ddbTableName) { // The item will be encrypted client-side according to your // configuration above before it is sent to DynamoDb. final SimpleClass item1 = new SimpleClass(); - item1.setPartitionKey("EnhancedPutGetExample1"); - item1.setSortKey(0); + item1.setPartitionKey(partitionKeyPrefix + "1"); + item1.setSortKey(sortKeyValue); item1.setAttribute1("item1 encrypt and sign me!"); item1.setAttribute2("item1 sign me!"); item1.setAttribute3("item1 ignore me!"); final SimpleClass2 item2 = new SimpleClass2(); - item2.setPartitionKey("EnhancedPutGetExample2"); - item2.setSortKey(0); + item2.setPartitionKey(partitionKeyPrefix + "2"); + item2.setSortKey(sortKeyValue); item2.setAttribute4("item2 encrypt and sign me!"); item2.setAttribute5("item2 sign me!"); item2.setAttribute3("item2 ignore me!"); final SimpleClass3 item3 = new SimpleClass3(); - item3.setPartitionKey("EnhancedPutGetExample3"); - item3.setSortKey(0); + item3.setPartitionKey(partitionKeyPrefix + "3"); + item3.setSortKey(sortKeyValue); item3.setAttribute6("item3 encrypt and sign me!"); item3.setAttribute2("item3 sign me!"); item3.setAttribute7("item3 sign and include me!"); @@ -202,16 +202,16 @@ public static void TransactWriteItems(String kmsKeyId, String ddbTableName) { // The item will be decrypted client-side, and you will get back the // original item. final SimpleClass key1 = new SimpleClass(); - key1.setPartitionKey("EnhancedPutGetExample1"); - key1.setSortKey(0); + key1.setPartitionKey(partitionKeyPrefix + "1"); + key1.setSortKey(sortKeyValue); final SimpleClass2 key2 = new SimpleClass2(); - key2.setPartitionKey("EnhancedPutGetExample2"); - key2.setSortKey(0); + key2.setPartitionKey(partitionKeyPrefix + "2"); + key2.setSortKey(sortKeyValue); final SimpleClass3 key3 = new SimpleClass3(); - key3.setPartitionKey("EnhancedPutGetExample3"); - key3.setSortKey(0); + key3.setPartitionKey(partitionKeyPrefix + "3"); + key3.setSortKey(sortKeyValue); final TransactGetItemsEnhancedRequest getRequest = TransactGetItemsEnhancedRequest @@ -240,6 +240,6 @@ public static void main(final String[] args) { } final String kmsKeyId = args[0]; final String ddbTableName = args[1]; - TransactWriteItems(kmsKeyId, ddbTableName); + TransactWriteItems(kmsKeyId, ddbTableName, "EnhancedPutGetExample", 0); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java index 2ec8e61675..35f4f179c8 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java @@ -52,7 +52,7 @@ and uses the high level putItem() and getItem() APIs to demonstrate */ public class TableSchemaBuilderPutGetExample { - public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { + public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String partitionKeyValue, int sortKeyValue) { // 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data. // For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use. // We will use the `CreateMrkMultiKeyring` method to create this keyring, @@ -212,8 +212,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // The item will be encrypted client-side according to your // configuration above before it is sent to DynamoDb. final SimpleClass item = new SimpleClass(); - item.setPartitionKey("TableSchemaBuilderPutGetExample"); - item.setSortKey(0); + item.setPartitionKey(partitionKeyValue); + item.setSortKey(sortKeyValue); item.setAttribute1("encrypt and sign me!"); item.setAttribute2("sign me!"); item.setAttribute3("ignore me!"); @@ -224,8 +224,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // original item. final Key key = Key .builder() - .partitionValue("TableSchemaBuilderPutGetExample") - .sortValue(0) + .partitionValue(partitionKeyValue) + .sortValue(sortKeyValue) .build(); final SimpleClass decrypted = @@ -303,6 +303,6 @@ public static void main(final String[] args) { } final String kmsKeyId = args[0]; final String ddbTableName = args[1]; - PutItemGetItem(kmsKeyId, ddbTableName); + PutItemGetItem(kmsKeyId, ddbTableName, "TableSchemaBuilderPutGetExample", 0); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java index ea6b296054..59848ecbf1 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java @@ -34,7 +34,7 @@ */ public class ItemEncryptDecryptExample { - public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { + public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String partitionKeyValue, String sortKeyValue) { // 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data. // For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use. // We will use the `CreateMrkMultiKeyring` method to create this keyring, @@ -124,9 +124,9 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { final Map originalItem = new HashMap<>(); originalItem.put( "partition_key", - AttributeValue.builder().s("ItemEncryptDecryptExample").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - originalItem.put("sort_key", AttributeValue.builder().n("0").build()); + originalItem.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); originalItem.put( "attribute1", AttributeValue.builder().s("encrypt and sign me!").build() @@ -150,8 +150,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { assert encryptedItem .get("partition_key") .s() - .equals("ItemEncryptDecryptExample"); - assert encryptedItem.get("sort_key").n().equals("0"); + .equals(partitionKeyValue); + assert encryptedItem.get("sort_key").n().equals(sortKeyValue); assert encryptedItem.get("attribute1").b() != null; // 7. Directly decrypt the encrypted item using the DynamoDb Item Encryptor @@ -165,8 +165,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { assert decryptedItem .get("partition_key") .s() - .equals("ItemEncryptDecryptExample"); - assert decryptedItem.get("sort_key").n().equals("0"); + .equals(partitionKeyValue); + assert decryptedItem.get("sort_key").n().equals(sortKeyValue); assert decryptedItem.get("attribute1").s().equals("encrypt and sign me!"); } @@ -178,6 +178,6 @@ public static void main(final String[] args) { } final String kmsKeyId = args[0]; final String ddbTableName = args[1]; - PutItemGetItem(kmsKeyId, ddbTableName); + PutItemGetItem(kmsKeyId, ddbTableName, "ItemEncryptDecryptExample", "0"); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java index a0ad297bb3..1178e61c35 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java @@ -76,7 +76,9 @@ public static void HierarchicalKeyringGetItemPutItem( String tenant2BranchKeyId, String keyStoreTableName, String logicalKeyStoreName, - String kmsKeyId + String kmsKeyId, + String partitionKeyValue, + String sortKeyValue ) { // Initial KeyStore Setup: This example requires that you have already // created your KeyStore, and have populated it with two new branch keys. @@ -235,8 +237,8 @@ public static void HierarchicalKeyringGetItemPutItem( // based on the code we wrote in the ExampleBranchKeySupplier, // `tenant1BranchKeyId` will be used to encrypt this item. final HashMap item = new HashMap<>(); - item.put("partition_key", AttributeValue.builder().s("tenant1Id").build()); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("partition_key", AttributeValue.builder().s(partitionKeyValue).build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "tenant_sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -262,9 +264,9 @@ public static void HierarchicalKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("tenant1Id").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -302,7 +304,9 @@ public static void main(final String[] args) { tenant2BranchKeyId, keyStoreTableName, logicalKeyStoreName, - kmsKeyId + kmsKeyId, + "tenant1Id", + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java index bb9978d4db..c6a51e2335 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java @@ -111,7 +111,9 @@ public static void KmsEcdhKeyringGetItemPutItem( String ddbTableName, String eccKeyArn, String eccPublicKeySenderFileName, - String eccPublicKeyRecipientFileName + String eccPublicKeyRecipientFileName, + String partitionKeyValue, + String sortKeyValue ) { // Load UTF-8 encoded public key PEM files as DER encoded bytes. // You may provide your own PEM files to use here. If you provide this, it MUST @@ -174,7 +176,7 @@ public static void KmsEcdhKeyringGetItemPutItem( createAwsKmsEcdhKeyringInput ); - PutGetItemWithKeyring(kmsEcdhKeyring, ddbTableName); + PutGetItemWithKeyring(kmsEcdhKeyring, ddbTableName, partitionKeyValue, sortKeyValue); } /* @@ -200,7 +202,9 @@ public static void KmsEcdhKeyringGetItemPutItem( */ public static void KmsEcdhDiscoveryGetItem( String ddbTableName, - String eccRecipientKeyArn + String eccRecipientKeyArn, + String partitionKeyValue, + String sortKeyValue ) { // Create a KMS ECDH keyring. // This keyring uses the KmsPublicKeyDiscovery configuration. @@ -240,12 +244,14 @@ public static void KmsEcdhDiscoveryGetItem( createAwsKmsEcdhKeyringInput ); - GetItemWithKeyring(kmsEcdhKeyring, ddbTableName); + GetItemWithKeyring(kmsEcdhKeyring, ddbTableName, partitionKeyValue, sortKeyValue); } private static void GetItemWithKeyring( IKeyring kmsEcdhKeyring, - String ddbTableName + String ddbTableName, + String partitionKeyValue, + String sortKeyValue ) { // Configure which attributes are encrypted and/or signed when writing new items. // For each attribute that may exist on the items we plan to write to our DynamoDbTable, @@ -339,9 +345,9 @@ private static void GetItemWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsEcdhKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -362,7 +368,9 @@ private static void GetItemWithKeyring( private static void PutGetItemWithKeyring( IKeyring awsKmsEcdhKeyring, - String ddbTableName + String ddbTableName, + String partitionKeyValue, + String sortKeyValue ) { // Configure which attributes are encrypted and/or signed when writing new items. // For each attribute that may exist on the items we plan to write to our DynamoDbTable, @@ -456,9 +464,9 @@ private static void PutGetItemWithKeyring( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("awsKmsEcdhKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -481,9 +489,9 @@ private static void PutGetItemWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsEcdhKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -548,7 +556,9 @@ public static void KmsEcdhKeyringGetItemPutItem( ddbTableName, eccKeyArn, EXAMPLE_ECC_PUBLIC_KEY_SENDER_FILENAME, - EXAMPLE_ECC_PUBLIC_KEY_RECIPIENT_FILENAME + EXAMPLE_ECC_PUBLIC_KEY_RECIPIENT_FILENAME, + "awsKmsEcdhKeyringItem", + "0" ); } @@ -609,7 +619,9 @@ public static void main(final String[] args) { ddbTableName, eccKeyArn, eccPublicKeySenderFilename, - eccPublicKeyRecipientFilename + eccPublicKeyRecipientFilename, + "awsKmsEcdhKeyringItem", + "0" ); } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java index cd02dd4595..80af96885e 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java @@ -68,7 +68,9 @@ public class KmsRsaKeyringExample { public static void KmsRsaKeyringGetItemPutItem( String ddbTableName, String rsaKeyArn, - String rsaPublicKeyFilename + String rsaPublicKeyFilename, + String partitionKeyValue, + String sortKeyValue ) { // 1. Load UTF-8 encoded public key PEM file. // You may have an RSA public key file already defined. @@ -201,9 +203,9 @@ public static void KmsRsaKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("awsKmsRsaKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -226,9 +228,9 @@ public static void KmsRsaKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsRsaKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -249,12 +251,16 @@ public static void KmsRsaKeyringGetItemPutItem( public static void KmsRsaKeyringGetItemPutItem( String ddbTableName, - String rsaKeyArn + String rsaKeyArn, + String partitionKeyValue, + String sortKeyValue ) { KmsRsaKeyringGetItemPutItem( ddbTableName, rsaKeyArn, - DEFAULT_EXAMPLE_RSA_PUBLIC_KEY_FILENAME + DEFAULT_EXAMPLE_RSA_PUBLIC_KEY_FILENAME, + partitionKeyValue, + sortKeyValue ); } @@ -280,7 +286,7 @@ public static void main(final String[] args) { writePublicKeyPemForRsaKey(rsaKeyArn, rsaPublicKeyFilename); } - KmsRsaKeyringGetItemPutItem(ddbTableName, rsaKeyArn, rsaPublicKeyFilename); + KmsRsaKeyringGetItemPutItem(ddbTableName, rsaKeyArn, rsaPublicKeyFilename, "awsKmsRsaKeyringItem", "0"); } static boolean shouldGetNewPublicKey() { diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java index 7f896876c3..95c142f1f6 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java @@ -50,7 +50,9 @@ public static void MultiMrkDiscoveryKeyringGetItemPutItem( String ddbTableName, String keyArn, List accountIds, - List regions + List regions, + String partitionKeyValue, + String sortKeyValue ) { // 1. Create a single MRK multi-keyring using the key arn. // Although this example demonstrates use of the MRK discovery multi-keyring, @@ -157,9 +159,9 @@ public static void MultiMrkDiscoveryKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkDiscoveryMultiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -250,9 +252,9 @@ public static void MultiMrkDiscoveryKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkDiscoveryMultiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -307,7 +309,9 @@ public static void main(final String[] args) { ddbTableName, mrkArn, accounts, - regions + regions, + "awsKmsMrkDiscoveryMultiKeyringItem", + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java index 635f637c23..cfae59e4a0 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java @@ -65,7 +65,9 @@ public class MultiKeyringExample { public static void MultiKeyringGetItemPutItem( String ddbTableName, String keyArn, - ByteBuffer aesKeyBytes + ByteBuffer aesKeyBytes, + String partitionKeyValue, + String sortKeyValue ) { // 1. Create the raw AES keyring. final MaterialProviders matProv = MaterialProviders @@ -203,9 +205,9 @@ public static void MultiKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("multiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -230,9 +232,9 @@ public static void MultiKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("multiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -298,11 +300,11 @@ public static void MultiKeyringGetItemPutItem( new HashMap<>(); onlyAesKeyringKeyToGet.put( "partition_key", - AttributeValue.builder().s("multiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); onlyAesKeyringKeyToGet.put( "sort_key", - AttributeValue.builder().n("0").build() + AttributeValue.builder().n(sortKeyValue).build() ); final GetItemRequest onlyAesKeyringGetRequest = GetItemRequest @@ -336,7 +338,7 @@ public static void main(final String[] args) { // Generate a new AES key ByteBuffer aesKeyBytes = generateAesKeyBytes(); - MultiKeyringGetItemPutItem(ddbTableName, keyArn, aesKeyBytes); + MultiKeyringGetItemPutItem(ddbTableName, keyArn, aesKeyBytes, "multiKeyringItem", "0"); } static ByteBuffer generateAesKeyBytes() { diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java index 3024a67397..aad5170462 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java @@ -73,7 +73,9 @@ public static void MultiMrkKeyringGetItemPutItem( String ddbTableName, String mrkKeyArn, String keyArn, - String mrkReplicaKeyArn + String mrkReplicaKeyArn, + String partitionKeyValue, + String sortKeyValue ) { // 1. Create a single MRK multi-keyring using the MRK arn and the single-region key arn. final MaterialProviders matProv = MaterialProviders @@ -187,9 +189,9 @@ public static void MultiMrkKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -214,9 +216,9 @@ public static void MultiMrkKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -296,11 +298,11 @@ public static void MultiMrkKeyringGetItemPutItem( new HashMap<>(); onlyReplicaKeyKeyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); onlyReplicaKeyKeyToGet.put( "sort_key", - AttributeValue.builder().n("0").build() + AttributeValue.builder().n(sortKeyValue).build() ); final GetItemRequest onlyReplicaKeyGetRequest = GetItemRequest @@ -378,9 +380,9 @@ public static void MultiMrkKeyringGetItemPutItem( final HashMap onlySrkKeyToGet = new HashMap<>(); onlySrkKeyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - onlySrkKeyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + onlySrkKeyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest onlySrkGetRequest = GetItemRequest .builder() @@ -416,7 +418,9 @@ public static void main(final String[] args) { ddbTableName, mrkKeyArn, srkArn, - mrkReplicaKeyArn + mrkReplicaKeyArn, + "awsKmsMrkMultiKeyringItem", + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java index 5ef15b1f1b..fa4f01b22e 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java @@ -52,7 +52,9 @@ public class RawAesKeyringExample { public static void RawAesKeyringGetItemPutItem( String ddbTableName, - ByteBuffer aesKeyBytes + ByteBuffer aesKeyBytes, + String partitionKeyValue, + String sortKeyValue ) { // 1. Create the keyring. // The DynamoDb encryption client uses this to encrypt and decrypt items. @@ -156,9 +158,9 @@ public static void RawAesKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("rawAesKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -181,9 +183,9 @@ public static void RawAesKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("rawAesKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -213,7 +215,7 @@ public static void main(final String[] args) { // Generate a new AES key ByteBuffer aesKeyBytes = generateAesKeyBytes(); - RawAesKeyringGetItemPutItem(ddbTableName, aesKeyBytes); + RawAesKeyringGetItemPutItem(ddbTableName, aesKeyBytes, "rawAesKeyringItem", "0"); } static ByteBuffer generateAesKeyBytes() { diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java index 97fbac6f0c..a88d56d721 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java @@ -101,7 +101,9 @@ public class RawEcdhKeyringExample { */ public static void RawEcdhKeyringGetItemPutItem( String ddbTableName, - ECDHCurveSpec curveSpec + ECDHCurveSpec curveSpec, + String partitionKeyValue, + String sortKeyValue ) { // Load key pair from UTF-8 encoded PEM files. // You may provide your own PEM files to use here. If you provide this, it MUST @@ -190,7 +192,7 @@ public static void RawEcdhKeyringGetItemPutItem( .build(); IKeyring rawEcdhKeyring = matProv.CreateRawEcdhKeyring(keyringInput); - PutGetExampleWithKeyring(rawEcdhKeyring, ddbTableName); + PutGetExampleWithKeyring(rawEcdhKeyring, ddbTableName, partitionKeyValue, sortKeyValue); } /* @@ -205,7 +207,9 @@ public static void RawEcdhKeyringGetItemPutItem( */ public static void EphemeralRawEcdhKeyringPutItem( String ddbTableName, - ECDHCurveSpec ecdhCurveSpec + ECDHCurveSpec ecdhCurveSpec, + String partitionKeyValue, + String sortKeyValue ) { // Load public key from UTF-8 encoded PEM files into a DER encoded public key. // You may provide your own PEM files to use here. If you provide this, it MUST @@ -278,7 +282,7 @@ public static void EphemeralRawEcdhKeyringPutItem( // A raw ecdh keyring with Ephemeral configuration cannot decrypt data since the key pair // used as the sender is ephemeral. This means that at decrypt time it does not have // the private key that corresponds to the public key that is stored on the message. - PutExampleWithKeyring(rawEcdhKeyring, ddbTableName); + PutExampleWithKeyring(rawEcdhKeyring, ddbTableName, partitionKeyValue, sortKeyValue); } /* @@ -293,7 +297,9 @@ public static void EphemeralRawEcdhKeyringPutItem( */ public static void DiscoveryRawEcdhKeyringGetItem( String ddbTableName, - ECDHCurveSpec ecdhCurveSpec + ECDHCurveSpec ecdhCurveSpec, + String partitionKeyValue, + String sortKeyValue ) { // Load key pair from UTF-8 encoded PEM files. // You may provide your own PEM files to use here. If you provide this, it MUST @@ -344,12 +350,14 @@ public static void DiscoveryRawEcdhKeyringGetItem( // A raw ecdh keyring with discovery configuration cannot encrypt data since the keyring // looks for its configured public key on the message. - GetExampleWithKeyring(rawEcdhKeyring, ddbTableName); + GetExampleWithKeyring(rawEcdhKeyring, ddbTableName, partitionKeyValue, sortKeyValue); } public static void PutGetExampleWithKeyring( IKeyring rawEcdhKeyring, - String ddbTableName + String ddbTableName, + String partitionKeyValue, + String sortKeyValue ) { // Configure which attributes are encrypted and/or signed when writing new items. // For each attribute that may exist on the items we plan to write to our DynamoDbTable, @@ -438,9 +446,9 @@ public static void PutGetExampleWithKeyring( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("rawEcdhKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -463,9 +471,9 @@ public static void PutGetExampleWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("rawEcdhKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -486,7 +494,9 @@ public static void PutGetExampleWithKeyring( public static void PutExampleWithKeyring( IKeyring rawEcdhKeyring, - String ddbTableName + String ddbTableName, + String partitionKeyValue, + String sortKeyValue ) { // Configure which attributes are encrypted and/or signed when writing new items. // For each attribute that may exist on the items we plan to write to our DynamoDbTable, @@ -575,9 +585,9 @@ public static void PutExampleWithKeyring( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("rawEcdhKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -597,7 +607,9 @@ public static void PutExampleWithKeyring( public static void GetExampleWithKeyring( IKeyring rawEcdhKeyring, - String ddbTableName + String ddbTableName, + String partitionKeyValue, + String sortKeyValue ) { // Configure which attributes are encrypted and/or signed when writing new items. // For each attribute that may exist on the items we plan to write to our DynamoDbTable, @@ -685,9 +697,9 @@ public static void GetExampleWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("rawEcdhKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -720,7 +732,7 @@ public static void main(final String[] args) { } final String ddbTableName = args[0]; - RawEcdhKeyringGetItemPutItem(ddbTableName, ECDHCurveSpec.ECC_NIST_P256); + RawEcdhKeyringGetItemPutItem(ddbTableName, ECDHCurveSpec.ECC_NIST_P256, "rawEcdhKeyringItem", "0"); } public static boolean shouldGenerateNewEccKeyPairs() { diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java index e5b9e608e3..064152110e 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java @@ -76,7 +76,7 @@ public class RawRsaKeyringExample { private static String EXAMPLE_RSA_PUBLIC_KEY_FILENAME = "RawRsaKeyringExamplePublicKey.pem"; - public static void RawRsaKeyringGetItemPutItem(String ddbTableName) { + public static void RawRsaKeyringGetItemPutItem(String ddbTableName, String partitionKeyValue, String sortKeyValue) { // 1. Load key pair from UTF-8 encoded PEM files. // You may provide your own PEM files to use here. // If you do not, the main method in this class will generate PEM @@ -210,9 +210,9 @@ public static void RawRsaKeyringGetItemPutItem(String ddbTableName) { final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("rawRsaKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -235,9 +235,9 @@ public static void RawRsaKeyringGetItemPutItem(String ddbTableName) { final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("rawRsaKeyringItem").build() + AttributeValue.builder().s(partitionKeyValue).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -272,7 +272,7 @@ public static void main(final String[] args) { generateRsaKeyPair(); } - RawRsaKeyringGetItemPutItem(ddbTableName); + RawRsaKeyringGetItemPutItem(ddbTableName, "rawRsaKeyringItem", "0"); } static boolean shouldGenerateNewRsaKeyPair() { diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java index dfed4b84de..8db2515d73 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java @@ -100,7 +100,9 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem( String keyStoreTableName, String logicalKeyStoreName, String partitionId, - String kmsKeyId + String kmsKeyId, + String partitionKeyValue, + String sortKeyValue ) { // 1. Create the CryptographicMaterialsCache (CMC) to share across multiple Hierarchical Keyrings // using the Material Providers Library @@ -202,7 +204,7 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem( ); // 6. Encrypt Decrypt roundtrip with ddbClient1 - PutGetItems(ddbTableName, ddbClient1); + PutGetItems(ddbTableName, ddbClient1, partitionKeyValue, sortKeyValue); // Through the above encrypt and decrypt roundtrip, the cache will be populated and // the cache entries can be used by another Hierarchical Keyring with the @@ -270,7 +272,7 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem( ); // 10. Encrypt Decrypt roundtrip with ddbClient2 - PutGetItems(ddbTableName, ddbClient2); + PutGetItems(ddbTableName, ddbClient2, partitionKeyValue, sortKeyValue); } public static DynamoDbClient GetDdbClient( @@ -350,7 +352,9 @@ public static DynamoDbClient GetDdbClient( public static void PutGetItems( String ddbTableName, - DynamoDbClient ddbClient + DynamoDbClient ddbClient, + String partitionKeyValue, + String sortKeyValue ) { // Put an item into our table using the given ddb client. // Before the item gets sent to DynamoDb, it will be encrypted @@ -359,8 +363,8 @@ public static void PutGetItems( // BranchKeyIdSupplier as per your use-case. See the HierarchicalKeyringsExample.java for more // information. final HashMap item = new HashMap<>(); - item.put("partition_key", AttributeValue.builder().s("id").build()); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("partition_key", AttributeValue.builder().s(partitionKeyValue).build()); + item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -384,8 +388,8 @@ public static void PutGetItems( // BranchKeyIdSupplier as per your use-case. See the HierarchicalKeyringsExample.java for more // information. final HashMap keyToGet = new HashMap<>(); - keyToGet.put("partition_key", AttributeValue.builder().s("id").build()); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("partition_key", AttributeValue.builder().s(partitionKeyValue).build()); + keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -423,7 +427,9 @@ public static void main(final String[] args) { keyStoreTableName, logicalKeyStoreName, partitionId, - kmsKeyId + kmsKeyId, + "id", + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 8434693712..afe7382afb 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -66,7 +66,8 @@ public static void PutItemQueryItemWithBeacon( String ddbTableName, String branchKeyId, String branchKeyWrappingKmsKeyArn, - String branchKeyDdbTableName + String branchKeyDdbTableName, + String workId ) { // 1. Configure Beacons. // The beacon name must be the name of a table attribute that will be encrypted. @@ -318,7 +319,7 @@ public static void PutItemQueryItemWithBeacon( final HashMap item = new HashMap<>(); item.put( "work_id", - AttributeValue.builder().s("1313ba89-5661-41eb-ba6c-cb1b4cb67b2d").build() + AttributeValue.builder().s(workId).build() ); item.put( "inspection_date", @@ -416,7 +417,8 @@ public static void main(final String[] args) { ddbTableName, branchKeyId, branchKeyWrappingKmsKeyArn, - branchKeyDdbTableName + branchKeyDdbTableName, + "1313ba89-5661-41eb-ba6c-cb1b4cb67b2d" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BeaconStylesSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BeaconStylesSearchableEncryptionExample.java index 65714e0eba..d1bcd00f70 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BeaconStylesSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BeaconStylesSearchableEncryptionExample.java @@ -77,7 +77,8 @@ public static void PutItemQueryItemWithBeaconStyles( String ddbTableName, String branchKeyId, String branchKeyWrappingKmsKeyArn, - String branchKeyDdbTableName + String branchKeyDdbTableName, + String workId ) { // 1. Create Beacons. List standardBeaconList = new ArrayList<>(); @@ -276,7 +277,7 @@ public static void PutItemQueryItemWithBeaconStyles( // 8. Create item one, specifically with "dessert != fruit", and "fruit in basket". final HashMap item1 = new HashMap<>(); - item1.put("work_id", AttributeValue.builder().s("1").build()); + item1.put("work_id", AttributeValue.builder().s(workId + "-1").build()); item1.put( "inspection_date", AttributeValue.builder().s("2023-06-13").build() @@ -297,7 +298,7 @@ public static void PutItemQueryItemWithBeaconStyles( // 9. Create item two, specifically with "dessert == fruit", and "fruit not in basket". final HashMap item2 = new HashMap<>(); - item2.put("work_id", AttributeValue.builder().s("2").build()); + item2.put("work_id", AttributeValue.builder().s(workId + "-2").build()); item2.put( "inspection_date", AttributeValue.builder().s("2023-06-13").build() @@ -460,7 +461,7 @@ public static void PutItemQueryItemWithBeaconStyles( // 17. Test the compound beacon 'work_unit' : expressionAttributeValues.put( ":value", - AttributeValue.builder().s("I-1.T-small").build() + AttributeValue.builder().s("I-" + workId + "-1.T-small").build() ); scanRequest = @@ -495,7 +496,8 @@ public static void main(final String[] args) { ddbTableName, branchKeyId, branchKeyWrappingKmsKeyId, - branchKeyDdbTableName + branchKeyDdbTableName, + "beacon-styles-test" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java index ce837a51e5..96daec1805 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java @@ -85,7 +85,8 @@ public static void PutItemQueryItemWithCompoundBeacon( String ddbTableName, String branchKeyId, String branchKeyWrappingKmsKeyArn, - String branchKeyDdbTableName + String branchKeyDdbTableName, + String workId ) { // 1. Create Beacons. // These are the same beacons as in the "BasicSearchableEncryptionExample" in this directory. @@ -286,7 +287,7 @@ public static void PutItemQueryItemWithCompoundBeacon( final HashMap item = new HashMap<>(); item.put( "work_id", - AttributeValue.builder().s("9ce39272-8068-4efd-a211-cd162ad65d4c").build() + AttributeValue.builder().s(workId).build() ); item.put( "inspection_date", @@ -448,7 +449,8 @@ public static void main(final String[] args) { ddbTableName, branchKeyId, branchKeyWrappingKmsKeyId, - branchKeyDdbTableName + branchKeyDdbTableName, + "9ce39272-8068-4efd-a211-cd162ad65d4c" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/VirtualBeaconSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/VirtualBeaconSearchableEncryptionExample.java index 0d9f23da14..3500ba0e58 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/VirtualBeaconSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/VirtualBeaconSearchableEncryptionExample.java @@ -134,7 +134,8 @@ public static void PutItemQueryItemWithVirtualBeacon( String ddbTableName, String branchKeyId, String branchKeyWrappingKmsKeyArn, - String branchKeyDdbTableName + String branchKeyDdbTableName, + String customerId ) { // 1. Construct a length-1 prefix virtual transform. // `hasTestResult` is a binary attribute, containing either `true` or `false`. @@ -366,7 +367,7 @@ public static void PutItemQueryItemWithVirtualBeacon( new HashMap<>(); itemWithHasTestResult.put( "customer_id", - AttributeValue.builder().s("ABC-123").build() + AttributeValue.builder().s(customerId + "-1").build() ); itemWithHasTestResult.put( "create_time", @@ -386,7 +387,7 @@ public static void PutItemQueryItemWithVirtualBeacon( new HashMap<>(); itemWithNoHasTestResult.put( "customer_id", - AttributeValue.builder().s("DEF-456").build() + AttributeValue.builder().s(customerId + "-2").build() ); itemWithNoHasTestResult.put( "create_time", @@ -561,7 +562,8 @@ public static void main(final String[] args) { ddbTableName, branchKeyId, branchKeyWrappingKmsKeyArn, - branchKeyDdbTableName + branchKeyDdbTableName, + "virtual-beacon-test" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/ComplexSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/ComplexSearchableEncryptionExample.java index 6f32430a95..d621afbe86 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/ComplexSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/ComplexSearchableEncryptionExample.java @@ -18,7 +18,8 @@ public static void runExample( String ddbTableName, String branchKeyId, String branchKeyWrappingKmsKeyArn, - String branchKeyDdbTableName + String branchKeyDdbTableName, + String partitionKeyPrefix ) { DynamoDbClient ddb = BeaconConfig.SetupBeaconConfig( ddbTableName, @@ -26,26 +27,28 @@ public static void runExample( branchKeyWrappingKmsKeyArn, branchKeyDdbTableName ); - PutRequests.putAllItemsToTable(ddbTableName, ddb); - QueryRequests.runQueries(ddbTableName, ddb); + PutRequests.putAllItemsToTable(ddbTableName, ddb, partitionKeyPrefix); + QueryRequests.runQueries(ddbTableName, ddb, partitionKeyPrefix); } public static void main(final String[] args) { if (args.length <= 1) { throw new IllegalArgumentException( "To run this example, include ddbTableName as args[0], " + - "branchKeyId as args[1], branchKeyWrappingKmsKeyId as args[2], and branchKeyDdbTableName as args[3]" + "branchKeyId as args[1], branchKeyWrappingKmsKeyId as args[2], branchKeyDdbTableName as args[3], and partitionKeyPrefix as args[4]" ); } final String ddbTableName = args[0]; final String branchKeyId = args[1]; final String branchKeyWrappingKmsKeyId = args[2]; final String branchKeyDdbTableName = args[3]; + final String partitionKeyPrefix = args.length > 4 ? args[4] : ""; runExample( ddbTableName, branchKeyId, branchKeyWrappingKmsKeyId, - branchKeyDdbTableName + branchKeyDdbTableName, + partitionKeyPrefix ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/PutRequests.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/PutRequests.java index 09a716358f..36383800f4 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/PutRequests.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/PutRequests.java @@ -28,20 +28,22 @@ public class PutRequests { public static void putAllItemsToTable( String ddbTableName, - DynamoDbClient ddb + DynamoDbClient ddb, + String partitionKeyPrefix ) { - putAllMeetingItemsToTable(ddbTableName, ddb); - putAllEmployeeItemsToTable(ddbTableName, ddb); - putAllProjectItemsToTable(ddbTableName, ddb); - putAllReservationItemsToTable(ddbTableName, ddb); - putAllTicketItemsToTable(ddbTableName, ddb); - putAllTimecardItemsToTable(ddbTableName, ddb); + putAllMeetingItemsToTable(ddbTableName, ddb, partitionKeyPrefix); + putAllEmployeeItemsToTable(ddbTableName, ddb, partitionKeyPrefix); + putAllProjectItemsToTable(ddbTableName, ddb, partitionKeyPrefix); + putAllReservationItemsToTable(ddbTableName, ddb, partitionKeyPrefix); + putAllTicketItemsToTable(ddbTableName, ddb, partitionKeyPrefix); + putAllTimecardItemsToTable(ddbTableName, ddb, partitionKeyPrefix); } // emeeting.json public static void putAllMeetingItemsToTable( String ddbTableName, - DynamoDbClient ddb + DynamoDbClient ddb, + String partitionKeyPrefix ) { final List meeting1AttendeeList = new ArrayList<>(); meeting1AttendeeList.add( @@ -58,7 +60,7 @@ public static void putAllMeetingItemsToTable( final HashMap meeting1 = new HashMap<>(); meeting1.put( "partition_key", - AttributeValue.builder().s("meeting1").build() + AttributeValue.builder().s(partitionKeyPrefix + "meeting1").build() ); meeting1.put("EmployeeID", AttributeValue.builder().s("emp_001").build()); meeting1.put( @@ -99,7 +101,7 @@ public static void putAllMeetingItemsToTable( final HashMap meeting2 = new HashMap<>(); meeting2.put( "partition_key", - AttributeValue.builder().s("meeting2").build() + AttributeValue.builder().s(partitionKeyPrefix + "meeting2").build() ); meeting2.put("EmployeeID", AttributeValue.builder().s("emp_002").build()); meeting2.put( @@ -140,7 +142,7 @@ public static void putAllMeetingItemsToTable( final HashMap meeting3 = new HashMap<>(); meeting3.put( "partition_key", - AttributeValue.builder().s("meeting3").build() + AttributeValue.builder().s(partitionKeyPrefix + "meeting3").build() ); meeting3.put("EmployeeID", AttributeValue.builder().s("emp_003").build()); meeting3.put( @@ -181,7 +183,7 @@ public static void putAllMeetingItemsToTable( final HashMap meeting4 = new HashMap<>(); meeting4.put( "partition_key", - AttributeValue.builder().s("meeting4").build() + AttributeValue.builder().s(partitionKeyPrefix + "meeting4").build() ); meeting4.put("EmployeeID", AttributeValue.builder().s("emp_004").build()); meeting4.put( @@ -222,7 +224,7 @@ public static void putAllMeetingItemsToTable( final HashMap meeting5 = new HashMap<>(); meeting5.put( "partition_key", - AttributeValue.builder().s("meeting5").build() + AttributeValue.builder().s(partitionKeyPrefix + "meeting5").build() ); meeting5.put("EmployeeID", AttributeValue.builder().s("emp_002").build()); meeting5.put( @@ -263,7 +265,7 @@ public static void putAllMeetingItemsToTable( final HashMap meeting6 = new HashMap<>(); meeting6.put( "partition_key", - AttributeValue.builder().s("meeting6").build() + AttributeValue.builder().s(partitionKeyPrefix + "meeting6").build() ); meeting6.put("EmployeeID", AttributeValue.builder().s("emp_003").build()); meeting6.put( @@ -293,7 +295,8 @@ public static void putAllMeetingItemsToTable( // employee.json public static void putAllEmployeeItemsToTable( String ddbTableName, - DynamoDbClient ddb + DynamoDbClient ddb, + String partitionKeyPrefix ) { final HashMap employee1Location = new HashMap<>(); employee1Location.put("Building", AttributeValue.builder().s("44").build()); @@ -307,7 +310,7 @@ public static void putAllEmployeeItemsToTable( final HashMap employee1 = new HashMap<>(); employee1.put( "partition_key", - AttributeValue.builder().s("employee1").build() + AttributeValue.builder().s(partitionKeyPrefix + "employee1").build() ); employee1.put("EmployeeID", AttributeValue.builder().s("emp_001").build()); employee1.put( @@ -344,7 +347,7 @@ public static void putAllEmployeeItemsToTable( final HashMap employee2 = new HashMap<>(); employee2.put( "partition_key", - AttributeValue.builder().s("employee2").build() + AttributeValue.builder().s(partitionKeyPrefix + "employee2").build() ); employee2.put("EmployeeID", AttributeValue.builder().s("emp_002").build()); employee2.put( @@ -381,7 +384,7 @@ public static void putAllEmployeeItemsToTable( final HashMap employee3 = new HashMap<>(); employee3.put( "partition_key", - AttributeValue.builder().s("employee3").build() + AttributeValue.builder().s(partitionKeyPrefix + "employee3").build() ); employee3.put("EmployeeID", AttributeValue.builder().s("emp_003").build()); employee3.put( @@ -415,7 +418,7 @@ public static void putAllEmployeeItemsToTable( final HashMap employee4 = new HashMap<>(); employee4.put( "partition_key", - AttributeValue.builder().s("employee4").build() + AttributeValue.builder().s(partitionKeyPrefix + "employee4").build() ); employee4.put("EmployeeID", AttributeValue.builder().s("emp_004").build()); employee4.put( @@ -444,12 +447,13 @@ public static void putAllEmployeeItemsToTable( // project.json public static void putAllProjectItemsToTable( String ddbTableName, - DynamoDbClient ddb + DynamoDbClient ddb, + String partitionKeyPrefix ) { final HashMap project1 = new HashMap<>(); project1.put( "partition_key", - AttributeValue.builder().s("project1").build() + AttributeValue.builder().s(partitionKeyPrefix + "project1").build() ); project1.put( "ProjectName", @@ -479,7 +483,7 @@ public static void putAllProjectItemsToTable( final HashMap project2 = new HashMap<>(); project2.put( "partition_key", - AttributeValue.builder().s("project2").build() + AttributeValue.builder().s(partitionKeyPrefix + "project2").build() ); project2.put( "ProjectName", @@ -506,7 +510,7 @@ public static void putAllProjectItemsToTable( final HashMap project3 = new HashMap<>(); project3.put( "partition_key", - AttributeValue.builder().s("project3").build() + AttributeValue.builder().s(partitionKeyPrefix + "project3").build() ); project3.put( "ProjectName", @@ -530,7 +534,7 @@ public static void putAllProjectItemsToTable( final HashMap project4 = new HashMap<>(); project4.put( "partition_key", - AttributeValue.builder().s("project4").build() + AttributeValue.builder().s(partitionKeyPrefix + "project4").build() ); project4.put( "ProjectName", @@ -555,7 +559,8 @@ public static void putAllProjectItemsToTable( // reservation.json public static void putAllReservationItemsToTable( String ddbTableName, - DynamoDbClient ddb + DynamoDbClient ddb, + String partitionKeyPrefix ) { final List reservation1AttendeeList = new ArrayList<>(); reservation1AttendeeList.add( @@ -577,7 +582,7 @@ public static void putAllReservationItemsToTable( final HashMap reservation1 = new HashMap<>(); reservation1.put( "partition_key", - AttributeValue.builder().s("reservation1").build() + AttributeValue.builder().s(partitionKeyPrefix + "reservation1").build() ); reservation1.put( "Location", @@ -629,7 +634,7 @@ public static void putAllReservationItemsToTable( final HashMap reservation2 = new HashMap<>(); reservation2.put( "partition_key", - AttributeValue.builder().s("reservation2").build() + AttributeValue.builder().s(partitionKeyPrefix + "reservation2").build() ); reservation2.put( "Location", @@ -662,10 +667,11 @@ public static void putAllReservationItemsToTable( // ticket.json public static void putAllTicketItemsToTable( String ddbTableName, - DynamoDbClient ddb + DynamoDbClient ddb, + String partitionKeyPrefix ) { final HashMap ticket1 = new HashMap<>(); - ticket1.put("partition_key", AttributeValue.builder().s("ticket1").build()); + ticket1.put("partition_key", AttributeValue.builder().s(partitionKeyPrefix + "ticket1").build()); ticket1.put( "TicketNumber", AttributeValue.builder().s("ticket_001").build() @@ -694,7 +700,7 @@ public static void putAllTicketItemsToTable( ); final HashMap ticket2 = new HashMap<>(); - ticket2.put("partition_key", AttributeValue.builder().s("ticket2").build()); + ticket2.put("partition_key", AttributeValue.builder().s(partitionKeyPrefix + "ticket2").build()); ticket2.put( "TicketNumber", AttributeValue.builder().s("ticket_001").build() @@ -723,7 +729,7 @@ public static void putAllTicketItemsToTable( ); final HashMap ticket3 = new HashMap<>(); - ticket3.put("partition_key", AttributeValue.builder().s("ticket3").build()); + ticket3.put("partition_key", AttributeValue.builder().s(partitionKeyPrefix + "ticket3").build()); ticket3.put( "TicketNumber", AttributeValue.builder().s("ticket_002").build() @@ -752,7 +758,7 @@ public static void putAllTicketItemsToTable( ); final HashMap ticket4 = new HashMap<>(); - ticket4.put("partition_key", AttributeValue.builder().s("ticket4").build()); + ticket4.put("partition_key", AttributeValue.builder().s(partitionKeyPrefix + "ticket4").build()); ticket4.put( "TicketNumber", AttributeValue.builder().s("ticket_002").build() @@ -784,12 +790,13 @@ public static void putAllTicketItemsToTable( // timecard.json public static void putAllTimecardItemsToTable( String ddbTableName, - DynamoDbClient ddb + DynamoDbClient ddb, + String partitionKeyPrefix ) { final HashMap timecard1 = new HashMap<>(); timecard1.put( "partition_key", - AttributeValue.builder().s("timecard1").build() + AttributeValue.builder().s(partitionKeyPrefix + "timecard1").build() ); timecard1.put( "ProjectName", @@ -813,7 +820,7 @@ public static void putAllTimecardItemsToTable( final HashMap timecard2 = new HashMap<>(); timecard2.put( "partition_key", - AttributeValue.builder().s("timecard2").build() + AttributeValue.builder().s(partitionKeyPrefix + "timecard2").build() ); timecard2.put( "ProjectName", @@ -837,7 +844,7 @@ public static void putAllTimecardItemsToTable( final HashMap timecard3 = new HashMap<>(); timecard3.put( "partition_key", - AttributeValue.builder().s("timecard3").build() + AttributeValue.builder().s(partitionKeyPrefix + "timecard3").build() ); timecard3.put( "ProjectName", @@ -861,7 +868,7 @@ public static void putAllTimecardItemsToTable( final HashMap timecard4 = new HashMap<>(); timecard4.put( "partition_key", - AttributeValue.builder().s("timecard4").build() + AttributeValue.builder().s(partitionKeyPrefix + "timecard4").build() ); timecard4.put( "ProjectName", diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/QueryRequests.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/QueryRequests.java index 353d7d3ddd..ec6e340a4e 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/QueryRequests.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/complexexample/QueryRequests.java @@ -24,33 +24,33 @@ public class QueryRequests { - public static void runQueries(String ddbTableName, DynamoDbClient ddb) { - runQuery1(ddbTableName, ddb); - runQuery2(ddbTableName, ddb); - runQuery3(ddbTableName, ddb); - runQuery4(ddbTableName, ddb); - runQuery5(ddbTableName, ddb); - runQuery6(ddbTableName, ddb); - runQuery7(ddbTableName, ddb); - runQuery8(ddbTableName, ddb); - runQuery9(ddbTableName, ddb); - runQuery10(ddbTableName, ddb); - runQuery11(ddbTableName, ddb); - runQuery12(ddbTableName, ddb); - runQuery13(ddbTableName, ddb); - runQuery14(ddbTableName, ddb); - runQuery15(ddbTableName, ddb); - runQuery16(ddbTableName, ddb); - runQuery17(ddbTableName, ddb); - runQuery18(ddbTableName, ddb); - runQuery19(ddbTableName, ddb); - runQuery20(ddbTableName, ddb); - runQuery21(ddbTableName, ddb); - runQuery22(ddbTableName, ddb); - runQuery23(ddbTableName, ddb); + public static void runQueries(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { + runQuery1(ddbTableName, ddb, partitionKeyPrefix); + runQuery2(ddbTableName, ddb, partitionKeyPrefix); + runQuery3(ddbTableName, ddb, partitionKeyPrefix); + runQuery4(ddbTableName, ddb, partitionKeyPrefix); + runQuery5(ddbTableName, ddb, partitionKeyPrefix); + runQuery6(ddbTableName, ddb, partitionKeyPrefix); + runQuery7(ddbTableName, ddb, partitionKeyPrefix); + runQuery8(ddbTableName, ddb, partitionKeyPrefix); + runQuery9(ddbTableName, ddb, partitionKeyPrefix); + runQuery10(ddbTableName, ddb, partitionKeyPrefix); + runQuery11(ddbTableName, ddb, partitionKeyPrefix); + runQuery12(ddbTableName, ddb, partitionKeyPrefix); + runQuery13(ddbTableName, ddb, partitionKeyPrefix); + runQuery14(ddbTableName, ddb, partitionKeyPrefix); + runQuery15(ddbTableName, ddb, partitionKeyPrefix); + runQuery16(ddbTableName, ddb, partitionKeyPrefix); + runQuery17(ddbTableName, ddb, partitionKeyPrefix); + runQuery18(ddbTableName, ddb, partitionKeyPrefix); + runQuery19(ddbTableName, ddb, partitionKeyPrefix); + runQuery20(ddbTableName, ddb, partitionKeyPrefix); + runQuery21(ddbTableName, ddb, partitionKeyPrefix); + runQuery22(ddbTableName, ddb, partitionKeyPrefix); + runQuery23(ddbTableName, ddb, partitionKeyPrefix); } - public static void runQuery1(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery1(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 1: Get meetings by date and email // Key condition: PK1=email SK1 between(date1, date2) // Filter condition: duration > 0 @@ -93,7 +93,7 @@ public static void runQuery1(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery1 = false; for (Map item : query1Response.items()) { - if (item.get("partition_key").s().equals("meeting1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "meeting1")) { foundKnownValueItemQuery1 = true; assert item.get("Subject").s().equals("Scan Beacons"); assert item.get("Location").m().get("Floor").s().equals("12"); @@ -106,7 +106,7 @@ public static void runQuery1(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery1; } - public static void runQuery2(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery2(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 2: Get meetings by date and employeeID // Key condition: PK=employeeID SK between(date1, date2) // Filter condition: duration > 0 @@ -151,7 +151,7 @@ public static void runQuery2(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery2 = false; for (Map item : query2Response.items()) { - if (item.get("partition_key").s().equals("meeting1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "meeting1")) { foundKnownValueItemQuery2 = true; assert item.get("Subject").s().equals("Scan Beacons"); assert item.get("Location").m().get("Floor").s().equals("12"); @@ -164,7 +164,7 @@ public static void runQuery2(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery2; } - public static void runQuery3(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery3(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 3: Get meetings by date and building/floor/room // Key condition: PK=employeeID SK between(date1, date2) // Filter condition: SK contains building.floor.room (see NOTE) @@ -228,7 +228,7 @@ public static void runQuery3(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery3 = false; for (Map item : query3Response.items()) { - if (item.get("partition_key").s().equals("reservation1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "reservation1")) { foundKnownValueItemQuery3 = true; assert item.get("Subject").s().equals("Scan beacons"); assert item.get("Location").m().get("Building").s().equals("SEA33"); @@ -241,7 +241,7 @@ public static void runQuery3(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery3; } - public static void runQuery4(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery4(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 4: Get employee data by email // Key condition: PK1=email SK1=employee ID Map query4AttributeNames = new HashMap<>(); @@ -276,7 +276,7 @@ public static void runQuery4(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery4 = false; for (Map item : query4Response.items()) { - if (item.get("partition_key").s().equals("employee1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "employee1")) { foundKnownValueItemQuery4 = true; assert item.get("EmployeeID").s().equals("emp_001"); assert item.get("Location").m().get("Desk").s().equals("3"); @@ -285,7 +285,7 @@ public static void runQuery4(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery4; } - public static void runQuery5(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery5(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 5: Get meetings by email // Key condition: PK1=email SK1 > 30 days ago Map query5AttributeNames = new HashMap<>(); @@ -326,7 +326,7 @@ public static void runQuery5(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery5 = false; for (Map item : query5Response.items()) { - if (item.get("partition_key").s().equals("meeting1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "meeting1")) { foundKnownValueItemQuery5 = true; assert item.get("Subject").s().equals("Scan Beacons"); assert item.get("Location").m().get("Floor").s().equals("12"); @@ -339,7 +339,7 @@ public static void runQuery5(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery5; } - public static void runQuery6(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery6(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 6: Get tickets by email // Key condition: PK1=email SK1 > 30 days ago Map query6AttributeNames = new HashMap<>(); @@ -375,7 +375,7 @@ public static void runQuery6(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery6 = false; for (Map item : query6Response.items()) { - if (item.get("partition_key").s().equals("ticket1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "ticket1")) { foundKnownValueItemQuery6 = true; assert item.get("TicketNumber").s().equals("ticket_001"); } @@ -383,7 +383,7 @@ public static void runQuery6(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery6; } - public static void runQuery7(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery7(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 7: Get reservations by email // Key condition: PK1=organizeremail SK1 > 30 days ago Map query7AttributeNames = new HashMap<>(); @@ -420,7 +420,7 @@ public static void runQuery7(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery7 = false; for (Map item : query7Response.items()) { - if (item.get("partition_key").s().equals("reservation1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "reservation1")) { foundKnownValueItemQuery7 = true; assert item.get("Subject").s().equals("Scan beacons"); assert item.get("Location").m().get("Floor").s().equals("12"); @@ -433,7 +433,7 @@ public static void runQuery7(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery7; } - public static void runQuery8(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery8(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 8: Get time cards by email // Key condition: PK1=employeeemail SK1 > 30 days ago Map query8AttributeNames = new HashMap<>(); @@ -474,7 +474,7 @@ public static void runQuery8(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery8 = false; for (Map item : query8Response.items()) { - if (item.get("partition_key").s().equals("timecard1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "timecard1")) { foundKnownValueItemQuery8 = true; assert item.get("ProjectName").s().equals("project_002"); } @@ -482,7 +482,7 @@ public static void runQuery8(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery8; } - public static void runQuery9(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery9(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 9: Get employee info by employee ID // Key condition: PK1=employeeID SK starts with "E-" Map query9AttributeNames = new HashMap<>(); @@ -517,7 +517,7 @@ public static void runQuery9(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery9 = false; for (Map item : query9Response.items()) { - if (item.get("partition_key").s().equals("employee1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "employee1")) { foundKnownValueItemQuery9 = true; assert item.get("EmployeeID").s().equals("emp_001"); } @@ -525,7 +525,7 @@ public static void runQuery9(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery9; } - public static void runQuery10(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery10(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 10: Get employee info by email // Key condition: PK1=email // Filter condition: SK starts with "E-" @@ -561,7 +561,7 @@ public static void runQuery10(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery10 = false; for (Map item : query10Response.items()) { - if (item.get("partition_key").s().equals("employee1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "employee1")) { foundKnownValueItemQuery10 = true; assert item.get("EmployeeID").s().equals("emp_001"); } @@ -569,7 +569,7 @@ public static void runQuery10(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery10; } - public static void runQuery11(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery11(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 11: Get ticket history by ticket number // Key condition: PK=TicketNumber Map query11AttributeNames = new HashMap<>(); @@ -600,7 +600,7 @@ public static void runQuery11(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery11 = false; for (Map item : query11Response.items()) { - if (item.get("partition_key").s().equals("ticket1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "ticket1")) { foundKnownValueItemQuery11 = true; assert item.get("TicketNumber").s().equals("ticket_001"); } @@ -608,7 +608,7 @@ public static void runQuery11(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery11; } - public static void runQuery12(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery12(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 12: Get Ticket History by employee email // Key condition: PK1=CreatorEmail // Filter condition: PK=TicketNumber @@ -645,7 +645,7 @@ public static void runQuery12(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery12 = false; for (Map item : query12Response.items()) { - if (item.get("partition_key").s().equals("ticket1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "ticket1")) { foundKnownValueItemQuery12 = true; assert item.get("TicketNumber").s().equals("ticket_001"); } @@ -653,7 +653,7 @@ public static void runQuery12(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery12; } - public static void runQuery13(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery13(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 13: Get ticket history by assignee email // Key condition: PK=AssigneeEmail // Filter condition: PK=ticketNumber @@ -690,7 +690,7 @@ public static void runQuery13(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery13 = false; for (Map item : query13Response.items()) { - if (item.get("partition_key").s().equals("ticket1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "ticket1")) { foundKnownValueItemQuery13 = true; assert item.get("Subject").s().equals("Bad bug"); } @@ -698,7 +698,7 @@ public static void runQuery13(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery13; } - public static void runQuery14(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery14(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 14: Get employees by city.building.floor.desk // Key condition: PK3=city SK3 begins_with(building.floor.desk) Map query14AttributeNames = new HashMap<>(); @@ -745,7 +745,7 @@ public static void runQuery14(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery14 = false; for (Map item : query14Response.items()) { - if (item.get("partition_key").s().equals("employee1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "employee1")) { foundKnownValueItemQuery14 = true; assert item.get("EmployeeID").s().equals("emp_001"); assert item.get("Location").m().get("Desk").s().equals("3"); @@ -756,7 +756,7 @@ public static void runQuery14(String ddbTableName, DynamoDbClient ddb) { } } - public static void runQuery15(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery15(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 15: Get employees by manager email // Key condition: PK2 = ManagerEmail Map query15AttributeNames = new HashMap<>(); @@ -787,7 +787,7 @@ public static void runQuery15(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery15 = false; for (Map item : query15Response.items()) { - if (item.get("partition_key").s().equals("employee1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "employee1")) { foundKnownValueItemQuery15 = true; assert item.get("EmployeeID").s().equals("emp_001"); assert item.get("Location").m().get("Desk").s().equals("3"); @@ -796,7 +796,7 @@ public static void runQuery15(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery15; } - public static void runQuery16(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery16(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 16: Get assigned tickets by assignee email // Key condition: PK2 = AssigneeEmail Map query16AttributeNames = new HashMap<>(); @@ -827,7 +827,7 @@ public static void runQuery16(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery16 = false; for (Map item : query16Response.items()) { - if (item.get("partition_key").s().equals("ticket1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "ticket1")) { foundKnownValueItemQuery16 = true; assert item.get("TicketNumber").s().equals("ticket_001"); } @@ -835,7 +835,7 @@ public static void runQuery16(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery16; } - public static void runQuery17(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery17(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 17: Get tickets updated within the last 24 hours // Key condition: PK3 = Severity, SK3 > 24 hours ago // (For the sake of this example, we will assume @@ -875,7 +875,7 @@ public static void runQuery17(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery17 = false; for (Map item : query17Response.items()) { - if (item.get("partition_key").s().equals("ticket1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "ticket1")) { foundKnownValueItemQuery17 = true; assert item.get("TicketNumber").s().equals("ticket_001"); } @@ -883,7 +883,7 @@ public static void runQuery17(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery17; } - public static void runQuery18(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery18(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 18: Get projects by status, start and target date // Key condition: PK1 = Status, SK1 > StartDate // Filter condition: TargetDelivery < TargetDate @@ -925,7 +925,7 @@ public static void runQuery18(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery18 = false; for (Map item : query18Response.items()) { - if (item.get("partition_key").s().equals("project1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "project1")) { foundKnownValueItemQuery18 = true; assert item.get("ProjectName").s().equals("project_001"); } @@ -933,7 +933,7 @@ public static void runQuery18(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery18; } - public static void runQuery19(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery19(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 19: Get projects by name // Key condition: PK = ProjectName, SK = ProjectName Map query19AttributeNames = new HashMap<>(); @@ -964,7 +964,7 @@ public static void runQuery19(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery19 = false; for (Map item : query19Response.items()) { - if (item.get("partition_key").s().equals("project1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "project1")) { foundKnownValueItemQuery19 = true; assert item.get("ProjectName").s().equals("project_001"); } @@ -972,7 +972,7 @@ public static void runQuery19(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery19; } - public static void runQuery20(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery20(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 20: Get Project History by date range (against timecard record) // Key condition: PK = ProjectName, SK between(date1, date2) Map query20AttributeNames = new HashMap<>(); @@ -1014,7 +1014,7 @@ public static void runQuery20(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery20 = false; for (Map item : query20Response.items()) { - if (item.get("partition_key").s().equals("timecard1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "timecard1")) { foundKnownValueItemQuery20 = true; assert item.get("ProjectName").s().equals("project_002"); } @@ -1022,7 +1022,7 @@ public static void runQuery20(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery20; } - public static void runQuery21(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery21(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 21: Get Project History by role // Key condition: PK = ProjectName // Filter condition: role=rolename @@ -1059,7 +1059,7 @@ public static void runQuery21(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery21 = false; for (Map item : query21Response.items()) { - if (item.get("partition_key").s().equals("timecard1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "timecard1")) { foundKnownValueItemQuery21 = true; assert item.get("ProjectName").s().equals("project_002"); } @@ -1067,7 +1067,7 @@ public static void runQuery21(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery21; } - public static void runQuery22(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery22(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 22: Get reservations by building ID // Key condition: PK = Building ID Map query22AttributeNames = new HashMap<>(); @@ -1098,7 +1098,7 @@ public static void runQuery22(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery22 = false; for (Map item : query22Response.items()) { - if (item.get("partition_key").s().equals("reservation1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "reservation1")) { foundKnownValueItemQuery22 = true; assert item.get("Subject").s().equals("Scan beacons"); } @@ -1106,7 +1106,7 @@ public static void runQuery22(String ddbTableName, DynamoDbClient ddb) { assert foundKnownValueItemQuery22; } - public static void runQuery23(String ddbTableName, DynamoDbClient ddb) { + public static void runQuery23(String ddbTableName, DynamoDbClient ddb, String partitionKeyPrefix) { // Query 23: Get reservations by building ID and time range // Key condition: PK = Building ID, SK between(date1, date2) // Filter condition: Duration > 0 @@ -1155,7 +1155,7 @@ public static void runQuery23(String ddbTableName, DynamoDbClient ddb) { // Known value test: Assert some properties on one of the items boolean foundKnownValueItemQuery23 = false; for (Map item : query23Response.items()) { - if (item.get("partition_key").s().equals("reservation1")) { + if (item.get("partition_key").s().equals(partitionKeyPrefix + "reservation1")) { foundKnownValueItemQuery23 = true; assert item.get("Subject").s().equals("Scan beacons"); } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java index 6c7a4069ed..d087b3935c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java @@ -2,6 +2,7 @@ import java.util.Collections; import java.util.List; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.awssdk.regions.Region; import software.amazon.cryptography.examples.TestUtils; @@ -10,6 +11,7 @@ public class TestClientSupplierExample { @Test public void TestClientSupplierExample() { + final String partitionKeyValue = "ClientSupplierExample" + UUID.randomUUID(); List accounts = Collections.singletonList( TestUtils.TEST_AWS_ACCOUNT_ID ); @@ -21,7 +23,17 @@ public void TestClientSupplierExample() { TestUtils.TEST_MRK_REPLICA_KEY_ID_US_EAST_1, accounts, // ...and access its replica in eu-west-1 - regions + regions, + partitionKeyValue, + "0" + ); + + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestEnhancedPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestEnhancedPutGetExample.java index 0bf211d424..f1ffa79475 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestEnhancedPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestEnhancedPutGetExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.enhanced; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -7,25 +8,55 @@ public class TestEnhancedPutGetExample { @Test public void TestEnhancedPutGet() { + final String partitionKeyValue = "EnhancedPutGetExample" + UUID.randomUUID(); EnhancedPutGetExample.PutItemGetItem( TestUtils.TEST_KMS_KEY_ID, - TestUtils.TEST_DDB_TABLE_NAME + TestUtils.TEST_DDB_TABLE_NAME, + partitionKeyValue, + 0 + ); + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } @Test public void TestLombokPutGet() { + final String partitionKeyValue = "LombokPutGetExample" + UUID.randomUUID(); LombokPutGetExample.PutItemGetItem( TestUtils.TEST_KMS_KEY_ID, - TestUtils.TEST_DDB_TABLE_NAME + TestUtils.TEST_DDB_TABLE_NAME, + partitionKeyValue, + 0 + ); + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } @Test public void TestTableSchemaBuilderPutGet() { + final String partitionKeyValue = "TableSchemaBuilderPutGetExample" + UUID.randomUUID(); TableSchemaBuilderPutGetExample.PutItemGetItem( TestUtils.TEST_KMS_KEY_ID, - TestUtils.TEST_DDB_TABLE_NAME + TestUtils.TEST_DDB_TABLE_NAME, + partitionKeyValue, + 0 + ); + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestSingleTableExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestSingleTableExample.java index 7b64a049f9..a365118c34 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestSingleTableExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestSingleTableExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.enhanced; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -7,9 +8,33 @@ public class TestSingleTableExample { @Test public void TestEnhancedSingleTable() { + final String partitionKeyPrefix = "SingleTableExample" + UUID.randomUUID(); SingleTableExample.TransactWriteItems( TestUtils.TEST_KMS_KEY_ID, - TestUtils.TEST_DDB_TABLE_NAME + TestUtils.TEST_DDB_TABLE_NAME, + partitionKeyPrefix, + 0 + ); + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyPrefix + "1", + "0" + ); + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyPrefix + "2", + "0" + ); + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyPrefix + "3", + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/itemencryptor/TestItemEncryptDecryptExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/itemencryptor/TestItemEncryptDecryptExample.java index 92b1b7add2..ac2249826d 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/itemencryptor/TestItemEncryptDecryptExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/itemencryptor/TestItemEncryptDecryptExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.itemencryptor; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -7,9 +8,12 @@ public class TestItemEncryptDecryptExample { @Test public void TestItemEncryptDecrypt() { + final String partitionKeyValue = "ItemEncryptDecryptExample" + UUID.randomUUID(); ItemEncryptDecryptExample.PutItemGetItem( TestUtils.TEST_KMS_KEY_ID, - TestUtils.TEST_DDB_TABLE_NAME + TestUtils.TEST_DDB_TABLE_NAME, + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestHierarchicalKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestHierarchicalKeyringExample.java index 92f0d7f629..1da6a10f39 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestHierarchicalKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestHierarchicalKeyringExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.keyring; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.CreateKeyStoreKeyExample; import software.amazon.cryptography.examples.TestUtils; @@ -8,6 +9,7 @@ public class TestHierarchicalKeyringExample { @Test public void TestHierarchicalKeyringExample() throws InterruptedException { + final String partitionKeyValue = "HierarchicalKeyringExample" + UUID.randomUUID(); // Create new branch keys for test String keyId1 = CreateKeyStoreKeyExample.KeyStoreCreateKey( TestUtils.TEST_KEYSTORE_NAME, @@ -30,7 +32,17 @@ public void TestHierarchicalKeyringExample() throws InterruptedException { keyId2, TestUtils.TEST_KEYSTORE_NAME, TestUtils.TEST_LOGICAL_KEYSTORE_NAME, - TestUtils.TEST_KEYSTORE_KMS_KEY_ID + TestUtils.TEST_KEYSTORE_KMS_KEY_ID, + partitionKeyValue, + "0" + ); + + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java index 7495261af3..4e9f05c0fe 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java @@ -5,11 +5,15 @@ import static software.amazon.cryptography.examples.keyring.KmsEcdhKeyringExample.shouldGetNewPublicKeys; import static software.amazon.cryptography.examples.keyring.KmsEcdhKeyringExample.writePublicKeyPemForEccKey; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; public class TestKmsEcdhKeyringExample { + private static final String partitionKeyValue = "KmsEcdhKeyringExample" + UUID.randomUUID(); + private static final String sortKeyValue = "0"; + @Test public void TestKmsEcdhKeyringExampleStatic() { // You may provide your own ECC public keys at @@ -31,7 +35,11 @@ public void TestKmsEcdhKeyringExampleStatic() { KmsEcdhKeyringExample.KmsEcdhKeyringGetItemPutItem( TestUtils.TEST_DDB_TABLE_NAME, - TestUtils.TEST_KMS_ECDH_KEY_ID_P256_SENDER + TestUtils.TEST_KMS_ECDH_KEY_ID_P256_SENDER, + EXAMPLE_ECC_PUBLIC_KEY_SENDER_FILENAME, + EXAMPLE_ECC_PUBLIC_KEY_RECIPIENT_FILENAME, + partitionKeyValue, + sortKeyValue ); } @@ -43,7 +51,9 @@ public void TestKmsEcdhKeyringExampleDiscovery() { // to write an item meant for the recipient. KmsEcdhKeyringExample.KmsEcdhDiscoveryGetItem( TestUtils.TEST_DDB_TABLE_NAME, - TestUtils.TEST_KMS_ECDH_KEY_ID_P256_RECIPIENT + TestUtils.TEST_KMS_ECDH_KEY_ID_P256_RECIPIENT, + partitionKeyValue, + sortKeyValue ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsRsaKeyringExample.java index 9f0156d9d3..f9095482e9 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsRsaKeyringExample.java @@ -3,6 +3,7 @@ import static software.amazon.cryptography.examples.keyring.KmsRsaKeyringExample.shouldGetNewPublicKey; import static software.amazon.cryptography.examples.keyring.KmsRsaKeyringExample.writePublicKeyPemForRsaKey; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -10,6 +11,7 @@ public class TestKmsRsaKeyringExample { @Test public void TestKmsRsaKeyringExample() { + final String partitionKeyValue = "KmsRsaKeyringExample" + UUID.randomUUID(); // You may provide your own RSA public key at EXAMPLE_RSA_PUBLIC_KEY_FILENAME. // This must be the public key for the RSA key represented at rsaKeyArn. // If this file is not present, this will write a UTF-8 encoded PEM file for you. @@ -19,7 +21,17 @@ public void TestKmsRsaKeyringExample() { software.amazon.cryptography.examples.keyring.KmsRsaKeyringExample.KmsRsaKeyringGetItemPutItem( TestUtils.TEST_DDB_TABLE_NAME, - TestUtils.TEST_KMS_RSA_KEY_ID + TestUtils.TEST_KMS_RSA_KEY_ID, + partitionKeyValue, + "0" + ); + + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkDiscoveryMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkDiscoveryMultiKeyringExample.java index ceace75fa3..fcd7803517 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkDiscoveryMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkDiscoveryMultiKeyringExample.java @@ -2,6 +2,7 @@ import java.util.Collections; import java.util.List; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -9,6 +10,7 @@ public class TestMrkDiscoveryMultiKeyringExample { @Test public void TestMrkDiscoveryMultiKeyringExample() { + final String partitionKeyValue = "MrkDiscoveryMultiKeyringExample" + UUID.randomUUID(); List accounts = Collections.singletonList( TestUtils.TEST_AWS_ACCOUNT_ID ); @@ -18,7 +20,17 @@ public void TestMrkDiscoveryMultiKeyringExample() { TestUtils.TEST_DDB_TABLE_NAME, TestUtils.TEST_MRK_KEY_ID, accounts, - regions + regions, + partitionKeyValue, + "0" + ); + + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkMultiKeyringExample.java index c4f313ac4b..275e508e3c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkMultiKeyringExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.keyring; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -7,11 +8,23 @@ public class TestMrkMultiKeyringExample { @Test public void TestMrkMultiKeyringExample() { + final String partitionKeyValue = "MrkMultiKeyringExample" + UUID.randomUUID(); + MultiMrkKeyringExample.MultiMrkKeyringGetItemPutItem( TestUtils.TEST_DDB_TABLE_NAME, TestUtils.TEST_MRK_KEY_ID, TestUtils.TEST_KMS_KEY_ID, - TestUtils.TEST_MRK_REPLICA_KEY_ID_US_EAST_1 + TestUtils.TEST_MRK_REPLICA_KEY_ID_US_EAST_1, + partitionKeyValue, + "0" + ); + + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMultiKeyringExample.java index 0c54c4a89d..745ea61743 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMultiKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.nio.ByteBuffer; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -8,13 +9,24 @@ public class TestMultiKeyringExample { @Test public void TestMultiKeyringExample() { + final String partitionKeyValue = "MultiKeyringExample" + UUID.randomUUID(); // Generate a new AES key ByteBuffer aesKeyBytes = RawAesKeyringExample.generateAesKeyBytes(); MultiKeyringExample.MultiKeyringGetItemPutItem( TestUtils.TEST_DDB_TABLE_NAME, TestUtils.TEST_KMS_KEY_ID, - aesKeyBytes + aesKeyBytes, + partitionKeyValue, + "0" + ); + + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawAesKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawAesKeyringExample.java index 4f31ef9a7c..23b8aa3b82 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawAesKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawAesKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.nio.ByteBuffer; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -8,12 +9,23 @@ public class TestRawAesKeyringExample { @Test public void TestRawAesKeyringExample() { + final String partitionKeyValue = "RawAesKeyringExample" + UUID.randomUUID(); // Generate a new AES key ByteBuffer aesKeyBytes = RawAesKeyringExample.generateAesKeyBytes(); RawAesKeyringExample.RawAesKeyringGetItemPutItem( TestUtils.TEST_DDB_TABLE_NAME, - aesKeyBytes + aesKeyBytes, + partitionKeyValue, + "0" + ); + + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawEcdhKeyringExample.java index a6ee1aff65..76fba3b55a 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawEcdhKeyringExample.java @@ -2,6 +2,7 @@ import java.nio.ByteBuffer; import java.security.spec.ECGenParameterSpec; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; import software.amazon.cryptography.primitives.model.ECDHCurveSpec; @@ -20,11 +21,16 @@ public void TestStaticRawEcdhKeyringExample() { RawEcdhKeyringExample.generateEccKeyPairs(); } + String partitionKeyValue = "RawEcdhKeyringExample" + UUID.randomUUID(); + String sortKeyValue = "0"; + // Part of using these keyrings is knowing which curve the keys used in the key agreement // lie on. The keyring will fail if the keys do not lie on the configured curve. RawEcdhKeyringExample.RawEcdhKeyringGetItemPutItem( TestUtils.TEST_DDB_TABLE_NAME, - ECDHCurveSpec.ECC_NIST_P256 + ECDHCurveSpec.ECC_NIST_P256, + partitionKeyValue, + sortKeyValue ); } @@ -39,11 +45,16 @@ public void TestEphemeralRawEcdhKeyringExample() { RawEcdhKeyringExample.generateEccKeyPairs(); } + String partitionKeyValue = "RawEcdhKeyringExample" + UUID.randomUUID(); + String sortKeyValue = "0"; + // Part of using these keyrings is knowing which curve the keys used in the key agreement // lie on. The keyring will fail if the keys do not lie on the configured curve. RawEcdhKeyringExample.EphemeralRawEcdhKeyringPutItem( TestUtils.TEST_DDB_TABLE_NAME, - ECDHCurveSpec.ECC_NIST_P256 + ECDHCurveSpec.ECC_NIST_P256, + partitionKeyValue, + sortKeyValue ); } @@ -59,6 +70,9 @@ public void TestDiscoveryRawEcdhKeyringExample() { RawEcdhKeyringExample.generateEccKeyPairs(); } + String partitionKeyValue = "RawEcdhKeyringExample" + UUID.randomUUID(); + String sortKeyValue = "0"; + // The discovery configuration is not allowed to encrypt // To understand this example best, we will write a record with the ephemeral configuration // in the previous example. This means that the recipient public key configured on @@ -69,7 +83,9 @@ public void TestDiscoveryRawEcdhKeyringExample() { // The recipient will be able to decrypt the message RawEcdhKeyringExample.EphemeralRawEcdhKeyringPutItem( TestUtils.TEST_DDB_TABLE_NAME, - ECDHCurveSpec.ECC_NIST_P256 + ECDHCurveSpec.ECC_NIST_P256, + partitionKeyValue, + sortKeyValue ); // In this call we are reading a record that was written with the recipient's public key. @@ -77,7 +93,9 @@ public void TestDiscoveryRawEcdhKeyringExample() { // calculate the appropriate shared secret to successfully decrypt the message. RawEcdhKeyringExample.DiscoveryRawEcdhKeyringGetItem( TestUtils.TEST_DDB_TABLE_NAME, - ECDHCurveSpec.ECC_NIST_P256 + ECDHCurveSpec.ECC_NIST_P256, + partitionKeyValue, + sortKeyValue ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawRsaKeyringExample.java index 5baea772c2..43fc971503 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawRsaKeyringExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.keyring; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -7,6 +8,7 @@ public class TestRawRsaKeyringExample { @Test public void TestRawRsaKeyringExample() { + final String partitionKeyValue = "RawRsaKeyringExample" + UUID.randomUUID(); // You may provide your own RSA key pair in the files located at // - EXAMPLE_RSA_PRIVATE_KEY_FILENAME // - EXAMPLE_RSA_PUBLIC_KEY_FILENAME @@ -16,7 +18,17 @@ public void TestRawRsaKeyringExample() { } RawRsaKeyringExample.RawRsaKeyringGetItemPutItem( - TestUtils.TEST_DDB_TABLE_NAME + TestUtils.TEST_DDB_TABLE_NAME, + partitionKeyValue, + "0" + ); + + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestSharedCacheAcrossHierarchicalKeyringsExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestSharedCacheAcrossHierarchicalKeyringsExample.java index 452da3f36b..1c5f8a7d77 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestSharedCacheAcrossHierarchicalKeyringsExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestSharedCacheAcrossHierarchicalKeyringsExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.keyring; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.CreateKeyStoreKeyExample; import software.amazon.cryptography.examples.TestUtils; @@ -9,6 +10,7 @@ public class TestSharedCacheAcrossHierarchicalKeyringsExample { @Test public void TestSharedCacheAcrossHierarchicalKeyringsExample() throws InterruptedException { + final String partitionKeyValue = "SharedCacheAcrossHierarchicalKeyringsExample" + UUID.randomUUID(); // Create new branch key for test String keyId = CreateKeyStoreKeyExample.KeyStoreCreateKey( TestUtils.TEST_KEYSTORE_NAME, @@ -26,7 +28,17 @@ public void TestSharedCacheAcrossHierarchicalKeyringsExample() TestUtils.TEST_KEYSTORE_NAME, TestUtils.TEST_LOGICAL_KEYSTORE_NAME, TestUtils.TEST_PARTITION_ID, - TestUtils.TEST_KEYSTORE_KMS_KEY_ID + TestUtils.TEST_KEYSTORE_KMS_KEY_ID, + partitionKeyValue, + "0" + ); + + TestUtils.cleanUpDDBItem( + TestUtils.TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + partitionKeyValue, + "0" ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestBasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestBasicSearchableEncryptionExample.java index 57539f58d4..d817525944 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestBasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestBasicSearchableEncryptionExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.searchableencryption; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.CreateKeyStoreKeyExample; @@ -18,11 +19,14 @@ public void TestBasicExample() throws InterruptedException { // our test fails due to eventual consistency issues. Thread.sleep(5000); + final String workId = UUID.randomUUID().toString(); + BasicSearchableEncryptionExample.PutItemQueryItemWithBeacon( SearchableEncryptionTestUtils.UNIT_INSPECTION_TEST_DDB_TABLE_NAME, keyId, SearchableEncryptionTestUtils.TEST_BRANCH_KEY_WRAPPING_KMS_KEY_ARN, - SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME + SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME, + workId ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestBeaconStylesSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestBeaconStylesSearchableEncryptionExample.java index 82f7be3408..17b7bd0dc1 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestBeaconStylesSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestBeaconStylesSearchableEncryptionExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.searchableencryption; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.CreateKeyStoreKeyExample; @@ -18,11 +19,14 @@ public void TestCompoundItemEncryptDecrypt() throws InterruptedException { // our test fails due to eventual consistency issues. Thread.sleep(5000); + final String workId = UUID.randomUUID().toString(); + BeaconStylesSearchableEncryptionExample.PutItemQueryItemWithBeaconStyles( SearchableEncryptionTestUtils.UNIT_INSPECTION_TEST_DDB_TABLE_NAME, keyId, SearchableEncryptionTestUtils.TEST_BRANCH_KEY_WRAPPING_KMS_KEY_ARN, - SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME + SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME, + workId ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestCompoundBeaconSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestCompoundBeaconSearchableEncryptionExample.java index 9661c1f8f0..bb52c705f6 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestCompoundBeaconSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestCompoundBeaconSearchableEncryptionExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.searchableencryption; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.CreateKeyStoreKeyExample; @@ -18,11 +19,14 @@ public void TestCompoundItemEncryptDecrypt() throws InterruptedException { // our test fails due to eventual consistency issues. Thread.sleep(5000); + final String workId = UUID.randomUUID().toString(); + CompoundBeaconSearchableEncryptionExample.PutItemQueryItemWithCompoundBeacon( SearchableEncryptionTestUtils.UNIT_INSPECTION_TEST_DDB_TABLE_NAME, keyId, SearchableEncryptionTestUtils.TEST_BRANCH_KEY_WRAPPING_KMS_KEY_ARN, - SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME + SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME, + workId ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestVirtualBeaconSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestVirtualBeaconSearchableEncryptionExample.java index 0ba8587802..aa26118bec 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestVirtualBeaconSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/TestVirtualBeaconSearchableEncryptionExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.searchableencryption; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.CreateKeyStoreKeyExample; @@ -18,11 +19,14 @@ public void TestVirtualBeaconExample() throws InterruptedException { // our test fails due to eventual consistency issues. Thread.sleep(5000); + final String customerId = UUID.randomUUID().toString(); + VirtualBeaconSearchableEncryptionExample.PutItemQueryItemWithVirtualBeacon( SearchableEncryptionTestUtils.SIMPLE_BEACON_TEST_DDB_TABLE_NAME, keyId, SearchableEncryptionTestUtils.TEST_BRANCH_KEY_WRAPPING_KMS_KEY_ARN, - SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME + SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME, + customerId ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/complexexample/TestComplexSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/complexexample/TestComplexSearchableEncryptionExample.java index 06174d0bb4..1fa9324783 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/complexexample/TestComplexSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/searchableencryption/complexexample/TestComplexSearchableEncryptionExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.searchableencryption.complexexample; +import java.util.UUID; import org.testng.annotations.Test; import software.amazon.cryptography.examples.CreateKeyStoreKeyExample; import software.amazon.cryptography.examples.searchableencryption.SearchableEncryptionTestUtils; @@ -19,11 +20,15 @@ public void TestComplexExample() throws InterruptedException { // our test fails due to eventual consistency issues. Thread.sleep(5000); + // Generate UUID-based partition key prefix for test isolation + String partitionKeyPrefix = UUID.randomUUID().toString() + "-"; + ComplexSearchableEncryptionExample.runExample( ComplexSearchableEncryptionTestUtils.TEST_DDB_TABLE_NAME, keyId, SearchableEncryptionTestUtils.TEST_BRANCH_KEY_WRAPPING_KMS_KEY_ARN, - SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME + SearchableEncryptionTestUtils.TEST_BRANCH_KEYSTORE_DDB_TABLE_NAME, + partitionKeyPrefix ); } }