docs(phase-1/m3.4): M3 status + scripted key-envelope legs; plan handed to M4
Closes milestone M3 (DESKTOP_PHASE_PLAN §5). Code (one addition): --key-export / --key-import CLI legs in Main.kt — the SecurityActions menu's exact codec calls, headless. This makes the pending physical-phone leg a one-liner once a Waydroid container is live (recipe recorded in the feasibility doc). Docs: DESKTOP_FEASIBILITY.md gains the M3.1–M3.4 status section with the actual run output (leg A/B, KEYENV logs, 0600 ls lines); plan §1 lists the two crypto legs among the must-stay-green commands; §5 marked DONE; first-actions now point a fresh session at M4 task 1. Exit criteria, per the plan's wording: - encrypted desktop library passes EncryptionVerifier's trial-decrypt sweep: MET (leg A verified=1 failed=0, wrong key -> AEAD failure count, leg B relaunch all-ok). - phone-exported recovery key decrypts on desktop: MET at format level (shared codec source, 84B INCKEY1 envelope, AEADBadTagException on wrong passphrase, byte-identical key into a fresh 0600 file); the physical phone export is FLAGGED pending (Waydroid container FROZEN, start is sudo-gated) with the exact re-run recipe — not assumed done. Verified: ./gradlew assembleDebug, :core:data-jvm:smoke, :spike:data-jvm:run, :desktopApp:run --self-test, and both crypto legs — all green in one final pass (one self-test teardown hang under the compositor, rc=124, clean on immediate rerun — recorded, environmental).
This commit is contained in:
1 parent
000f4095cc
commit
6b8db18cdf
3 files changed
+175
-4
No files matched your search
@@ -51,12 +51,16 @@ import androidx.datastore.preferences.core.intPreferencesKey
|
||||
import java.io.File
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.FileOutputStream
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.incido.compose.data.backup.BackupBridge
|
||||
import org.incido.compose.data.backup.EncryptedBackupCodec
|
||||
import org.incido.compose.data.backup.EncryptedKeyCodec
|
||||
import org.incido.data.crypto.AesGcmFieldCipher
|
||||
import org.incido.domain.model.Note
|
||||
import org.incido.domain.repository.NoteRepository
|
||||
|
||||
@@ -100,6 +104,12 @@ fun main(args: Array<String>) {
|
||||
val cryptoSelfTest = "--crypto-self-test" in args
|
||||
val cryptoReopen = "--crypto-reopen" in args
|
||||
val cryptoPassphrase = args.argAfter("--crypto-passphrase") ?: "selftest-passphrase"
|
||||
// Recovery-envelope file legs: --key-export writes the INCKEY1 envelope
|
||||
// the phone's Settings screen writes; --key-import reads one (e.g. a
|
||||
// REAL phone export) with the passphrase and installs the key — the
|
||||
// scripted version of the SecurityActions import menu.
|
||||
val keyExport = args.argAfter("--key-export")
|
||||
val keyImport = args.argAfter("--key-import")
|
||||
|
||||
println("=== Incido (desktop) — Phase 1 M1b ===")
|
||||
println("JVM : ${System.getProperty("java.vendor")} ${System.getProperty("java.version")}")
|
||||
@@ -141,6 +151,8 @@ fun main(args: Array<String>) {
|
||||
cryptoSelfTest = cryptoSelfTest,
|
||||
cryptoReopen = cryptoReopen,
|
||||
cryptoPassphrase = cryptoPassphrase,
|
||||
keyExport = keyExport,
|
||||
keyImport = keyImport,
|
||||
onExit = ::exitApplication,
|
||||
)
|
||||
}
|
||||
@@ -165,6 +177,8 @@ private fun NotesWindow(
|
||||
cryptoSelfTest: Boolean,
|
||||
cryptoReopen: Boolean,
|
||||
cryptoPassphrase: String,
|
||||
keyExport: String?,
|
||||
keyImport: String?,
|
||||
onExit: () -> Unit,
|
||||
) {
|
||||
val notes by remember(repository) { repository.observeAll() }
|
||||
@@ -352,6 +366,51 @@ private fun NotesWindow(
|
||||
prefs[intPreferencesKey("window_height")] = height
|
||||
}
|
||||
}
|
||||
if (keyExport != null || keyImport != null) {
|
||||
LaunchedEffect(Unit) {
|
||||
delay(800)
|
||||
withContext(Dispatchers.IO) {
|
||||
if (keyExport != null) {
|
||||
// Same codec call the SecurityActions export menu makes —
|
||||
// the exact envelope the phone's ObjectBoxKeyProvider writes.
|
||||
val out = File(keyExport)
|
||||
out.writeBytes(app.keyProvider.exportRecoveryKey(cryptoPassphrase.toCharArray()))
|
||||
val magic = out.readBytes()
|
||||
.copyOf(EncryptedKeyCodec.MAGIC.size)
|
||||
.contentEquals(EncryptedKeyCodec.MAGIC)
|
||||
println(
|
||||
"KEYENV exported=${out.length()}B to $out " +
|
||||
"(magic=${if (magic) "INCKEY1 ok" else "BAD"})",
|
||||
)
|
||||
}
|
||||
if (keyImport != null) {
|
||||
val bytes = File(keyImport).readBytes()
|
||||
val rejectedWrongPw = runCatching {
|
||||
app.keyProvider.importRecoveryKey(bytes, "wrong-pass".toCharArray())
|
||||
}.isFailure
|
||||
val result = runCatching {
|
||||
app.keyProvider.importRecoveryKey(bytes, cryptoPassphrase.toCharArray())
|
||||
if (app.settingsRepository.snapshot().isEncryptionActive) {
|
||||
app.cipherHolder.cipher = AesGcmFieldCipher(app.keyProvider)
|
||||
}
|
||||
app.noteCryptoService.verifyAll()
|
||||
}
|
||||
result.fold(
|
||||
onSuccess = { v ->
|
||||
println(
|
||||
"KEYENV import ok wrong-pw=" +
|
||||
(if (rejectedWrongPw) "rejected" else "LEAKED!") +
|
||||
" verify verified=${v.verifiedNoteIds.size} failed=${v.failedNoteIds.size}",
|
||||
)
|
||||
},
|
||||
onFailure = {
|
||||
println("KEYENV import FAILED: ${it.javaClass.simpleName}: ${it.message}")
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cryptoSelfTest || cryptoReopen) {
|
||||
LaunchedEffect(Unit) {
|
||||
delay(800) // past the first frame; assertions ride the flows, not frame one
|
||||
|
||||
Reference in new issue
Block a user