Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions id/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
public <init>(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.**
Expand Down
4 changes: 4 additions & 0 deletions id/src/main/java/com/simprints/id/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,5 +63,8 @@ open class Application :
syncOrchestrator.cleanupWorkers()
syncOrchestrator.scheduleBackgroundWork()
}
if (DB_ENCRYPTION) {
System.loadLibrary("sqlcipher")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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
Expand All @@ -68,7 +68,6 @@ internal abstract class EventRoomDatabase : RoomDatabase() {
if (BuildConfig.DB_ENCRYPTION) {
builder.openHelperFactory(factory)
}

return builder.build()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down