You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found an inconsistency between the regular client and the encryption client.
With the regular client, a ranged query past the size of the files raises and exception (software.amazon.awssdk.services.s3.model.S3Exception: The requested range is not satisfiable), while the encryption client does not.
The encryption client actually blocks when performing the call the to ResponseInputStream<GetObjectResponse>.read()
packagecom.test.aws;
importjava.io.InputStream;
importjava.nio.ByteBuffer;
importjava.security.KeyFactory;
importjava.security.KeyPair;
importjava.security.PrivateKey;
importjava.security.PublicKey;
importjava.security.spec.PKCS8EncodedKeySpec;
importjava.security.spec.X509EncodedKeySpec;
importjava.time.Duration;
importjava.util.Base64;
importorg.junit.jupiter.api.Test;
importsoftware.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
importsoftware.amazon.awssdk.core.ResponseInputStream;
importsoftware.amazon.awssdk.core.sync.RequestBody;
importsoftware.amazon.awssdk.http.apache.ApacheHttpClient;
importsoftware.amazon.awssdk.http.async.SdkAsyncHttpClient;
importsoftware.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
importsoftware.amazon.awssdk.regions.Region;
importsoftware.amazon.awssdk.services.s3.S3AsyncClient;
importsoftware.amazon.awssdk.services.s3.S3Client;
importsoftware.amazon.awssdk.services.s3.model.DeleteObjectRequest;
importsoftware.amazon.awssdk.services.s3.model.GetObjectRequest;
importsoftware.amazon.awssdk.services.s3.model.GetObjectResponse;
importsoftware.amazon.awssdk.services.s3.model.PutObjectRequest;
importsoftware.amazon.encryption.s3.S3EncryptionClient;
publicclassTestEndOfStreamBehavior {
privatestaticfinalRegionDEFAULT_REGION = AwsTestUtil.DEFAULT_REGION;
privatestaticfinalStringBUCKET = AwsTestUtil.AWS_TEST_BUCKET;
privatestaticfinalStringKEY = "filename.txt";
privatestaticfinalbyte[] CONTENT = "abcdefghijklmnopqrstuvwxyz0123456789".repeat(4).getBytes();
/** The encryption key to use in client-side encryption tests. */protectedstaticfinalKeyPairKEY_PAIR;
static {
finalStringpublicKeyString = "yourPublicKey";
finalStringprivateKeyString = "yourPrivateKey";
try {
finalKeyFactoryfactory = KeyFactory.getInstance("RSA");
finalPublicKeypublicKey =
factory.generatePublic(
newX509EncodedKeySpec(Base64.getDecoder().decode(publicKeyString.getBytes())));
finalPrivateKeyprivateKey =
factory.generatePrivate(
newPKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKeyString.getBytes())));
KEY_PAIR = newKeyPair(publicKey, privateKey);
} catch (Exceptione) {
thrownewRuntimeException(e);
}
}
@TestvoidtestEndOfStreamBehavior() throwsException {
// Pick the client to use, inconsistent behavior between the twofinalS3Clientclient = getClient(DEFAULT_REGION);
// final S3Client client = getEncryptionClient(KEY_PAIR, DEFAULT_REGION);// Delete the data if it existsfinalDeleteObjectRequestdeleteRequest = DeleteObjectRequest.builder()
.bucket(BUCKET)
.key(KEY)
.build();
client.deleteObject(deleteRequest);
// Upload the datafinalPutObjectRequestuploadRequest =
PutObjectRequest.builder().bucket(BUCKET).key(KEY).build();
client.putObject(uploadRequest, RequestBody.fromBytes(CONTENT));
// wait for the data to be uploadedThread.sleep(Duration.ofSeconds(5));
// Actual testfinalGetObjectRequestdownloadRequest =
GetObjectRequest.builder()
.bucket(BUCKET)
.key(KEY)
.range("bytes=144-160") // files ends at 143
.build();
// this throws with the regular client (expected behavior), it does not with the encryption clientfinalInputStreamstream = client.getObject(downloadRequest);
finalByteBufferbuffer = ByteBuffer.allocate(16);
finalbyte[] underlyingBuffer = buffer.array();
finalintcapacity = buffer.capacity();
stream.read(underlyingBuffer, 0, capacity);
}
publicstaticS3ClientgetEncryptionClient(finalKeyPairkeyPair, finalRegionregion) {
returnS3EncryptionClient.builder()
.rsaKeyPair(keyPair)
.enableLegacyUnauthenticatedModes(true)
.wrappedClient(getClient(region))
.wrappedAsyncClient(getAsyncClient(region))
.build();
}
publicstaticS3ClientgetClient(finalRegionregion) {
returnS3Client.builder()
.region(region)
.credentialsProvider(DefaultCredentialsProvider.create())
.httpClientBuilder(
ApacheHttpClient.builder().maxConnections(128) // Default is 50
)
.build();
}
publicstaticS3AsyncClientgetAsyncClient(finalRegionregion) {
finalSdkAsyncHttpClientnettyHttpClient =
NettyNioAsyncHttpClient.builder().maxConcurrency(100).build();
returnS3AsyncClient.builder()
.region(region)
.credentialsProvider(DefaultCredentialsProvider.create())
.httpClient(nettyHttpClient)
.build();
}
}
Workaround
I am not blocked by this issue, as i can check my range beforehand. I just wanted to signal it as it was a change of behavior with regards to the AWS SDK v1
The text was updated successfully, but these errors were encountered:
Problem:
I have found an inconsistency between the regular client and the encryption client.
With the regular client, a ranged query past the size of the files raises and exception (
software.amazon.awssdk.services.s3.model.S3Exception: The requested range is not satisfiable
), while the encryption client does not.The encryption client actually blocks when performing the call the to
ResponseInputStream<GetObjectResponse>.read()
Workaround
I am not blocked by this issue, as i can check my range beforehand. I just wanted to signal it as it was a change of behavior with regards to the AWS SDK v1
The text was updated successfully, but these errors were encountered: