使用sigv4

时间:2017-02-28 11:58:09

标签: amazon-web-services curl amazon-s3 amazon-iam

我正在寻找一种将大型文件直接上传到S3的安全方法(针对性能问题)。

经过几个小时的研究,我得出了(可能是错误的)结论,我应该使用“基于浏览器的上传使用POST”。 正如在这个帖子中引用的: Amazon S3 direct file upload from client browser - private key disclosure

在直接尝试之前,我考虑过使用直接上传和签名计算制作cURL POC。 我没有成功,并且使用Authentification Version 4手动设置在网络上找不到成功的POC。

我的签名没问题。 唯一的问题是亚马逊是双重SHA256我的文件内容,因此不验证我的x-amz-content-sha-256标题。

  • 下(SHA256(e8379a31b13fb9423928fe28dd41a5e3204a52072634503c31e8b3ea42605b46)) = 4fa84cd7d18e0d33dbd62d0492eca4a159e122391ae0a3e636bd3cf527680c87

我不确定我应该在我的cURL和规范请求有效负载(以及链接的内容长度值)和x-amz-content-sha-256标头中加入什么。 它应该是相同的值吗? 如果是,那么亚马逊文档指定它应该全部加密到SHA256,所以我不知道为什么亚马逊reSHA256我的SHA256有效载荷...

错误:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>XAmzContentSHA256Mismatch</Code>
<Message>The provided 'x-amz-content-sha256' header does not match what was computed.</Message><ClientComputedContentSHA256>e8379a31b13fb9423928fe28dd41a5e3204a52072634503c31e8b3ea42605b46</ClientComputedContentSHA256><S3ComputedContentSHA256>4fa84cd7d18e0d33dbd62d0492eca4a159e122391ae0a3e636bd3cf527680c87</S3ComputedContentSHA256>
<RequestId>419A185269B0F891</RequestId><HostId>QHWxK0Mzz6AfG44ypXBti3W0tYx1xkG9lZGqc2kUKyMF9STwP18M3racio0k06aH5+1ok/Irdn8=</HostId>
</Error>

cURL命令:

curl 
-v https://??.s3.amazonaws.com/recordtest/test.jpg        
-H "Authorization: AWS4-HMAC-SHA256 Credential=??/20170228/eu-west-1/s3/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-content-sha256;x-amz-date, Signature=43750caa762314eb70aace1f7f8ae34633b93352aa25646433ef21e48dd79429"        -H "Content-Length: 64"        
-H "Content-Type: application/octet-stream"        
-H "x-amz-content-sha256: e8379a31b13fb9423928fe28dd41a5e3204a52072634503c31e8b3ea42605b46"        
-H "x-amz-date: 20170228T111828Z"        
-d "e8379a31b13fb9423928fe28dd41a5e3204a52072634503c31e8b3ea42605b46"        
-X PUT

生成的规范请求:

PUT
/recordtest/test.jpg

content-length:64
content-type:application/octet-stream
host:??.s3.amazonaws.com
x-amz-content-sha256:e8379a31b13fb9423928fe28dd41a5e3204a52072634503c31e8b3ea42605b46
x-amz-date:20170228T111200Z

content-length;content-type;host;x-amz-content-sha256;x-amz-date
e8379a31b13fb9423928fe28dd41a5e3204a52072634503c31e8b3ea42605b46

0 个答案:

没有答案