Skip to content

[SES-3593] - Disable KDF for sqlcipher #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 17, 2025
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 app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ configurations.configureEach {
exclude module: "commons-logging"
}

def canonicalVersionCode = 403
def canonicalVersionCode = 404
def canonicalVersionName = "1.22.1"

def postFixSize = 10
Expand Down Expand Up @@ -336,7 +336,7 @@ dependencies {
}
implementation 'com.annimon:stream:1.1.8'
implementation 'androidx.sqlite:sqlite-ktx:2.3.1'
implementation 'net.zetetic:sqlcipher-android:4.6.1@aar'
implementation 'net.zetetic:sqlcipher-android:4.7.2'
implementation project(":libsignal")
implementation project(":libsession")
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxJsonVersion"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
android:value="org.thoughtcrime.securesms.home.HomeActivity" />
</activity>
<activity android:name="org.thoughtcrime.securesms.media.MediaOverviewActivity" />
<activity android:name="org.thoughtcrime.securesms.migration.DatabaseMigrationStateActivity" />

<service
android:name="org.thoughtcrime.securesms.service.KeyCachingService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
import org.thoughtcrime.securesms.logging.AndroidLogger
import org.thoughtcrime.securesms.logging.PersistentLogger
import org.thoughtcrime.securesms.logging.UncaughtExceptionLogger
import org.thoughtcrime.securesms.migration.DatabaseMigrationManager
import org.thoughtcrime.securesms.notifications.BackgroundPollManager
import org.thoughtcrime.securesms.notifications.NotificationChannels
import org.thoughtcrime.securesms.notifications.PushRegistrationHandler
Expand Down Expand Up @@ -164,6 +165,7 @@ class ApplicationContext : Application(), DefaultLifecycleObserver,
@Inject lateinit var destroyedGroupSync: DestroyedGroupSync
@Inject lateinit var removeGroupMemberHandler: RemoveGroupMemberHandler // Exists here only to start upon app starts
@Inject lateinit var snodeClock: SnodeClock
@Inject lateinit var migrationManager: DatabaseMigrationManager

@get:Deprecated(message = "Use proper DI to inject this component")
@Inject
Expand Down Expand Up @@ -318,6 +320,9 @@ class ApplicationContext : Application(), DefaultLifecycleObserver,
adminStateSync.start()
cleanupInvitationHandler.start()

// Start our migration process as early as possible so we can show the user a progress UI
migrationManager.requestMigration(fromRetry = false)

