aws / aws-sdk-net

The official AWS SDK for .NET. For more information on the AWS SDK for .NET, see our web site:
http://aws.amazon.com/sdkfornet/
Apache License 2.0
2.07k stars 862 forks source link

Intermitent Bad Request for StartWithSrpAuthAsync #834

Closed pramodpaudel377 closed 5 years ago

pramodpaudel377 commented 6 years ago

While logging sometimes there is an error - "Invalid Input Given" due to Bad Request while using StartWithSrpAuthAsync. this is not happening every time and is an intermittent issue.

Expected Behavior

While creating a BigInteger it should check and make sure it is a valid number and should able to authenticate SRP auth request.

Current Behavior

Right now while generating BigInteger with random value here -

 internal static Tuple<BigInteger, BigInteger> CreateAaTuple()
        {
            BigInteger a, A;
            do
            {
                a = new BigInteger(16, new Random());
                A = g.ModPow(a, N);
            } while (A.Mod(N).Equals(BigInteger.Zero));

            return Tuple.Create<BigInteger, BigInteger>(A, a);
        }

sometimes its generating valid value which is not valid for AWS Cognito SRP auth. and should be identified early

Possible Solution

Steps to Reproduce (for bugs)

using this Auth-request I am able to reproduce the issue -

        InitiateAuthRequest initiateAuthRequest = new InitiateAuthRequest()
        {
            AuthFlow = AuthFlowType.USER_SRP_AUTH,
            ClientId = <AWS-CLIENT-ID>,
            AuthParameters = new Dictionary<string, string>(StringComparer.Ordinal)
            {
                { CognitoConstants.ChlgParamUsername, username },
                { CognitoConstants.ChlgParamSrpA, "b8feb74c204ff5" }
                //
            }
        };

        InitiateAuthResponse initiateResponse = await 
       provider.InitiateAuthAsync(initiateAuthRequest).ConfigureAwait(false);

Context

I am trying to authenticate the user using StartWithSrpAuthAsync it works fine 95 % but fails sometimes with Bad Request error and ended up showing Invalid Input Given error.

Your Environment

gokarnm commented 6 years ago

@pramodpaudel377, thanks for reporting this, we'll look into it.

sstevenkang commented 6 years ago

Hi, I am a little confused by your report. Could you distinguish which portion of the report is your theory/diagnosis and which is the observed behavior? Why do you think CreateAaTuple() is generating an invalid value?

To help you diagnose this, could you capture the request IDs? Also, if you could capture the HTTP request and response via Fiddler or some other traffic monitoring tool, that would be helpful.

pramodpaudel377 commented 6 years ago

this is a random issue, and can't be reproduced as desired by the system. So fiddler log is not possible, but I'll give it a try if I can manage to capture some. but I am getting "Invalid Input Given" sometimes.

So I tried passing a value in ChlgParamSrpA (ie - b8feb74c204ff5 ) which is following this pattern - ^[0-9a-fA-F]+$ and still throwing the same error - "Invalid Input Given" and CreateAaTuple is the only function whose output is used to set ChlgParamSrpA value.

So I am sure CreateAaTuple, sometimes not generating the desired output. Since this works most of the time with same Inputs from Users, but failing couple of times.

Also, this is a rare issue, it happens very very few times.

sstevenkang commented 6 years ago

I get that this is intermittent. The string b8feb74c204ff5 follows the pattern ^[0-9a-fA-F]+$--did you mean to say that the service returns invalid input despite following the regex pattern?

In your application's catch block, could you log the requestid and share that with us?

pramodpaudel377 commented 6 years ago

I am sorry, Yes I meant it follows the pattern but will throw Invalid Input even when it follows the pattern.

Here is the stack trace I find in elmah -

   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.HttpRequest.<GetResponseAsync>d__16.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\HttpHandler\_bcl\HttpWebRequestFactory.cs:line 230
   --- End of inner exception stack trace ---
   at Amazon.Runtime.Internal.HttpRequest.<GetResponseAsync>d__16.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\HttpHandler\_bcl\HttpWebRequestFactory.cs:line 247
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.HttpHandler`1.<InvokeAsync>d__9`1.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\HttpHandler\HttpHandler.cs:line 175
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.Unmarshaller.<InvokeAsync>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext()
   --- End of inner exception stack trace ---
   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException exception) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\HttpErrorResponseExceptionHandler.cs:line 114
   at Amazon.Runtime.Internal.ExceptionHandler`1.Handle(IExecutionContext executionContext, Exception exception) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\ExceptionHandler.cs:line 38
   at Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext executionContext, Exception exception) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\ErrorHandler.cs:line 204
   at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\ErrorHandler.cs:line 104
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\CredentialsRetriever.cs:line 98
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\RetryHandler\RetryHandler.cs:line 137
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\ErrorCallbackHandler.cs:line 58
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Extensions.CognitoAuthentication.CognitoUser.<StartWithSrpAuthAsync>d__77.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\extensions\src\AWSSDK.Extensions.CognitoAuthentication\CognitoUserAuthentication.cs:line 48
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at iota.Services.UserService.<LoginAsync>d__6.MoveNext() in Service.cs:line 48
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at iota.Business.UserBusiness.<LoginAsync>d__4.MoveNext() in Business.cs:line 30
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at iota.Controllers.UserController.<Login>d__5.MoveNext() in Controller.cs:line---
pramodpaudel377 commented 6 years ago

I'll add the logging for requestID too and will share with you once I'll get the issue again.

pramodpaudel377 commented 6 years ago

Here is the request ID - f1526660-fd36-11e7-a701-9951c60f2a98 Please let me know if you want anything else ?

sstevenkang commented 6 years ago

I think that's all we need for now. I'll get in touch with the service team to chase down what's going on here.

behrooziAWS commented 6 years ago

Could you provide a timestamp and region? I agree it is likely an issue with the client as the javascript/ios/android implementations exhibited this behavior when there were client code bugs and now they work 100%.

sstevenkang commented 6 years ago

@behrooziAWS do you by any chance remember what those bugs were? I can check our code to see the same bugs are present.

pramodpaudel377 commented 6 years ago

@behrooziAWS Here is the timestamp of the request Id I shared earlier - Date: Fri, 19 Jan 2018 16:36:47 GMT, Region is us-east-1

pramodpaudel377 commented 6 years ago

hey Guys, any luck here. I am wondering if you need any more info on my side? Can you confirm if this is an issue with Client?

sstevenkang commented 6 years ago

We are looking into it. Last correspondence with the service team indicate that it might be a client side issue after all. We are reviewing how SRP_A is generated.

normj commented 5 years ago

Is anybody seeing this issue with the latest release of the library. Note the library was also renamed to Amazon.Extensions.CognitoAuthentication

normj commented 5 years ago

Closing for lack of activity