use of software.amazon.awssdk.auth.signer.params.SignerChecksumParams in project aws-sdk-java-v2 by aws.
the class Aws4SignerTest method signing_with_Crc32Checksum_WithOut_x_amz_sha25_header.
@Test
public void signing_with_Crc32Checksum_WithOut_x_amz_sha25_header() 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(false).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);
}
use of software.amazon.awssdk.auth.signer.params.SignerChecksumParams in project aws-sdk-java-v2 by aws.
the class DefaultAwsCrtS3V4aSigner method sign.
@Override
public SdkHttpFullRequest sign(SdkHttpFullRequest request, ExecutionAttributes executionAttributes) {
if (credentialsAreAnonymous(executionAttributes)) {
return request;
}
ExecutionAttributes defaultsApplied = applyDefaults(executionAttributes);
AwsSigningConfig requestSigningConfig = configProvider.createS3CrtSigningConfig(defaultsApplied);
SignerChecksumParams signerChecksumParams = signerChecksumParamsFromAttributes(defaultsApplied);
if (shouldSignPayload(request, defaultsApplied)) {
SdkHttpFullRequest.Builder mutableRequest = request.toBuilder();
if (signerChecksumParams != null) {
requestSigningConfig.setSignedBodyValue(AwsSigningConfig.AwsSignedBodyValue.STREAMING_AWS4_ECDSA_P256_SHA256_PAYLOAD_TRAILER);
updateRequestWithTrailer(signerChecksumParams, mutableRequest);
} else {
requestSigningConfig.setSignedBodyValue(AwsSigningConfig.AwsSignedBodyValue.STREAMING_AWS4_ECDSA_P256_SHA256_PAYLOAD);
}
setHeaderContentLength(mutableRequest, signerChecksumParams);
SdkSigningResult signingResult = signerAdapter.sign(mutableRequest.build(), requestSigningConfig);
AwsSigningConfig chunkConfig = configProvider.createChunkedSigningConfig(defaultsApplied);
return enablePayloadSigning(signingResult, chunkConfig, signerChecksumParams);
} else {
requestSigningConfig.setSignedBodyValue(signerChecksumParams != null ? STREAMING_UNSIGNED_PAYLOAD_TRAILER : AwsSigningConfig.AwsSignedBodyValue.UNSIGNED_PAYLOAD);
return signerAdapter.signRequest(request, requestSigningConfig);
}
}
Aggregations