2017-03-31 109 views
2

我一直使用AWS SDK V3 for PHP将对象放到使用客户提供的密钥的服务器端加密的S3上。文档很粗略(或者至少我没有找到它)。CreateSignedURL失败使用PHP的AWS SSE-C

对于使用S3client上传的对象,我用putobject与

 $params['SSECustomerAlgorithm'] = 'AES256'; 
     $params['SSECustomerKey'] = $this->encryptioncustkey; 
     $params['SSECustomerKeyMD5'] = $this->encryptioncustkeymd5; 

的$这个 - > encryptioncustkey是一个普通的用户密码(不Base64编码的,因为SDK似乎是这样做的)和这个 - > encryptioncustkeymd5 = md5($ this-> encryptioncustkey,true);

put对象正常工作。但是,问题在于生成createSignedURL。

$cmd = $client->getCommand('GetObject', array(
      'Bucket' => $bucket, 
      'Key' => $storedPath, 
      'ResponseContentDisposition' => 'attachment;charset=utf-8;filename="'.utf8_encode($fileName).'"', 
      'ResponseContentType' => $ctype, 
      'SSECustomerAlgorithm' => 'AES256', 
      'SSECustomerKey' => $this->encryptioncustkey, 
      'SSECustomerKeyMD5' => $this->encryptioncustkey64md5 
    )); 

但我得到其中根据文档不需要SSE-C怪异响应表明它缺少“X-AMZ-服务器端加密”(ServerSideEncryption)。即使我将它设置为ServerSideEncryption ='AES256',它也不起作用。

<Error> 
<Code>InvalidArgument</Code> 
<Message> 
Requests specifying Server Side Encryption with Customer provided keys must provide an appropriate secret key. 
</Message> 
<ArgumentName>x-amz-server-side-encryption</ArgumentName> 
<ArgumentValue>null</ArgumentValue> 
<RequestId>A3368F6CE5DD310D</RequestId> 
<HostId> 
nHavXXz/gFOoJT0tnh+wgFTbTgGdpggRkyb0sDh07H7SomcX7HrcKU1dDzgZimrQwyaVQEqAjdk= 
</HostId> 
</Error> 

回答

0

我遇到了同样的问题,并试图尽可能使每个可能的组合变得有效。我终于得出结论,这个用例不支持。阅读关于这个主题的分散和神秘的文档,似乎访问S3上的SSE-C内容的唯一方式是通过在HTTP请求标题中指定x-amz-server-side-encryption-customer-algorithm/x-amz-server-side-encryption-customer-key/字段而不是在URL中。

我最终什么事做是有问题的内容存储在S3 加密,并设置为private的ACL(你可以把它上传这样从一开始走,或使用copyObject()使这些设置的副本)。然后,当我想要获取GET请求的[“time-bombed”]预签名URL时,我只是使用了类似于您的问题的命令,但省略了SSE参数。这对我有效。