0

I am using AWS4 to generate signature and passing in request header. Generated signature is not getting validated.

const opts = {
        service: 's3',
        region: 'region-name',
        method: 'GET',
        host: 's3-{region-name}.amazonaws.com',
        path: '/',
    };

I am using following code snipped to generate signature

   var signature =  aws4.sign(opts, {
      accessKeyId: 'XXXXXX',
      secretAccessKey: 'XXXXXXXXXXXXXXXXXXXX',
    });

And updating request header for AutoUpdater(some module) which ultimately hits aws.

autoUpdater.requestHeaders = signature.headers;

Ending up with error message

<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

Any suggestion to get this worked ?

CoronaVirus
  • 401
  • 2
  • 7
  • 20
  • The most likely explanation is that the parameters you are using do not match what's actually in your request. There is no tolerance for inconsistencies. Is the request really for the path `/`? If so, that is a List Objects request, and you didn't mention what kind of request you are actually making. – Michael - sqlbot Jul 26 '19 at 14:57
  • Just hit this exact same issue @SteadyReader - did you ever resolve? – JTInfinite Oct 26 '19 at 20:24
  • @JTInfinite - Not yet. could not get enough to resolve it. so, still in my tech-parking area. – CoronaVirus Nov 06 '19 at 09:32

2 Answers2

0

To Calculate a signature

1.Create a policy using UTF-8 encoding.

2.Convert the UTF-8-encoded policy to Base64. The result is the string to sign.

3.Create the signature as an HMAC-SHA256 hash of the string to sign. You will provide the signing key as key to the hash function.

4.Encode the signature by using hex encoding.

Hope this will help.

Thanks Mukesh

0

Try this:

request(aws4.sign({
hostname: 'test.amazonAPI.com',
service: 'execute-api',
region: 'us-east-1',
method: 'POST',
url: 'https://test.amazonAPI.com/test/doThing', // this field is not 
recommended in the document.
  body: load
 },
{
accessKeyId: tempCreds.Credentials.AccessKeyId,
secretAccessKey: tempCreds.Credentials.SecretAccessKey,
sessionToken: tempCreds.Credentials.SessionToken
}))
sultania23
  • 322
  • 3
  • 11