Skip to content

Commit b50ee55

Browse files
author
Anirav Kareddy
committed
added fixes based on PR
1 parent 3ed8dde commit b50ee55

File tree

4 files changed

+83
-3
lines changed

4 files changed

+83
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ public ReEncryptInstructionFileResponse reEncryptInstructionFile(ReEncryptInstru
222222
.key(reEncryptInstructionFileRequest.key())
223223
.build();
224224

225+
if (!_instructionFileConfig.isInstructionFilePutEnabled()) {
226+
throw new S3EncryptionClientException("Instruction file put operations must be enabled to re-encrypt instruction files");
227+
}
228+
225229
ResponseInputStream<GetObjectResponse> response = this.getObject(request);
226230
ContentMetadataDecodingStrategy decodingStrategy = new ContentMetadataDecodingStrategy(_instructionFileConfig);
227231
ContentMetadata contentMetadata = decodingStrategy.decode(request, response.response());

src/main/java/software/amazon/encryption/s3/internal/InstructionFileConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public enum InstructionFileClientType {
4545
ASYNC
4646
}
4747

48-
boolean isInstructionFilePutEnabled() {
48+
public boolean isInstructionFilePutEnabled() {
4949
return _enableInstructionFilePut;
5050
}
5151

src/main/java/software/amazon/encryption/s3/internal/ReEncryptInstructionFileRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import software.amazon.encryption.s3.S3EncryptionClientException;
88
import software.amazon.encryption.s3.materials.AesKeyring;
99
import software.amazon.encryption.s3.materials.RawKeyring;
10+
import software.amazon.encryption.s3.materials.RsaKeyring;
1011

1112
/**
1213
* Request object for re-encrypting instruction files in S3.
@@ -162,10 +163,10 @@ public ReEncryptInstructionFileRequest build() {
162163
if (newKeyring == null) {
163164
throw new S3EncryptionClientException("New keyring must be provided!");
164165
}
165-
if (newKeyring instanceof AesKeyring) {
166+
if (!(newKeyring instanceof RsaKeyring)) {
166167
if (!instructionFileSuffix.equals(DEFAULT_INSTRUCTION_FILE_SUFFIX)) {
167168
throw new S3EncryptionClientException(
168-
"Custom Instruction file suffix is not applicable for AES keyring!"
169+
"Custom Instruction file suffix is only applicable for RSA keyring!"
169170
);
170171
}
171172
}

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,81 @@ public void testAesReEncryptInstructionFileRejectsCustomInstructionFileSuffix()
283283
deleteObject(BUCKET, objectKey, client);
284284
}
285285

286+
@Test
287+
public void testReEncryptInstructionFileFailsWhenInstructionFilePutNotEnabled() {
288+
PublicKey originalPublicKey = RSA_KEY_PAIR.getPublic();
289+
PrivateKey originalPrivateKey = RSA_KEY_PAIR.getPrivate();
290+
291+
PartialRsaKeyPair originalPartialRsaKeyPair = PartialRsaKeyPair
292+
.builder()
293+
.publicKey(originalPublicKey)
294+
.privateKey(originalPrivateKey)
295+
.build();
296+
297+
RsaKeyring oldKeyring = RsaKeyring
298+
.builder()
299+
.wrappingKeyPair(originalPartialRsaKeyPair)
300+
.materialsDescription(
301+
MaterialsDescription.builder().put("rotated", "no").build()
302+
)
303+
.build();
304+
305+
S3Client wrappedClient = S3Client.create();
306+
S3EncryptionClient client = S3EncryptionClient
307+
.builder()
308+
.keyring(oldKeyring)
309+
.instructionFileConfig(
310+
InstructionFileConfig
311+
.builder()
312+
.instructionFileClient(wrappedClient)
313+
.build()
314+
)
315+
.build();
316+
317+
final String objectKey = appendTestSuffix(
318+
"rsa-re-encrypt-instruction-file"
319+
);
320+
321+
PublicKey newPublicKey = RSA_KEY_PAIR_TWO.getPublic();
322+
PrivateKey newPrivateKey = RSA_KEY_PAIR_TWO.getPrivate();
323+
324+
PartialRsaKeyPair newPartialRsaKeyPair = PartialRsaKeyPair
325+
.builder()
326+
.publicKey(newPublicKey)
327+
.privateKey(newPrivateKey)
328+
.build();
329+
330+
RsaKeyring newKeyring = RsaKeyring
331+
.builder()
332+
.wrappingKeyPair(newPartialRsaKeyPair)
333+
.materialsDescription(
334+
MaterialsDescription.builder().put("rotated", "yes").build()
335+
)
336+
.build();
337+
338+
ReEncryptInstructionFileRequest reEncryptInstructionFileRequest =
339+
ReEncryptInstructionFileRequest
340+
.builder()
341+
.bucket(BUCKET)
342+
.key(objectKey)
343+
.newKeyring(newKeyring)
344+
.build();
345+
346+
try {
347+
ReEncryptInstructionFileResponse response =
348+
client.reEncryptInstructionFile(reEncryptInstructionFileRequest);
349+
} catch (S3EncryptionClientException e) {
350+
System.out.println(e.getMessage());
351+
assertTrue(
352+
e
353+
.getMessage()
354+
.contains(
355+
"Instruction file put operations must be enabled to re-encrypt instruction files"
356+
)
357+
);
358+
}
359+
}
360+
286361
@Test
287362
public void testAesKeyringReEncryptInstructionFile() {
288363
AesKeyring oldKeyring = AesKeyring

0 commit comments

Comments
 (0)