aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 885 forks source link

Clock skew not being handled by didCompleteWithError method #1077

Closed ghost closed 11 months ago

ghost commented 6 years ago

Describe the bug When making a request on a device with wrong time, the response comes with the following error Signature not yet current: 20130909T170846Z is still later than 20130909T170823Z (20130909T170323Z + 5 min.).

To Reproduce Steps to reproduce the behavior:

  1. Put your phone clock back 20 minutes
  2. Try to make a request to an AWSLambda instance

Which AWS service(s) are affected? • AWSLambda

Expected behavior When making a request on a device with wrong time, the SDK should attempt a new request with the clock skew fixed.

Screenshots Not applicable.

Environment(please complete the following information):

Device Information (please complete the following information):

Additional context When an error related to clock skew returns from the request it should call the method - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)sessionTask didCompleteWithError:(NSError *)error in order to retry the task with clock skew fixed (AWSNetworkingRetryTypeShouldCorrectClockSkewAndRetry).

mutablealligator commented 6 years ago

@ghearly Sorry for the inconvenience. Can you post a code snippet that reproduces the issue?

ghost commented 6 years ago

@kvasukib This is the AWSAPIGatewayRequest we are using: AWSAPIGatewayRequest *request = [[AWSAPIGatewayRequest alloc] initWithHTTPMethod:@"POST" URLString:@"/users" queryParameters:queryParameters headerParameters:_headersPOST HTTPBody:HTTPBody];

We call it like this [[[APIClient defaultClient] usersPostWithHTTPBody:HTTPBody] continueWithBlock:^id _Nullable(AWSTask * _Nonnull task) { BLOCK GOES HERE }];.

The APIClient class is generated by AWS, it works fine when the client has the correct hour and date set.

palpatim commented 5 years ago

The APIGatewayClient and its API-specific subclasses use custom network handling rather than the core stack, which means that even defining a retry handler and injecting it into the API client's configuration wouldn't be respected.

The request returned from the API Gateway includes enough information that a caller could potentially inspect and retry manually, but that's not really a good solution--the SDK should do this on the client's behalf.

Because the APIGateway network stack is custom, the behavior isn't technically a bug so much as a feature gap. Therefore, I'm characterizing this as a feature request to this capability to bring this SDK into parity with other SDKs. At implementation time, we'll need to decide whether to expand the client with retry-specific custom code in both invoke methods of the API Gateway client, or migrate the APIGatewayClient networking code to use AWSCore networking.

svsharsha commented 5 years ago

We are also facing this issue. In IOS we implemented direct lambda invocation, when user changes iPads time manually got below exception "{"message":"Signature not yet current: 20190604T152329Z is still later than 20190604T090443Z (20190604T085943Z + 5 min.)"}" AND "Error Domain=com.amazonaws.AWSLambdaErrorDomain Code=0 "InvalidSignatureException" UserInfo={StatusCode=403, responseStatusCode=403, message=Signature not yet }"

And there is no proper solution for Clock skew issue in IOS. Please let us know the solution for this.

atierian commented 11 months ago

Thanks for opening this feature request. We’re closing this due to the lack of community engagement on the request.