tpyo / amazon-s3-php-class

A standalone Amazon S3 (REST) client for PHP 5/CURL
1.03k stars 503 forks source link

[InvalidRequest] The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256 #96

Open damient opened 9 years ago

damient commented 9 years ago

Hi,

I use the new location "Franckfurt" for my bucket and Amazon use the new signature version 4 only.

Can you adapt your code for this version ?

Thx.

stuartford commented 9 years ago

vote++. This would be very useful.

fb3rasp commented 9 years ago

vote++ Does anybody have a work around for now?

MaiKaY commented 9 years ago

vote++

Luzifer commented 9 years ago

Someone would need to implement the new hashing algorithm described at http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html / http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html - Currently I didn't manage to do so…

DavidAnderson684 commented 9 years ago

Example implementation: https://github.com/chrismeller/awstools/blob/master/aws/signature/v4.php

boussou commented 9 years ago

AWS4-HMAC-SHA256 - described here http://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html

from http://blog.paddez.com/?p=2781

DavidAnderson684 commented 9 years ago

I actually started work on this, and got the signature in the header working. Then I spotted the requirement that if you use this signature, then there's also a requirement to sign the payload with a new hash too - and doing this for multipart uploads had another complicating factor as well.

At that point, I decided to instead switch to the official AWS PHP SDK as a better long-term option. I created a compatibility layer that was sufficient for the use-case of my code, but won't handle a lot of other scenarios - but it may be useful for others to consult if they decide to port over to the AWS SDK; it's here: http://plugins.svn.wordpress.org/updraftplus/trunk/includes/S3compat.php

boussou commented 9 years ago

I found that when you create a bucket from this package, it work perfectly. it end up in the region "US Standard" and then in this region AWS4-HMAC-SHA256 is pefectly accepted then a file uploads actually work.

When I use a bucket name created in the regions "Frankfurt" I got an error

DavidAnderson684 commented 9 years ago

@bouusoou: Which package are you referring to as "this package" ? tpyo's class, or mine?

boussou commented 9 years ago

tpyo's class.

I am a bit confused with yours and did not use it in the end, because tpyo's was. (when region is "US Standard")

I think call should look like this:

$compat=new UpdraftPlus_S3_Compat; $compat->setAuth($awsAccessKey, $awsSecretKey); $compat-> setRegion($region); $compat->putObjectFile($file, $bucket, $uri, $acl = self::ACL_PRIVATE)

robertotremonti commented 9 years ago

+1 on this

Bakual commented 9 years ago

Also run into this today. Using the official SDK kit is no option for me as it imho requires PHP 5.5 and my code has to run on PHP 5.3.10+. As a workaround I just don't use the newer servers like Frankfurt, but it would be helpful if that is supported.

DavidAnderson684 commented 9 years ago

"it imho requires PHP 5.5"

The 2.x branch of the official SDK is still maintained, and requires PHP 5.3.3+ : https://github.com/aws/aws-sdk-php/tree/2.8

Bakual commented 9 years ago

Thanks! Didn't know that.

tpyo commented 9 years ago

Sorry everyone, I haven't been able to look into this. Would anyone be willing to work on a PR?

philicious commented 8 years ago

unfortunately I dont have the time to fix up the code and make a PR but I'd like to +1 this

Edit: now I saw there is PR #122 which looks quite promising on first glance