flutter_secure_storage icon indicating copy to clipboard operation
flutter_secure_storage copied to clipboard

Weird exception on first start Android 11 Samsung A51

Open ervindobri opened this issue 2 years ago • 11 comments

Hello, as title says weird error appearing. Device: Samsung A51 Android: 11

The following error appears TWICE for the first start; then never again. After uninstall it appears again.

W/AndroidKeysetManager(30639): keyset not found, will generate a new one
W/AndroidKeysetManager(30639): java.io.FileNotFoundException: can’t read keyset; the pref value __androidx_security_crypto_encrypted_prefs_key_keyset__ does not exist
W/AndroidKeysetManager(30639): 	at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readPref(SharedPrefKeysetReader.java:71)
W/AndroidKeysetManager(30639): 	at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readEncrypted(SharedPrefKeysetReader.java:89)
W/AndroidKeysetManager(30639): 	at com.google.crypto.tink.KeysetHandle.read(KeysetHandle.java:105)
W/AndroidKeysetManager(30639): 	at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:311)
W/AndroidKeysetManager(30639): 	at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:287)
W/AndroidKeysetManager(30639): 	at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:238)
W/AndroidKeysetManager(30639): 	at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:155)
W/AndroidKeysetManager(30639): 	at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:120)
W/AndroidKeysetManager(30639): 	at [com.it](http://com.it/)_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.initializeEncryptedSharedPreferencesManager(FlutterSecureStoragePlugin.java:136)
W/AndroidKeysetManager(30639): 	at [com.it](http://com.it/)_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.ensureInitialized(FlutterSecureStoragePlugin.java:105)
W/AndroidKeysetManager(30639): 	at [com.it](http://com.it/)_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.access$100(FlutterSecureStoragePlugin.java:37)
W/AndroidKeysetManager(30639): 	at [com.it](http://com.it/)_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:299)
W/AndroidKeysetManager(30639): 	at android.os.Handler.handleCallback(Handler.java:938)
W/AndroidKeysetManager(30639): 	at android.os.Handler.dispatchMessage(Handler.java:99)

ervindobri avatar Feb 08 '22 14:02 ervindobri

Same issue on Google Pixel 3XL, Android 12.

zigapovhe avatar Feb 11 '22 09:02 zigapovhe

Same issue Xiaomi Mi 9T, Android 11

kkoken avatar Feb 15 '22 07:02 kkoken

Happening on Samsung Galaxy A50 too.

W/KeyStore(27959): get(USRCERT_com.acme.my_app.development.FlutterSecureStoragePluginKey) return_code(7)
W/KeyStore(27959): get(CACERT_com.acme.my_app.development.FlutterSecureStoragePluginKey) return_code(7)
E/FlutterSecureStoragePl(27959): StorageCipher initialization failed
E/FlutterSecureStoragePl(27959): java.lang.Exception: No certificate found under alias: com.acme.my_app.development.FlutterSecureStoragePluginKey
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.getPublicKey(RSACipher18Implementation.java:92)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.wrap(RSACipher18Implementation.java:39)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:52)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.ensureInitialized(FlutterSecureStoragePlugin.java:95)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.access$100(FlutterSecureStoragePlugin.java:37)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:320)
E/FlutterSecureStoragePl(27959):        at android.os.Handler.handleCallback(Handler.java:938)
E/FlutterSecureStoragePl(27959):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/FlutterSecureStoragePl(27959):        at android.os.Looper.loop(Looper.java:246)
E/FlutterSecureStoragePl(27959):        at android.os.HandlerThread.run(HandlerThread.java:67)
W/KeyStore(27959): get(USRCERT_com.acme.my_app.development.FlutterSecureStoragePluginKey) return_code(7)
W/KeyStore(27959): get(CACERT_com.acme.my_app.development.FlutterSecureStoragePluginKey) return_code(7)
E/FlutterSecureStoragePl(27959): StorageCipher initialization failed
E/FlutterSecureStoragePl(27959): java.lang.Exception: No certificate found under alias: com.acme.my_app.development.FlutterSecureStoragePluginKey
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.getPublicKey(RSACipher18Implementation.java:92)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.wrap(RSACipher18Implementation.java:39)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:52)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.ensureInitialized(FlutterSecureStoragePlugin.java:95)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.access$100(FlutterSecureStoragePlugin.java:37)
E/FlutterSecureStoragePl(27959):        at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:284)
E/FlutterSecureStoragePl(27959):        at android.os.Handler.handleCallback(Handler.java:938)
E/FlutterSecureStoragePl(27959):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/FlutterSecureStoragePl(27959):        at android.os.Looper.loop(Looper.java:246)
E/FlutterSecureStoragePl(27959):        at android.os.HandlerThread.run(HandlerThread.java:67)

comatory avatar Feb 21 '22 12:02 comatory

I have encountered this error when someone tried to migrate to the new encrypted method for android. See https://github.com/mogol/flutter_secure_storage/issues/313

I have a few other plugins that require some attention so i don't have the time to look in to this right now. It would be great if some could debug this and check what the problem can be. I will check all PR's asap.

juliansteenbakker avatar Feb 21 '22 13:02 juliansteenbakker

Same Android 11 Google Pixel 4 & Samsung S10

MahmoudTarek avatar Feb 23 '22 10:02 MahmoudTarek

Same issue in Android API 31 and Google Pixel 5 (simulator). Same issue on my Samsung Galaxy S10+ with Android 12

sbordier-scgames avatar Mar 05 '22 01:03 sbordier-scgames

