diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fc34fa3653..164c9fb468 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -52,7 +52,7 @@ okttp_version = "4.12.0" jackson_version = "2.13.4" chuck_version = "4.1.0" -sqlCipher_version = "4.5.4" +sqlCipher_version = "4.7.2" fuzzywuzzy_version = "1.4.0" rootbeer_version = "0.1.1" commons_io_version = "2.18.0" @@ -151,7 +151,7 @@ firebase-analytics = { module = "com.google.firebase:firebase-analytics", versio firebase-perf = { module = "com.google.firebase:firebase-perf", version.ref = "firebase_perf_version" } #SqlCipher -sqlCipher-core = { module = "net.zetetic:android-database-sqlcipher", version.ref = "sqlCipher_version" } +sqlCipher-core = { module = "net.zetetic:sqlcipher-android", version.ref = "sqlCipher_version" } #Realm realm_base = { module = "io.realm.kotlin:library-base", version.ref = "realm_version" } diff --git a/id/proguard-rules.pro b/id/proguard-rules.pro index 4265b99fe6..80e8289fd1 100644 --- a/id/proguard-rules.pro +++ b/id/proguard-rules.pro @@ -55,8 +55,8 @@ public (java.lang.reflect.Type); } -#net.zetetic:android-database-sqlcipher --keep class net.sqlcipher.** { *; } +#net.zetetic:android-sqlcipher +-keep class net.zetetic.database.sqlcipher.** { *; } # Dont warn about the missing files during the obfuscation -dontwarn com.simprints.** diff --git a/id/src/main/java/com/simprints/id/Application.kt b/id/src/main/java/com/simprints/id/Application.kt index e1c56c782b..560a0c0e40 100644 --- a/id/src/main/java/com/simprints/id/Application.kt +++ b/id/src/main/java/com/simprints/id/Application.kt @@ -8,6 +8,7 @@ import com.simprints.core.CoreApplication import com.simprints.core.ExcludedFromGeneratedTestCoverageReports import com.simprints.core.tools.extentions.deviceHardwareId import com.simprints.core.tools.utils.LanguageHelper +import com.simprints.infra.eventsync.BuildConfig.DB_ENCRYPTION import com.simprints.infra.logging.LoggingConstants.CrashReportingCustomKeys.DEVICE_ID import com.simprints.infra.logging.Simber import com.simprints.infra.logging.SimberBuilder @@ -62,5 +63,8 @@ open class Application : syncOrchestrator.cleanupWorkers() syncOrchestrator.scheduleBackgroundWork() } + if (DB_ENCRYPTION) { + System.loadLibrary("sqlcipher") + } } } diff --git a/infra/events/src/main/java/com/simprints/infra/events/event/local/EventDatabaseFactory.kt b/infra/events/src/main/java/com/simprints/infra/events/event/local/EventDatabaseFactory.kt index 447111fe4d..c065a5bbf3 100644 --- a/infra/events/src/main/java/com/simprints/infra/events/event/local/EventDatabaseFactory.kt +++ b/infra/events/src/main/java/com/simprints/infra/events/event/local/EventDatabaseFactory.kt @@ -4,8 +4,8 @@ import android.content.Context import com.simprints.infra.logging.Simber import com.simprints.infra.security.SecurityManager import dagger.hilt.android.qualifiers.ApplicationContext -import net.sqlcipher.database.SQLiteDatabase.getBytes -import net.sqlcipher.database.SupportFactory +import net.zetetic.database.sqlcipher.SupportOpenHelperFactory +import java.nio.charset.Charset import javax.inject.Inject import javax.inject.Singleton @@ -26,8 +26,8 @@ internal class EventDatabaseFactory @Inject constructor( private fun build() { try { val key = getOrCreateKey(DB_NAME) - val passphrase: ByteArray = getBytes(key) - val factory = SupportFactory(passphrase) + val passphrase: ByteArray = key.toByteArray(Charset.forName("UTF-8")) + val factory = SupportOpenHelperFactory(passphrase) eventDatabase = EventRoomDatabase.getDatabase( ctx, factory, @@ -41,13 +41,13 @@ internal class EventDatabaseFactory @Inject constructor( private fun getOrCreateKey( @Suppress("SameParameterValue") dbName: String, - ): CharArray = try { + ) = try { securityManager.getLocalDbKeyOrThrow(dbName) } catch (t: Throwable) { t.message?.let { Simber.d(it) } securityManager.createLocalDatabaseKeyIfMissing(dbName) securityManager.getLocalDbKeyOrThrow(dbName) - }.value.decodeToString().toCharArray() + }.value.decodeToString() fun recreateDatabase() { // DB corruption detected; either DB file or key is corrupt diff --git a/infra/events/src/main/java/com/simprints/infra/events/event/local/EventRoomDatabase.kt b/infra/events/src/main/java/com/simprints/infra/events/event/local/EventRoomDatabase.kt index e515ec6ec8..323dc422a4 100644 --- a/infra/events/src/main/java/com/simprints/infra/events/event/local/EventRoomDatabase.kt +++ b/infra/events/src/main/java/com/simprints/infra/events/event/local/EventRoomDatabase.kt @@ -24,7 +24,7 @@ import com.simprints.infra.events.event.local.migrations.EventMigration8to9 import com.simprints.infra.events.event.local.migrations.EventMigration9to10 import com.simprints.infra.events.event.local.models.DbEvent import com.simprints.infra.events.event.local.models.DbEventScope -import net.sqlcipher.database.SupportFactory +import net.zetetic.database.sqlcipher.SupportOpenHelperFactory @Database( entities = [ @@ -44,7 +44,7 @@ internal abstract class EventRoomDatabase : RoomDatabase() { companion object { fun getDatabase( context: Context, - factory: SupportFactory, + factory: SupportOpenHelperFactory, dbName: String, ): EventRoomDatabase { val builder = Room @@ -68,7 +68,6 @@ internal abstract class EventRoomDatabase : RoomDatabase() { if (BuildConfig.DB_ENCRYPTION) { builder.openHelperFactory(factory) } - return builder.build() } } diff --git a/infra/events/src/main/java/com/simprints/infra/events/event/local/migrations/EventMigration14to15.kt b/infra/events/src/main/java/com/simprints/infra/events/event/local/migrations/EventMigration14to15.kt index 20bbf8e0e8..bb2ea542b8 100644 --- a/infra/events/src/main/java/com/simprints/infra/events/event/local/migrations/EventMigration14to15.kt +++ b/infra/events/src/main/java/com/simprints/infra/events/event/local/migrations/EventMigration14to15.kt @@ -8,7 +8,7 @@ import com.simprints.core.tools.extentions.getLongWithColumnName import com.simprints.core.tools.extentions.getStringWithColumnName import com.simprints.infra.logging.LoggingConstants.CrashReportTag.MIGRATION import com.simprints.infra.logging.Simber -import net.sqlcipher.database.SQLiteDatabase +import net.zetetic.database.sqlcipher.SQLiteDatabase import org.json.JSONObject internal class EventMigration14to15 : Migration(14, 15) {