Search in sources :

Example 1 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project engine by Lumeer.

the class LumeerS3Client method presign.

private static URI presign(final PresignUrlRequest request) {
    String encodedBucket, encodedKey;
    try {
        encodedBucket = URLEncoder.encode(request.bucket(), "UTF-8");
        encodedKey = URLEncoder.encode(request.key(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new UncheckedIOException(e);
    }
    SdkHttpFullRequest httpRequest = SdkHttpFullRequest.builder().method(request.httpMethod()).protocol("https").host(encodedBucket + "." + request.region().id() + "." + request.endpoint()).encodedPath(request.key()).build();
    Instant expirationTime = request.signatureDuration() == null ? null : Instant.now().plus(request.signatureDuration());
    Aws4PresignerParams presignRequest = Aws4PresignerParams.builder().expirationTime(expirationTime).awsCredentials(request.credentialsProvider().resolveCredentials()).signingName(software.amazon.awssdk.services.s3.S3Client.SERVICE_NAME).signingRegion(request.region()).build();
    return AwsS3V4Signer.create().presign(httpRequest, presignRequest).getUri();
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Instant(java.time.Instant) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Aws4PresignerParams(software.amazon.awssdk.auth.signer.params.Aws4PresignerParams) UncheckedIOException(java.io.UncheckedIOException)

Example 2 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project hibernate-search by hibernate.

the class AwsSigningRequestInterceptor method sign.

private void sign(HttpRequest request, HttpContext context, HttpEntityContentStreamProvider contentStreamProvider) {
    SdkHttpFullRequest awsRequest = toAwsRequest(request, context, contentStreamProvider);
    if (log.isTraceEnabled()) {
        log.tracef("HTTP request (before signing): %s", request);
        log.tracef("AWS request (before signing): %s", awsRequest);
    }
    AwsCredentials credentials = credentialsProvider.resolveCredentials();
    log.tracef("AWS credentials: %s", credentials);
    Aws4SignerParams signerParams = Aws4SignerParams.builder().awsCredentials(credentials).signingRegion(region).signingName(ELASTICSEARCH_SERVICE_NAME).build();
    awsRequest = signer.sign(awsRequest, signerParams);
    // We don't expect signing to affect anything else (path, query, content, ...).
    for (Map.Entry<String, List<String>> header : awsRequest.headers().entrySet()) {
        String name = header.getKey();
        boolean first = true;
        for (String value : header.getValue()) {
            if (first) {
                request.setHeader(name, value);
                first = false;
            } else {
                request.addHeader(name, value);
            }
        }
    }
    if (log.isTraceEnabled()) {
        log.tracef("AWS request (after signing): %s", awsRequest);
        log.tracef("HTTP request (after signing): %s", request);
    }
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) Aws4SignerParams(software.amazon.awssdk.auth.signer.params.Aws4SignerParams) List(java.util.List) Map(java.util.Map)

Example 3 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class AwsCrtV4aSignerTest method testQuerySigning.

@Test
public void testQuerySigning() {
    SigningTestCase testCase = SignerTestUtils.createBasicQuerySigningTestCase();
    ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
    SdkHttpFullRequest request = testCase.requestBuilder.build();
    SdkHttpFullRequest signed = v4aSigner.presign(request, executionAttributes);
    List<String> signatureValues = signed.rawQueryParameters().get("X-Amz-Signature");
    String signatureValue = signatureValues.get(0);
    List<String> regionHeader = signed.rawQueryParameters().get("X-Amz-Region-Set");
    assertThat(regionHeader.get(0)).isEqualTo(Region.AWS_GLOBAL.id());
    AwsSigningConfig signingConfig = configProvider.createCrtPresigningConfig(executionAttributes);
    assertTrue(SignerTestUtils.verifyEcdsaSignature(request, testCase.expectedCanonicalRequest, signingConfig, signatureValue));
}
Also used : ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) AwsSigningConfig(software.amazon.awssdk.crt.auth.signing.AwsSigningConfig) Test(org.junit.Test)

Example 4 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class AwsCrt4aSigningAdapterTest method sign_forHeader_works.

@Test
void sign_forHeader_works() {
    SigningTestCase testCase = SignerTestUtils.createBasicHeaderSigningTestCase();
    ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
    SdkHttpFullRequest request = testCase.requestBuilder.build();
    AwsSigningConfig signingConfig = configProvider.createCrtSigningConfig(executionAttributes);
    SdkSigningResult signed = crtSigningAdapter.sign(request, signingConfig);
    SdkHttpFullRequest signedRequest = signed.getSignedRequest();
    String signatureValue = extractSignatureFromAuthHeader(signedRequest);
    assertTrue(SignerTestUtils.verifyEcdsaSignature(request, testCase.expectedCanonicalRequest, signingConfig, signatureValue));
}
Also used : SigningTestCase(software.amazon.awssdk.authcrt.signer.SigningTestCase) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) AwsSigningConfig(software.amazon.awssdk.crt.auth.signing.AwsSigningConfig) Test(org.junit.jupiter.api.Test)

Example 5 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class AwsCrt4aSigningAdapterTest method signRequest_forHeader_works.

@Test
public void signRequest_forHeader_works() {
    SigningTestCase testCase = SignerTestUtils.createBasicHeaderSigningTestCase();
    ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
    SdkHttpFullRequest request = testCase.requestBuilder.build();
    AwsSigningConfig signingConfig = configProvider.createCrtSigningConfig(executionAttributes);
    SdkHttpFullRequest signed = crtSigningAdapter.signRequest(request, signingConfig);
    String signatureValue = extractSignatureFromAuthHeader(signed);
    assertTrue(SignerTestUtils.verifyEcdsaSignature(request, testCase.expectedCanonicalRequest, signingConfig, signatureValue));
}
Also used : SigningTestCase(software.amazon.awssdk.authcrt.signer.SigningTestCase) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) AwsSigningConfig(software.amazon.awssdk.crt.auth.signing.AwsSigningConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)178 Test (org.junit.Test)70 Test (org.junit.jupiter.api.Test)50 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)43 URI (java.net.URI)25 SigningTestCase (software.amazon.awssdk.authcrt.signer.SigningTestCase)23 ByteArrayInputStream (java.io.ByteArrayInputStream)18 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)16 List (java.util.List)13 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)13 RequestExecutionContext (software.amazon.awssdk.core.internal.http.RequestExecutionContext)12 ByteBuffer (java.nio.ByteBuffer)11 AsyncRequestBody (software.amazon.awssdk.core.async.AsyncRequestBody)11 Map (java.util.Map)10 ContentStreamProvider (software.amazon.awssdk.http.ContentStreamProvider)10 Instant (java.time.Instant)9 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)9 Aws4SignerParams (software.amazon.awssdk.auth.signer.params.Aws4SignerParams)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8