cloudydeno / deno-aws_api

From-scratch Typescript client for accessing AWS APIs
https://deno.land/x/aws_api
59 stars 3 forks source link

Backblaze B2 does not function #32

Closed fucksophie closed 2 years ago

fucksophie commented 2 years ago

code:

const s3 = new ApiFactory({
  credentials: {
    awsAccessKeyId: Deno.env.get("S3_ACCESS_KEY_ID")!,
    awsSecretKey: Deno.env.get("S3_SECRET_KEY")!,
  },
  fixedEndpoint: "https://s3.us-west-004.backblazeb2.com",
  region: "us-west-004",
}).makeNew(S3);

  await s3.createBucket({
    Bucket: s3Bucket,
  });

error:

header 'x-amz-content-sha256' must be included in signature [Request ID: 6df5c7d7d56e595d

sha256 is not sent alongside requests to b2 (b2 requires sha256's)

danopia commented 2 years ago

Hello, thanks for the report. This sounds like a difference between the Backblaze and AWS API implementations.

In reviewing my code, I believe that the header is being sent properly, but is not included in the signature. I suppose AWS is fine with that since the request overall is still signed.

I believe that I just need to swap these two blocks of signing code, so that x-amz-content-sha256 is computed before the request headers are observed. https://github.com/cloudydeno/deno-aws_api/blob/a383db0f0793f0211be46f039ccce9b3e49f8974/lib/client/signing.ts#L117-L133

I'll test the change with AWS for regressions when preparing a PR. I do not have a Backblaze account handy to verify any fixes, so once I attach a PR, I'd love to get a yes-or-no on whether it resolves the stated problem.

danopia commented 2 years ago

Ok, here's an importable module from the associated PR which should resolve this signing issue: https://raw.githubusercontent.com/cloudydeno/deno-aws_api/666991bff325933f28954bc4878fca6aff2f89a1/lib/client/mod.ts

I've lightly tested with real S3 and don't see any regressions there

fucksophie commented 2 years ago

Works perfectly. Thanks!!