简体   繁体   English

带有iOS AWS S3 SDK SignatureDoesNotMatch的Minio

[英]Minio with the iOS AWS S3 SDK SignatureDoesNotMatch

I have an iOS app that uploads / downloads to / from Amazon's S3. 我有一个iOS应用程序,可以从Amazon的S3上传/下载。 I'd like to replace Amazon's S3 with my own Minio cloud. 我想用自己的Minio云替换Amazon的S3。

I followed the quick tutorial here https://github.com/minio/minio and I have Minio running on my localhost and I can put files using s3cmd ( https://docs.minio.io/docs/s3cmd-with-minio ). 我在这里浏览了快速教程https://github.com/minio/minio ,我在本地主机上运行了Minio,可以使用s3cmd( https://docs.minio.io/docs/s3cmd-with-minio )。

Unfortunately I can't manage to get it to work from within my iOS app. 不幸的是,我无法在iOS应用程序中使其正常工作。

I'm using the AWS SDK v2.4.16 so I can change the endpoint and I made it my localhost ( http://my-imac.local:9000 ) and I updated my access and secret keys but I get a SignatureDoesNotMatch error: "The request signature we calculated does not match the signature you provided. Check your key and signing method.". 我使用的是AWS开发工具包SDK v2.4.16,因此可以更改终结点,并将其设置为本地主机( http://my-imac.local:9000 ),并更新了访问权限和密钥,但是出现SignatureDoesNotMatch错误: “我们计算出的请求签名与您提供的签名不匹配。请检查您的密钥和签名方法。”

Pointing to my local server: 指向我的本地服务器:

AWSEndpoint *minioEndpoint = [[AWSEndpoint alloc] initWithURLString:@"http://my-imac.local:9000"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:region 
        endpoint:minioEndpoint 
        credentialsProvider:credentialProvider];
[AWSS3 registerS3WithConfiguration:configuration forKey:s3RegionString];

Here's what I get on my localhost: 这是我在本地主机上得到的:

time="2017-04-10T23:36:21Z" level=error msg="{\\"method\\":\\"PUT\\",\\"path\\":\\"/mybucket/28AB7D6DCFC44102955EBC0AEFF6E4E2-20170407161228839-0700/foo_28AB7D6DCFC44102955EBC0AEFF6E4E2-20170407161228839-0700_v2.json_bin\\",\\"query\\":\\"\\",\\"header\\":{\\"Accept\\":[\\" / \\"],\\"Accept-Encoding\\":[\\"gzip, deflate\\"],\\"Accept-Language\\":[\\"en-us\\"],\\"Authorization\\":[\\"AWS4-HMAC-SHA256 Credential=LNTXV0YMMZ9SY7MD0ACZ/20170410/us-east-1/s3/aws4_request, SignedHeaders=content-length;content-type;host;user-agent;x-amz-date, Signature=7b2f4172dd926ba84c7edba5170028e0f9361bd8a656ad8f01c7e232f585ab31\\"],\\"Connection\\":[\\"keep-alive\\"],\\"Content-Length\\":[\\"282416\\"],\\"Content-Type\\":[\\"application/octet-stream\\"],\\"Host\\":[\\"my-imac.local\\"],\\"User-Agent\\":[\\"aws-sdk-iOS/2.4.16 iPhone-OS/9.1 en_US\\"],\\"X-Amz-Date\\":[\\"20170410T233620Z\\"]}}" cause="Signature does not match" source="[object-handlers.go:472:objectAPIHandlers.PutObjectHandler()]" time =“ 2017-04-10T23:36:21Z” level = error msg =“ {\\” method \\“:\\” PUT \\“,\\” path \\“:\\” / mybucket / 28AB7D6DCFC44102955EBC0AEFF6E4E2-2017040716122828839-0700 / foo_28AB7D6DCFC44102955EBC0AEFF6E4 -20170407161228839-0700_v2.json_bin \\“,\\” query \\“:\\” \\“,\\” header \\“:{\\” Accept \\“:[\\” / \\“],\\” Accept-Encoding \\“:[ \\“ gzip,deflate \\”],\\“接受语言\\”:[\\“ en-us \\”],\\“授权\\”:[\\“ AWS4-HMAC-SHA256凭据= LNTXV0YMMZ9SY7MD0ACZ / 20170410 / us-east -1 / s3 / aws4_request,SignedHeaders =内容长度;内容类型;主机;用户代理; x-amz日期,Signature = 7b2f4172dd926ba84c7edba5170028e0f9361bd8a656ad8f01c7e232f585ab31 \\“],\\”连接“:[\\”保持],\\ “内容长度\\”:[\\ “282416 \\”],\\ “内容类型\\”:[\\ “应用/八位字节流\\”],\\ “主机\\”:[\\“我的iMac .local \\“],\\” User-Agent \\“:[\\” aws-sdk-iOS / 2.4.16 iPhone-OS / 9.1 en_US \\“],\\” X-Amz-Date \\“:[\\” 20170410T233620Z \\“]}}”原因=“签名不匹配” source =“ [object-handlers.go:472:objectAPIHandlers.PutObjectHandler()]”

