celest-dev / celest

The Flutter cloud platform
https://celest.dev
Other
232 stars 12 forks source link

[native_storage] Reinstalling app throws `KeyStoreException` in `NativeStorage().secure.isolated.read()` #156

Open rubenferreira97 opened 5 days ago

rubenferreira97 commented 5 days ago

While debugging, I uninstalled and installed my app, and the following exception appeared:

JniException (Exception in Java code called through JNI: javax.crypto.AEADBadTagException
...
android.security.KeyStoreException: Signature/MAC verification failed
...

After some investigation, I found that Android's backup policy is the culprit. It tries to back up old data, and since these cryptographic keys do not match, this error occurs.

For more context, a similar issue is discussed in this package: flutter_secure_storage#43.

Currently, there are two ways to fix this:

Option 1: Disable backup completely:

<application
    ...
        android:allowBackup="false">

Option 2: Keep backup enable but exclude encrypted data used by this plugin:

<application
    ...
        android:allowBackup="true" 
        android:fullBackupContent="@xml/backup_rules">
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <exclude <!-- What to place here ??? --> /> 
</full-backup-content>

This issue asks to get better documentation for this. I also want to ask how to solve this using Option 2, as I don't know what to exclude. Additionally, is it possible to add this exclude directive directly to the dependency itself?