Search in sources :

Example 6 with AWSS3V4Signer

use of com.amazonaws.services.s3.internal.AWSS3V4Signer in project aws-sdk-android by aws-amplify.

the class DefaultSigningMethodTest method assertSigV4WithRegion.

/*
     * Test utility functions
     */
/**
 * Use reflection to call the private method "createSigner" of
 * AmazonS3Client to create the default signer based on a fake request.
 * Returns whether the created signer is in SigV4.
 */
private static void assertSigV4WithRegion(AmazonS3Client s3, String expectedRegion) {
    final Signer signer = invokeCreateSigner(s3);
    assertTrue(signer instanceof AWSS3V4Signer);
    assertEquals(expectedRegion, invokeExtractRegionName(s3, (AWSS3V4Signer) signer));
    testSignAnonymously(s3);
}
Also used : Signer(com.amazonaws.auth.Signer) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer) AWS4Signer(com.amazonaws.auth.AWS4Signer) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer)

Example 7 with AWSS3V4Signer

use of com.amazonaws.services.s3.internal.AWSS3V4Signer in project aws-sdk-android by aws-amplify.

the class AwsChunkedEncodingInputStreamTest method setup.

@Before
public void setup() throws FileNotFoundException {
    File data = new File(getClass().getResource("/com/amazonaws/auth/RandomTestData.txt").getPath());
    FileInputStream fis = new FileInputStream(data);
    byte[] key = BinaryUtils.fromBase64("3CzwdoZjnC/7siQkeHrlEmv0PE12RkMFZVG5qKt096s=");
    String keyPath = "20150513/us-west-2/s3/aws4_request";
    String headerSignature = "c61bd05d152a8ca5ca2a024ec45d0670c0f4aa2aa67ee26be9de8657f6cfea37";
    String dateTime = "20150513T222354Z";
    aceis = new AwsChunkedEncodingInputStream(fis, 262144, key, dateTime, keyPath, headerSignature, new AWSS3V4Signer());
}
Also used : AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 8 with AWSS3V4Signer

use of com.amazonaws.services.s3.internal.AWSS3V4Signer in project aws-sdk-android by aws-amplify.

the class AWSS3V4SignerTest method testSignGetObject.

@Test
public void testSignGetObject() throws URISyntaxException {
    final AWSS3V4Signer signer = new S3SignerWithDateOverride(new Date(1431114076667L));
    // THESE ARE BOGUS CREDENTIALS
    final AWSCredentials credentials = new BasicAWSCredentials("AKIAJd4scjDDmxXZTESTGOZQ", "LYd/ad4scjDDmxXZTESTtRz7xdOM1SiD6");
    // Simulates getObject
    final GetObjectRequest getRequest = new GetObjectRequest("test-bucket123456", "key");
    final Request<?> gr = new DefaultRequest(getRequest, Constants.S3_SERVICE_DISPLAY_NAME);
    gr.setEndpoint(new URI("https://test-bucket123456.s3-us-west-2.amazonaws.com"));
    gr.setHttpMethod(HttpMethodName.GET);
    gr.setResourcePath("key");
    gr.addHeader("Host", "test-bucket123456.s3-us-west-2.amazonaws.com");
    signer.sign(gr, credentials);
    assertEquals(getSignature(gr), "7f8a09e22f7d2899e8b41857516d16ecf10680627c35693958e6e205fda8419e");
}
Also used : DefaultRequest(com.amazonaws.DefaultRequest) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) URI(java.net.URI) Date(java.util.Date) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Test(org.junit.Test)

Example 9 with AWSS3V4Signer

use of com.amazonaws.services.s3.internal.AWSS3V4Signer in project aws-sdk-android by aws-amplify.

the class AmazonS3Client method createSigner.

/**
 * Returns a "complete" S3 specific signer, taking into the S3 bucket, key,
 * and the current S3 client configuration into account.
 *
 * Signer = get a Signer based on the bucket endpoint // InternalConfig in CoreRuntime makes this decision
 * [If the region is not specified, uses SigV2 signer,
 * Else If the region is specified, and If the region only supports SigV4, then uses SigV4]
 * If Signer is not Overriden {
 *    If Signer is a V4 Signer and Region is null
 *       Get the region from AmazonS3Client or BucketRegionCache
 *       If available
 *           Use SigV4
 *       Else If PresignedUrl
 *           Use SigV2
 *   If Signer Region is overriden
 *       Use SigV4
 *   If BucketRegionCache has a region
 *       Use SigV4
 * }
 *
 * If Signer is SigV2 signer
 *      Use SigV2
 */
