Skip to content

Commit 142413d

Browse files
author
Anirav Kareddy
committed
Implemented enforceRotation method and it is invoked in the reEncryptInstructionFile method
1 parent 7099cde commit 142413d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/software/amazon/encryption/s3/S3EncryptionClient.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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>

0 commit comments

Comments
 (0)