Ok, this is driving me nuts.
I'm trying to create a simple AWS S3 client that would allow for basic interaction with S3, but it seems I'm doing something wrong and can't figure out what it is. It might be blatently obvious, but I'm not seeing it.
My keys are correct and have been tested - no trailing whitespace etc.
The issue seems to be with the signature, it keeps getting the 'the request signature we calculated does not match the signature you provided. Check your key and signing method' error from Amazon's REST API. I've create various categories that add the base64, HMAC SHA1 generation functionality and I've also looked through various online examples, but no success so far.
The reason for not using the library provided by Amazon is because it's aimed at Cocoa Touch and I don't want to hack around to make it work on Cocoa.
You can grab a copy of all the files/code here: https://www.dropbox.com/s/8ts9q71dz3uopxp/S3Lite.zip
I am however following Amazon's documentation around authentication and to my simple mind, everything is being done correctly.
Here's how I'm generating the signature:
-(NSString *)signRequest:(NSURLRequest *)request {
NSMutableString *sig = [[NSMutableString alloc] init];
// Request Method
[sig appendFormat:@"%@\n", [request HTTPMethod]];
// Content MD5
[sig appendFormat:@"%@\n", [[request HTTPBody] MD5String]];
// Content Type
[sig appendFormat:@"%@\n", [request valueForHTTPHeaderField:@"Content-Type"]];
// Date
[sig appendFormat:@"%@\n", [request valueForHTTPHeaderField:@"Date"]];
// Canonicalized Headers
[sig appendFormat:@"%@\n", @""]; // Empty for now
// Canonicalized Resource
[sig appendFormat:@"%@", [NSString stringWithFormat:@"/%@%@", _bucket, request.URL.path]];
NSString *encodedString = [[[sig dataUsingEncoding:NSUTF8StringEncoding] hmacSHA1SignatureWithKey:_secretKey] base64String];
return [[NSString alloc] initWithFormat:@"AWS %@:%@", _accessKey, encodedString];
}
Here's how you go about working with it to attempt to perform a simple PUT request.
#import "S3Lite.h"
S3Lite *aws = [[S3Lite alloc] initWithAccessKey:@"<access key>"
secretKey:@"<secret key>"
bucketName:@"<bucket name>"
region:kAmazonS3EUWest1Region
useSSL:NO];
NSData *file = [[NSData alloc] initWithContentsOfFile:@"<path to a file>"];
[aws putObjectWithData:file inPath:@"aRandomFile.png" withContentType:nil];
Any help in the right direction would be greatly appreciated.
S