Amazon S3 invalid signature

1,199 views
Skip to first unread message

creztoe

unread,
Apr 30, 2010, 5:06:36 AM4/30/10
to ASIHTTPRequest
Im am having trouble generating a valid signature when sending a
request to Amazon S3.
Below is the code snippet used to generate and send the request.

fileName = @"test.caf";
[ASIS3Request setSharedSecretAccessKey:*mySecretKey*];
[ASIS3Request setSharedAccessKey:*myAccessKey*];

NSString *filePath = [NSTemporaryDirectory()
stringByAppendingPathComponent: @"recordedFile.caf"];
ASIS3ObjectRequest *request =
[ASIS3ObjectRequest PUTRequestForFile:filePath
withBucket:@"MarkerAudio" key:fileName];
[request startSynchronous];
if ([request error]) {
NSLog(@"%@",[[request error] localizedDescription]);
}

Error reported is:
The request signature we calculated does not match the signature you
provided. Check your key and signing method.

I have used the same access and secret key to access the bucket
through other means and it works fine. Any help is much appreciated.

--
You received this message because you are subscribed to the Google Groups "ASIHTTPRequest" group.
To post to this group, send email to asihttp...@googlegroups.com.
To unsubscribe from this group, send email to asihttpreques...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/asihttprequest?hl=en.

Ben Copsey

unread,
Apr 30, 2010, 10:28:38 AM4/30/10
to asihttp...@googlegroups.com
Hi

> Im am having trouble generating a valid signature when sending a
> request to Amazon S3.
> Below is the code snippet used to generate and send the request.
>
> fileName = @"test.caf";
> [ASIS3Request setSharedSecretAccessKey:*mySecretKey*];
> [ASIS3Request setSharedAccessKey:*myAccessKey*];
>
> NSString *filePath = [NSTemporaryDirectory()
> stringByAppendingPathComponent: @"recordedFile.caf"];
> ASIS3ObjectRequest *request =
> [ASIS3ObjectRequest PUTRequestForFile:filePath
> withBucket:@"MarkerAudio" key:fileName];
> [request startSynchronous];
> if ([request error]) {
> NSLog(@"%@",[[request error] localizedDescription]);
> }
>
> Error reported is:
> The request signature we calculated does not match the signature you
> provided. Check your key and signing method.
>
> I have used the same access and secret key to access the bucket
> through other means and it works fine. Any help is much appreciated.

Your code looks fine. The first thing I'd do is to double check you've got the access key / secret access key round the right way, and that they are correct.

Best

Ben

creztoe

unread,
Apr 30, 2010, 6:54:52 PM4/30/10
to ASIHTTPRequest
I used the same access and secret key with S3 Browser and it works
just fine. I am really frustrated with this.

I also use the same keys to access my Amazon SimpleDB using a wrapper
someone wrote for the iPhone and it also works.

Alex Reynolds

unread,
Apr 30, 2010, 7:06:19 PM4/30/10
to asihttp...@googlegroups.com
Amazon's JavaScript S3 signature tester is a good way to locally compare the NSData going into the signature ("StringToSign") and the data that comes out, with what your methods are generating.

-Alex

Alex Reynolds

unread,
Apr 30, 2010, 7:06:40 PM4/30/10
to asihttp...@googlegroups.com

Ben Copsey

unread,
May 1, 2010, 4:40:42 AM5/1/10
to asihttp...@googlegroups.com
> I used the same access and secret key with S3 Browser and it works
> just fine. I am really frustrated with this.
>
> I also use the same keys to access my Amazon SimpleDB using a wrapper
> someone wrote for the iPhone and it also works.

I tested with your code yesterday using my own S3 account, and it worked perfectly.

If you downloaded ASIHTTPRequest a while ago, you might have been unlucky enough to get a version where S3 support was broken. I think that's probably quite unlikely, but it might be worth updating your copy just in case.

Robert Hawkey

unread,
Jun 18, 2010, 11:51:34 AM6/18/10
to ASIHTTPRequest
Just in case anyone else runs into this, I had this same problem and
the problem came down to having capital letters in my bucket name. I
created my bucked on the AWS Management console, something like:
MyBucket. But, somewhere along the line the process was turning the
MyBucket into mybucket, and I only discovered this by checking the
reply XML from the server reporting the invalid signature and I could
see a line with mybucket in lowercase. Figuring that can't be good I
made a new bucket "mybucket" no caps, and moved all the files into
it. Once I did that the same code worked perfectly.

Rob Hawkey

On May 1, 1:40 am, Ben Copsey <b...@allseeing-i.com> wrote:
> > I used the same access and secret key withS3Browser and it works
> > just fine.  I am really frustrated with this.
>
> > I also use the same keys to access my Amazon SimpleDB using a wrapper
> > someone wrote for the iPhone and it also works.
>
> I tested with your code yesterday using my ownS3account, and it worked perfectly.
>
> If you downloaded ASIHTTPRequest a while ago, you might have been unlucky enough to get a version whereS3support was broken. I think that's probably quite unlikely, but it might be worth updating your copy just in case.

Ben Copsey

unread,
Jun 19, 2010, 6:12:07 AM6/19/10
to asihttp...@googlegroups.com
Hi Robert

> Just in case anyone else runs into this, I had this same problem and
> the problem came down to having capital letters in my bucket name. I
> created my bucked on the AWS Management console, something like:
> MyBucket. But, somewhere along the line the process was turning the
> MyBucket into mybucket, and I only discovered this by checking the
> reply XML from the server reporting the invalid signature and I could
> see a line with mybucket in lowercase. Figuring that can't be good I
> made a new bucket "mybucket" no caps, and moved all the files into
> it. Once I did that the same code worked perfectly.

I think this is because ASIS3Request refers to the bucket using the virtual host style, eg: http://mybucket.s3.amazonaws.com.

IIRC you can perform requests with the REST API in a different way that would allow you to use a mix of upper and lowercase characters, but I think the value of being able to use a subdomain to refer to your bucket probably outweighs the advantage of this, especially if you are making your resources public.

Incidentally, there are other restrictions on the names you can use with the dns style (eg: no underscores), see:

http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?BucketRestrictions.html

I should probably add a note on this to the documentation.

Best

Ben

Reply all
Reply to author
Forward
0 new messages