|
46 | 46 | import software.amazon.awssdk.services.s3.multipart.MultipartConfiguration; |
47 | 47 | import software.amazon.encryption.s3.algorithms.AlgorithmSuite; |
48 | 48 | import software.amazon.encryption.s3.internal.InstructionFileConfig; |
| 49 | +import software.amazon.encryption.s3.materials.AesKeyring; |
49 | 50 | import software.amazon.encryption.s3.materials.KmsKeyring; |
50 | 51 | import software.amazon.encryption.s3.utils.BoundedInputStream; |
51 | 52 | import software.amazon.encryption.s3.utils.S3EncryptionClientTestResources; |
52 | 53 | import software.amazon.encryption.s3.utils.TinyBufferAsyncRequestBody; |
53 | 54 |
|
54 | 55 | import javax.crypto.KeyGenerator; |
55 | 56 | import javax.crypto.SecretKey; |
| 57 | +import javax.crypto.spec.SecretKeySpec; |
56 | 58 | import java.io.IOException; |
57 | 59 | import java.io.InputStream; |
58 | 60 | import java.security.NoSuchAlgorithmException; |
@@ -349,6 +351,30 @@ public void asyncTopLevelConfigurationWrongRegion() { |
349 | 351 | } |
350 | 352 | } |
351 | 353 |
|
| 354 | + @RetryingTest(3) |
| 355 | + public void roundTripWithCrossRegionAccessEnabled() { |
| 356 | + final String objectKey = appendTestSuffix("roundTripWithCrossRegionAccessEnabled-async-s3ec"); |
| 357 | + SecretKeySpec aesKey = new SecretKeySpec(new byte[32], "AES"); |
| 358 | + AesKeyring keyRing = AesKeyring.builder().wrappingKey(aesKey).build(); |
| 359 | + |
| 360 | + S3AsyncClient s3Client = S3AsyncEncryptionClient.builderV4() |
| 361 | + .region(Region.EU_CENTRAL_1) |
| 362 | + .crossRegionAccessEnabled(true) |
| 363 | + .keyring(keyRing) |
| 364 | + .build(); |
| 365 | + |
| 366 | + try { |
| 367 | + PutObjectRequest request = PutObjectRequest.builder().bucket(BUCKET).key(objectKey).build(); |
| 368 | + S3EncryptionClientException ex = assertThrows(S3EncryptionClientException.class, () -> |
| 369 | + s3Client.putObject(request, AsyncRequestBody.fromBytes("test".getBytes())).join()); |
| 370 | + // Cross-region redirect causes the SDK to re-subscribe to the request body. |
| 371 | + // NoRetriesAsyncRequestBody blocks this to prevent GCM cipher key/IV reuse. |
| 372 | + assertTrue(ex.getMessage().contains("Re-subscription is not supported")); |
| 373 | + } finally { |
| 374 | + s3Client.close(); |
| 375 | + } |
| 376 | + } |
| 377 | + |
352 | 378 | @RetryingTest(3) |
353 | 379 | public void asyncTopLevelConfigurationNullCreds() { |
354 | 380 | final String objectKey = appendTestSuffix("wrapped-s3-client-with-null-credentials-async"); |
|
0 commit comments