Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(middleware-flexible-checksums): use RequestChecksumCalculation and ResponseChecksumValidation #6492

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Sep 18, 2024

Issue

Description

  • Uses values in RequestChecksumCalculation and ResponseChecksumValidation to decide flexible checksums algorithm.
  • Adds flexibleChecksumsInterceptorMiddleware to populate input[requestValidationModeMember]
  • Deprecates MD5, and sets CRC32 as default.

Testing

Unit testing in CI

Also, verified that checksums are computed by default

import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { NodeHttpHandler } from "@smithy/node-http-handler";
import { equal } from "assert";

// Prints checksum headers for request and response.
class CustomHandler extends NodeHttpHandler {
  constructor() {
    super();
  }

  printChecksumHeaders(prefix, headers) {
    for (const [header, value] of Object.entries(headers)) {
      if (header.startsWith("x-amz-checksum-")) {
        console.log(`${prefix}['${header}']: '${value}'`);
      }
    }
  }

  async handle(request, options) {
    this.printChecksumHeaders("request", request.headers);
    const response = await super.handle(request, options);
    this.printChecksumHeaders("response", response.response.headers);
    return response;
  }
}

// WHEN_SUPPORTED is default.
const client = new S3({
  requestHandler: new CustomHandler(),
});
const Bucket = "test-flexible-checksums-v2"; // Replace with your test bucket name.
const Key = "hello-world.txt";
const Body = "Hello World"; // Replace with the content you want to test.

console.log("Put Object");
// ChecksumAlgorithm is not explicitly required to be specified.
await client.putObject({ Bucket, Key, Body });

console.log("\nGet Object");
// ChecksumMode is not explicitly required to be specified.
const response = await client.getObject({ Bucket, Key });

equal(Body, await response.Body.transformToString());

Output

Put Object
request['x-amz-checksum-sha256']: 'pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4='
response['x-amz-checksum-sha256']: 'pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4='

Get Object
request['x-amz-checksum-mode']: 'ENABLED'
request['x-amz-checksum-sha256']: '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='
response['x-amz-checksum-sha256']: 'pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4='

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr changed the title chore(middleware-flexible-checksums): add flexibleChecksumsInterceptorMiddleware chore(middleware-flexible-checksums): use RequestChecksumCalculation and ResponseChecksumValidation Sep 18, 2024
@trivikr
Copy link
Member Author

trivikr commented Sep 19, 2024

The PR is ready for review. It's marked as draft, as it shouldn't be merged at this time.

@trivikr
Copy link
Member Author

trivikr commented Sep 20, 2024

The default checksum is changed from CRC32 to SHA256 based on benchmarks provided in #6499

@trivikr trivikr force-pushed the middleware-flexcheck-interceptor branch from 28c1222 to aad6e6f Compare September 20, 2024 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants