Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Getting App crash while login and logout in aws android sdk 2.52.1 #3391

Closed
VijaySonawane5 opened this issue Aug 16, 2023 · 10 comments
Labels
closing soon Issue will auto-close if there is no additional activity within 7 days. cognito Issues with the AWS Android SDK for Cognito

Comments

@VijaySonawane5
Copy link

VijaySonawane5 commented Aug 16, 2023

Logs:-

E com.amazonaws.internal.keyvaluestore.KeyNotFoundException: Error occurred while accessing AndroidKeyStore to retrieve the key for keyAlias: CognitoIdentityProviderCache.aesKeyStoreAlias
I Deleting the encryption key identified by the keyAlias: CognitoIdentityProviderCache.aesKeyStoreAlias
E Error in retrieving the decryption key used to decrypt the data from the persistent store. Returning null for the requested dataKey = CognitoIdentityProvider.xxxxxxxxxxxxxx.LastAuthUser
I hsifw() - flags=0, caller=android.view.inputmethod.InputMethodManager.hideSoftInputFromWindow:1858 android.view.inputmethod.InputMethodManager.hideSoftInputFromWindow:1827
I hsifw() ignore mServedView == null or mServedView.getWindowToken() != windowToken, mServedView D onsize change changed

To Reproduce
Login A user
Logout a user
Again login same user

Environment Information (please complete the following information):

  • AWS Android SDK Version: 2.52.1
  • Device: SAMSUNG M12
  • Android Version: 12
  • Specific to simulators: No
@tjleing tjleing added cognito Issues with the AWS Android SDK for Cognito pending-triage Issue is pending triage labels Aug 21, 2023
@gpanshu
Copy link
Contributor

gpanshu commented Aug 22, 2023

Hello @VijaySonawane5 is this a fatal crash?
Would you be able to upgrade to V2 and try again?

@VijaySonawane5
Copy link
Author

Thanks @gpanshu , Yes it is fatal crash, I tried v2 as well with same backend aws cognito setup but still same fatal exception.

AWS Amplify Logs:

pid-618 E keystore2::error: Rc(ResponseCode(7)), "In get_key_entry, while trying to load key info. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.364 618-31054 keystore2 pid-618 E keystore2::error: Rc(ResponseCode(7)), "In delete_key: Trying to unbind the key. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.367 618-31054 keystore2 pid-618 E keystore2::error: Rc(ResponseCode(7)), "In get_key_entry, while trying to load key info. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.369 618-31054 keystore2 pid-618 E keystore2::error: Rc(ResponseCode(7)), "In delete_key: Trying to unbind the key. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.372 618-31054 keystore2 pid-618 E keystore2::error: Rc(ResponseCode(7)), "In get_key_entry, while trying to load key info. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.375 618-31054 keystore2 pid-618 E keystore2::error: Rc(ResponseCode(7)), "In delete_key: Trying to unbind the key. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.379 618-31054 keystore2 pid-618 E keystore2::error: Rc(ResponseCode(7)), "In get_key_entry, while trying to load key info. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.381 618-31054 keystore2 pid-618 E keystore2::error: Rc(ResponseCode(7)), "In delete_key: Trying to unbind the key. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.385 618-31054 keystore2 pid-618 E keystore2::error: Rc(ResponseCode(7)), "In get_key_entry, while trying to load key info. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.388 618-31054 keystore2 pid-618 E keystore2::error: Rc(ResponseCode(7)), "In delete_key: Trying to unbind the key. 10761, Some("com.amazonaws.android.auth.aesKeyStoreAlias")"
2023-08-21 16:52:35.619 17362-17393 EngineFactory

@gpanshu
Copy link
Contributor

gpanshu commented Aug 22, 2023

Can you share the aws configuration file (with redacted values) and build.gradle dependencies block?
Additionally there is a similar issue where the solution was to simply restart the device as this was happening on device farm. Is that the case here as well or this is happening with your actual users?
Also are you able to reproduce this locally?

@VijaySonawane5
Copy link
Author

VijaySonawane5 commented Aug 22, 2023

@gpanshu Our use case is connect to different aws congnito pools so I have created config json by programatically as follow.

