Search in sources :

Example 1 with SignerChecksumParams

use of software.amazon.awssdk.auth.signer.params.SignerChecksumParams in project aws-sdk-java-v2 by aws.

the class Aws4SignerTest method signing_with_Crc32Checksum_with__trailer_header_already_present.

@Test
public void signing_with_Crc32Checksum_with__trailer_header_already_present() throws Exception {
    String expectedAuthorization = AWS_4_HMAC_SHA_256_AUTHORIZATION + SIGNER_HEADER_WITH_CHECKSUMS_IN_TRAILER + "Signature=3436c4bc175d31e87a591802e64756cebf2d1c6c2054d26ca3dc91bdd3de303e";
    final SignerChecksumParams signerChecksumParams = SignerChecksumParams.builder().algorithm(Algorithm.CRC32).checksumHeaderName("x-amzn-header-crc").isStreamingRequest(false).build();
    SdkHttpFullRequest signed = SignerTestUtils.signRequest(signer, request.contentStreamProvider(() -> new ByteArrayInputStream(("{\"TableName" + "\": " + "\"foo\"}").getBytes(StandardCharsets.UTF_8))).appendHeader("x-amz-trailer", "x-amzn-header-crc").build(), credentials, "demo", signingOverrideClock, "us-east-1", signerChecksumParams);
    assertThat(signed.firstMatchingHeader("x-amzn-header-crc")).isNotPresent();
    assertThat(signed.firstMatchingHeader("x-amz-trailer")).contains("x-amzn-header-crc");
    assertThat(signed.firstMatchingHeader(SignerConstant.X_AMZ_CONTENT_SHA256)).isNotPresent();
    assertThat(signed.firstMatchingHeader("Authorization")).hasValue(expectedAuthorization);
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SignerChecksumParams(software.amazon.awssdk.auth.signer.params.SignerChecksumParams) Test(org.junit.Test)

Example 2 with SignerChecksumParams

use of software.amazon.awssdk.auth.signer.params.SignerChecksumParams in project aws-sdk-java-v2 by aws.

the class AbstractAws4Signer method createSdkChecksumFromParams.

private SdkChecksum createSdkChecksumFromParams(T signingParams, SdkHttpFullRequest request) {
    SignerChecksumParams signerChecksumParams = signingParams.checksumParams();
    boolean isValidChecksumHeader = signerChecksumParams != null && StringUtils.isNotBlank(signerChecksumParams.checksumHeaderName());
    if (isValidChecksumHeader && !HttpChecksumUtils.isHttpChecksumPresent(request, ChecksumSpecs.builder().headerName(signerChecksumParams.checksumHeaderName()).build())) {
        return SdkChecksum.forAlgorithm(signerChecksumParams.algorithm());
    }
    return null;
}
Also used : SignerChecksumParams(software.amazon.awssdk.auth.signer.params.SignerChecksumParams)

Example 3 with SignerChecksumParams

use of software.amazon.awssdk.auth.signer.params.SignerChecksumParams in project aws-sdk-java-v2 by aws.

the class Aws4SignerTest method signing_with_Crc32Checksum_with_x_amz_sha25_header_preset.

@Test
public void signing_with_Crc32Checksum_with_x_amz_sha25_header_preset() throws Exception {
    // Note here x_amz_sha25_header is  present in SignedHeaders, we make sure checksum is calculated even in this case.
    String expectedAuthorization = AWS_4_HMAC_SHA_256_AUTHORIZATION + "SignedHeaders=host;x-amz-archive-description;x-amz-content-sha256;x-amz-date;x-amzn-header-crc, " + "Signature=bc931232666f226854cdd9c9962dc03d791cf4024f5ca032fab996c1d15e4a5d";
    final SignerChecksumParams signerChecksumParams = SignerChecksumParams.builder().algorithm(Algorithm.CRC32).checksumHeaderName("x-amzn-header-crc").isStreamingRequest(true).build();
    request = generateBasicRequest();
    // presetting of the header
    request.putHeader(SignerConstant.X_AMZ_CONTENT_SHA256, "required");
    SdkHttpFullRequest signed = SignerTestUtils.signRequest(signer, request.build(), credentials, "demo", signingOverrideClock, "us-east-1", signerChecksumParams);
    assertThat(signed.firstMatchingHeader("Authorization")).hasValue(expectedAuthorization);
    assertThat(signed.firstMatchingHeader("x-amzn-header-crc").get()).contains("oL+a/g==");
    assertThat(signed.firstMatchingHeader(SignerConstant.X_AMZ_CONTENT_SHA256)).isPresent();
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SignerChecksumParams(software.amazon.awssdk.auth.signer.params.SignerChecksumParams) Test(org.junit.Test)

Example 4 with SignerChecksumParams

use of software.amazon.awssdk.auth.signer.params.SignerChecksumParams in project aws-sdk-java-v2 by aws.

the class Aws4SignerTest method signing_with_Crc32Checksum_with_streaming_input_request.

@Test
public void signing_with_Crc32Checksum_with_streaming_input_request() throws Exception {
    // Note here x_amz_sha25_header is not present in SignedHeaders
    String expectedAuthorization = AWS_4_HMAC_SHA_256_AUTHORIZATION + SIGNER_HEADER_WITH_CHECKSUMS_IN_HEADER + "Signature=c1804802dc623d1689e7d0a7f9f5caee3588cc8d3df4495425129dbd52965d1f";
    final SignerChecksumParams signerChecksumParams = SignerChecksumParams.builder().algorithm(Algorithm.CRC32).checksumHeaderName("x-amzn-header-crc").isStreamingRequest(true).build();
    SdkHttpFullRequest signed = SignerTestUtils.signRequest(signer, request.contentStreamProvider(() -> new ByteArrayInputStream("{\"TableName\": \"foo\"}".getBytes(StandardCharsets.UTF_8))).build(), credentials, "demo", signingOverrideClock, "us-east-1", signerChecksumParams);
    assertThat(signed.firstMatchingHeader("x-amzn-header-crc").get()).contains("oL+a/g==");
    assertThat(signed.firstMatchingHeader(SignerConstant.X_AMZ_CONTENT_SHA256)).isNotPresent();
    assertThat(signed.firstMatchingHeader("Authorization")).hasValue(expectedAuthorization);
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SignerChecksumParams(software.amazon.awssdk.auth.signer.params.SignerChecksumParams) Test(org.junit.Test)

Example 5 with SignerChecksumParams

use of software.amazon.awssdk.auth.signer.params.SignerChecksumParams in project aws-sdk-java-v2 by aws.

the class Aws4SignerTest method signing_with_Crc32Checksum_with_header_already_present.

@Test
public void signing_with_Crc32Checksum_with_header_already_present() throws Exception {
    String expectedAuthorization = AWS_4_HMAC_SHA_256_AUTHORIZATION + SIGNER_HEADER_WITH_CHECKSUMS_IN_HEADER + "Signature=f6fad563460f2ac50fe2ab5f5f5d77a787e357897ac6e9bb116ff12d30f45589";
    final SignerChecksumParams signerChecksumParams = SignerChecksumParams.builder().algorithm(Algorithm.CRC32).checksumHeaderName("x-amzn-header-crc").isStreamingRequest(false).build();
    SdkHttpFullRequest signed = SignerTestUtils.signRequest(signer, request.contentStreamProvider(() -> new ByteArrayInputStream("{\"TableName\": \"foo\"}".getBytes(StandardCharsets.UTF_8))).appendHeader("x-amzn-header-crc", "preCalculatedChecksum").build(), credentials, "demo", signingOverrideClock, "us-east-1", signerChecksumParams);
    assertThat(signed.firstMatchingHeader("x-amzn-header-crc")).hasValue("preCalculatedChecksum");
    assertThat(signed.firstMatchingHeader(SignerConstant.X_AMZ_CONTENT_SHA256)).isNotPresent();
    assertThat(signed.firstMatchingHeader("Authorization")).hasValue(expectedAuthorization);
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SignerChecksumParams(software.amazon.awssdk.auth.signer.params.SignerChecksumParams) Test(org.junit.Test)

Aggregations

SignerChecksumParams (software.amazon.awssdk.auth.signer.params.SignerChecksumParams)7 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)6 Test (org.junit.Test)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)1 AwsSigningConfig (software.amazon.awssdk.crt.auth.signing.AwsSigningConfig)1