// add our shortcut debug menu if we are not in a release build
if (BuildConfig.BUILD_TYPE != "release") {
// add the config settings shortcut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ import android.app.ActivityManager.TaskDescription
import android.content.res.Resources
import android.graphics.BitmapFactory
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.annotation.StyleRes
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewGroupCompat
import androidx.core.view.WindowCompat
import network.loki.messenger.R
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.ThemeUtil
Expand All @@ -28,16 +24,13 @@ private val DefaultLightScrim = Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
private val DefaultDarkScrim = Color.argb(0x80, 0x1b, 0x1b, 0x1b)

abstract class BaseActionBarActivity : AppCompatActivity() {
var currentThemeState: ThemeState? = null
private var currentThemeState: ThemeState? = null

private var modifiedTheme: Resources.Theme? = null

// This can not be dep injected as it is required very early during activity creation
private val preferences: TextSecurePreferences
get() {
val appContext =
applicationContext as ApplicationContext
return appContext.textSecurePreferences
}
get() = (applicationContext as ApplicationContext).textSecurePreferences

// Whether to apply default window insets to the decor view
open val applyDefaultWindowInsets: Boolean
Expand Down Expand Up @@ -153,5 +146,7 @@ abstract class BaseActionBarActivity : AppCompatActivity() {

companion object {
private val TAG: String = BaseActionBarActivity::class.java.simpleName

private const val MIGRATION_DIALOG_TAG = "migration_dialog"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package org.thoughtcrime.securesms
import android.os.Bundle
import android.view.Window
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.Composable
import org.thoughtcrime.securesms.ui.setComposeContent

/**
* Base class for activities that use Compose UI for their full content.
*
* It fine-tunes options so that Compose can take over the entire screen.
*
* Note: you should use [FullComposeScreenLockActivity] by default, who handles the authentication
* and routing logic. This class is only for activities that do not need these logic which should
* be rare.
*/
abstract class FullComposeActivity : BaseActionBarActivity() {
@Composable
Expand All @@ -19,17 +24,26 @@ abstract class FullComposeActivity : BaseActionBarActivity() {
get() = false

override fun onCreate(savedInstanceState: Bundle?) {
// Disable action bar for compose
supportRequestWindowFeature(Window.FEATURE_NO_TITLE)

// Deprecated note: this flag is set for older devices that do not support IME insets
// For recent Android versions this simply doesn't work and you have to do the IME insets
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
applyCommonPropertiesForCompose()

super.onCreate(savedInstanceState)

setComposeContent {
ComposeContent()
}
}

companion object {
/**
* Apply some common properties for activities that display compose as full content.
*/
fun AppCompatActivity.applyCommonPropertiesForCompose() {
// Disable action bar for compose
supportRequestWindowFeature(Window.FEATURE_NO_TITLE)

// Deprecated note: this flag is set for older devices that do not support IME insets
// For recent Android versions this simply doesn't work and you have to do the IME insets
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.thoughtcrime.securesms

import android.os.Bundle
import android.view.Window
import android.view.WindowManager
import androidx.compose.runtime.Composable
import org.thoughtcrime.securesms.FullComposeActivity.Companion.applyCommonPropertiesForCompose
import org.thoughtcrime.securesms.ui.setComposeContent

/**
* Base class for activities that use Compose UI for their full content.
*
* It fine-tunes options so that Compose can take over the entire screen.
*/
abstract class FullComposeScreenLockActivity : ScreenLockActionBarActivity() {
@Composable
abstract fun ComposeContent()

final override val applyDefaultWindowInsets: Boolean
get() = false

override fun onCreate(savedInstanceState: Bundle?) {
applyCommonPropertiesForCompose()

super.onCreate(savedInstanceState)
}

override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
super.onCreate(savedInstanceState, ready)

setComposeContent {
ComposeContent()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import java.io.File
import java.io.FileOutputStream
import java.lang.Exception
Expand All @@ -23,13 +24,19 @@ import org.session.libsession.utilities.TextSecurePreferences.Companion.getLocal
import org.session.libsession.utilities.TextSecurePreferences.Companion.isScreenLockEnabled
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.home.HomeActivity
import org.thoughtcrime.securesms.migration.DatabaseMigrationManager
import org.thoughtcrime.securesms.migration.DatabaseMigrationStateActivity
import org.thoughtcrime.securesms.onboarding.landing.LandingActivity
import org.thoughtcrime.securesms.service.KeyCachingService
import org.thoughtcrime.securesms.util.FileProviderUtil
import org.thoughtcrime.securesms.util.FilenameUtils
import javax.inject.Inject

abstract class ScreenLockActionBarActivity : BaseActionBarActivity() {

private val migrationManager: DatabaseMigrationManager
get() = (applicationContext as ApplicationContext).migrationManager

companion object {
private val TAG = ScreenLockActionBarActivity::class.java.simpleName

Expand All @@ -39,6 +46,7 @@ abstract class ScreenLockActionBarActivity : BaseActionBarActivity() {
private const val STATE_SCREEN_LOCKED = 1
private const val STATE_UPGRADE_DATABASE = 2
private const val STATE_WELCOME_SCREEN = 3
private const val STATE_DATABASE_MIGRATE = 4 // This is different from STATE_UPGRADE_DATABASE as it is used to migrate database in a whole rather than the internal db schema upgrades

private fun getStateName(state: Int): String {
return when (state) {
Expand Down Expand Up @@ -152,12 +160,15 @@ abstract class ScreenLockActionBarActivity : BaseActionBarActivity() {
STATE_SCREEN_LOCKED -> getScreenUnlockIntent() // Note: This is a suspend function
STATE_UPGRADE_DATABASE -> getUpgradeDatabaseIntent()
STATE_WELCOME_SCREEN -> getWelcomeIntent()
STATE_DATABASE_MIGRATE -> getRoutedIntent(DatabaseMigrationStateActivity::class.java, getConversationListIntent())
else -> null
}
}

private fun getApplicationState(locked: Boolean): Int {
return if (getLocalNumber(this) == null) {
return if (migrationManager.migrationState.value.shouldShowUI) {
STATE_DATABASE_MIGRATE
} else if (getLocalNumber(this) == null) {
STATE_WELCOME_SCREEN
} else if (locked) {
STATE_SCREEN_LOCKED
Expand All @@ -168,6 +179,9 @@ abstract class ScreenLockActionBarActivity : BaseActionBarActivity() {
}
}

private val DatabaseMigrationManager.MigrationState.shouldShowUI: Boolean
get() = this is DatabaseMigrationManager.MigrationState.Migrating || this is DatabaseMigrationManager.MigrationState.Error

private suspend fun getScreenUnlockIntent(): Intent {
// If this is an attempt to externally share something while the app is locked then we need
// to rewrite the intent to reference a cached copy of the shared file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ import org.thoughtcrime.securesms.mms.PartAuthority
import org.thoughtcrime.securesms.util.MediaUtil
import java.io.IOException
import java.io.InputStream
import javax.inject.Provider

class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), MessageDataProvider {
class DatabaseAttachmentProvider(context: Context, helper: Provider<SQLCipherOpenHelper>) : Database(context, helper), MessageDataProvider {

override fun getAttachmentStream(attachmentId: Long): SessionServiceAttachmentStream? {
val attachmentDatabase = DatabaseComponent.get(context).attachmentDatabase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@

import java.io.IOException;

import javax.inject.Inject;
import javax.inject.Singleton;

import dagger.hilt.android.qualifiers.ApplicationContext;

@Singleton
public class DatabaseSecretProvider {

@SuppressWarnings("unused")
private static final String TAG = DatabaseSecretProvider.class.getSimpleName();

private final Context context;

public DatabaseSecretProvider(@NonNull Context context) {
@Inject
public DatabaseSecretProvider(@ApplicationContext @NonNull Context context) {
this.context = context.getApplicationContext();
}

Expand Down
Loading