mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 16:22:49 +00:00
Avoid SQLCipher key derivation (#6774)
* Avoid SQLCipher key derivation by manually providing the generated as a raw key: this needs a series of DB re-key operations, performed as part of a 'dummy' DB migration * Set key generation length to 32 bytes in `RandomSecretPassphraseProvider`. * Use `ClientSecret` for handling the keys for SQLCipher. Move `ClientSecret` to `:libraries:androidutils` so it's shared.
This commit is contained in:
committed by
GitHub
parent
4cafdae22d
commit
1e00353f29
+16
-3
@@ -16,7 +16,9 @@ import dev.zacsweers.metro.SingleIn
|
||||
import io.element.android.libraries.cachestore.impl.CacheDatabase
|
||||
import io.element.android.libraries.di.annotations.ApplicationContext
|
||||
import io.element.encrypteddb.SqlCipherDriverFactory
|
||||
import io.element.encrypteddb.passphrase.RandomSecretPassphraseProvider
|
||||
import io.element.encrypteddb.passphrase.RandomDatabaseSecretProvider
|
||||
import io.element.encrypteddb.utils.ReplaceDatabaseKey
|
||||
import timber.log.Timber
|
||||
|
||||
@BindingContainer
|
||||
@ContributesTo(AppScope::class)
|
||||
@@ -35,9 +37,20 @@ object CacheStoreModule {
|
||||
parentDir.mkdirs()
|
||||
}
|
||||
|
||||
val passphraseProvider = RandomSecretPassphraseProvider(context, secretFile)
|
||||
val rekeyMigrationVersion = 2L
|
||||
val passphraseProvider = RandomDatabaseSecretProvider(context, secretFile)
|
||||
val driver = SqlCipherDriverFactory(passphraseProvider)
|
||||
.create(CacheDatabase.Schema, "$name.db", context)
|
||||
.create(
|
||||
schema = CacheDatabase.Schema,
|
||||
name = "$name.db",
|
||||
context = context
|
||||
) { db, oldVersion, newVersion ->
|
||||
Timber.d("Migrating $name database from version $oldVersion to $newVersion")
|
||||
if (rekeyMigrationVersion in oldVersion..newVersion) {
|
||||
ReplaceDatabaseKey(passphraseProvider).replaceKey(name, db)
|
||||
}
|
||||
}
|
||||
|
||||
return CacheDatabase(driver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Migrate DB from version 1
|
||||
-- Initial schema for CacheData table
|
||||
|
||||
CREATE TABLE IF NOT EXISTS CacheData (
|
||||
key TEXT NOT NULL PRIMARY KEY,
|
||||
value TEXT NOT NULL,
|
||||
updatedAt INTEGER NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
-- Migrate DB from version 2
|
||||
-- Dummy migration to trigger a re-key
|
||||
Reference in New Issue
Block a user