【发布时间】:2015-10-30 00:55:07
【问题描述】:
我正在尝试执行 HTTP PUT 以创建和更新对象,同时指定自定义元数据标头。我无法生成正确的签名,而为其他请求的操作生成签名没有问题。这是我的基本 bash / CURL 示例。让我强调一下,我必须看到并使用 Bash 和 Curl,而不是在我的特定情况下利用 s3curl 或其他库或 CLI:
#!/bin/bash
file="$1"
key_id="raanan"
key_secret="my-secret"
url="my-s3-endpoint"
bucket="testbucket"
path="$file"
content_type="application/octet-stream"
date="$(LC_ALL=C date -u +"%a, %d %b %Y %X %z")"
md5="$(openssl md5 -binary < "$file" | base64)"
daheader="x-amz-meta-user:qatester\n"
sig="$(printf "PUT\n$md5\n$content_type\n$date\n$daheader$bucket/$path" |
openssl sha1 -binary -hmac "$key_secret" | base64)"
curl -k -w "@curl-format.txt" -T $file http://my-s3-endpoint/$bucket$path -vv \
-H "Date: $date" \
-H "Authorization: AWS $key_id:$sig" \
-H "Content-Type: $content_type" \
-H "Content-MD5: $md5" \
-H "x-amz-meta-user: qatester"
>>>>HTTP/1.1 403 Forbidden
>>>>?xml version="1.0" encoding="UTF-8" standalone="yes"?><Error>
<Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated
does not match the signature you provided. Check your secret access key and signing method.</Message><Resource></Resource><RequestId></RequestId> </Error>
我错过了什么吗?
谢谢
【问题讨论】:
-
你在这里使用什么版本的签名?这个方法的文档在哪里?
-
您好,v4 签名,相关文档位于 docs.aws.amazon.com/AmazonS3/latest/API/…。
-
我没有在任何地方看到该文档中引用的 md5。你确定你在你的代码中遵循这些指示而不是旧版本吗?
-
是的,我在 PUT、GET 和 HEAD 请求中成功使用了它,但是当我包含元数据标头时只有 auth sig 失败消息。
-
@EtanReisner 您的观察是准确的,这不是 V4。是V2。 md5 不是实际 hmac 签名算法的一部分本身,而是用于
Content-MD5标头,它是要签名的字符串中的一个组件。
标签: bash http amazon-web-services curl amazon-s3