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

UnrecoverableKeyException while initializing CognitoCachingCredentialsProvider in Android 6 #1001

Closed
fernando-owlapps opened this issue May 29, 2019 · 6 comments
Assignees
Labels
bug Something isn't working closing soon Issue will auto-close if there is no additional activity within 7 days. core Issues with the AWS Android Core library pending-community-response Issue is pending response from the issue requestor

Comments

@fernando-owlapps
Copy link

fernando-owlapps commented May 29, 2019

Describe the bug
Firebase Crash report show many errors/crashs in android.

Implementation Code

Class BaseAplication
        credentialsProvider = new CognitoCachingCredentialsProvider(
                context,    /* get the context for the application */
                IDENTITY_POOL_ID,    /* Identity Pool ID */
                Regions.US_EAST_1           /* Region for your identity pool--US_EAST_1 or EU_WEST_1*/
        );
private class CognitoAuthTask extends AsyncTask<String, Void, Credentials> {
        @Override
        protected Credentials doInBackground(String... strings) {
            String userId = strings[0];
            String token = strings[1];
            GetCredentialsForIdentityResult tokenResp = null;
            try {
                Map<String, String> providerTokens = new HashMap<String, String>();
                providerTokens.put("cognito-identity.amazonaws.com", token);
                AmazonCognitoIdentityClient identityClient = new AmazonCognitoIdentityClient(credentialsProvider);
                identityClient.setRegion(Region.getRegion(Regions.US_EAST_1));
                GetCredentialsForIdentityRequest request = new GetCredentialsForIdentityRequest();
                request.setIdentityId(userId);
                request.withLogins(providerTokens);
                tokenResp = identityClient.getCredentialsForIdentity(request);
            } catch (Exception e) {
                if (BuildConfig.DEBUG) {
                    e.printStackTrace();
                }
            } finally {
                return tokenResp == null ? null : tokenResp.getCredentials();
            }
        }

        @Override
        protected void onPostExecute(Credentials credentials) {
            super.onPostExecute(credentials);
            cognitoCredentials = credentials;
            if (BuildConfig.DEBUG) {
                Log.d("Cognito Credentials", credentials == null ? "null" : credentials.toString());
            }
        }
    }

Last 5 days - Firebase Crash Error

744 errors
Fatal Exception: java.lang.RuntimeException: Unable to create application com.pontomobi.Application: java.lang.IllegalStateException: Error in initializing the CognitoCachingCredentialsProvider. 
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6499)
       at android.app.ActivityThread.access$1800(ActivityThread.java:229)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7406)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by java.lang.IllegalStateException: Error in initializing the CognitoCachingCredentialsProvider. 
       at com.amazonaws.auth.CognitoCachingCredentialsProvider.initialize(CognitoCachingCredentialsProvider.java:434)
       at com.amazonaws.auth.CognitoCachingCredentialsProvider.<init>(CognitoCachingCredentialsProvider.java:190)
       at com.pontomobi.Application.onCreate(Application.java:143)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6496)
       at android.app.ActivityThread.access$1800(ActivityThread.java:229)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7406)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by java.lang.IllegalStateException: java.security.UnrecoverableKeyException: Failed to obtain information about key
       at com.amazonaws.internal.keyvaluestore.KeyProvider23.getKey(KeyProvider23.java:69)
       at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.setPersistenceEnabled(AWSKeyValueStore.java:131)
       at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.<init>(AWSKeyValueStore.java:108)
       at com.amazonaws.auth.CognitoCachingCredentialsProvider.initialize(CognitoCachingCredentialsProvider.java:425)
       at com.amazonaws.auth.CognitoCachingCredentialsProvider.<init>(CognitoCachingCredentialsProvider.java:190)
       at com.pontomobi.Application.onCreate(Application.java:143)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6496)
       at android.app.ActivityThread.access$1800(ActivityThread.java:229)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7406)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by java.security.UnrecoverableKeyException: Failed to obtain information about key
       at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreSecretKeyFromKeystore(AndroidKeyStoreProvider.java:275)
       at android.security.keystore.AndroidKeyStoreSpi.engineGetKey(AndroidKeyStoreSpi.java:97)
       at java.security.KeyStore.getKey(KeyStore.java:253)
       at com.amazonaws.internal.keyvaluestore.KeyProvider23.getKey(KeyProvider23.java:65)
       at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.setPersistenceEnabled(AWSKeyValueStore.java:131)
       at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.<init>(AWSKeyValueStore.java:108)
       at com.amazonaws.auth.CognitoCachingCredentialsProvider.initialize(CognitoCachingCredentialsProvider.java:425)
       at com.amazonaws.auth.CognitoCachingCredentialsProvider.<init>(CognitoCachingCredentialsProvider.java:190)
       at com.pontomobi.Application.onCreate(Application.java:143)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6496)
       at android.app.ActivityThread.access$1800(ActivityThread.java:229)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7406)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by android.security.KeyStoreException: -49
       at android.security.KeyStore.getKeyStoreException(KeyStore.java:945)
       at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreSecretKeyFromKeystore(AndroidKeyStoreProvider.java:275)
       at android.security.keystore.AndroidKeyStoreSpi.engineGetKey(AndroidKeyStoreSpi.java:97)
       at java.security.KeyStore.getKey(KeyStore.java:253)
       at com.amazonaws.internal.keyvaluestore.KeyProvider23.getKey(KeyProvider23.java:65)
       at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.setPersistenceEnabled(AWSKeyValueStore.java:131)
       at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.<init>(AWSKeyValueStore.java:108)
       at com.amazonaws.auth.CognitoCachingCredentialsProvider.initialize(CognitoCachingCredentialsProvider.java:425)
       at com.amazonaws.auth.CognitoCachingCredentialsProvider.<init>(CognitoCachingCredentialsProvider.java:190)
       at com.pontomobi.Application.onCreate(Application.java:143)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6496)
       at android.app.ActivityThread.access$1800(ActivityThread.java:229)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7406)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Screenshots
