Skip to content

Conversation

@akareddy04
Copy link
Contributor

Description of changes:

I implemented the Enforce Rotation check for the ReEncrypt feature and I also wrote some test cases to test this logic.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Check any applicable:

  • Were any files moved? Moving files changes their URL, which breaks all hyperlinks to the files.
Anirav Kareddy added 30 commits June 17, 2025 15:16
…on files with AES + RSA keyrings and both of these tests pass
… third-party client is unable toretrieve the encrypted object in s3 if they do not include the overrideConfiguration with their custom instruction file suffix since it will by default use the original instruction file, not theirs.:
…ion object, not the object itself. Also reworded one of the exception messages to be clearer for when instruction file suffix request is specified for AES keyring (which should not happen)
Anirav Kareddy added 17 commits July 10, 2025 21:13
… support both the default and custom instruction file suffixes
… since secureRandom should now be initialized by default. I also removed all the unused imports
…file suffix + legacy wrapping algorithm upgrades from V1/V2 to V3
…eSuffix to mention that the . prefix is automatically added to the suffix + in reEncryptInstructionFileResponse, the . prefix will be removed from the suffix and return what the user requested the suffix be
@akareddy04 akareddy04 requested a review from a team as a code owner July 16, 2025 22:30
DecryptionMaterials decryptedMaterials = this._cryptoMaterialsManager.decryptMaterials(
DecryptMaterialsRequest.builder()
.algorithmSuite(newEncryptionMaterials.algorithmSuite())
.encryptedDataKeys(Collections.singletonList(newEncryptionMaterials.encryptedDataKeys()).get(0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.encryptedDataKeys(Collections.singletonList(newEncryptionMaterials.encryptedDataKeys()).get(0))
.encryptedDataKeys(newEncryptionMaterials.encryptedDataKeys())
} catch (S3EncryptionClientException e) {
return;
}
throw new S3EncryptionClientException("Key rotation is not enforced! Old keyring is still able to decrypt the newly encrypted data key");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this a bit. Instead of Key rotation is not enforced! (this kind of implies that enforceRotation is not set), maybe say Re-encryption failed due to enforced rotation! (then the second sentence).

}

/**
* Sets whether to enforce rotation for the re-encrypted instruction file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's give a bit more info here:

When enabled, the client will attempt to decrypt the re-encrypted instruction file with the old key material and throw an exception when decryption succeeds. This is a stronger level of validation that the wrapping key has been rotated than the standard assertion that the materials descriptions are different.

ReEncryptInstructionFileResponse response = client.reEncryptInstructionFile(reEncryptInstructionFileRequest);
assertTrue(response.enforceRotation());
} catch (S3EncryptionClientException e) {
throw new RuntimeException("Enforce rotation should not throw exception");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException("Enforce rotation should not throw exception");
fail("Enforce rotation should not throw exception");

try {
ReEncryptInstructionFileResponse response = client.reEncryptInstructionFile(reEncryptInstructionFileRequest);
throw new RuntimeException("Enforce rotation should throw exception");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException("Enforce rotation should throw exception");
fail("Enforce rotation should throw exception");
ReEncryptInstructionFileResponse response = v3OriginalClient.reEncryptInstructionFile(reEncryptInstructionFileRequest);
assertTrue(response.enforceRotation());
} catch (S3EncryptionClientException e) {
throw new RuntimeException("Enforce rotation should not throw exception");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException("Enforce rotation should not throw exception");
fail("Enforce rotation should not throw exception");

try {
ReEncryptInstructionFileResponse response = v3OriginalClient.reEncryptInstructionFile(reEncryptInstructionFileRequest);
throw new RuntimeException("Enforce rotation should throw exception");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException("Enforce rotation should throw exception");
fail("Enforce rotation should throw exception");
ReEncryptInstructionFileResponse response = v3OriginalClient.reEncryptInstructionFile(reEncryptInstructionFileRequest);
assertTrue(response.enforceRotation());
} catch (S3EncryptionClientException e) {
throw new RuntimeException("Enforce rotation should not throw exception");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException("Enforce rotation should not throw exception");
fail("Enforce rotation should not throw exception");
ReEncryptInstructionFileResponse response = v3OriginalClient.reEncryptInstructionFile(reEncryptInstructionFileRequest);
assertTrue(response.enforceRotation());
} catch (S3EncryptionClientException e) {
throw new RuntimeException("Enforce rotation should not throw exception");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException("Enforce rotation should not throw exception");
fail("Enforce rotation should not throw exception");

try {
ReEncryptInstructionFileResponse response = v3OriginalClient.reEncryptInstructionFile(reEncryptInstructionFileRequest);
throw new RuntimeException("Enforce rotation should throw exception");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException("Enforce rotation should throw exception");
fail("Enforce rotation should throw exception");
Copy link
Contributor

@kessplas kessplas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@akareddy04 akareddy04 merged commit 5e41470 into aniravk/ReEncrypt-feature Jul 18, 2025
32 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants