ErrorCode: AccessDenied, Message: AWS authentication requires a valid Date header or x-amz-date

my application works fine in ios 6 .. it downloads and downloads data from the amazon s3 web server..but when I upgrade ios 6 to ios 7 ... I got a warning message “cannot connect to server” error in the log window

"Exception = AmazonServiceException {RequestId: 5DC8AEF01DD9FB91, ErrorCode: AccessDenied, Message: A valid Date or x-amz-date header is required for AWS authentication."

to solve this problem, I upgrade my aws ios sdk 1.0.0 to aws ios sdk 1.6.1. and try to run my application, it freezes for 10-12 seconds, and then the application works.

so please can someone tell me a solution how to remove the "x-amz-date header" problem in aws ios sdk 1.0.0 and its alternative freeze problem in aws ios sdk 1.6.1 ..

+6
source share
4 answers

I sent an Apple error report (to find out if this error is or not).

In the meantime, I created a terrible hack that solves the problem in S3Request.m in the configureURLRequest method:

NSString *checkFormat =[self.date requestFormat]; if(![checkFormat hasSuffix:@":00"]) checkFormat = [NSString stringWithFormat:@"%@:00",checkFormat]; [self.urlRequest setValue:checkFormat forHTTPHeaderField:kHttpHdrDate]; 

This may not be the case with your version of the AWS SDK.

I would not use this fix in the long run - I will send any response from the Apple bug report team here as soon as they return with the recommended solution

I also posted a question here: https://forums.aws.amazon.com/thread.jspa?threadID=135829#

EDIT: in the latest version of the hack toolkit:

 NSString *checkFormat =[self.date stringWithRFC822Format]; if(![checkFormat hasSuffix:@":00"]) checkFormat = [NSString stringWithFormat:@"%@:00",checkFormat]; [self.urlRequest setValue:checkFormat forHTTPHeaderField:kHttpHdrDate]; 
0
source

At AmazonSDKUtil.m we have the following methods:

 +(NSDate *)convertStringToDate:(NSString *)string usingFormat:(NSString *)dateFormat { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:dateFormat]; [dateFormatter setLocale:[AmazonSDKUtil timestampLocale]]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; NSDate *parsed = [dateFormatter dateFromString:string]; NSDate *localDate = [parsed dateByAddingTimeInterval:_clockskew]; [dateFormatter release]; return localDate; } +(NSString *)convertDateToString:(NSDate *)date usingFormat:(NSString *)dateFormat { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; [dateFormatter setDateFormat:dateFormat]; [dateFormatter setLocale:[AmazonSDKUtil timestampLocale]]; NSDate *realDate = [date dateByAddingTimeInterval:-1*_clockskew]; NSString *formatted = [dateFormatter stringFromDate:realDate]; [dateFormatter release]; return formatted; } 

In older versions of the SDK, the locale and time zone were incorrectly set to en_US and GMT . This can cause problems depending on the locale of your device and time zone settings. The latest version of the SDK fixed the problem. If for some reason you cannot update the SDK, you can change AmazonSDKUtil.m and explicitly set the language and time zone.

EDIT:

If you run the following code snippet on iOS 6 and iOS 7, you can see how setting the locale affects the date format.

 NSDateFormatter *dateFormatter = [NSDateFormatter new]; dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z"; dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"PDT"]; dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; NSString *dateWithoutTimezoneAndLocale = [dateFormatter stringFromDate:[NSDate date]]; NSLog(@"Date 1: %@", dateWithoutTimezoneAndLocale); dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; NSString *dateWithTimezoneAndLocale = [dateFormatter stringFromDate:[NSDate date]]; NSLog(@"Date 2: %@", dateWithTimezoneAndLocale); 

On iOS 6

 Date 1: Wed, 25 Sep 2013 16:25:29 PDT Date 2: Wed, 25 Sep 2013 23:25:29 GMT 

On iOS 7

 Date 1: Wed, 25 Sep 2013 16:24:11 GMT-7 Date 2: Wed, 25 Sep 2013 23:24:11 GMT 

As you said earlier, the behavior of NSDateFormatter has changed in iOS 7; however, the main reason for this problem is that you are not explicitly setting the locale to en_US . If the locale is set to a value other than en_US , this can cause a problem. That's why we explicitly set the locale in the latest version of our SDK so that it works on devices with any locale settings.

Hope this makes sense

+3
source

Finally, I got a solution, and it works for me, I used awsios sdk 1.3.1 instead of awsios sdk 1.6.1. and make some changes to S3Request.m in the method

 -(AmazonURLRequest *)configureURLRequest{ .... .... NSString *checkFormat =[self.date stringWithRFC822Format]; if(![checkFormat hasSuffix:@":00"]) checkFormat = [NSString stringWithFormat:@"%@+00:00",checkFormat]; [self.urlRequest setValue:checkFormat forHTTPHeaderField:kHttpHdrDate]; ... ... 

}

0
source

I had the same problem and after upgrading to version 1.6 SDK SDK the problem went away.

0
source

Source: https://habr.com/ru/post/954318/


All Articles