If applicable, add screenshots to help explain your problem.

Environment Information (please complete the following information):

  • AWS Android SDK Version:
    implementation 'com.amazonaws:aws-android-sdk-core:2.2.+'
    implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.2.+'
    implementation 'com.amazonaws:aws-android-sdk-appsync:2.9.0'
  • Device: 97% Samsung (84% Galaxy Grand Prime Plus, 12% Galaxy J2 Prime)
  • Android Version: 97% Android 6

Additional context
Problems before update sdk version on app

@mutablealligator mutablealligator self-assigned this May 29, 2019
@mutablealligator mutablealligator added bug Something isn't working core Issues with the AWS Android Core library labels May 29, 2019
@mutablealligator mutablealligator changed the title Unable to create application java.lang.IllegalStateException: Error in initializing the CognitoCachingCredentialsProvider UnrecoverableKeyException while initializing CognitoCachingCredentialsProvider in Android 6 May 29, 2019
@mutablealligator
Copy link
Contributor

@owdeveloper Sorry for the inconvenience caused.

  1. Are you able to reproduce this problem locally?
  2. Do you have insights on if the end-user who is experiencing the crash
    2.1) upgraded from an older Android version to Android 6 recently?
    2.2) changed their password recently?
    2.3) set the phone state to NO_LOCK

@mutablealligator mutablealligator added the pending-community-response Issue is pending response from the issue requestor label May 29, 2019
@fernando-owlapps
Copy link
Author

@kvasukib ,
1 - We can not reproduce this location.
2 - Our users did not report the problem in store.

We are concerned about the volume of errors in the crahs report.

@minbi minbi removed the pending-community-response Issue is pending response from the issue requestor label Jun 3, 2019
@ahsan7766
Copy link

I am also getting the same error as described above.
Alot of reports on google play console and firebase crashes
.at this line
CognitoCachingCredentialsProvider awsCreds = new CognitoCachingCredentialsProvider(context, config);
and our crash log is
Caused by: java.lang.IllegalStateException: at com.amazonaws.auth.CognitoCachingCredentialsProvider.initialize (CognitoCachingCredentialsProvider.java:434) at com.amazonaws.auth.CognitoCachingCredentialsProvider.<init> (CognitoCachingCredentialsProvider.java:230) at com.jbsia_dani.thumbnilmaker.s3Bucket.S3BucketDownloader.<init> (S3BucketDownloader.java:86) at com.jbsia_dani.thumbnilmaker.Home.onCreate (Home.java:123) at android.app.Activity.performCreate (Activity.java:5582) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1093) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2405)

@palpatim
Copy link
Member

palpatim commented Aug 2, 2019

Working on a fix for this now as part of #937

@palpatim palpatim added pending-community-response Issue is pending response from the issue requestor and removed Investigating labels Aug 21, 2019
@palpatim
Copy link
Member

We released a fix for this on 2.15.1. Please let us know if you have any questions or continue to see crashes related to retrieving encrypted data.

@desokroshan desokroshan added the closing soon Issue will auto-close if there is no additional activity within 7 days. label Aug 30, 2019
@stale
Copy link

stale bot commented Sep 6, 2019

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

@stale stale bot closed this as completed Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closing soon Issue will auto-close if there is no additional activity within 7 days. core Issues with the AWS Android Core library pending-community-response Issue is pending response from the issue requestor
Projects
None yet
Development

No branches or pull requests

6 participants