Skip to content

Conversation

@juliansteenbakker
Copy link
Owner

fixes #853

Copy link

@michael-markl michael-markl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!
Sorry, I am quite busy these days... I hope, I'll get to testing it soon! The changes look promising though :)

Copy link

@michael-markl michael-markl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this change and it solves the issue I described in #853. The Secure Storage is resetted when a backup+restore is done (even if the backup+restore was done on version 9.2.2 followed by updating the app to the version of this branch).

One thing that I noticed is that (if the backup+restore was done on version 9.2.2) the migration will continue to fail on the version of this branch; maybe we can even clean up these old keys if the migration failed due to the BadPaddingException (caused by the backup+restore):

01-19 14:54:52.373 10353 10353 E SecureStorageAndroid: Migration failed for key: VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIHNlY3VyZSBzdG9yYWdlCg_userCodesBase64
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid: javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at com.android.org.conscrypt.NativeCrypto.EVP_CipherFinal_ex(Native Method)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at com.android.org.conscrypt.OpenSSLEvpCipher.doFinalInternal(OpenSSLEvpCipher.java:152)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at com.android.org.conscrypt.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:374)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at javax.crypto.Cipher.doFinal(Cipher.java:2074)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at com.it_nomads.fluttersecurestorage.ciphers.h.a(SourceFile:36)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at P2.a.c(SourceFile:8)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at P2.a.i(SourceFile:81)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at P2.a.g(SourceFile:7)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at P2.a.<init>(SourceFile:23)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at P2.e.d(SourceFile:20)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at P2.e.c(SourceFile:39)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at P2.e.onAttachedToEngine(SourceFile:7)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at a3.b.c(SourceFile:116)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(SourceFile:50)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at java.lang.reflect.Method.invoke(Native Method)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at h3.a.a(SourceFile:22)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at Z2.i.E(SourceFile:10)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at app.entitlementcard.MainActivity.E(SourceFile:6)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at Z2.j.s(SourceFile:59)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at Z2.i.onCreate(SourceFile:14)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at app.entitlementcard.MainActivity.onCreate(SourceFile:4)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.Activity.performCreate(Activity.java:9002)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.Activity.performCreate(Activity.java:8980)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1526)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4030)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4235)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:112)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:174)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:109)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:81)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2636)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.os.Handler.dispatchMessage(Handler.java:107)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.os.Looper.loopOnce(Looper.java:232)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.os.Looper.loop(Looper.java:317)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at android.app.ActivityThread.main(ActivityThread.java:8705)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at java.lang.reflect.Method.invoke(Native Method)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
01-19 14:54:52.373 10353 10353 E SecureStorageAndroid:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
01-19 14:54:52.373 10353 10353 I SecureStorageAndroid: Failed to migrate 1 keys.

@juliansteenbakker
Copy link
Owner Author

I have added some fixes i noticed to your PR!

  • Options where not passed correctly.
  • ResetOnError is now being applied. If a migration failsand resetOnError is set to true, the migration will delete the old entries so no error is being thrown and the user can start using the encryptedSharedPreferences
  • Added a check so that the migration is only run once, and when done, will not be run again to improve efficiency.
  • Scoped exception catching

@juliansteenbakker juliansteenbakker merged commit 4d4dc57 into develop Jan 26, 2025
5 checks passed
@juliansteenbakker juliansteenbakker deleted the feat/reset-after-exception branch February 4, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v10.0.0-beta2: After Backup+Restore: Read and write fails without throwing exceptions

2 participants