same issue in android 12 Samsung A52S

Nagy25 avatar Mar 06 '22 10:03 Nagy25

same issue on Pixel C emulator (API level 30)

bartekpacia avatar Jul 07 '22 10:07 bartekpacia

Does it work the first time you launch the app?

hmawla avatar Jul 29 '22 15:07 hmawla

Still happens on flutter_secure_storage: 6.0.0, initial launch.

[log] initialLaunch null
W/AndroidKeysetManager(24394): keyset not found, will generate a new one
W/AndroidKeysetManager(24394): java.io.FileNotFoundException: can't read keyset; the pref value __androidx_security_crypto_encrypted_prefs_key_keyset__ does not exist
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readPref(SharedPrefKeysetReader.java:71)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readEncrypted(SharedPrefKeysetReader.java:89)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.KeysetHandle.read(KeysetHandle.java:105)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:311)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:287)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:238)
W/AndroidKeysetManager(24394): 	at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:155)
W/AndroidKeysetManager(24394): 	at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:120)
W/AndroidKeysetManager(24394): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStorage.initializeEncryptedSharedPreferencesManager(FlutterSecureStorage.java:226)
W/AndroidKeysetManager(24394): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStorage.ensureInitialized(FlutterSecureStorage.java:149)
W/AndroidKeysetManager(24394): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStorage.deleteAll(FlutterSecureStorage.java:115)
W/AndroidKeysetManager(24394): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:182)
W/AndroidKeysetManager(24394): 	at android.os.Handler.handleCallback(Handler.java:938)
W/AndroidKeysetManager(24394): 	at android.os.Handler.dispatchMessage(Handler.java:99)
W/AndroidKeysetManager(24394): 	at android.os.Looper.loop(Looper.java:236)
W/AndroidKeysetManager(24394): 	at android.os.HandlerThread.run(HandlerThread.java:67)
W/AndroidKeysetManager(24394): keyset not found, will generate a new one
W/AndroidKeysetManager(24394): java.io.FileNotFoundException: can't read keyset; the pref value __androidx_security_crypto_encrypted_prefs_value_keyset__ does not exist
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readPref(SharedPrefKeysetReader.java:71)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readEncrypted(SharedPrefKeysetReader.java:89)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.KeysetHandle.read(KeysetHandle.java:105)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:311)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:287)
W/AndroidKeysetManager(24394): 	at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:238)
W/AndroidKeysetManager(24394): 	at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:160)
W/AndroidKeysetManager(24394): 	at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:120)
W/AndroidKeysetManager(24394): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStorage.initializeEncryptedSharedPreferencesManager(FlutterSecureStorage.java:226)
W/AndroidKeysetManager(24394): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStorage.ensureInitialized(FlutterSecureStorage.java:149)
W/AndroidKeysetManager(24394): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStorage.deleteAll(FlutterSecureStorage.java:115)
W/AndroidKeysetManager(24394): 	at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:182)
W/AndroidKeysetManager(24394): 	at android.os.Handler.handleCallback(Handler.java:938)
W/AndroidKeysetManager(24394): 	at android.os.Handler.dispatchMessage(Handler.java:99)
W/AndroidKeysetManager(24394): 	at android.os.Looper.loop(Looper.java:236)
W/AndroidKeysetManager(24394): 	at android.os.HandlerThread.run(HandlerThread.java:67)

DaemonChoejur avatar Aug 31 '22 09:08 DaemonChoejur

confirming this issue still there in 6.0.0 version plugin

DjordjeMancic97 avatar Sep 08 '22 12:09 DjordjeMancic97

this an android jetpack crypto lib "problem" (it's just a debug message..) so not related to this plugin and nothing they can do about it

ps-filipefreitas avatar Sep 30 '22 14:09 ps-filipefreitas

Thank you for your information @ps-filipefreitas

juliansteenbakker avatar Sep 30 '22 14:09 juliansteenbakker

this an android jetpack crypto lib "problem" (it's just a debug message..) so not related to this plugin and nothing they can do about it

Well, this is not the case in 4.2.1 version of flutter_secure_storage plugin. At least what @mogol can do is downgrade the crypto library to the same version as it was in v4.2.1. If this is really just a "debug message", something else is going on in flutter_secure_storage, because the plugin never initialize after this error occur (can be replicated by clearing app storage). I wouldn't close the issue if people still experience the same issue on latest version (6.0.0). @juliansteenbakker

zigapovhe avatar Sep 30 '22 16:09 zigapovhe

I second @zigapovhe and don't think that this issue should be closed.

bartekpacia avatar Sep 30 '22 21:09 bartekpacia

This is because the crypto library was introduced in version 5.0.0. It was not present in version 4.2.1 and thus not used.

The message just says it can't find any keys because there hasn't been created any, or it can't read it anymore and thus it recreates a new one. keyset not found, will generate a new one

juliansteenbakker avatar Sep 30 '22 21:09 juliansteenbakker

As source: https://issuetracker.google.com/issues/185219606

This has been a long issue with the library, however development activity seems low on this library.

juliansteenbakker avatar Sep 30 '22 21:09 juliansteenbakker

Maybe this message is related or maybe not, but there are one or more blocker failures that causes initialisation issues on recent clients (like the A51).

I suspect that all of us are suffering these ones but we don't have a clear idea about what is causing them. Sadly I had to discard this package for Android.

Because of this for now I cannot add more info, maybe anyone will have more luck than me 🤞🤞

henry2man avatar Oct 01 '22 06:10 henry2man