Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS java SDK manually set signature version

I'm trying to access a blob store service which is on top of AWS S3. It supports AWS SDK and it's signature version 2.

I'm using code here to access the this service.

Is it possible to manually set the signature version of the request made by AWS SDK ?

According to this page

AWS currently supports two signature versions: signature version 2 and signature version 4, which are covered in this section. Most services support version 4, and if a service supports version 4, we strongly recommend that you use that version.

I'm unable to find how to set the signature version to 2 or 4 manually.

like image 918
11thdimension Avatar asked Mar 22 '16 12:03

11thdimension


People also ask

How do I use AWS SDK without credentials?

To prevent the SDK from requiring the credentials, you need to use the makeUnauthenticatedRequest method to place any calls. This allows you to call "an operation on a service with the given input parameters, without any authentication data". var AWS = require('aws-sdk'); AWS.

How do I validate my AWS signature?

To verify a digital signature, you can use the Verify operation. Specify the same asymmetric KMS key, message, and signing algorithm that were used to produce the signature. You can also verify the digital signature by using the public key of the KMS key outside of AWS KMS.


2 Answers

From the S3 Developer Guide - Specifying Signature Version in Request Authentication:

Java SDK

Add the following in your code.

System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "true");

Or, on the command line, specify the following.

-Dcom.amazonaws.services.s3.enableV4

It looks like v2 was the default in the AWS SDK previously, but v4 is now the default starting in SDK v1.11.0 (May, 2016).

like image 192
James Avatar answered Oct 11 '22 22:10

James


as of

aws-java-sdk-core-1.11.163

SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY is deprecated.

I used the below code to call using signature_version='s3'

private static ClientConfiguration config = new ClientConfiguration();

static {
    config.setProtocol(Protocol.HTTP);
    config.setSignerOverride("S3SignerType");
}
private static AmazonS3 s3client = AmazonS3ClientBuilder
    .standard()
    .withClientConfiguration(config)
    .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("endpoint", null))
    .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("access_key_id", "secret_Key")))
    .build();
like image 26
best wishes Avatar answered Oct 11 '22 20:10

best wishes