【问题标题】:JMeter throws error 'Signature doesn't match' while uploading file to s3JMeter 在将文件上传到 s3 时抛出错误“签名不匹配”
【发布时间】:2020-03-19 23:35:07
【问题描述】:

谁能帮我弄清楚发生了什么?

我正在尝试加载测试用户可以上传和下载文件的应用程序。

旅程:

第 1 步:当用户从磁盘中选择一个文件(POST 请求)时,它会创建一个带有 uuid 的文件 ID 和路径。

响应如下所示: {"id":"FILE-VX-1234","path":"uuid/filename.jpg","uri":["s3://{location}/{uuid}/{filename}?endpoint=s3.dualstack.eu-west-1.amazonaws.com"],"state":"OPEN","size":-1,"timestamp":"2020-02-13T10:59:43.146+0000","refreshFlag":1,"storage":"STORAGEID","metadata":{}

第 2 步:使用这些(POST 请求)以 s3 uri 和assesskeyID、secretaccesskey 和 sessionToken 进行响应。

响应如下所示: {"uri":["s3://{accesskeyID}:{secretaccesskey}@{storage location}/{uuid}/{filename}?endpoint=s3.dualstack.eu-west-1.amazonaws.com&sessionToken={security token}"]}

第 3 步:使用这些和添加的临时参数(日期),PUT 请求将文件上传到 s3 存储桶中。

标题看起来像:

Accept: */*

Accept-Encoding: gzip, deflate, br

Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

Authorization: AWS4-HMAC-SHA256 Credential=${accesskeyID}/${currentDate}/{region}/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=${secretaccesskey}

Connection: keep-alive

Content-Length: 145541

Content-Type: image/jpeg

Host: <the host address>

Origin: https://{url}

Referer: https://{url}/upload/

Sec-Fetch-Mode: cors

Sec-Fetch-Site: cross-site

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36

X-Amz-Content-Sha256: UNSIGNED-PAYLOAD

X-Amz-Date:${currentDateInUTC}

x-amz-security-token: ${sessionToken}

X-Amz-User-Agent: aws-sdk-js/2.409.0 callback

错误: &lt;Error&gt;&lt;Code&gt;SignatureDoesNotMatch&lt;/Code&gt;&lt;Message&gt;The request signature we calculated does not match the signature you provided. Check your key and signing method.&lt;/Message&gt;

我已经验证了PUT请求中传递的签名(secretaccesskey)、accesskeyID和sessionToken是正确的。

注意:附加参数 date 和 "{region}/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz授权错误中的 -user-agent" 是硬编码的。

【问题讨论】:

  • 大家好!这里有什么帮助吗?我的进步是,理论上这应该在我传递所有参数时起作用。但是,使用一些库来使授权标头工作会更好/更容易。我还在aws documentation 中找到了示例。无论如何,如果有人能指出我正确的方向,那将会很有帮助。

标签: amazon-web-services amazon-s3 jmeter performance-testing


【解决方案1】:

如果不了解如何为请求生成签名,就不可能提供任何帮助,即Authorization 标头

根据Signing and Authenticating REST Requests文章

Amazon S3 REST API 使用基于密钥 HMAC(哈希消息身份验证代码)的自定义 HTTP 方案进行身份验证。要对请求进行身份验证,您首先连接请求的选定元素以形成字符串。然后,您使用您的 AWS 秘密访问密钥来计算该字符串的 HMAC。非正式地,我们将此过程称为“签名请求”,我们将 HMAC 算法的输出称为签名,因为它模拟了真实签名的安全属性。最后,使用本节中描述的语法将此签名添加为请求的参数。

这是一个伪代码,演示了如何生成标头:

Authorization = "AWS" + " " + AWSAccessKeyId + ":" + Signature;

Signature = Base64( HMAC-SHA1( YourSecretAccessKey, UTF-8-Encoding-Of( StringToSign ) ) );

StringToSign = HTTP-Verb + "\n" +
    Content-MD5 + "\n" +
    Content-Type + "\n" +
    Date + "\n" +
    CanonicalizedAmzHeaders +
    CanonicalizedResource;

CanonicalizedResource = [ "/" + Bucket ] +
    <HTTP-Request-URI, from the protocol name up to the query string> +
    [ subresource, if present. For example "?acl", "?location", "?logging", or "?torrent"];

CanonicalizedAmzHeaders = <described below>

您可以查看How to Handle Dynamic AWS SigV4 in JMeter for API Testing 文章的示例实现。

【讨论】:

    猜你喜欢
    • 2019-06-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多