On the iOS side: 在iOS方面:

The request headers are: 请求标头为:

{
    Authorization = "AWS4-HMAC-SHA256 Credential=LNTXV0YMMZ9SY7MD0ACZ/20170410/us-east-1/s3/aws4_request, SignedHeaders=content-length;content-type;host;user-agent;x-amz-date, Signature=454c8bad35bdd3a15a08c9bf555fc69f1d5c0dabad78a474eabd4d844ca69aef";
    "Content-Length" = 282416;
    "Content-Type" = "application/octet-stream";
    Host = "my-imac.local";
    "User-Agent" = "aws-sdk-iOS/2.4.16 iPhone-OS/9.1 en_US";
    "X-Amz-Date" = 20170410T233622Z;
}

The response: 响应:

2017-04-10 16:36:22.507 demo[7969:4711709] AWSiOSSDK v2.4.16 [Debug] AWSURLSessionManager.m line:566 | -[AWSURLSessionManager printHTTPHeadersForResponse:] | Response headers:
{
    "Accept-Ranges" = bytes;
    Connection = close;
    "Content-Type" = "application/xml";
    Date = "Mon, 10 Apr 2017 23:36:22 GMT";
    Server = "Minio/RELEASE.2017-03-16T21-50-32Z (linux; amd64)";
    "Transfer-Encoding" = Identity;
    Vary = Origin;
    "X-Amz-Request-Id" = 14B42D7AE5B09A2B;
}

Please replace accessKey , secretKey , and url , change the region base on what you need, service must set to .S3 请替换accessKeysecretKeyurl ,根据需要更改区域,服务必须设置为.S3

( AWSS3 will auto remove port number if you type xxxx:9000 in url , currently it only support full url without port, so please make sure you have a domain map to port 9000, you may need refer to this Setup Nginx proxy with Minio Server ) (如果您在url输入xxxx:9000AWSS3会自动删除端口号,当前它仅支持不带端口的完整url,因此请确保您具有到端口9000的域映射,您可能需要使用Minio Server来参考此Setup Nginx代理

let accessKey = "XXXXXXX"
let secretKey = "XXXXXXX"

let credentialsProvider = AWSStaticCredentialsProvider(accessKey: accessKey, secretKey: secretKey)
let configuration = AWSServiceConfiguration(region: .USEast1, endpoint: AWSEndpoint(region: .USEast1, service: .S3, url: URL(string:"XXXXXX")),credentialsProvider: credentialsProvider)

AWSServiceManager.default().defaultServiceConfiguration = configuration

let S3BucketName = "images"
let remoteName = "test.jpg"
let fileURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(remoteName)
let image = UIImage(named: "test")
let data = UIImageJPEGRepresentation(image!, 0.9)
do {
    try data?.write(to: fileURL)
}
catch {}

let uploadRequest = AWSS3TransferManagerUploadRequest()!
uploadRequest.body = fileURL
uploadRequest.key = remoteName
uploadRequest.bucket = S3BucketName
uploadRequest.contentType = "image/jpeg"
uploadRequest.acl = .publicRead

let transferManager = AWSS3TransferManager.default()

transferManager.upload(uploadRequest).continueWith { (task: AWSTask<AnyObject>) -> Any? in
  ...
}

Full example project here 完整的示例项目在这里

NOTE you need to apply the following change as well to make it fully work https://github.com/aws/aws-sdk-ios/pull/638 注意您还需要应用以下更改以使其完全起作用https://github.com/aws/aws-sdk-ios/pull/638

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

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