libsqlfs
libsqlfs copied to clipboard
Stick with backwards compat
I couldn't make the cipher migration for SQLCipher 4 to work with an existing larger IOCipher instance. The easier solution for now is to set the v3 compatibility mode.
Why do this here? Why not in the app?
You can't issue PRAGMA commands from the IOCipher interface. There is no way to inject custom SQL commands when you mount the volume.
sticking that hardcoded in the library will break any app that has already upgraded. How about using old 3.x binaries of sqlcipher with this version of IOCipher?
I need the 64-bit builds unfortunately. For now, I will just use my own v3 compat flag. I will think about modifying the API to support the ability to issue custom PRAGMA in the mount process.
Seems like figuring out the proper migration is the best way forward, to avoid the technical debt building up. What ended up happening there that blocked you?
The proper migration still requires using a PRAGMA command. It would be nice to have a way for IOCipher instances to migrate without requiring to use the SQLCipher API to mount, etc. Adding a way to call PRAGMA would make that possible.
What happened in my case was it would always return a failure code instantly. I migrated my standard SQLCipher database without an issue. What makes IOCipher different possible is that we use a different SQL page size, and also my IOCipher volume was 400MB.
For now, since I need to ship an important update to keanu, I am just building my own compat v3 version of IOCipher which works fine, but we should def figure this out for others.
If I remember correrctly, you can just open the IOCipher database file directly e.g. outside of IOCipher and issue PRAGMA commands there for things like migrating the database. Just use the plain sqlicpher database API.
There is more info here, including a claim that v3.5.9 includes 64-bit binaries: https://github.com/sqlcipher/android-database-sqlcipher/issues/446
What would a proper fix here look like?
- IOCipher detects version of database and sqlcipher runtime
- Provides an
isMigrationNeeded
method for devs - Throws a
MigrationNeededException
when sqlcipher runtime and database version mismatch - Provides a
migrate()
method for devs
Additionally we should also provide a way to tweak the compatibility settings (option 2 in this post), perhaps a new mount method like mountWithCompatibility
(also, I think this issue belongs in iocipher not libslfs)
I'm pretty sure that IOCipher would work against a wide range of SQLCipher releases, so really this belongs in SQLCipher. I suppose there could be example migration code in IOCipher. I haven't heard anything specific to IOCipher in this issue, it seems entirely a low-level SQLCipher thing. The migration needs to happen when SQLCipher goes from 3.x to 4.x.
Feel free to build off of this, ideally it should be configurable: https://github.com/ChatSecure/libsqlfs/commit/4456f8a83c7af7dc6b8cf6456dae94fe7979c24c