-
Notifications
You must be signed in to change notification settings - Fork 119
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
javax.crypto.AEADBadTagException and android.security.KeyStoreException #2723
Comments
Hello, @sayasheng. can you upgrade to latest version of Amplify v2.14.11? Latest release has fix for adding fallback logic for corrupt keys to EncryptedKeyValueRepository. |
@ankpshah Yes, I already upgraded to Amplify v2.14.11 from v1 yesterday. This issue still happens on v2.14.11 after clearing all data. |
Hello @sayasheng, Here are some questions I have:
|
@sayasheng If you have any specific test devices where you can replicate this issue, I would be curious if you are able to use EncryptedSharedPreferences at all on these devices: https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences. It is possible that we are running into a limited set of devices where EncryptedSharedPreferences library does not work properly. This class is critical to securely storing information on the device and we cannot operate without it. Let us know if this is an edge case you are seeing in the wild, or if you have a test device youi can replicate this with. |
|
@sayasheng Since you mentioned custom hardware, I'm a bit concerned the devices have a non-standard implementation of the Android KeyStore. Amplify v2 uses the latest official release of EncryptedSharedPrefrences provided directly from Google. This is a best practice for securely encrypting data on the device. The logs shown indicate that the device attempted to use the apps default master key, but failed. We then tried to create a fallback master key, which is also failing. If the device is unable to use EncryptedSharedPreferences, Amplify v2 will not function properly. Amplify v1 is not failing because it uses its own encryption methods and does not use EncryptedSharedPreferences. |
Closing this issue due to inactivity. Please feel free to open a new issue if required, thank you |
This issue is now closed. Comments on closed issues are hard for our team to see. |
I had this issue popup in one of our apps as well, seemed to be limited to 1 specific device but I am curious as to what the path forward maybe as Google seems to have deprecated Jetpack security crypto library. @tylerjroach https://android-review.googlesource.com/c/platform/frameworks/support/+/2761067 https://developer.android.com/privacy-and-security/cryptography#jetpack_security_crypto_library |
@Uma1r We will determine our best past forward away from EncryptedSharedPreferences and internally handle the data migration when it is time to change. While no new updates are being made to EncryptedSharedPreferences, functionality would not immediately break on current versions of Android. It will continue to be used until we have an alternative ready. |
This issue still persists, is there any update ? |
Before opening, please confirm:
Language and Async Model
Java
Amplify Categories
GraphQL API
Gradle script dependencies
Environment information
Please include any relevant guides or documentation you're referencing
No response
Describe the bug
02-20 14:36:40.059 E/AndroidRuntime( 4405): java.security.KeyStoreException: the master key android-keystore://amplify_master_key exists but is unusable
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey(AndroidKeysetManager.java:275)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:236)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:123)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.core.store.EncryptedKeyValueRepository.getSharedPreferencesOrThrow(EncryptedKeyValueRepository.kt:110)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.core.store.EncryptedKeyValueRepository.openKeystoreWithAmplifyMasterKey(EncryptedKeyValueRepository.kt:86)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.core.store.EncryptedKeyValueRepository.getOrCreateSharedPreferences(EncryptedKeyValueRepository.kt:64)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.core.store.EncryptedKeyValueRepository.access$getOrCreateSharedPreferences(EncryptedKeyValueRepository.kt:32)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.core.store.EncryptedKeyValueRepository$sharedPreferences$2.invoke(EncryptedKeyValueRepository.kt:48)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.core.store.EncryptedKeyValueRepository$sharedPreferences$2.invoke(EncryptedKeyValueRepository.kt:48)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.core.store.EncryptedKeyValueRepository.getSharedPreferences(EncryptedKeyValueRepository.kt:48)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.core.store.EncryptedKeyValueRepository.get(EncryptedKeyValueRepository.kt:51)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.auth.cognito.data.AWSCognitoAuthCredentialStore.retrieveCredential(AWSCognitoAuthCredentialStore.kt:63)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.auth.cognito.actions.CredentialStoreCognitoActions$loadCredentialStoreAction$$inlined$invoke$1.execute(Action.kt:70)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.amplifyframework.statemachine.ConcurrentEffectExecutor$execute$1$1.invokeSuspend(ConcurrentEffectExecutor.kt:26)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
02-20 14:36:40.059 E/AndroidRuntime( 4405): Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@13a33af, Dispatchers.Default]
02-20 14:36:40.059 E/AndroidRuntime( 4405): Caused by: javax.crypto.AEADBadTagException
02-20 14:36:40.059 E/AndroidRuntime( 4405): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:517)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:531)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at javax.crypto.Cipher.doFinal(Cipher.java:2267)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encryptInternal(AndroidKeystoreAesGcm.java:87)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encrypt(AndroidKeystoreAesGcm.java:72)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.validateAead(AndroidKeystoreKmsClient.java:248)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.getAead(AndroidKeystoreKmsClient.java:165)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey(AndroidKeysetManager.java:267)
02-20 14:36:40.059 E/AndroidRuntime( 4405): ... 20 more
02-20 14:36:40.059 E/AndroidRuntime( 4405): Caused by: android.security.KeyStoreException: Signature/MAC verification failed
02-20 14:36:40.059 E/AndroidRuntime( 4405): at android.security.KeyStore.getKeyStoreException(KeyStore.java:1303)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
02-20 14:36:40.059 E/AndroidRuntime( 4405): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
Reproduction steps (if applicable)
upgrade v1 to v2 and get this issue.
Code Snippet
// Put your code below this line.
Log output
amplifyconfiguration.json
No response
GraphQL Schema
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: