feat: v0.3.6.0 — AES-GCM field encryption, PIN/passphrase security, encryption verifier, backup codec
build / Assemble debug APK (push) Failing after 2s

This commit is contained in:
Incido Developer committed 2026-08-20 01:14:15 +12:00
1 parent 089926377c
commit 14d61c78d3
55 files changed
+2474 -715

No files matched your search

@@ -2,10 +2,17 @@ package org.incido.compose.di
import android.content.Context
import io.objectbox.BoxStore
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import org.incido.data.ObjectBoxStore
import org.incido.data.crypto.CipherHolder
import org.incido.data.crypto.NoteCryptoService
import org.incido.data.repository.NoteRepositoryImpl
import org.incido.domain.repository.NoteRepository
import org.incido.compose.data.backup.BackupManager
import org.incido.compose.data.security.AesGcmFieldCipher
import org.incido.compose.data.security.EncryptionVerifier
import org.incido.compose.data.security.ObjectBoxKeyProvider
import org.incido.compose.data.security.SecurityManager
import org.incido.compose.data.settings.SettingsRepository
@@ -21,16 +28,25 @@ import org.incido.compose.data.settings.SettingsRepository
* - [SecurityManager] (PIN / biometric / app-lock state)
* - [BackupManager] (JSON + encrypted backup import / export)
*
* The constructor accepts a Context, builds the [SettingsRepository]
* first (so we can read the encryption preference synchronously),
* then either fetches the BoxStore encryption key from the Keystore
* (when `securityEnabled && encryptionEnabled`) or opens the store
* unencrypted.
* v0.3.5.0 — real at-rest encryption. The constructor reads the
* security preferences synchronously; when `securityEnabled &&
* encryptionEnabled` it installs an [AesGcmFieldCipher] into the
* shared [cipherHolder] so every repository read/write encrypts or
* decrypts note content + attachment bytes in place. The ObjectBox
* store file itself is still opened unencrypted (OSS ObjectBox has no
* page-level encryption) — the field-level layer IS the encryption.
* After startup the [encryptionVerifier] re-checks every encrypted row
* by trial-decrypting it; only rows that pass earn the "Encrypted"
* badge on the note cards.
*/
class AppContainer(context: Context) {
private val appContext: Context = context.applicationContext
/** Process-wide scope for fire-and-forget background work
* (verification sweeps, etc.). SupervisorJob isolates failures. */
val appScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
val settingsRepository: SettingsRepository = SettingsRepository(appContext)
val objectBoxKeyProvider: ObjectBoxKeyProvider = ObjectBoxKeyProvider(appContext)
@@ -38,17 +54,38 @@ class AppContainer(context: Context) {
val securityManager: SecurityManager =
SecurityManager(appContext, settingsRepository)
/** Shared cipher slot consulted by the repository on every I/O. */
val cipherHolder = CipherHolder()
val boxStore: BoxStore = run {
// v0.3.2.0: ObjectBox 4.0.3 OSS doesn't expose an
// `encryptionKey(byte[])` method on BoxStoreBuilder — the
// feature is only available in ObjectBox Pro. The key is
// still generated by ObjectBoxKeyProvider (so the wiring
// is ready for when/if the API lands), but we always
// open the store unencrypted for now.
ObjectBoxStore.init(appContext, encryptionKey = null)
}
val noteRepository: NoteRepository = NoteRepositoryImpl(boxStore)
/**
* v0.3.5.0: install the field cipher BEFORE the repository is
* constructed, so the very first snapshot already reads encrypted
* rows correctly. Key unwrap is a single Keystore operation — safe
* to do synchronously at Application.onCreate.
*/
init {
val s = settingsRepository.snapshot()
if (s.isEncryptionActive && objectBoxKeyProvider.hasKeyBlocking()) {
cipherHolder.cipher = AesGcmFieldCipher(objectBoxKeyProvider)
}
}
val noteRepository: NoteRepository = NoteRepositoryImpl(boxStore, cipherHolder)
val backupManager: BackupManager = BackupManager(appContext, noteRepository)
}
/** Migration sweep + startup integrity checker for the note store. */
val noteCryptoService = NoteCryptoService(boxStore, cipherHolder)
/** Runs on every app open — feeds the verified-encryption badge. */
val encryptionVerifier = EncryptionVerifier(noteCryptoService, appScope)
/** Kick the startup verification off immediately. */
init {
encryptionVerifier.checkNow()
}
}