- Notifications
You must be signed in to change notification settings - Fork 18
feat: ReEncryptInstructionFile Implementation #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ReEncryptInstructionFile Implementation #470
Conversation
…file implementation
…stom instruction file suffix if specified
…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)
…MaterialsDescription class
src/main/java/software/amazon/encryption/s3/S3EncryptionClient.java Outdated Show resolved Hide resolved
src/main/java/software/amazon/encryption/s3/S3EncryptionClient.java Outdated Show resolved Hide resolved
src/main/java/software/amazon/encryption/s3/S3EncryptionClient.java Outdated Show resolved Hide resolved
src/main/java/software/amazon/encryption/s3/S3EncryptionClient.java Outdated Show resolved Hide resolved
src/test/java/software/amazon/encryption/s3/S3EncryptionClientReEncryptInstructionFileTest.java Outdated Show resolved Hide resolved
src/test/java/software/amazon/encryption/s3/S3EncryptionClientReEncryptInstructionFileTest.java Outdated Show resolved Hide resolved
src/test/java/software/amazon/encryption/s3/S3EncryptionClientReEncryptInstructionFileTest.java Outdated Show resolved Hide resolved
src/test/java/software/amazon/encryption/s3/S3EncryptionClientReEncryptInstructionFileTest.java Outdated Show resolved Hide resolved
src/test/java/software/amazon/encryption/s3/S3EncryptionClientReEncryptInstructionFileTest.java Outdated Show resolved Hide resolved
…ataKeyMatDescOrContext()
… support both the default and custom instruction file suffixes
… since secureRandom should now be initialized by default. I also removed all the unused imports
…SA keyrings in all of the test cases
….encryptedDataKeyMatDescOrContext()
…r enforceRotation in javadoc
…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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nits about comments.
| * This example demonstrates generating a custom instruction file to enable access to encrypted object by a third party. | ||
| * This enables secure sharing of encrypted objects without sharing private keys. | ||
| * This example demonstrates re-encrypting the encrypted data key in an instruction file with a new RSA wrapping key. | ||
| * The other cryptographic parameters in the instruction file such as the IV and wrapping algorithm remain unchanged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * The other cryptographic parameters in the instruction file such as the IV and wrapping algorithm remain unchanged. |
This refers to an implementation detail that customers shouldn't need to worry about. It's a useful comment for internal stuff but not necessary in the examples.
| assertTrue(e.getMessage().contains("Unable to RSA-OAEP-SHA1 unwrap")); | ||
| } | ||
| | ||
| // Create a new client with the rotated AES key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Create a new client with the rotated AES key | |
| // Create a new client with the rotated RSA key |
| * - Default instruction file suffix required for AES keyrings | ||
| * - Legacy to V3: Can rotate same wrapping key from legacy wrapping algorithms to fully supported wrapping algorithms | ||
| * - Within V3: When rotating the wrapping key, the new keyring must be different from the current keyring | ||
| * - Enforce Rotation: When enabled, ensures old keyring cannot decrypt data encrypted by new keyring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * - Enforce Rotation: When enabled, ensures old keyring cannot decrypt data encrypted by new keyring |
nit: this PR doesn't have Enforce Rotation yet
| */ | ||
| public ReEncryptInstructionFileResponse reEncryptInstructionFile(ReEncryptInstructionFileRequest reEncryptInstructionFileRequest) { | ||
| GetObjectRequest request = GetObjectRequest.builder() | ||
| //GetObjectRequest MUST be kept the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| //GetObjectRequest MUST be kept the same |
these comments aren't terribly helpful, final enforces this
| EncryptedDataKey originalEncryptedDataKeys = contentMetadata.encryptedDataKey(); | ||
| Map<String, String> currentKeyringMaterialsDescription = contentMetadata.encryptedDataKeyContext(); | ||
| byte[] iv = contentMetadata.contentIv(); | ||
| // Algorithm Suite MUST be kept the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, redundant comment (each of these)
| ); | ||
| byte[] plaintextDataKey = decryptedMaterials.plaintextDataKey(); | ||
| | ||
| //Plaintext Data Key MUST be kept the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, redundant comment
| EncryptionMaterials encryptedMaterials = newKeyring.onEncrypt(encryptionMaterials); | ||
| | ||
| Map<String, String> newMaterialsDescription = encryptedMaterials.materialsDescription().getMaterialsDescription(); | ||
| //New Keyring MUST be kept the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, redundant comment
…odified test cases to illustrate this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one thing in the examples
| .key(objectKey) | ||
| .build(), RequestBody.fromString(input)); | ||
| | ||
| // Generate a new RSA key pair for the third party customer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bit nitty but I think worth it:
we should create two separate keyrings using the third party's key:
- one with just the public key (used in ReEncrypt) maybe called
sharedKeyring - second with the public+private key (used to show decryption works)
this is more accurate to the workflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Issue #, if available:
Description of changes:
Implemented the reEncryptInstructionFile feature and I also modified the current API to help support this.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Check any applicable: