使用Temporary Credentials提供SignatureDoesNotMatch问题

时间:2017-04-28 13:10:35

标签: file-upload amazon-s3 multipart aws-sts evaporate.js

我们正在使用EvaporateJS处理基于s3浏览器的多部分文件,使用带有临时凭证的预签名URL。

以下将是我的配置

var amz_headers_common = {};
var amz_headers_at_initiate = {};
var amz_headers_at_upload = {};
var amz_headers_at_complete = {};

amz_headers_common['x-amz-acl'] = 'private';
amz_headers_common['x-amz-security-token'] = '<?=AWS_TOKEN;?>';
amz_headers_at_initiate['x-amz-acl'] = 'private';
amz_headers_at_initiate['x-amz-security-token'] = '<?=AWS_TOKEN;?>';

var customAuth = $("#signingMethod")[0].checked; 
Evaporate.create({
  signerUrl: customAuth ? undefined : '<?=AWS_SIGNER_URL;?>', 
  aws_key: '<?=AWS_KEY;?>' ,
  bucket: '<?=AWS_S3_BUCKET;?>',
  cloudfront: false,
  computeContentMd5: true,
  cryptoMd5Method: function (data) { return AWS.util.crypto.md5(data, 'base64'); },
  cryptoHexEncodedHash256: function (data) { return AWS.util.crypto.sha256(data, 'hex'); },
  logging: true,
  s3Acceleration: true,
  signTimeout: 10,
  s3FileCacheHoursAgo: 1,
  maxConcurrentParts:5,
  allowS3ExistenceOptimization: true,
  sendCanonicalRequestToSignerUrl: true,
  customAuthMethod: customAuth? doNotUseUnsafeJavaScriptV4Signer : undefined,
  evaporateChanged: function (file, evaporatingCount) {
     $('#totalParts').text(evaporatingCount);
     if (evaporatingCount > 0) {
        $("#pause-all, #pause-all-force, #cancel-all").show();
     } else if (evaporatingCount === 0) {
        $("#pause-all, #pause-all-force, #resume, #cancel-all").hide();
     }
  }
})
var promise = _e_.add({
 name: name,
 file: files[i],
 started: callback_methods.started,
 complete: callback_methods.complete,
 cancelled: callback_methods.cancelled,
 progress: callback_methods.progress,
 error: callback_methods.error,
 warn: callback_methods.warn,
 paused: callback_methods.paused,
 pausing: callback_methods.pausing,
 resumed: callback_methods.resumed,
 nameChanged: callback_methods.nameChanged,
 xAmzHeadersCommon: amz_headers_common,
 xAmzHeadersAtInitiate: amz_headers_at_initiate,
 xAmzHeadersAtUpload: amz_headers_at_upload,
 xAmzHeadersAtComplete: amz_headers_at_complete
},
{
 bucket: '<?=AWS_S3_BUCKET;?>',  // Shows that the bucket can be changed per
 aws_key: '<?=AWS_KEY;?>' // Shows that aws_key can be changed per
}

但我收到了以下签名不匹配错误。

AWS Code:SignatureDoesNotMatch,消息:我们计算的请求签名与您提供的签名不匹配。检查您的密钥和签名方法.status:403

以下将是log

Without temperary credentials following cannonical request and v4 string to sign.

POST
/test-video.mp474.6796611212833
uploads=
host:<bucket-name>.s3-accelerate.amazonaws.com
x-amz-date:20170428T055938Z

host;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

V4 stringToSign: AWS4-HMAC-SHA256
20170428T055938Z
20170428/ap-southeast-1/s3/aws4_request
ce2c7c5fbbf58483efbd4bd244551d138353ebb7b7233d3fdce73e85d96fad8d

--------------------------------------------------------------------------------------
Using temperary credentials following cannonical request and v4 string to sign.

initiate V4 CanonicalRequest: POST
/test-video.mp461.80892198840156
uploads=
host:<bucket-name>.s3-accelerate.amazonaws.com
x-amz-acl:private
x-amz-date:20170427T160400Z
x-amz-security-token:FQoDYXdzEDEaDIkS6zY1Oj8PQLLDVSK5A5pPusfWw81Yq3v0c4VqlyyQsBDW+PHosDuDnG8EYc9jlXD1tQwiTKU1E2Nf3aKcYmv/BHYwGwOen9GPStPeVBGbWNBzi1lT+B6xOnDvIXzelnuC6Eddt+jYIrjy9RVIKBN/s80NtVwfjmFK+93iOWJzdl2ruRSzQINZ+UuSmuthudkYLZzKy0pDmCrgIz8YCjXsjhN7FyeSZzXk9qmBDCASygVEFDNbkb/xidH/Yj7P9gYdsxY6YokV/CM8ZpAKmE8Lp+en+xs9rDclexFzCId8QyJaGj0xb205WoeRIHr8RSStvyounCxrmhWP6M/eijWTP/uHIfWVDqBadEPSgVWqcEzrW2iJ+0SGROb+In6BMmkEMaw+9L5M+lkgCfMDm5Fw9Ip8bujcb4okoNjEn6L+L0b1lm3yuqvLkT3oOzL3Sn48n3y0dXsYtt3yAq+C02bnfmgtYVQgv1C9TaMHrvipFADYNJ9U81HxQWlgvuSG5BEgqV59PIzGhwPFHais/GyA+a1bmxkyhzKEw1yq6F6+wQ+VBRskmPlahQd9ZK3wrnqvpQm+H7tD2YLkVVQb+AGKtRVU3mOL3yjgnYjIBQ==

host;x-amz-acl;x-amz-date;x-amz-security-token
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

V4 stringToSign: AWS4-HMAC-SHA256
20170427T160400Z
20170427/ap-southeast-1/s3/aws4_request
e0b18a695b23bc16b6727fd2dc417e445266111ebb4995794287a46304d2cc92

请帮我解决单一不匹配问题。

1 个答案:

答案 0 :(得分:0)

无论您为存储桶实例化S3客户端,您都希望将您的签名版本设置为v4,因为这是您的临时凭据的配置。像这样:

var s3 = new AWS.S3({
      signatureVersion: 'v4'
});