43
Views
5
Comments
Solved
[Ciphered Local Storage Plugin] How to fix broken app after removing Ciphered Local Storage plugin?
Question
ciphered-local-storage-plugin
Mobile icon
Forge asset by OutSystems
Application Type
Mobile

We currently have a mobile app in production with the Ciphered Local Storage plugin as a dependency. Our client however, wants to get rid of the requirement of having a PIN set on Android devices. As this doesn't seem to be possible with this plugin, we are trying to remove the plugin altogether, but this leaves the application stuck at the loading screen. 

I checked where the Local Storage is used for the first time, and it is used in the  SplashScreen (ApplicationVersionNumber) so it can't continue because the data is Ciphered.

Now my question, could this work?

- remove the reference to the CipheredLocalStoragePlugin and CheckSecureDevicePlugin

- add logic to the OnApplicationReady where we clear the Local Storage with Script in ClearLocalData component

Is this enough to clear the Ciphered data or do we have to drop and recreate the whole database and entities?

2024-12-17 14-32-59
Matthias Preuter
 
MVP
Solution

Found a working solution for Android and iPhone, we created a Plugin that overrides the openDatabase, this is also executing when the DB is accessed before the OnApplicationReady is triggered (in iOS).

javascript in plugin

var originalOpenDatabase = window.sqlitePlugin.openDatabase;

window.sqlitePlugin.openDatabase = function(options, successCallback, errorCallback) {

    return originalOpenDatabase.call(window.sqlitePlugin, options, successCallback, function() {

        sqlitePlugin.deleteDatabase(options, function() {

            window.sqlitePlugin.openDatabase(options, successCallback, errorCallback);

        }, function() {

            errorCallback();

        });

    });

};

Will create a Forge component and documentation for it later...

Happy LowCoding,

Matthias Preuter

UserImage.jpg
shravanth badithamani

Removing the Ciphered Local Storage plugin and attempting to clear the data through the OnApplicationReady event with a custom script in the ClearLocalData component might not be sufficient to resolve the issue. The data stored using the Ciphered Local Storage plugin is likely encrypted, and simply clearing the local storage may not properly decrypt or handle the encrypted data, leading to issues with your app.

To safely remove the Ciphered Local Storage plugin and handle the data stored in it, you'll need to follow a more structured approach. Here are the steps you should consider:

  1. Backup Data: Before making any changes, back up the data stored in the Ciphered Local Storage plugin. This way, you have a copy of the encrypted data in case any issues arise during the migration process.

  2. Data Migration Plan: Create a data migration plan to handle the transition from encrypted data to regular local storage or other storage mechanisms. This may involve decrypting the data and re-encrypting it using another mechanism or transferring it to a different storage format.

  3. Decryption and Cleanup: Develop a mechanism to decrypt the data from the Ciphered Local Storage plugin, remove the encryption, and store it in the regular local storage or another storage option that meets your client's requirements.

  4. Update Code References: Update all the code references in your app that interact with the Ciphered Local Storage plugin to use the new storage mechanism. This includes updating any read or write operations to local storage.

  5. Test and Validate: Thoroughly test the app after the changes to ensure that the data migration and new storage mechanism work as expected. Validate that the app behaves correctly without the Ciphered Local Storage plugin.

  6. Remove the Plugin: After you have successfully migrated the data and updated the app, remove the Ciphered Local Storage plugin from your OutSystems application.

Regarding your question about dropping and recreating the whole database and entities, that should not be necessary for this specific issue. The Ciphered Local Storage plugin typically encrypts data at the client-side, within the mobile app's storage. It should not directly affect your server-side database or entities. Therefore, removing the plugin and migrating the data as outlined above should be sufficient to resolve the issue.

2024-12-17 14-32-59
Matthias Preuter
 
MVP

Thank you @shravanth badithamani,

So, when the Local data that we have in this application, is only a local cache of data that we can easily Sync from the server, it is sufficient to:

- remove the reference to the CipheredLocalStoragePlugin and CheckSecureDevicePlugin

- add logic to the OnApplicationReady where we clear the Local Storage with Script in ClearLocalData component

- Login and trigger TriggerOfflineDataSync

Maybe @Platform Maintenance can confirm this?

Kind regards,

Matthias

2024-12-17 14-32-59
Matthias Preuter
 
MVP

Finally found a solution to this problem, thanks to fellow MVP @Leonardo Fernandes, i'm sharing this as a solution so the documentation can be updated. We use this solution to go from Ciphered to Unciphered, but I think this could work the other way also; without changing the Plugin.

In the same release that we removed the CipheredLocalStorage plugin, we also added the following javascript at the beginning of the OnApplicationReady. This will create a new empty database if the existing database cannot be open (because it was encrypted). 


JS: CheckLocalDatabase

if (window.sqlitePlugin) {

    var ApplicationInfo = require("OutSystems/ClientRuntime/ApplicationInfo")

    var dbObj = { name: ApplicationInfo.getDatabaseName(), location: "default" };

    window.sqlitePlugin.openDatabase(dbObj, function(db) {

      

        // Tests the connection to SQL Lite

        db.transaction(function(tx) {

            tx.addStatement("PRAGMA journal_mode;", [], function() {

                // Success - connection is working, no need to upgrade

            }, function() {

                // Error - connection is not working, likely the database file is corrupt

                // Delete the database, and reload the screen so a new empty database will be created

                window.sqlitePlugin.deleteDatabase(dbObj, function() {

                    window.location.reload();

                });

                $parameters.NewDatabaseCreated = true;

            });

        })

    });

}

When this script returns NewDatabaseCreated, we can GetLocaldata by DeviceId (we store this at server side) and update the LocalDatabase.

Result, new database is created and all data is available for the user.

Happy LowCoding!

Matthias Preuter

2024-12-17 14-32-59
Matthias Preuter
 
MVP

Have to reopen because the solution is working on Android but not on iPhone.

2024-12-17 14-32-59
Matthias Preuter
 
MVP
Solution

Found a working solution for Android and iPhone, we created a Plugin that overrides the openDatabase, this is also executing when the DB is accessed before the OnApplicationReady is triggered (in iOS).

javascript in plugin

var originalOpenDatabase = window.sqlitePlugin.openDatabase;

window.sqlitePlugin.openDatabase = function(options, successCallback, errorCallback) {

    return originalOpenDatabase.call(window.sqlitePlugin, options, successCallback, function() {

        sqlitePlugin.deleteDatabase(options, function() {

            window.sqlitePlugin.openDatabase(options, successCallback, errorCallback);

        }, function() {

            errorCallback();

        });

    });

};

Will create a Forge component and documentation for it later...

Happy LowCoding,

Matthias Preuter

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.