libsqlfs icon indicating copy to clipboard operation
libsqlfs copied to clipboard

Stick with backwards compat

Open n8fr8 opened this issue 5 years ago • 10 comments

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.

n8fr8 avatar Sep 27 '19 20:09 n8fr8

Why do this here? Why not in the app?

eighthave avatar Sep 27 '19 20:09 eighthave

You can't issue PRAGMA commands from the IOCipher interface. There is no way to inject custom SQL commands when you mount the volume.

n8fr8 avatar Sep 27 '19 21:09 n8fr8

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?

eighthave avatar Sep 27 '19 21:09 eighthave

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.

n8fr8 avatar Sep 28 '19 19:09 n8fr8

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?

eighthave avatar Sep 30 '19 09:09 eighthave

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.

n8fr8 avatar Sep 30 '19 11:09 n8fr8

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

eighthave avatar Sep 30 '19 11:09 eighthave

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)

abeluck avatar Sep 30 '19 14:09 abeluck

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.

eighthave avatar Sep 30 '19 18:09 eighthave

Feel free to build off of this, ideally it should be configurable: https://github.com/ChatSecure/libsqlfs/commit/4456f8a83c7af7dc6b8cf6456dae94fe7979c24c

chrisballinger avatar Mar 27 '20 02:03 chrisballinger