class MyClass : Application() {

override fun onCreate() {
    super.onCreate()
    try {
        val jsonObject = JSONObject()
        val auth = JSONObject()
        jsonObject.put("auth", auth)
        val plugins = JSONObject()
        auth.put("plugins", plugins)

        val awsCognitoAuthPlugin = JSONObject()
        plugins.put("awsCognitoAuthPlugin", awsCognitoAuthPlugin)


        val Auth = JSONObject()
        awsCognitoAuthPlugin.put("Auth", Auth)

        val CognitoUserPool = JSONObject()
        awsCognitoAuthPlugin.put("CognitoUserPool", CognitoUserPool)

        val cogUserPoolDefault = JSONObject()
        CognitoUserPool.put("Default", cogUserPoolDefault)

        cogUserPoolDefault.put("PoolId", "XXXXXXXXX")
        cogUserPoolDefault.put("AppClientId", "XXXXXXXXXXXXXXXXXXXXX")
        cogUserPoolDefault.put("Region", "XXXXXXX")

        val default = JSONObject()
        Auth.put("Default", default)

        val OAuth = JSONObject()
        default.put("OAuth", OAuth)

        default.put("authenticationFlowType","ALLOW_USER_SRP_AUTH")
     
        OAuth.put("WebDomain", "XXXXXXXX")
        OAuth.put("AppClientId", "XXXXXXXXXXXXXXXXXX")
        OAuth.put("SignInRedirectURI", "XXXXXXXXXXXXXXXXX")
        OAuth.put("SignOutRedirectURI", "XXXXXXXXXXXXXXXXXXXXXXXXX")

        val jsonArray = JSONArray()

        jsonArray.put("aws.cognito.signin.user.admin")
        jsonArray.put("openid")
        jsonArray.put("email")
        jsonArray.put("phone")
        jsonArray.put("profile")

        OAuth.putOpt("Scopes",jsonArray)

        Amplify.addPlugin(AWSCognitoAuthPlugin())
        Amplify.configure(AmplifyConfiguration.fromJson(jsonObject), this)
        Log.i("MyAmplifyApp", "Initialized Amplify")
    } catch (error: AmplifyException) {
        Log.e("MyAmplifyApp", "Could not initialize Amplify", error)
    }

In Activity:-

Amplify.Auth.signInWithWebUI(this, { it ->
Log.e("MyAmplifyApp", "Signin")
}, {
Log.e("MyAmplifyApp", "Error")
})

Amplify.Auth.signOut {
Log.e("MyAmplifyApp", "Could not initialize Amplify")
}

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
Log.e("MyAmplifyApp", "Logout")
}

Dependency:-
implementation 'com.amplifyframework:core:2.11.3'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
implementation 'com.amplifyframework:aws-auth-cognito:2.11.3'

With above hosted UI custom tab opened but getting above exception at start also not getting signin callback result.

@gpanshu
Copy link
Contributor

gpanshu commented Aug 22, 2023

Can you link the generated jsonObject that you create? I want to make sure your structure is good.

@VijaySonawane5
Copy link
Author

VijaySonawane5 commented Aug 22, 2023

@gpanshu Here is json structure

{ "auth": { "plugins": { "awsCognitoAuthPlugin": { "Auth": { "Default": { "OAuth": { "WebDomain": "xxxxxxxxx", "AppClientId": "xxxxxxxxxxxxxxxxx", "SignInRedirectURI": "xxxxxxxxxxxxxxxxxxxxxx", "SignOutRedirectURI": "xxxxxxxxxxxxxxxxxxxxxxx", "Scopes": [ "aws.cognito.signin.user.admin", "openid", "email", "phone", "profile" ] }, "authenticationFlowType": "ALLOW_USER_SRP_AUTH" } }, "CognitoUserPool": { "Default": { "PoolId": "xxxxxxxxxxxxx", "AppClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxx", "Region": "us-east-1" } } } } } }

@VijaySonawane5
Copy link
Author

VijaySonawane5 commented Aug 24, 2023

@gpanshu ,

As we using aws sdk with hosted ui which will launch web login ui using appclientId and cognito domainurl, First login attempt works well and we get idp token as well.

But if we logout or clear application cache and try same user again the application has fatal crash.

I try to catch some steps when app gets crash as follow

In AWSKeyValueStore
public synchronized void put(final String dataKey, final String value) {

}

The code_challenge and scope put success and app will get crash.

sqOQXXXXXXXXXX2nXWHacQ-ywY0mQEaUcode_challenge
sqOQtr6KXXXXXXXXXXXXnXWHacQ-ywY0mQEaUscope

In Succcessful login above code_challenage and scope will be put with sucesss as also other paramaters.

CognitoIdentityProvider.XXXXXXXXXXXX.xxxxxxxxx.08@yopmail.com.tokenType
CognitoIdentityProvider.XXXXXXXXXXXX.xxxxxxxxx.08@yopmail.com.idToken
CognitoIdentityProvider.XXXXXXXXXXXX.xxxxxxxxx.08@yopmail.com.accessToken
CognitoIdentityProvider.XXXXXXXXXXXX.xxxxxxxxx.08@yopmail.com.refreshToken
CognitoIdentityProvider.XXXXXXXXXXXX.xxxxxxxxx.08@yopmail.com.tokenScopes

Last code execution point where app gets crashed is

if (activity != null) {
// ### Here app will get crash.
activity.startActivityForResult(
CustomTabsManagerActivity.createStartIntent(context, mCustomTabsIntent.intent),
CUSTOM_TABS_ACTIVITY_CODE
);

} else {
Intent startIntent = CustomTabsManagerActivity.createStartIntent(context, mCustomTabsIntent.intent);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startIntent);
}

One more observation, If we used version 2.13.2 then this flow works fine but when we put app in background then crome custom tab get removed, If we upgrade version above 2.13.2 then app will get crashed as per above steps.

Could you please help here as we are facing crash in productions.

If I used browser insted of custom tab then above is fixed. In AuthClient.Java

mCustomTabsIntent.intent.setData(uri);
mCustomTabsIntent.setAlwaysUseBrowserUI( mCustomTabsIntent.intent);

@gpanshu
Copy link
Contributor

gpanshu commented Aug 24, 2023

@VijaySonawane5 I think you are mixing the sdk code with V2 code. If you are using V2 just simply follow how to use webUI here.

@VijaySonawane5
Copy link
Author

@gpanshu , Yes, we are trying both way sdk and v2, So query is by programatically constructing the AwsConfiguration work using json object as tried above, or awsconfigurations.json file must be part of app. As our usecase is to connect diff aws congnito pools depends on API response.

@gpanshu
Copy link
Contributor

gpanshu commented Aug 28, 2023

@VijaySonawane5 Amplify's AWS SDK for Android and Amplify Android V2 are not compatible with each other. Please use V2 for your purposes to avoid compatibility issues.

@mattcreaser mattcreaser added closing soon Issue will auto-close if there is no additional activity within 7 days. and removed pending-triage Issue is pending triage labels Sep 6, 2023
@tjleing tjleing closed this as completed Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing soon Issue will auto-close if there is no additional activity within 7 days. cognito Issues with the AWS Android SDK for Cognito
Projects
None yet
Development

No branches or pull requests

4 participants