File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
src/main/java/software/amazon/encryption/s3 Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,10 @@ public ReEncryptInstructionFileResponse reEncryptInstructionFile(ReEncryptInstru
259259 throw new S3EncryptionClientException ("New keyring must have new materials description!" );
260260 }
261261
262+ if (reEncryptInstructionFileRequest .enforceRotation ()) {
263+ enforceRotation (encryptedMaterials , request );
264+ }
265+
262266 ContentMetadataEncodingStrategy encodeStrategy = new ContentMetadataEncodingStrategy (_instructionFileConfig );
263267
264268 if (reEncryptInstructionFileRequest .instructionFileSuffix ().equals (INSTRUCTION_FILE_SUFFIX )) {
@@ -277,6 +281,21 @@ public ReEncryptInstructionFileResponse reEncryptInstructionFile(ReEncryptInstru
277281
278282 }
279283
284+ private void enforceRotation (EncryptionMaterials newEncryptionMaterials , GetObjectRequest request ) {
285+ try {
286+ DecryptionMaterials decryptedMaterials = this ._cryptoMaterialsManager .decryptMaterials (
287+ DecryptMaterialsRequest .builder ()
288+ .algorithmSuite (newEncryptionMaterials .algorithmSuite ())
289+ .encryptedDataKeys (Collections .singletonList (newEncryptionMaterials .encryptedDataKeys ()).get (0 ))
290+ .s3Request (request )
291+ .build ()
292+ );
293+ } catch (S3EncryptionClientException e ) {
294+ return ;
295+ }
296+ throw new S3EncryptionClientException ("Key rotation is not enforced! Old keyring is still able to decrypt the new encrypted data key" );
297+ }
298+
280299 /**
281300 * See {@link S3EncryptionClient#putObject(PutObjectRequest, RequestBody)}.
282301 * <p>
You can’t perform that action at this time.
0 commit comments