Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在403中通过CloudFront结果上传到S3_C#_Amazon Cloudfront_Aws Sdk - Fatal编程技术网

C# 在403中通过CloudFront结果上传到S3

C# 在403中通过CloudFront结果上传到S3,c#,amazon-cloudfront,aws-sdk,C#,Amazon Cloudfront,Aws Sdk,我正在尝试签署一个URL,以便通过CloudFront上传到S3 S3有一个bucket策略设置 CloudFront正在使用自定义域/证书 CloudFront配置为转发标头 GET的签名URL正在工作 如果我使用策略对URL进行签名: https://staging.*SNIP*.io/341-a25e82ef-8210-49bc-9fbd-b3f0c4807080-original.jpg?Policy=*SNIP*&Signature=*SNIP*&Key-Pair-

我正在尝试签署一个URL,以便通过CloudFront上传到S3

  • S3有一个bucket策略设置
  • CloudFront正在使用自定义域/证书
  • CloudFront配置为转发标头
  • GET的签名URL正在工作
如果我使用策略对URL进行签名:

https://staging.*SNIP*.io/341-a25e82ef-8210-49bc-9fbd-b3f0c4807080-original.jpg?Policy=*SNIP*&Signature=*SNIP*&Key-Pair-Id=*SNIP*
或者不使用策略但使用Expires

https://staging.*SNIP*.io/343-aa3e9a57-4d85-4c90-bf05-3d6fdac04a49-original.jpg?Expires=1457765627&Signature=*SNIP*&Key-Pair-Id=*SNIP*
我得到:

<Error>
    <Code>AccessDenied</Code>
    <Message>Query-string authentication requires the Signature, Expires and AWSAccessKeyId parameters</Message>
    <RequestId>*snip*</RequestId>
    <HostId>*snip*</HostId>
</Error>
我已经根据各种不同的SO答案推出了自己的签名。我已经尝试使用AWS SDK中的内置签名。我已经销毁并重新创建了CloudFront发行版

我完全没有办法尝试了

我可能已经看过了关于cloudfront签名URL的每一个问题,但没有任何帮助。我无法克服这个403错误


编辑:似乎AWS不知道它为什么不工作,似乎所有的配置都是正确的

我设法解决了这个问题。文档(在撰写本文时)让我感到困惑。基本上:

1) 需要设置Cloudfront分发以限制对bucket的访问。(如果不这样做,它似乎不会将auth头传递给S3)

2) 散列有效负载

3) 在CloudFrontURL上签名

4) 签署请求

为了散列有效负载,我使用Crypto.js(Core&SHA256)

并签署了我遵循的请求:

(如果需要更多信息,请发表评论)

var reader = new FileReader();

reader.onload = function(readerEvt) {
    var binaryString = readerEvt.target.result;
    var wordArray = arrayBufferToWordArray(binaryString);
    var hash = CryptoJS.SHA256(wordArray);

    var hashedPayload = hash.toString(CryptoJS.enc.Hex);

    // send the hashed payload serverside for use in calculating the signed request
};

reader.readAsArrayBuffer(file);