protected Signer createSigner(final Request<?> request, final String bucketName, final String key) {
    // Instead of using request.getEndpoint() for this parameter, we use
    // endpoint which is because
    // in accelerate mode, the endpoint in request is regionless. We need
    // the client-wide endpoint
    // to fetch the region information and pick the correct signer.
    final URI uri = clientOptions.isAccelerateModeEnabled() ? endpoint : request.getEndpoint();
    // This method retrieves the signer based on the URI. Currently
    // S3's default signer is a SigV2 signer implemented in S3Signer
    final Signer signer = getSignerByURI(uri);
    if (!isSignerOverridden()) {
        if ((signer instanceof AWSS3V4Signer) && noExplicitRegionProvided(request)) {
            final String region = clientRegion == null ? bucketRegionCache.get(bucketName) : clientRegion;
            if (region != null) {
                // If cache contains the region for the bucket, create an endpoint for the region and
                // update the request with that endpoint.
                resolveRequestEndpoint(request, bucketName, key, RuntimeHttpUtils.toUri(RegionUtils.getRegion(region).getServiceEndpoint(S3_SERVICE_NAME), clientConfiguration));
                AWSS3V4Signer sigV4Signer = (AWSS3V4Signer) signer;
                setAWSS3V4SignerWithServiceNameAndRegion((AWSS3V4Signer) signer, region);
                return sigV4Signer;
            } else if (request.getOriginalRequest() instanceof GeneratePresignedUrlRequest) {
                return createSigV2Signer(request, bucketName, key);
            }
        }
        // use the signer override if provided, else see if you can get the
        // signer from bucketreqion cache.
        final String regionOverride = getSignerRegionOverride() == null ? (clientRegion == null ? bucketRegionCache.get(bucketName) : clientRegion) : getSignerRegionOverride();
        if (regionOverride != null) {
            AWSS3V4Signer sigV4Signer = new AWSS3V4Signer();
            setAWSS3V4SignerWithServiceNameAndRegion(sigV4Signer, regionOverride);
            return sigV4Signer;
        }
    }
    if (signer instanceof S3Signer) {
        // new one with the appropriate values for this request.
        return createSigV2Signer(request, bucketName, key);
    }
    return signer;
}
Also used : S3Signer(com.amazonaws.services.s3.internal.S3Signer) S3QueryStringSigner(com.amazonaws.services.s3.internal.S3QueryStringSigner) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer) Signer(com.amazonaws.auth.Signer) S3Signer(com.amazonaws.services.s3.internal.S3Signer) AWSS3V4Signer(com.amazonaws.services.s3.internal.AWSS3V4Signer) URI(java.net.URI)

Aggregations

Test (org.junit.Test)6 AWSS3V4Signer (com.amazonaws.services.s3.internal.AWSS3V4Signer)5 URI (java.net.URI)5 DefaultRequest (com.amazonaws.DefaultRequest)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)4 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)4 Signer (com.amazonaws.auth.Signer)4 Date (java.util.Date)4 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)3 HttpMethodName (com.amazonaws.http.HttpMethodName)2 Regions (com.amazonaws.regions.Regions)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 AWS4Signer (com.amazonaws.auth.AWS4Signer)1 S3QueryStringSigner (com.amazonaws.services.s3.internal.S3QueryStringSigner)1 S3Signer (com.amazonaws.services.s3.internal.S3Signer)1 CompleteMultipartUploadRequest (com.amazonaws.services.s3.model.CompleteMultipartUploadRequest)1 HeadBucketRequest (com.amazonaws.services.s3.model.HeadBucketRequest)1 InitiateMultipartUploadRequest (com.amazonaws.services.s3.model.InitiateMultipartUploadRequest)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 PartETag (com.amazonaws.services.s3.model.PartETag)1