简体   繁体   English

在 AWS S3 中使用预签名 url 下载对象(文件)不起作用

[英]Download objects (files) using presigned url in AWS S3 doesn't work

I uploaded encrypted object using server-side encryption with customer-provided keys (SSE-C).我使用服务器端加密和客户提供的密钥 (SSE-C) 上传了加密的 object。 Is it possible to download an object using pre-signed URL in AWS S3?是否可以在 AWS S3 中使用预签名的 URL 下载 object?

I tried like this我试过这样

GeneratePresignedUrlRequest generatePresignedUrlRequest1 = new GeneratePresignedUrlRequest("bucketname", "objectpath")
       .withMethod(HttpMethod.GET)
       .withSSECustomerKey(new SSECustomerKey("base64mykey"))
       .withExpiration(new Date( System.currentTimeMillis() + (60 * 60 * 1000)));

The link is generated but when accessing it in the browser I'm getting this error The request signature we calculated does not match the signature you provided. Check your key and signing method.该链接已生成,但在浏览器中访问它时出现此错误The request signature we calculated does not match the signature you provided. Check your key and signing method. The request signature we calculated does not match the signature you provided. Check your key and signing method. Is there a solution for this?有解决方案吗?

SSE-C with pre-signed URLs may not work the way you expect.带有预签名 URL 的 SSE-C 可能无法按您预期的方式工作。

The input to the request-signing algorithm includes all headers that begin with x-amz-* .请求签名算法的输入包括所有以x-amz-*开头的标头。 This is significant for a reason that will become clearer in a moment.这很重要,因为稍后会变得更清楚。

The signature-generating code needs to know what these values will be when you actually make the request, and that is the only thing .withSSECustomerKey() does -- provides information that the signing algorithm needs so that the signature matches the actual request you eventually send.当您实际发出请求时,签名生成代码需要知道这些值是什么,这是.withSSECustomerKey()所做的唯一事情- 提供签名算法所需的信息,以便签名与您最终的实际请求相匹配发送。

The encryption key isn't actually embedded in the pre-signed URL.加密密钥实际上并未嵌入预签名的 URL 中。 It needs to be supplied a second time, when the request is actually made.它需要在实际发出请求时再次提供。

When using server-side encryption with customer-provided encryption keys (SSE-C), you must provide encryption key information using the following request headers.使用客户提供的加密密钥 (SSE-C) 的服务器端加密时,您必须使用以下请求标头提供加密密钥信息。

x-amz-server-side-encryption-customer-algorithm Use this header to specify the encryption algorithm. x-amz-server-side-encryption-customer-algorithm使用此 header 指定加密算法。 The header value must be AES256 . header 值必须是AES256

x-amz-server-side-encryption-customer-key Use this header to provide the 256-bit, base64-encoded encryption key for Amazon S3 to use to encrypt or decrypt your data. x-amz-server-side-encryption-customer-key使用此 header 为 Amazon S3 提供 256 位 base64 编码的加密密钥,用于加密或解密您的数据。

x-amz-server-side-encryption-customer-key-MD5 Use this header to provide the base64-encoded 128-bit MD5 digest of the encryption key according to RFC 1321. Amazon S3 uses this header for a message integrity check to ensure that the encryption key was transmitted without error. x-amz-server-side-encryption-customer-key-MD5使用此 header 根据 RFC 1321 提供加密密钥的 base64 编码的 128 位 MD5 摘要。Amazon S3 使用此 header 来确保消息完整性检查加密密钥的传输没有错误。

https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerSideEncryptionCustomerKeys.html https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerSideEncryptionCustomerKeys.html

So you can use the pre-signed URL from a server using an HTTP client library (by injecting these headers with the request) or you could use it from the browser from Javascript, similarly, or with tools like Postman and Curl, but you can't use it as a clickable or pastable hyperlink, because a URL doesn't provide a way to specify HTTP headers. So you can use the pre-signed URL from a server using an HTTP client library (by injecting these headers with the request) or you could use it from the browser from Javascript, similarly, or with tools like Postman and Curl, but you can不要将其用作可点击或可粘贴的超链接,因为 URL 不提供指定 HTTP 标头的方法。 And, of course, it seems like a bad idea to use it from browser-side JS, too, since that reveals the encryption key in clear text... so if you are planning to download an object stored with SSE-C, that's only appropriate in a secure environment, anyway, because of the need to handle the key in the clear.而且,当然,从浏览器端 JS 中使用它似乎也是一个坏主意,因为它会以明文形式显示加密密钥......所以如果你打算下载一个用 SSE-C 存储的 object,那就是只适合在安全的环境下,反正因为需要在明文中处理密钥。

Ok but with a curl lime this:好的,但是用 curl 石灰这个:

curl -v -T ${S3_UPLOAD_FILE} https://$S3_BUCKET.s3.amazonaws.com/${S3_DESTINATION_FILE} -H "Date: ${S3_DATE}" -H "Authorization: AWS ${S3_KEY}:${S3_SIGNATURE}" -H "Content-Type: ${S3_CONTENT_TYPE}" -H "Content-MD5: ${S3_MD5SUM}" -H "x-amz-server-side-encryption-customer-algorithm:${S3_SSEC_ALGORITHM}" -H "x-amz-server-side-encryption-customer-key:${S3_ENCRYPTION_KEY}" -H "x-amz-server-side-encryption-customer-key-MD5:${S3_ENCRYPTION_MD5}" curl -v -T ${S3_UPLOAD_FILE} https://$S3_BUCKET.s3.amazonaws.com/${S3_DESTINATION_FILE} -H "日期:${S33_$AWS_DATES3_KEY}"授权:${S3_DATES3_KEY} }" -H "内容类型:${S3_CONTENT_TYPE}" -H "内容 MD5:${S3_MD5SUM}" -H "x-amz-server-side-encryption-customer-algorithm:${S3_SSEC_ALGORITHM}" -H “x-amz-server-side-encryption-customer-key:${S3_ENCRYPTION_KEY}”-H “x-amz-server-side-encryption-customer-key-MD5:${S3_ENCRYPTION_MD5}”

I can upload a file ro an s3 bucket with sse-c key.我可以使用 sse-c 密钥将文件上传到 s3 存储桶。 Wath about download?怎么下载?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM