Flutter + SQLCipher, issue since iOS 15

Hi guys,

I’ve developped a Flutter app and use SQLCipher, and it’s working like charm on Windows, Android and iOS.
But since two weeks, I experienced some strange behaviors on iOS.

After seeking for the problem, I found that it was only on iOS 15 (iOS 14 is OK).

On the first launch of the app:

  • Database is created
  • PRAGMA key is set
  • PRAGMA cipher_version return current version (4.5.0)
  • Query the database is OK

On second launch (after killing the app):

  • Database is opened
  • PRAGMA key is set
  • PRAGMA cipher_version doesn’t provide a value
  • Query the database is NOT OK (file is not a database)

But if I re-launch the app, after I reboot the iPhone, everything works like expected.

In my investigations, I found that some deps I use in Flutter, need sqlite3 for working.
So I referred to Important Advisory: SQLCipher with Xcode 8 and new SDKs and Cannot open encrypted database with SQLCipher 4, and finally tried to apply iOS tutorial.

In the end, the issue is still here and I don’t know what to do now…

May have you experienced some case with latest version of iOS system ?

Help would be appreciated.
Thanks !

Maxime

Hi,

Got some news. After more investigations, I found that it seemed to work…
After all, it never worked on iOS 14. The databases were created with no encryption, and reopen without encryption too, so I thought there was no problems.

Furthermore, that behavior between these versions was strange…

Hello @Dev_Mobilite - if the database is not encrypted there are two possible problems:

  1. SQLCipher is not linked correctly, so a different SQLite version is being used. This can be identified by capturing the output of PRAGMA cipher_version;.
  2. The key is not being applied properly, resulting in SQLCipher operating without encrypting the database at all (i.e. operating as standard SQLite).

I am not aware of any mechanism that would cause linking to behave differently on a first launch than on secondary launches, unless there is some race condition in library loading (i.e. both SQLite and SQLCipher are packaged simultaneously and is is not predictably loading SQLCipher).

The best way to troubleshoot this would be to create a simple application without any dependencies except SQLCipher, and then check the results of PRAGMA cipher_version;. Once you have the linking working in the simple case, you could add in the other dependencies to see if you can isolate what is breaking it.