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:
Incido Developer committed 2026-10-06 07:39:54 +13:00
1 parent 000f4095cc
commit 6b8db18cdf
3 files changed
+175 -4

No files matched your search

+105
View File
@@ -499,6 +499,111 @@ before a 3 s-delayed screenshot — burst-capture spectacle at 1 s
intervals; `waydroid shell` needs sudo, but `waydroid app install` and
`pkill -f org.incido.app` from the host need none.
**M3.1 — `:core:settings`: DONE.** `UserSettings` + `SettingsRepository`
moved to a plain `kotlin("jvm")` module with package
`org.incido.compose.data.settings` kept, so the Android diff is two
constructor lines + one new provider file (`AndroidSettingsStore.kt` —
the `preferencesDataStore(name = "incido_settings")` Context extension,
moved verbatim). The repository now takes an **injected**
`DataStore<Preferences>`; the desktop creates the identical format with
`PreferenceDataStoreFactory.create(corruptionHandler, produceFile)`
(the Phase-0 API delta). `:app` gained `implementation(":core:settings")`
— MainActivity reads `userSettingsFlow` and the type moved with the
class, same reason `:core:domain` is there. `snapshot()`'s `runBlocking`
kept for startup-only use. `dynamic_color` / `use_biometric` /
`block_screenshots` ride in the file but have no desktop UI (hidden,
not faked). Verified: `assembleDebug` + `:desktopApp:run … --self-test`
+ `:core:data-jvm:smoke` green.
**M3.2 — cipher seam: DONE.** `AesGcmFieldCipher` moved into
`core/data/src/main/kotlin/…/crypto/` (compiled by BOTH modules) behind
new `fun interface FieldKeyProvider { getOrCreateKey(): ByteArray }`;
`EncryptionVerifier` (pure coroutines) moved with it. Android passes
`objectBoxKeyProvider::getOrCreateKey` (SAM). Verified: `assembleDebug`
+ desktop self-test green.
**M3.3 — desktop key + wiring + UI: DONE.** `DesktopKeyProvider`: the
32-byte key in `field.key` (temp+atomic-move, `0600` POSIX perms —
visible as `-rw-------` in every `ls` below). KEYRING STATUS, STATED
PLAINLY: no keyring library is in the catalog and no candidate was
verified on this stack, so the plan's fallback (file + `0600`) stands;
revisit in Phase 2 with `secret-service` behind a real test.
`DesktopContainer` now mirrors `AppContainer` completely — settings →
cipher auto-install (`isEncryptionActive` AND key on disk) BEFORE the
repository → `NoteCryptoService` → `EncryptionVerifier.checkNow()`.
`SecurityActions` menu: theme cycle (real shared `theme_mode` key —
Material3 switches via `colorScheme`, there is no `darkTheme` param),
encrypt/decrypt toggle (Android's enable/disable call order), recovery
key import/export (with Android's overwrite-warning gate); no dynamic
color, no biometrics, no screenshot blocking, no PIN — desktop hides
all four. Window geometry → its own `incido_window.preferences_pb`
(position deliberately not stored; KWin owns placement). Scripted legs
(`--crypto-self-test` / separate-process `--crypto-reopen`):
```
=== leg A: enable === (fresh /tmp/incido-desktop-crypto)
probe note written PASS id=1
encrypt sweep flipped rows PASS
verifier trial-decrypt sweep PASS verified=1 failed=0
repository decrypts transparently PASS notes=1
wrong key rejected (AEAD tag) PASS failed=1
recovery envelope (INCKEY1) PASS len=84
wrong passphrase rejected PASS
envelope carries library key PASS
CRYPTO LEG-A PASS (library left encrypted for leg B)
=== leg B: reopen (separate process = the real relaunch) ===
settings survived restart PASS
cipher auto-installed PASS
reopen verifier sweep all-ok PASS verified=1 failed=0
decrypt sweep reverses it PASS
CRYPTO LEG-B PASS
```
**M3.4 — recovery-key envelope file legs: DONE (desktop side).**
`--key-export` / `--key-import` drive the menu's exact codec calls
headlessly — export from one library, import into a FRESH one:
```
KEYENV exported=84B to /tmp/incido-recovery-key.incidokey (magic=INCKEY1 ok)
KEYENV import ok wrong-pw=rejected verify verified=0 failed=0
KEYENV import FAILED: AEADBadTagException: Tag mismatch! (wrong passphrase)
-rw------- 1 nick nick 32 … /tmp/incido-key-dst/field.key (imported key is 0600)
```
**M3 exit criteria:** (1) "an encrypted desktop library passes
`EncryptionVerifier`'s trial-decrypt sweep" — **met**, leg A step 3 +
leg B (auto-install + full-library sweep on relaunch). (2) "a
phone-exported recovery key decrypts … on desktop" — **met at format
level** (one shared `EncryptedKeyCodec` source compiled into both
platforms; 84-byte envelope, wrong-pw AEAD rejection, byte-identical
key — above); the **physical phone leg is the one item pending**: the
Waydroid container was FROZEN at session end and starting it is
sudo-gated, so the phone→desktop `Settings → Export recovery key` run
could not be executed here. Recipe for it (≈15 min with a live
container, mirrors the M2.4b pass): enable encryption on the phone →
export the recovery key to a shared-storage file → copy to host →
`./gradlew :desktopApp:run --args="--data-dir /tmp/incido-phonekey
--backup-import <phone-backup.incido.json> --key-import
<recovery.incidokey> --crypto-passphrase <pw> --exit-after 25"` →
enable encryption in that library → every imported note earns the badge.
Honesty notes: (a) intermittent XWayland window flakiness struck this
session's scripted runs three times — a startup wedge (never reached
first composition) and two teardown wedges (all output flushed, never
reached `exitApplication`); every occurrence passed cleanly on rerun,
none touched the data paths, and the first predates all M3 code, so it
is environmental (likely compositor power state after long uptime), not
a regression. Scripted verification should retry once before believing
a hang;
(b) `field.key` protects at-rest notes only against someone reading the
files — it cannot gate app opening (no desktop lock is wired; PIN gating
is deferred); (c) the PBKDF2 recovery path costs ~55 ms per unlock here,
so desktop may skip Android's async key handling for good.
**Next up: M4** — `composeApp` → Compose Multiplatform (plan §6).