Skip to content

Commit d1eecbf

Browse files
author
Anirav Kareddy
committed
V2 (Default) to V3 is not a legacy upgrade for wrapping algorithms. Modified test cases to illustrate this
1 parent 3092657 commit d1eecbf

File tree

1 file changed

+4
-46
lines changed

1 file changed

+4
-46
lines changed

src/test/java/software/amazon/encryption/s3/S3EncryptionClientReEncryptInstructionFileTest.java

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -598,14 +598,13 @@ public void testRsaKeyringReEncryptInstructionFileWithCustomSuffix() {
598598
}
599599

600600
@Test
601-
public void testReEncryptInstructionFileUpgradesV2AesToV3() {
602-
final String input = "Testing re-encryption of instruction file, upgrading legacy V2 AES to V3";
601+
public void testReEncryptInstructionFileV2AesToV3() {
602+
final String input = "Testing re-encryption of instruction file with AES keyrings from V2 to V3";
603603
final String objectKey = appendTestSuffix("v2-aes-to-v3-re-encrypt-instruction-file-test");
604604

605605
EncryptionMaterialsProvider materialsProvider =
606606
new StaticEncryptionMaterialsProvider(new EncryptionMaterials(AES_KEY)
607607
.addDescription("rotated", "no")
608-
.addDescription("isLegacy", "yes")
609608
);
610609

611610
CryptoConfigurationV2 cryptoConfig =
@@ -621,18 +620,14 @@ public void testReEncryptInstructionFileUpgradesV2AesToV3() {
621620

622621
AesKeyring oldKeyring = AesKeyring.builder()
623622
.wrappingKey(AES_KEY)
624-
.enableLegacyWrappingAlgorithms(true)
625623
.materialsDescription(MaterialsDescription.builder()
626624
.put("rotated", "no")
627-
.put("isLegacy", "yes")
628625
.build())
629626
.build();
630627

631628
S3Client wrappedClient = S3Client.create();
632629
S3EncryptionClient v3OriginalClient = S3EncryptionClient.builder()
633630
.keyring(oldKeyring)
634-
.enableLegacyUnauthenticatedModes(true)
635-
.enableLegacyWrappingAlgorithms(true)
636631
.instructionFileConfig(InstructionFileConfig.builder()
637632
.instructionFileClient(wrappedClient)
638633
.enableInstructionFilePutObject(true)
@@ -643,7 +638,6 @@ public void testReEncryptInstructionFileUpgradesV2AesToV3() {
643638
.wrappingKey(AES_KEY_TWO)
644639
.materialsDescription(MaterialsDescription.builder()
645640
.put("rotated", "yes")
646-
.put("isLegacy", "no")
647641
.build())
648642
.build();
649643

@@ -658,7 +652,6 @@ public void testReEncryptInstructionFileUpgradesV2AesToV3() {
658652
EncryptionMaterialsProvider newMaterialsProvider =
659653
new StaticEncryptionMaterialsProvider(new EncryptionMaterials(AES_KEY_TWO)
660654
.addDescription("rotated", "yes")
661-
.addDescription("isLegacy", "no")
662655
);
663656

664657
CryptoConfigurationV2 newCryptoConfig =
@@ -685,16 +678,6 @@ public void testReEncryptInstructionFileUpgradesV2AesToV3() {
685678

686679
assertEquals(input, v3DecryptObject.asUtf8String());
687680

688-
ResponseBytes<GetObjectResponse> instructionFile = wrappedClient.getObjectAsBytes(builder -> builder
689-
.bucket(BUCKET)
690-
.key(objectKey + ".instruction")
691-
.build());
692-
693-
JsonNodeParser parser = JsonNodeParser.create();
694-
JsonNode instructionFileNode = parser.parse(instructionFile.asUtf8String());
695-
String wrappingAlgorithm = instructionFileNode.asObject().get("x-amz-wrap-alg").asString();
696-
assertEquals("AES/GCM", wrappingAlgorithm);
697-
698681
String v2DecryptObject = v2RotatedClient.getObjectAsString(BUCKET, objectKey);
699682
assertEquals(input, v2DecryptObject);
700683

@@ -704,7 +687,7 @@ public void testReEncryptInstructionFileUpgradesV2AesToV3() {
704687

705688
@Test
706689
public void testReEncryptInstructionFileWithCustomSuffixUpgradesV2RsaToV3() throws IOException {
707-
final String input = "Testing re-encryption of instruction file, upgrading legacy V2 RSA to V3";
690+
final String input = "Testing re-encryption of instruction file with RSA keyrings from V2 to V3";
708691
final String objectKey = appendTestSuffix("v2-rsa-to-v3-re-encrypt-instruction-file-with-custom-suffix-test");
709692

710693
EncryptionMaterialsProvider materialsProvider =
@@ -733,7 +716,6 @@ public void testReEncryptInstructionFileWithCustomSuffixUpgradesV2RsaToV3() thro
733716

734717
RsaKeyring clientKeyring = RsaKeyring.builder()
735718
.wrappingKeyPair(clientPartialRsaKeyPair)
736-
.enableLegacyWrappingAlgorithms(true)
737719
.materialsDescription(MaterialsDescription.builder()
738720
.put("isOwner", "yes")
739721
.put("access-level", "admin")
@@ -743,8 +725,6 @@ public void testReEncryptInstructionFileWithCustomSuffixUpgradesV2RsaToV3() thro
743725
S3Client wrappedClient = S3Client.create();
744726
S3EncryptionClient v3OriginalClient = S3EncryptionClient.builder()
745727
.keyring(clientKeyring)
746-
.enableLegacyWrappingAlgorithms(true)
747-
.enableLegacyUnauthenticatedModes(true)
748728
.instructionFileConfig(InstructionFileConfig.builder()
749729
.instructionFileClient(wrappedClient)
750730
.enableInstructionFilePutObject(true)
@@ -761,7 +741,6 @@ public void testReEncryptInstructionFileWithCustomSuffixUpgradesV2RsaToV3() thro
761741

762742
RsaKeyring thirdPartyKeyring = RsaKeyring.builder()
763743
.wrappingKeyPair(thirdPartyPartialRsaKeyPair)
764-
.enableLegacyWrappingAlgorithms(true)
765744
.materialsDescription(MaterialsDescription.builder()
766745
.put("isOwner", "no")
767746
.put("access-level", "user")
@@ -770,8 +749,6 @@ public void testReEncryptInstructionFileWithCustomSuffixUpgradesV2RsaToV3() thro
770749

771750
S3EncryptionClient v3ThirdPartyClient = S3EncryptionClient.builder()
772751
.keyring(thirdPartyKeyring)
773-
.enableLegacyWrappingAlgorithms(true)
774-
.enableLegacyUnauthenticatedModes(true)
775752
.instructionFileConfig(InstructionFileConfig.builder()
776753
.instructionFileClient(wrappedClient)
777754
.enableInstructionFilePutObject(true)
@@ -832,13 +809,12 @@ public void testReEncryptInstructionFileWithCustomSuffixUpgradesV2RsaToV3() thro
832809

833810
@Test
834811
public void testReEncryptInstructionFileUpgradesV2RsaToV3() throws IOException {
835-
final String input = "Testing re-encryption of instruction file, upgrading legacy V2 RSA to V3";
812+
final String input = "Testing re-encryption of instruction file with RSA keyrings from V2 to V3";
836813
final String objectKey = appendTestSuffix("v2-rsa-to-v3-re-encrypt-instruction-file-test");
837814

838815
EncryptionMaterialsProvider materialsProvider =
839816
new StaticEncryptionMaterialsProvider(new EncryptionMaterials(RSA_KEY_PAIR)
840817
.addDescription("rotated", "no")
841-
.addDescription("isLegacy", "yes")
842818
);
843819
CryptoConfigurationV2 cryptoConfig =
844820
new CryptoConfigurationV2(CryptoMode.AuthenticatedEncryption)
@@ -861,18 +837,14 @@ public void testReEncryptInstructionFileUpgradesV2RsaToV3() throws IOException {
861837

862838
RsaKeyring clientKeyring = RsaKeyring.builder()
863839
.wrappingKeyPair(originalPartialRsaKeyPair)
864-
.enableLegacyWrappingAlgorithms(true)
865840
.materialsDescription(MaterialsDescription.builder()
866841
.put("rotated", "no")
867-
.put("isLegacy", "yes")
868842
.build())
869843
.build();
870844

871845
S3Client wrappedClient = S3Client.create();
872846
S3EncryptionClient v3OriginalClient = S3EncryptionClient.builder()
873847
.keyring(clientKeyring)
874-
.enableLegacyWrappingAlgorithms(true)
875-
.enableLegacyUnauthenticatedModes(true)
876848
.instructionFileConfig(InstructionFileConfig.builder()
877849
.instructionFileClient(wrappedClient)
878850
.enableInstructionFilePutObject(true)
@@ -889,7 +861,6 @@ public void testReEncryptInstructionFileUpgradesV2RsaToV3() throws IOException {
889861

890862
RsaKeyring newKeyring = RsaKeyring.builder()
891863
.wrappingKeyPair(newPartialRsaKeyPair)
892-
.enableLegacyWrappingAlgorithms(true)
893864
.materialsDescription(MaterialsDescription.builder()
894865
.put("rotated", "yes")
895866
.put("isLegacy", "no")
@@ -898,8 +869,6 @@ public void testReEncryptInstructionFileUpgradesV2RsaToV3() throws IOException {
898869

899870
S3EncryptionClient v3RotatedClient = S3EncryptionClient.builder()
900871
.keyring(newKeyring)
901-
.enableLegacyWrappingAlgorithms(true)
902-
.enableLegacyUnauthenticatedModes(true)
903872
.instructionFileConfig(InstructionFileConfig.builder()
904873
.instructionFileClient(wrappedClient)
905874
.enableInstructionFilePutObject(true)
@@ -909,7 +878,6 @@ public void testReEncryptInstructionFileUpgradesV2RsaToV3() throws IOException {
909878
EncryptionMaterialsProvider newMaterialsProvider =
910879
new StaticEncryptionMaterialsProvider(new EncryptionMaterials(RSA_KEY_PAIR_TWO)
911880
.addDescription("rotated", "yes")
912-
.addDescription("isLegacy", "no")
913881
);
914882

915883
CryptoConfigurationV2 newCryptoConfig =
@@ -939,16 +907,6 @@ public void testReEncryptInstructionFileUpgradesV2RsaToV3() throws IOException {
939907
String v2DecryptObject = v2RotatedClient.getObjectAsString(BUCKET, objectKey);
940908
assertEquals(input, v2DecryptObject);
941909

942-
ResponseBytes<GetObjectResponse> instructionFile = wrappedClient.getObjectAsBytes(builder -> builder
943-
.bucket(BUCKET)
944-
.key(objectKey + ".instruction")
945-
.build());
946-
947-
JsonNodeParser parser = JsonNodeParser.create();
948-
JsonNode instructionFileNode = parser.parse(instructionFile.asUtf8String());
949-
String wrappingAlgorithm = instructionFileNode.asObject().get("x-amz-wrap-alg").asString();
950-
assertEquals("RSA-OAEP-SHA1", wrappingAlgorithm);
951-
952910
deleteObject(BUCKET, objectKey, v3OriginalClient);
953911

954912
}

0 commit comments

Comments
 (0)