diff --git a/.crumb b/.crumb index 86c59a29..9fa5ea94 100644 --- a/.crumb +++ b/.crumb @@ -28,32 +28,32 @@ }, { "digest": "6098d439031bb73f0defd23222fe41ed8786929160f9285c456c10c70891361d", - "last_commit": "a9d120b", + "last_commit": "1feaca1", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "bd21781b57471cd22c7d3a37f5ce588145ecc0ac05f5a75fde1028d406bd2d9c", - "last_commit": "a9d120b", + "digest": "b31f2fbe0098a7147db621948947a4f65981798cd8f38dfb90f2925bdf923534", + "last_commit": "101c710", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "9f409f70dc736ec25cc1fb97a221db84f7ac631b613bf50563740171fabc6983", - "last_commit": "a9d120b", + "digest": "87981170f9983b962d7b2c8ea7f2f4811b354e13514dcb6365f0cc7a49cb1e9f", + "last_commit": "101c710", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:4bc63395eee8ae0cf3f86afe19d41c378a83395f8556f75d89a44cf9d1333f5f", - "compiled_at": "2026-10-12T05:32:10Z", + "children_root": "sha256:eef5b71658818e8bf015518ee54e49bfb131d7b684900c605feff63bc34a501e", + "compiled_at": "2026-10-12T06:35:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:2fbe81c18985c09dcff20c9db146d01f743621ea65ef720ce2a919b33d9b3a58", + "digest": "sha256:2886dcfc976f771e9c109ff4f00d6ca5d3e497df71dfbef80551615edd80cf42", "evidence_files": 155, "evidence_root": "sha256:d59c0cef4e7dd5172923754a95b411ca54b01f35baca4587f792f1b259f1eaf7", - "files": 3073, - "generated_at_commit": "a9d120b2e91893bb80a378dc746cf0a274e42878", - "source_tree": "sha256:c24d4e737b9c52f845b889c98ac767f2bda59b9028d8542324b7b3e9b2836cb8" + "files": 3075, + "generated_at_commit": "101c710b24fad41fc9a8797222e366ed71e6b6f2", + "source_tree": "sha256:fd7bfde997ed3035059431248fbf4c14c71413507be0b2674cf9d8a0a70f13ee" }, "owner_lane": "", "provenance": { diff --git a/native/.crumb b/native/.crumb index d6c26210..33c8793d 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,14 +79,14 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "43d5aaa5344f8b3514ebe464c12e3ba1b74b2d3ded7e7dbed891b5d884567de2", - "last_commit": "a9d120b", + "digest": "169522946ffcd95a36106c1d8a0f6bdba1130e97a5b8dad204696a7245de1948", + "last_commit": "101c710", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, { "digest": "3883ad91cdafdb9158b14c4d8b11d4dcbfe1205ad8071c988b8f7c4b959a4004", - "last_commit": "a9d120b", + "last_commit": "1feaca1", "name": "m5", "purpose": "Directory native/m5. Purpose not yet described by a human." }, @@ -104,20 +104,20 @@ }, { "digest": "9146f4be830fe28ed14ce6bfac89cd97bd2043c825a60a00451152309e1f87ea", - "last_commit": "a9d120b", + "last_commit": "1feaca1", "name": "store", "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:ac40341f41da03e1d5079c91920b80ac3be094e6035abf4d81d78b33192827d4", - "compiled_at": "2026-10-12T05:32:10Z", + "children_root": "sha256:bf53e2b5d96c2ab47143ebc4bb6d1864f1116a267bc9fe10abc549c25b5de3ad", + "compiled_at": "2026-10-12T06:35:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:bd21781b57471cd22c7d3a37f5ce588145ecc0ac05f5a75fde1028d406bd2d9c", + "digest": "sha256:b31f2fbe0098a7147db621948947a4f65981798cd8f38dfb90f2925bdf923534", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 460, - "generated_at_commit": "a9d120b2e91893bb80a378dc746cf0a274e42878", - "source_tree": "sha256:31c62df5a9e06b6886576242287883d70704900b1cae722c12116f22b51471c2" + "files": 462, + "generated_at_commit": "101c710b24fad41fc9a8797222e366ed71e6b6f2", + "source_tree": "sha256:d45042e6d50a30dd9e6c8929ede1c45208c05d61ddead84bf1fba932f1ebbdd2" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index f4c4660d..9ac008e1 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -57,8 +57,8 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "2c67028de54aa45d784364bf04b531a9160802bdea23fc1ee521b9e53173a00c", - "last_commit": "a9d120b", + "digest": "438c62d03d5cc14b9d2b663dbdd54dbd4153124e759bd3a97467e8dc0f5a6f74", + "last_commit": "101c710", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, @@ -81,14 +81,14 @@ "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { - "digest": "3bca3564005f4581d6646e0b3ef797ec8157b80af1f1389e27e6e5089d1de042", - "last_commit": "a9d120b", + "digest": "5901ee6ca8dd0417ed55c72cc01cb3c2e9d55d71cd91d89f9cad9e6901e7a64e", + "last_commit": "101c710", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { "digest": "08b0938d801a9dfeea54c16f1f585ff01e806ef264047b625e3d0555389087ac", - "last_commit": "a9d120b", + "last_commit": "1feaca1", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, @@ -99,15 +99,15 @@ "purpose": "Directory native/kernel/tools. Purpose not yet described by a human." } ], - "children_root": "sha256:66e1de38e86954327f2760f0afb7d72a7fb669ba28f06136d111303185cb9499", - "compiled_at": "2026-10-12T05:32:10Z", + "children_root": "sha256:dcf283b3305e4989150c05c97b1dd3fac672a0112769ddc7adab58e773bbc806", + "compiled_at": "2026-10-12T06:35:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:43d5aaa5344f8b3514ebe464c12e3ba1b74b2d3ded7e7dbed891b5d884567de2", + "digest": "sha256:169522946ffcd95a36106c1d8a0f6bdba1130e97a5b8dad204696a7245de1948", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 296, - "generated_at_commit": "a9d120b2e91893bb80a378dc746cf0a274e42878", - "source_tree": "sha256:a690fc0ca1fea1283afc1c77c805e69e95d416aba7205c058a1196b0c74a63e9" + "files": 298, + "generated_at_commit": "101c710b24fad41fc9a8797222e366ed71e6b6f2", + "source_tree": "sha256:1b874766907d3cf7dab922682886f87da433f84c1b2622334df9f30b405636a0" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md index 9d95b8fc..96d1af59 100644 --- a/native/kernel/GATES.md +++ b/native/kernel/GATES.md @@ -821,7 +821,10 @@ The product boundary. A `CK_SERVICE=1` image (`full-service/`, allowed with `CK_ | 166 | bounds: a 97-byte line (limit 96, room for `unlock ` + 64 hex) is refused whole and never run; `evidence` counts agree (`tasks=3 approved=1 denied=1 cancelled=1 overlong=1`) with the last commit generation and object id | LIFECYCLE | QEMU PASS (hardware NOT_RUN) | | 167 | stop order: `lifecycle: ready` < `dma_gate: nvme bus master revoked` < `stop order store=closed nvme=released` < `stage lifecycle: ok` < final report; no panic or fault; QEMU exit 0; M1 checks | LIFECYCLE | QEMU PASS (hardware NOT_RUN) | | 167a | build shape: the default image carries no lifecycle; `CK_SERVICE` refused with `CK_CONSOLE_SESSION`, `CK_QEMU_UNSAFE_DMA` and any `CK_TEST_*`; `CK_SERVICE_TEST_KEYS` refused with `CK_HARDWARE_STAGING` | LIFECYCLE (build) | PASS | -| 167b | limits: operator input is serial only (USB keyboard binding stays with the xHCI session code, later cut); a committed note is not yet read back after a cold boot (P05/P06); the lifecycle loop polls with interrupts as the boot stages left them (no scheduler integration yet) | LIFECYCLE | LIMIT (declared) | -| 168 | P04 cut 1, recovery keyslot GENESIS (production service image, blank disk): `unlock deadbeef` refused (`rc=-2004`, 64 hex digits expected); `unlock <64-hex secret>` draws K_vol/salt/nonce from the entropy service, wraps K_vol into the ADR 0017 Slot 1 Recovery_RawSecret descriptor (HKDF-SHA256 KEK) and commits the KeySlotManifest (kind 21, plaintext, bound by the sealed transaction record) in the same first transaction as the boot record: `formatted production store`, `key source=recovery-keyslot genesis=1`, `committed generation=2 boot_count=1`, `unlock ok ... genesis=1`, lifecycle READY; a note is approved and committed at generation 3; stop order closes the Store; QEMU exit 0; M1 checks | LIFECYCLE / TRUST-1 | QEMU PASS (hardware NOT_RUN) | -| 169 | P04 cut 1, recovery keyslot RESUME (same disk, cold boot): the wrong secret is refused by the keyslot AES-GCM-SIV tag (`RecoverySecretRejected rc=-2004`, disk not opened, not reformatted, lifecycle stays locked, `refused=1`); the right secret unwraps K_vol, derives PRODUCTION-class keys (owner hierarchy generation = active_key_epoch 1), the keyed open re-binds the manifest through the transaction record: `opened generation=3 boot_count=1 ... anchor=valid-resume`, `committed generation=4 boot_count=2`, `unlock ok ... genesis=0`; stop order closes the Store; QEMU exit 0; M1 checks | LIFECYCLE / TRUST-1 | QEMU PASS (hardware NOT_RUN) | +| 167b | limits: operator input is serial only (USB keyboard binding stays with the xHCI session code, later cut); a committed note is not yet read back after a cold boot (P06; the continuity identity and ALLEN subject are, rows 171-172); the lifecycle loop polls with interrupts as the boot stages left them (no scheduler integration yet) | LIFECYCLE | LIMIT (declared) | +| 168 | P04 cut 1, recovery keyslot GENESIS (production service image, blank disk): `unlock deadbeef` refused (`rc=-2004`, 64 hex digits expected); `unlock <64-hex secret>` draws K_vol/salt/nonce from the entropy service, wraps K_vol into the ADR 0017 Slot 1 Recovery_RawSecret descriptor (HKDF-SHA256 KEK) and commits the KeySlotManifest (kind 21, plaintext, bound by the sealed transaction record) in the same first transaction as the boot record: `formatted production store`, `key source=recovery-keyslot genesis=1`, `committed generation=2 boot_count=1`, `unlock ok ... genesis=1`, lifecycle READY; the continuity genesis commits generation 3 (row 171); a note is approved and committed at generation 4; stop order closes the Store; QEMU exit 0; M1 checks | LIFECYCLE / TRUST-1 | QEMU PASS (hardware NOT_RUN) | +| 169 | P04 cut 1, recovery keyslot RESUME (same disk, cold boot): the wrong secret is refused by the keyslot AES-GCM-SIV tag (`RecoverySecretRejected rc=-2004`, disk not opened, not reformatted, lifecycle stays locked, `refused=1`); the right secret unwraps K_vol, derives PRODUCTION-class keys (owner hierarchy generation = active_key_epoch 1), the keyed open re-binds the manifest through the transaction record: `opened generation=4 boot_count=1 ... anchor=valid-resume`, `committed generation=5 boot_count=2`, `unlock ok ... genesis=0`; the continuity resume commits generation 6 (row 172); stop order closes the Store; QEMU exit 0; M1 checks | LIFECYCLE / TRUST-1 | QEMU PASS (hardware NOT_RUN) | | 170 | secret hygiene and limits: the typed secret is echoed as 64 `*` and neither secret's hex appears in any serial log; no TEST key banner; no key material is compiled into the image (`ck_store_production_keys` still refuses `rc=-2002`: TPM Slot 0 BLOCKED_HARDWARE); no key rotation (`active_key_epoch` 1); the manifest is not yet bound into the secman `keyslot_manifest_id`; host rig (`stage_test` `test_unlock_recovery`): entropy refusal leaves a blank disk untouched, wrong secret and wrong provisioned uuid leave the image byte-identical, a TEST-key Store has no manifest (`NoKeyslotManifest rc=-2003`) | LIFECYCLE / TRUST-1 | QEMU PASS + LIMIT (declared) | +| 171 | P05 cut 1, production continuity GENESIS (unlock boot, after `store: unlock ok`): `svc/continuity_service.c` (linked only into `CK_SERVICE` images; the TEST-ONLY mode selection `continuity_boot.c`, the `AIENCONT` plan line and the Recovery Core are not) finds the Store unprovisioned and mints the identity (AgentRoot, genesis AgentState, Manifest incarnation 1) and the ALLEN subject (kind 24, sequence 1) in ONE sealed transaction (`svc/continuity_subject_provision.c`, generation 3) with entropy from the kernel RNDR service: `continuity: genesis source=qualification provenance=store-uuid-only`, `continuity: PROVISIONED agent=<64 hex> incarnation=1 sequence=1 cortex=0 branches=1`, `allen: GENESIS subject=<64 hex> sequence=1 lineage=<64 hex> intents=0 active=0 knowledge=0`; order `unlock ok` < `PROVISIONED` < `lifecycle: unlock ok`; `status` reports `continuity=provisioned agent=<16 hex> incarnation=1 subject_seq=1`. Genesis inputs are public and deterministic: provenance = SHA-256("AIENOS/ALLEN/PROVENANCE-V1" \|\| owner root public key (hardware staging image) \|\| store uuid), cortex lineage = SHA-256("AIENOS/ALLEN/CORTEX-LINEAGE-V1" \|\| store uuid): the Cortex of this subject is the sealed Store on this disk (CURRENT_EXECUTION_PLAN addendum, conflict 3). A hardware staging service image uses `source=operator` and the owner root key (`ck_owner_root_pk`) | LIFECYCLE / M4_CONTINUITY / M4_ALLEN | QEMU PASS (hardware NOT_RUN) | +| 172 | P05 cut 1, production continuity RESUME (relock boot, cold start of the same disk): the ALLEN subject is restored read-only first (`allen: RESTORED ... sequence=1`; absent, corrupt, forked or foreign: REFUSED, nothing written, never minted over), then `cr_resume` commits incarnation 2 (generation 6): `continuity: RESUMED agent= incarnation=2 sequence=2 cortex=0 branches=1`; no second genesis, no degraded mount; order `unlock ok` < `RESUMED` < `lifecycle: unlock ok`; `status` reports `continuity=resumed ... incarnation=2 subject_seq=1`; after the wrong secret `status` reports `continuity=none`. Host rig (`stage_test` `test_continuity_service`): provisioned at generation 3, resumed at incarnation 2 then 3 on the same agent, an entropy refusal on a fresh Store leaves the disk byte-identical and the state `refused` (not writable) | LIFECYCLE / M4_CONTINUITY / M4_ALLEN | QEMU PASS (hardware NOT_RUN) | +| 173 | shape and refusal path: the locked service boot prints no `continuity:` or `allen:` line (nothing runs before the Store opens); the test-keys image provisions at boot before `store: service lifetime: Store open`; the service EFI carries `continuity: REFUSED` and neither `AIENCONT` nor `RECOVERY_OPERATOR_KEY` (Makefile `cont_check` for `CK_SERVICE` images: `cr_provision`/`cr_resume` allowed, `ck_cont_boot_stage`/`rc_inspect` and the uppercase `CONTINUITY: ` markers refused; the markers are fenced out of `continuity_commit.c` under `CK_SERVICE`). A refusal (`continuity: REFUSED step=... outcome=... store_rc=...`) erases the Store keys, leaves the disk as found and keeps the lifecycle LOCKED with the NVMe bound for the stop order (`store: service lifetime: continuity REFUSED ...`, `ContinuityRefused rc=-2007`); `approve` is refused on a degraded (read-only) mount. Limits: the approved note is a plain Store object, not yet a continuity WAL / Cortex record (P06 CxStore adapter); no Recovery Core in the service image (its operator key is TEST-only); aienos#285 resource incarnations are NOT triggered (continuity objects are Store objects, not ADR 0013 domain-1 channels/objects); physical NVMe geometry, confined DMA, flush, shutdown and interrupted-transaction qualification (aienos#31) NOT_RUN | LIFECYCLE / M4_CONTINUITY | QEMU PASS + LIMIT (declared) | diff --git a/native/kernel/Makefile b/native/kernel/Makefile index db638178..51f21ecc 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -653,6 +653,13 @@ FULL_NAME := full-service$(if $(strip $(CK_HARDWARE_STAGING)),-hardware-staging, STAGE_DMA_FLAGS += -DCK_SERVICE=1 endif STAGE_SRCS += $(KDIR)/core/lifecycle.c $(KDIR)/core/lifecycle_fsm.c +# P05 cut 1: production continuity on the service lifecycle (svc/continuity_service.c): +# the continuity layer without its TEST-ONLY mode selection (continuity_boot.c) +# and without the Recovery Core (continuity_recovery.c, TEST operator key). +STAGE_DMA_FLAGS += -I$(KDIR)/core +STAGE_SRCS += $(KDIR)/svc/continuity_codec.c $(KDIR)/svc/continuity_resolve.c \ + $(KDIR)/svc/continuity_resolve_sealed.c $(KDIR)/svc/continuity_commit.c \ + $(KDIR)/svc/continuity_subject.c $(KDIR)/svc/continuity_subject_provision.c $(KDIR)/svc/continuity_service.c endif ifeq ($(strip $(CK_TEST_DISK_XLATE_BYPASS)),1) FULL_NAME := $(FULL_NAME)-test-xlate-bypass @@ -859,20 +866,26 @@ define crash_check endef # cont_check(elf): a full image built without CK_TEST_CONTINUITY must carry no -# continuity wiring code or strings; a TEST continuity image must announce itself. -# The bare "TEST-ONLY MUTANT" phrase is refused here except in the TEST Store -# crash image, whose own mutants print it (crash_check refuses it in every -# image built without CK_TEST_STORE_CRASH; continuity mutants are still caught -# by the continuity strings). +# TEST continuity wiring code or strings; a TEST continuity image must announce +# itself. A CK_SERVICE image carries the production continuity layer (P05 cut 1: +# cr_provision/cr_resume through svc/continuity_service.c) and must still carry +# neither the TEST mode selection (ck_cont_boot_stage, AIENCONT plan line) nor +# the Recovery Core (rc_inspect, the TEST operator key). define cont_check @if [ "$(strip $(CK_TEST_CONTINUITY))" = 1 ]; then \ grep -aqF "TEST-ONLY continuity mode selection image" $(1) || { echo "TEST continuity image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ else \ m="|TEST-ONLY MUTANT"; [ "$(strip $(CK_TEST_STORE_CRASH))" = 1 ] && m=""; \ - s=$$(grep -aoE "AIENCONT|RECOVERY_OPERATOR_KEY|RECOVERY_CORE:|CONTINUITY: $$m" $(1) | sort -u | tr "\n" " "); \ - y=$$($(KNM) $(1) | grep -E " (ck_cont_boot_stage|cr_resume|cr_provision|rc_inspect)$$" | tr "\n" " "); \ - if [ -n "$$s$$y" ]; then echo "default image carries the TEST continuity wiring: $$s$$y"; rm -f $(1); exit 1; fi; \ - echo "no continuity wiring code in $(1)"; \ + if [ "$(strip $(CK_SERVICE))" = 1 ]; then \ + s=$$(grep -aoE "AIENCONT|RECOVERY_OPERATOR_KEY|RECOVERY_CORE:|CONTINUITY: $$m" $(1) | sort -u | tr "\n" " "); \ + y=$$($(KNM) $(1) | grep -E " (ck_cont_boot_stage|rc_inspect)$$" | tr "\n" " "); \ + grep -aqF "continuity: REFUSED" $(1) || { echo "service image lacks the production continuity wiring"; rm -f $(1); exit 1; }; \ + else \ + s=$$(grep -aoE "AIENCONT|RECOVERY_OPERATOR_KEY|RECOVERY_CORE:|CONTINUITY: |continuity: REFUSED$$m" $(1) | sort -u | tr "\n" " "); \ + y=$$($(KNM) $(1) | grep -E " (ck_cont_boot_stage|cr_resume|cr_provision|rc_inspect|ck_cont_service_start)$$" | tr "\n" " "); \ + fi; \ + if [ -n "$$s$$y" ]; then echo "image carries the TEST continuity wiring: $$s$$y"; rm -f $(1); exit 1; fi; \ + echo "no TEST continuity wiring in $(1)"; \ fi endef diff --git a/native/kernel/README.md b/native/kernel/README.md index 89bf80b3..dbe11c2f 100644 --- a/native/kernel/README.md +++ b/native/kernel/README.md @@ -83,6 +83,21 @@ of them: `keyslot_manifest_id`. `store_boot_run` refuses TEST-identity keys in a hardware staging build before any disk access (host test `stage_test`, including `test_unlock_recovery`; QEMU rows 168-170). +- **Production continuity on the service lifecycle (P05 cut 1).** Every + Store open of a `CK_SERVICE` image (boot with keys, or `unlock`) runs + `svc/continuity_service.c`: an unprovisioned Store gets the identity + (AgentRoot, AgentState, Manifest) and the ALLEN subject minted in one + sealed transaction with RNDR entropy (no entropy: refused, nothing + written); a provisioned Store has the subject restored read-only, then the + identity resumed at incarnation + 1. A refusal erases the Store keys and + keeps the lifecycle LOCKED. The TEST-ONLY mode selection + (`continuity_boot.c`, `CK_TEST_CONTINUITY`, the `AIENCONT` plan line) and + the Recovery Core are never in a service image (`cont_check`). Serial lines + `continuity: PROVISIONED|RESUMED|REFUSED ...` and `allen: GENESIS|RESTORED + ...`; `status` appends `continuity=...`. Limits: the approved note is not a + Cortex record yet (P06); no Recovery Core, no TPM; aienos#285 not + triggered; physical disk qualification NOT_RUN (host test + `test_continuity_service`; QEMU rows 171-173). - Proof: `scripts/ck_owner_keys_check.sh` (build only, takes the quiet flag) checks the refusals, the generator refusals, and builds the hardware staging image from the labelled TEST-fixture files in `tests/fixtures/owner/` diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index 7b703bae..bec8e447 100644 --- a/native/kernel/core/.crumb +++ b/native/kernel/core/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T05:32:10Z", + "compiled_at": "2026-10-12T06:35:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:2c67028de54aa45d784364bf04b531a9160802bdea23fc1ee521b9e53173a00c", + "digest": "sha256:438c62d03d5cc14b9d2b663dbdd54dbd4153124e759bd3a97467e8dc0f5a6f74", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 42, - "generated_at_commit": "a9d120b2e91893bb80a378dc746cf0a274e42878", - "source_tree": "sha256:08e6e7db7e8da50a46500f437f10687280037ed6491247260ac1d4e9d2983594" + "generated_at_commit": "101c710b24fad41fc9a8797222e366ed71e6b6f2", + "source_tree": "sha256:66d1ea8b2342167efb5faa17673dc684f297f5f3c6c1710e533a881eb33e36d8" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/lifecycle.c b/native/kernel/core/lifecycle.c index 928f8229..b7c08d1b 100644 --- a/native/kernel/core/lifecycle.c +++ b/native/kernel/core/lifecycle.c @@ -20,17 +20,22 @@ * (3) return to kmain: final report, ck_reset (quiesce hook, PSCI). Never * the other way round. * - * LOCKED is the production truth today: ck_store_production_keys refuses - * (no in-kernel K_vol unwrap until P04). A full-service image therefore - * stays locked; only the TEST-ONLY full-service-testkeys image (refused - * with CK_HARDWARE_STAGING) opens the Store with TEST keys so the READY and - * SERVE paths can run in QEMU. */ + * LOCKED at boot is the production truth: ck_store_production_keys refuses + * (no TPM Slot 0 unwrap); the operator opens the Store with the recovery + * secret (`unlock <64-hex>`, P04 cut 1). The TEST-ONLY full-service-testkeys + * image (refused with CK_HARDWARE_STAGING) opens it with TEST keys at boot so + * the READY and SERVE paths run in QEMU. + * + * Continuity (P05 cut 1): every Store open runs svc/continuity_service.c: + * identity + ALLEN subject provisioned once, restored and resumed on every + * later boot; a refusal keeps the lifecycle LOCKED. `status` reports it. */ #include #include #include "ck.h" #include "lifecycle_fsm.h" #include "store_boot.h" #include "store_sealed.h" +#include "continuity_service.h" #if !defined(CK_SERVICE) #error "lifecycle.c is only part of a CK_SERVICE=1 image" @@ -62,8 +67,10 @@ static void help(void) static void status(void) { - ck_printf("lifecycle: state=%s store=%s pending=%s requests=%u\n", ck_lc_state_name(g_lc.state), - ck_store_service_ready() ? "open" : "locked", g_lc.task_len ? g_lc.task : "-", g_lc.requests); + char cs[96]; + ck_cont_service_status(cs, sizeof cs); + ck_printf("lifecycle: state=%s store=%s pending=%s requests=%u %s\n", ck_lc_state_name(g_lc.state), + ck_store_service_ready() ? "open" : "locked", g_lc.task_len ? g_lc.task : "-", g_lc.requests, cs); } static void evidence(void) @@ -83,6 +90,7 @@ static int commit_task(void) size_t n = 0, i; ss_store *s = store_boot_store(); if (!s || !ck_store_service_ready()) return -1; + if (!ck_cont_service_writable()) return CK_SB_E_CONTINUITY; /* degraded mount: read-only */ for (i = 0; i < sizeof hdr - 1; i++) buf[n++] = (uint8_t)hdr[i]; for (i = 0; i < g_lc.task_len; i++) buf[n++] = (uint8_t)g_lc.task[i]; ss_object o = { CK_LC_OBJ_KIND, 1, buf, n }; @@ -123,6 +131,9 @@ static void handle_line(const char *line, size_t len) ck_printf("lifecycle: approve committed gen=%llu id=%02x%02x%02x%02x state=%s\n", (unsigned long long)g_last_gen, g_last_id[0], g_last_id[1], g_last_id[2], g_last_id[3], ck_lc_state_name(g_lc.state)); + else if (rc == CK_SB_E_CONTINUITY) + ck_printf("lifecycle: REFUSED verb=approve rc=%d state=%s reason=\"continuity read-only (degraded mount)\"\n", rc, + ck_lc_state_name(g_lc.state)); else ck_printf("lifecycle: REFUSED verb=approve rc=%d state=%s reason=\"%s\"\n", rc, ck_lc_state_name(g_lc.state), g_lc.reason); diff --git a/native/kernel/stage.mk b/native/kernel/stage.mk index 2d2229ef..f1cd1808 100644 --- a/native/kernel/stage.mk +++ b/native/kernel/stage.mk @@ -89,9 +89,16 @@ stage-free: $(STAGE_OUT)/stage_all.o echo "CK_STAGE_FREE: PASS objects=$(words $(STAGE_FREE_OBJS))" # ---- host tests ---------------------------------------------------------- +# P05: the production continuity layer (svc/continuity_service.c) is tested here +# with CK_CONT_SERVICE_HOST_TEST (the image links it only under CK_SERVICE=1). +STAGE_CONT_SRCS := $(STAGE_DIR)/svc/continuity_codec.c $(STAGE_DIR)/svc/continuity_resolve.c \ + $(STAGE_DIR)/svc/continuity_resolve_sealed.c $(STAGE_DIR)/svc/continuity_commit.c \ + $(STAGE_DIR)/svc/continuity_subject.c $(STAGE_DIR)/svc/continuity_subject_provision.c $(STAGE_DIR)/svc/continuity_service.c \ + $(STAGE_DIR)/core/entropy.c $(STAGE_DIR)/core/fmt.c STAGE_HOST_SRCS := $(STAGE_OWN_SRCS) $(STAGE_DIR)/core/ipc.c $(STAGE_NATIVE_SRCS) $(STAGE_NATIVE)/disk/disk_file.c \ - $(STAGE_DIR)/svc/tests/ck_host.c $(STAGE_DIR)/svc/tests/stage_test.c -STAGE_HOST_FLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -pthread -DCK_ART_STORE_WRITER -DCK_HOST_TEST + $(STAGE_CONT_SRCS) $(STAGE_DIR)/svc/tests/ck_host.c $(STAGE_DIR)/svc/tests/stage_test.c +STAGE_HOST_FLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -pthread -DCK_ART_STORE_WRITER -DCK_HOST_TEST \ + -DCK_CONT_SERVICE_HOST_TEST -I$(STAGE_DIR)/core STAGE_SAN_FLAGS := -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer $(STAGE_OUT)/stage_test: $(STAGE_HOST_SRCS) $(wildcard $(STAGE_DIR)/dev/*.h $(STAGE_DIR)/svc/*.h $(STAGE_DIR)/include/*.h) diff --git a/native/kernel/svc/.crumb b/native/kernel/svc/.crumb index 17e59568..2d338c75 100644 --- a/native/kernel/svc/.crumb +++ b/native/kernel/svc/.crumb @@ -23,21 +23,21 @@ "purpose": "Directory native/kernel/svc/compat. Purpose not yet described by a human." }, { - "digest": "9c684a5898006e4b5ad249a723740c94ef783b84475ad949f69b30c255ace5ba", - "last_commit": "a9d120b", + "digest": "4e044d7fe1d514bd13baa4e84872a66e46f96b86c7a7589d14489aec0978e366", + "last_commit": "101c710", "name": "tests", "purpose": "Directory native/kernel/svc/tests. Purpose not yet described by a human." } ], - "children_root": "sha256:2daefe867d6e169fa9fbbb2580e8cb53b4f1de2e5d097047195e38d406c53a71", - "compiled_at": "2026-10-12T05:32:10Z", + "children_root": "sha256:e44defe690939de314fec75a24c9369748bd9153c9511478d13fb58173a1ea74", + "compiled_at": "2026-10-12T06:35:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:3bca3564005f4581d6646e0b3ef797ec8157b80af1f1389e27e6e5089d1de042", + "digest": "sha256:5901ee6ca8dd0417ed55c72cc01cb3c2e9d55d71cd91d89f9cad9e6901e7a64e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 35, - "generated_at_commit": "a9d120b2e91893bb80a378dc746cf0a274e42878", - "source_tree": "sha256:6a5a010ba7dc7862fa7f94bf159f04831fe87d38c8859d3b6826360301a5166c" + "files": 37, + "generated_at_commit": "101c710b24fad41fc9a8797222e366ed71e6b6f2", + "source_tree": "sha256:b38670ec128a2b278c0e948e306d7aa50e4b350e3d0aa35f1efaf94658813624" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/continuity_commit.c b/native/kernel/svc/continuity_commit.c index 01e8b44a..4cdce210 100644 --- a/native/kernel/svc/continuity_commit.c +++ b/native/kernel/svc/continuity_commit.c @@ -278,7 +278,10 @@ int cr_resume(const struct cr_source *src, const struct cr_sink *snk, struct cr_ #endif } -/* ---- markers ---- */ +/* ---- markers (TEST-ONLY serial lines of continuity_boot.c; a CK_SERVICE image + * prints its own lowercase "continuity:" lines and must not carry the + * "CONTINUITY: " prefix: Makefile cont_check) ---- */ +#if !defined(CK_SERVICE) struct mb { char *p; size_t cap, n; @@ -384,3 +387,4 @@ size_t cr_marker_outcome(char *out, size_t cap, int outcome, const char *why, in } return mb_done(&b); } +#endif /* !CK_SERVICE */ diff --git a/native/kernel/svc/continuity_commit.h b/native/kernel/svc/continuity_commit.h index d8d5e59b..5082e67a 100644 --- a/native/kernel/svc/continuity_commit.h +++ b/native/kernel/svc/continuity_commit.h @@ -86,7 +86,8 @@ int cr_resume(const struct cr_source *src, const struct cr_sink *snk, struct cr_ struct cr_txwork *tw, struct cr_view *out, int *committed, const char **why, int *store_rc); -/* ---- serial markers (contract section 3, nvme_read.rs:1118-1155) ---- +/* ---- serial markers (contract section 3, nvme_read.rs:1118-1155; TEST-ONLY, + * absent from a CK_SERVICE image) ---- * Write the NUL-terminated line, without newline, into out[0..cap). Return the * length, or 0 when cap is too small. word: "PROVISIONED", "RESUMED", * "RESUMED_READONLY", "REMEMBERED", "COMMITTED". */ diff --git a/native/kernel/svc/continuity_service.c b/native/kernel/svc/continuity_service.c new file mode 100644 index 00000000..f0957e53 --- /dev/null +++ b/native/kernel/svc/continuity_service.c @@ -0,0 +1,218 @@ +/* continuity_service.c -- production continuity on the resident lifecycle + * (native v1 plan P05, cut 1). Contract and limits: continuity_service.h. */ +#include "continuity_service.h" +#include +#include "ck.h" +#include "continuity_resolve_sealed.h" +#include "continuity_subject_provision.h" +#include "entropy.h" +#include "fmt.h" +#include "sha256.h" + +#if !defined(CK_SERVICE) && !defined(CK_CONT_SERVICE_HOST_TEST) +#error "continuity_service.c is only part of a CK_SERVICE=1 image (or the host stage test)" +#endif +#if defined(CK_TEST_CONTINUITY) +#error "continuity_service.c is never combined with the TEST-ONLY continuity mode selection" +#endif + +/* ---- the entropy source: the kernel's RNDR service or a refusal, no fallback ---- */ +static int ent_present(void *ctx) +{ + (void)ctx; + return ck_entropy_status() == CK_RNG_OK; +} +static int ent_read(void *ctx, uint64_t *out) +{ + (void)ctx; + uint64_t w = 0; + if (ck_entropy_fill(&w, sizeof w) != 0) return 0; + *out = w; + return 1; +} +static const struct ck_rng_ops k_ent_ops = {ent_present, ent_read, 0}; + +/* ---- workspace (heap, once; the view is kept for the service lifetime) ---- */ +static struct { + struct cr_work *w; + struct cr_txwork *tw; + struct cr_view *v; + struct cs_subject *subj; + uint8_t sid[32]; + int state; + int allocated; +} g; + +static int alloc_all(void) +{ + if (g.allocated) return 0; + g.w = ck_alloc(sizeof *g.w); + g.tw = ck_alloc(sizeof *g.tw); + g.v = ck_alloc(sizeof *g.v); + g.subj = ck_alloc(sizeof *g.subj); + g.allocated = g.w && g.tw && g.v && g.subj; + return g.allocated ? 0 : -1; +} + +static void hex_into(char *o, const uint8_t *b, size_t n) +{ + static const char hx[] = "0123456789abcdef"; + for (size_t i = 0; i < n; i++) { + o[2 * i] = hx[b[i] >> 4]; + o[2 * i + 1] = hx[b[i] & 15]; + } + o[2 * n] = 0; +} + +static void view_line(const char *word, const struct cr_view *v) +{ + char ag[65]; + hex_into(ag, v->root.agent_id, 32); + ck_printf("continuity: %s agent=%s incarnation=%llu sequence=%llu cortex=%llu branches=%u\n", word, ag, + (unsigned long long)v->manifest.incarnation, (unsigned long long)v->manifest.sequence, + (unsigned long long)v->cortex_count, (unsigned)v->state.n); +} + +static void subject_line(const char *word, const struct cs_subject *s, const uint8_t id[32]) +{ + char sub[65], ln[65]; + uint32_t active = 0; + for (uint32_t i = 0; i < s->n_intents; i++) active += s->in[i].state == CS_ACTIVE; + hex_into(sub, id, 32); + hex_into(ln, s->cortex, 32); + ck_printf("allen: %s subject=%s sequence=%llu lineage=%s intents=%u active=%u knowledge=%u\n", word, sub, + (unsigned long long)s->sequence, ln, (unsigned)s->n_intents, (unsigned)active, (unsigned)s->n_knowledge); +} + +static int refused(const char *step, int outcome, const char *why, int store_rc) +{ + ck_printf("continuity: REFUSED step=\"%s\" outcome=%s%s%s store_rc=%d (nothing written; lifecycle stays locked)\n", + step, cr_outcome_name(outcome), why ? " why=" : "", why ? why : "", store_rc); + g.state = CK_CONT_REFUSED; + return g.state; +} + +/* provenance = SHA-256(label || owner pk || store uuid); lineage = SHA-256(label || store uuid). */ +static void genesis_inputs(struct cs_genesis *gen, const uint8_t store_uuid[16], const uint8_t *owner_pk, + size_t owner_pk_len) +{ + static const char lp[] = "AIENOS/ALLEN/PROVENANCE-V1"; + static const char ll[] = "AIENOS/ALLEN/CORTEX-LINEAGE-V1"; + uint8_t buf[sizeof lp + 64 + 16]; + size_t n = 0; + memset(gen, 0, sizeof *gen); + memcpy(buf, lp, sizeof lp - 1); + n = sizeof lp - 1; + if (owner_pk && owner_pk_len && owner_pk_len <= 64) { + memcpy(buf + n, owner_pk, owner_pk_len); + n += owner_pk_len; + } + memcpy(buf + n, store_uuid, 16); + n += 16; + sha256_hash(buf, n, gen->provenance); + memcpy(buf, ll, sizeof ll - 1); + memcpy(buf + sizeof ll - 1, store_uuid, 16); + sha256_hash(buf, sizeof ll - 1 + 16, gen->cortex); + gen->origin = CS_ORIGIN_OPERATOR; +} + +int ck_cont_service_start(ss_store *s, const uint8_t store_uuid[16], const uint8_t *owner_pk, size_t owner_pk_len, + uint8_t source) +{ + struct cr_source src; + struct cr_sink snk; + struct cr_sealed_sink sk = {s, 0, 0}; + const char *why = 0; + int store_rc = 0; + g.state = CK_CONT_NONE; + if (!s || !store_uuid) return refused("arguments", CR_E_ARG, "null", 0); + if (alloc_all()) return refused("workspace", CR_LIMIT, "heap", 0); + cr_bind_sealed(&src, s); + cr_bind_sealed_sink(&snk, &sk); + + int o = cr_resolve(&src, g.w, g.v, &why, &store_rc); + if (o == CR_UNPROVISIONED) { + struct ck_rng rng; + struct cs_genesis gen; + memset(&rng, 0, sizeof rng); + if (ck_rng_probe(&rng, &k_ent_ops) != CK_RNG_OK) + return refused("genesis entropy", CR_NO_ENTROPY, ck_rng_reason(rng.state), 0); + genesis_inputs(&gen, store_uuid, owner_pk, owner_pk_len); + o = cs_provision(&src, &snk, g.w, g.tw, &rng, store_uuid, source, &gen, g.v, g.subj, g.sid, &why, &store_rc); + if (o != CR_RESOLVED) return refused("provision", o, why, store_rc); + ck_printf("continuity: genesis source=%s provenance=%s (identity and ALLEN subject in one transaction)\n", + source == CC_SOURCE_OPERATOR ? "operator" : "qualification", + owner_pk && owner_pk_len ? "owner-root-pk+store-uuid" : "store-uuid-only"); + view_line("PROVISIONED", g.v); + subject_line("GENESIS", g.subj, g.sid); + g.state = CK_CONT_PROVISIONED; + return g.state; + } + if (o != CR_RESOLVED) return refused("resolve", o, why, store_rc); + + /* Restore the subject read-only before anything is written. */ + int cs = cs_resolve(&src, g.w, g.v, g.subj, g.sid, &why, &store_rc); + if (cs == CS_ABSENT) return refused("subject", CR_CORRUPT, "provisioned without a subject (never minted here)", store_rc); + if (cs != CS_RESOLVED) return refused("subject", cs, why, store_rc); + subject_line("RESTORED", g.subj, g.sid); + + int committed = 0; + o = cr_resume(&src, &snk, g.w, g.tw, g.v, &committed, &why, &store_rc); + if (o != CR_RESOLVED) return refused("resume", o, why, store_rc); + if (!committed) { + view_line("RESUMED_READONLY", g.v); + ck_puts("continuity: degraded mount: restored without writing; commits are refused until a valid mount\n"); + g.state = CK_CONT_RESUMED_READONLY; + return g.state; + } + view_line("RESUMED", g.v); + g.state = CK_CONT_RESUMED; + return g.state; +} + +int ck_cont_service_state(void) +{ + return g.state; +} + +int ck_cont_service_writable(void) +{ + return g.state == CK_CONT_PROVISIONED || g.state == CK_CONT_RESUMED; +} + +static const char *state_word(int st) +{ + switch (st) { + case CK_CONT_PROVISIONED: return "provisioned"; + case CK_CONT_RESUMED: return "resumed"; + case CK_CONT_RESUMED_READONLY: return "resumed-readonly"; + case CK_CONT_REFUSED: return "refused"; + default: return "none"; + } +} + +void ck_cont_service_status(char *out, size_t cap) +{ + if (!out || !cap) return; + if (g.state > 0 && g.v && g.subj) { + char ag[17]; + hex_into(ag, g.v->root.agent_id, 8); + ck_snprintf(out, cap, "continuity=%s agent=%s incarnation=%llu subject_seq=%llu", state_word(g.state), ag, + (unsigned long long)g.v->manifest.incarnation, (unsigned long long)g.subj->sequence); + } else { + ck_snprintf(out, cap, "continuity=%s", state_word(g.state)); + } +} + +const uint8_t *ck_cont_service_agent(void) +{ + return g.state > 0 && g.v ? g.v->root.agent_id : 0; +} + +void ck_cont_service_stop(void) +{ + g.state = CK_CONT_NONE; + if (g.v) memset(g.v, 0, sizeof *g.v); + if (g.subj) memset(g.subj, 0, sizeof *g.subj); + memset(g.sid, 0, sizeof g.sid); +} diff --git a/native/kernel/svc/continuity_service.h b/native/kernel/svc/continuity_service.h new file mode 100644 index 00000000..4795a032 --- /dev/null +++ b/native/kernel/svc/continuity_service.h @@ -0,0 +1,58 @@ +/* continuity_service.h -- production continuity on the resident lifecycle + * (native v1 plan P05, cut 1; aienos#35, #31). + * + * Linked only into a CK_SERVICE=1 image (and the host stage test with + * CK_CONT_SERVICE_HOST_TEST). The TEST-ONLY mode selection of + * svc/continuity_boot.c (plan line on the disk, modes 5..11, the TEST + * operator key, the Recovery Core) is never part of this image: the Makefile + * cont_check refuses its symbols and strings in every service image. + * + * What runs, once per Store open (store stage with keys, or `unlock`): + * unprovisioned Store -> PROVISIONED: identity (AgentRoot, genesis + * AgentState, Manifest 1) AND the genesis ALLEN subject (kind 24, + * sequence 1) in ONE Store transaction (svc/continuity_subject_provision.c); + * entropy from the kernel RNDR service, no fallback (NO_ENTROPY refuses). + * provisioned Store -> the ALLEN subject is restored read-only first; absent, + * corrupt, forked or foreign subject: REFUSED, nothing written, never + * minted over. Then cr_resume commits incarnation + 1 (RESUMED), or on a + * degraded mount restores without writing (RESUMED_READONLY: commits refused). + * anything else (Conflict, Corrupt, Limit, Store error) -> REFUSED. + * A REFUSED outcome keeps the lifecycle LOCKED: the Store keys are erased and + * the disk bytes are left as found (svc/store_boot.c). + * + * Genesis inputs (v1, deterministic, public): provenance = SHA-256("AIENOS/ALLEN/PROVENANCE-V1" + * || owner root public key (if the image carries one) || store uuid); cortex + * lineage = SHA-256("AIENOS/ALLEN/CORTEX-LINEAGE-V1" || store uuid): the Cortex of + * this subject is the sealed Store on this disk (CURRENT_EXECUTION_PLAN addendum, + * conflict 3; the Omega CxStore adapter of P06 writes the records). + * + * Not here (limits): Cortex records / the approved note are not yet continuity + * WAL records (P06); no Recovery Core in the service image (its operator key + * is TEST-only); no TPM; hardware NOT_RUN. */ +#ifndef CK_CONTINUITY_SERVICE_H +#define CK_CONTINUITY_SERVICE_H +#include +#include +#include "continuity_codec.h" +#include "store_sealed.h" + +enum { + CK_CONT_NONE = 0, /* not started (Store locked / stopped) */ + CK_CONT_PROVISIONED = 1, /* identity + genesis subject minted, one transaction */ + CK_CONT_RESUMED = 2, /* restored; incarnation + 1 committed */ + CK_CONT_RESUMED_READONLY = 3, /* degraded mount: restored, nothing written, commits refused */ + CK_CONT_REFUSED = -1, /* explicit refusal: lifecycle stays LOCKED */ +}; + +/* source: CC_SOURCE_OPERATOR (hardware staging image) or CC_SOURCE_QUALIFICATION + * (TEST-key service image, QEMU). owner_pk/owner_pk_len: the build-time owner + * root public key or NULL/0. Prints its "continuity:" and "allen:" lines. */ +int ck_cont_service_start(ss_store *s, const uint8_t store_uuid[16], const uint8_t *owner_pk, + size_t owner_pk_len, uint8_t source); +int ck_cont_service_state(void); /* CK_CONT_* of the last start (CK_CONT_NONE after stop) */ +int ck_cont_service_writable(void); /* 1 after PROVISIONED or RESUMED */ +/* "continuity= agent=<8 hex> incarnation= subject_seq=" (NUL-terminated). */ +void ck_cont_service_status(char *out, size_t cap); +const uint8_t *ck_cont_service_agent(void); /* 32 bytes, or NULL before a successful start */ +void ck_cont_service_stop(void); /* forget the view (the Store keys are gone) */ +#endif diff --git a/native/kernel/svc/store_boot.c b/native/kernel/svc/store_boot.c index 95176967..ce3bb6d4 100644 --- a/native/kernel/svc/store_boot.c +++ b/native/kernel/svc/store_boot.c @@ -8,6 +8,9 @@ #include "sha256.h" #include "store_crash.h" #include "continuity_boot.h" +#ifdef CK_SERVICE +#include "continuity_service.h" +#endif #ifdef CK_HARDWARE_STAGING /* Hardware staging image: owner provisioning generated at build time by @@ -447,6 +450,7 @@ static const char *err_name(int rc) if (rc == CK_SB_E_SECRET_REJECTED) return "RecoverySecretRejected"; if (rc == CK_SB_E_ENTROPY) return "EntropyRefused"; if (rc == CK_SB_E_KEYSLOT_BAD) return "KeyslotManifestUnusable"; + if (rc == CK_SB_E_CONTINUITY) return "ContinuityRefused"; return "error"; } @@ -487,6 +491,29 @@ void store_boot_print(const ck_store_report *r) "(needs TPM NV or another external counter)\n"); } +#ifdef CK_SERVICE +/* P05 cut 1: continuity (identity + ALLEN subject) runs on every Store open + * (svc/continuity_service.c). 0 = REFUSED: the Store keys are erased, the + * disk bytes stay as found, the lifecycle stays LOCKED and the NVMe stays + * bound for the stop order. */ +static int service_continuity(void) +{ +#ifdef CK_HARDWARE_STAGING + int o = ck_cont_service_start(g_ss, g_ss->uuid, ck_owner_root_pk, sizeof ck_owner_root_pk, CC_SOURCE_OPERATOR); +#else + int o = ck_cont_service_start(g_ss, g_ss->uuid, 0, 0, CC_SOURCE_QUALIFICATION); +#endif + if (o == CK_CONT_REFUSED) { + bz(&g_ss->keys, sizeof g_ss->keys); + g_service_locked_rc = CK_SB_E_CONTINUITY; + ck_puts("store: service lifetime: continuity REFUSED, Store keys erased, lifecycle stays LOCKED " + "(disk as found; NVMe stays bound for the stop order)\n"); + return 0; + } + return 1; +} +#endif + /* Kernel stage. ck_dev_boot_disk comes from dev/devices.c. */ const disk_dev *ck_dev_boot_disk(void); void ck_dev_nvme_release(void); @@ -579,6 +606,7 @@ int ck_stage_store(void) * until the lifecycle stop order releases it, in that order. A refused * Store releases the disk now, exactly as the diagnostic image does. */ if (r.verdict == CK_SB_COMMITTED) { + if (!service_continuity()) return CK_SB_E_CONTINUITY; g_service_open = 1; ck_puts("store: service lifetime: Store open, NVMe stays bound until the lifecycle stop order\n"); return rc; @@ -600,6 +628,7 @@ int ck_store_service_close(void) { if (!g_service_open) return 0; g_service_open = 0; + ck_cont_service_stop(); if (g_ss) bz(&g_ss->keys, sizeof g_ss->keys); return 1; } @@ -671,6 +700,10 @@ int ck_store_service_unlock(const char *arg, size_t arg_len) (unsigned long long)r.boot_count_new); /* Signed artifact candidates live in this Store; read them now that it is open. */ ck_art_stage_load(g_ss, r.step); + if (!service_continuity()) { + g_service_open = 0; + return 0; + } return 1; } #endif diff --git a/native/kernel/svc/store_boot.h b/native/kernel/svc/store_boot.h index 162f7240..e9ce0f3d 100644 --- a/native/kernel/svc/store_boot.h +++ b/native/kernel/svc/store_boot.h @@ -72,6 +72,7 @@ typedef struct { #define CK_SB_E_SECRET_REJECTED (-2004) /* recovery secret did not unwrap K_vol (tag failed) */ #define CK_SB_E_ENTROPY (-2005) /* genesis refused: kernel entropy service refused */ #define CK_SB_E_KEYSLOT_BAD (-2006) /* manifest decoded but has no usable recovery descriptor / wrong uuid */ +#define CK_SB_E_CONTINUITY (-2007) /* service: continuity refused after the Store opened (lifecycle stays LOCKED) */ #define CK_SB_SECRET_LEN 32u /* TEST keys and store uuid. Public, not secret, never production. Not diff --git a/native/kernel/svc/tests/.crumb b/native/kernel/svc/tests/.crumb index 2c64060d..6b5a9665 100644 --- a/native/kernel/svc/tests/.crumb +++ b/native/kernel/svc/tests/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T05:32:10Z", + "compiled_at": "2026-10-12T06:35:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:9c684a5898006e4b5ad249a723740c94ef783b84475ad949f69b30c255ace5ba", + "digest": "sha256:4e044d7fe1d514bd13baa4e84872a66e46f96b86c7a7589d14489aec0978e366", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 3, - "generated_at_commit": "a9d120b2e91893bb80a378dc746cf0a274e42878", - "source_tree": "sha256:8b71d730fb8592983dab48f46313e6ebabe62dbdde1b9736e6f8375a8339d46a" + "generated_at_commit": "101c710b24fad41fc9a8797222e366ed71e6b6f2", + "source_tree": "sha256:4596e6dfcbec6b205ed0d7563bf337e369f97bc54428471b4754ee91d9957bc4" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/tests/stage_test.c b/native/kernel/svc/tests/stage_test.c index 25ce962e..fafbf8e8 100644 --- a/native/kernel/svc/tests/stage_test.c +++ b/native/kernel/svc/tests/stage_test.c @@ -20,6 +20,7 @@ #include "mmio_window.h" #include "security.h" #include "store_boot.h" +#include "continuity_service.h" #include "artifact_store.h" #include "sha256.h" #include "net_bind.h" @@ -1190,6 +1191,87 @@ static void test_unlock_recovery(void) free(after); } +/* P05 cut 1: production continuity on the service lifecycle + * (svc/continuity_service.c) over the real sealed Store in a file, opened the + * production way (recovery keyslot unlock). Identity + ALLEN subject are + * provisioned once, restored and resumed on every later open; an entropy + * refusal on a blank Store writes nothing. */ +static void test_continuity_service(void) +{ + ck_store_report r; + uint8_t S[32], U[16]; + for (int i = 0; i < 32; i++) S[i] = (uint8_t)(i * 11 + 3); + for (int i = 0; i < 16; i++) U[i] = (uint8_t)(0xC0 + i); + uint8_t *now = malloc(T_BYTES), *after = malloc(T_BYTES); + CHECK(now && after); + if (!now || !after) return; + char st[96]; + uint8_t agent[32]; + + printf(" [continuity: not started -> none, not writable]\n"); + CHECK(ck_cont_service_state() == CK_CONT_NONE && ck_cont_service_writable() == 0 && ck_cont_service_agent() == 0); + ck_cont_service_status(st, sizeof st); + CHECK(strstr(st, "continuity=none") != 0); + + printf(" [continuity: blank Store, unlock genesis, then PROVISIONED in one transaction]\n"); + CHECK(dopen(1) == 0); + dclose(); + CHECK(unlock(S, U, "cont-1", 1, &r) == 0 && r.formatted == 1 && r.gen_commit == 2); + CHECK(dopen(0) == 0); + int o = ck_cont_service_start(store_boot_store(), U, 0, 0, CC_SOURCE_QUALIFICATION); + CHECK(o == CK_CONT_PROVISIONED && ck_cont_service_state() == CK_CONT_PROVISIONED && ck_cont_service_writable() == 1); + CHECK(ss_generation(store_boot_store()) == 3); + CHECK(ck_cont_service_agent() != 0); + if (ck_cont_service_agent()) memcpy(agent, ck_cont_service_agent(), 32); + ck_cont_service_status(st, sizeof st); + CHECK(strstr(st, "continuity=provisioned") != 0 && strstr(st, "incarnation=1") != 0 && strstr(st, "subject_seq=1") != 0); + dclose(); + ck_cont_service_stop(); + CHECK(ck_cont_service_state() == CK_CONT_NONE && ck_cont_service_writable() == 0); + + printf(" [continuity: reboot -> RESTORED + RESUMED incarnation 2, same agent]\n"); + CHECK(unlock(S, U, "cont-2", 1, &r) == 0 && r.formatted == 0 && r.gen_open == 3 && r.gen_commit == 4); + CHECK(dopen(0) == 0); + o = ck_cont_service_start(store_boot_store(), U, 0, 0, CC_SOURCE_QUALIFICATION); + CHECK(o == CK_CONT_RESUMED && ck_cont_service_writable() == 1); + CHECK(ss_generation(store_boot_store()) == 5); + CHECK(ck_cont_service_agent() && memcmp(ck_cont_service_agent(), agent, 32) == 0); + ck_cont_service_status(st, sizeof st); + CHECK(strstr(st, "continuity=resumed") != 0 && strstr(st, "incarnation=2") != 0); + dclose(); + ck_cont_service_stop(); + + printf(" [continuity: third boot -> incarnation 3]\n"); + CHECK(unlock(S, U, "cont-3", 1, &r) == 0 && r.gen_open == 5); + CHECK(dopen(0) == 0); + o = ck_cont_service_start(store_boot_store(), U, 0, 0, CC_SOURCE_QUALIFICATION); + CHECK(o == CK_CONT_RESUMED); + ck_cont_service_status(st, sizeof st); + CHECK(strstr(st, "incarnation=3") != 0); + dclose(); + ck_cont_service_stop(); + + printf(" [continuity: blank Store, entropy refused at genesis -> REFUSED, disk unchanged]\n"); + CHECK(dopen(1) == 0); + dclose(); + CHECK(unlock(S, U, "cont-r", 1, &r) == 0 && r.formatted == 1); + CHECK(load(now) == 0); + CHECK(dopen(0) == 0); + ck_host_entropy_refuse = 1; + o = ck_cont_service_start(store_boot_store(), U, 0, 0, CC_SOURCE_QUALIFICATION); + ck_host_entropy_refuse = 0; + CHECK(o == CK_CONT_REFUSED && ck_cont_service_state() == CK_CONT_REFUSED && ck_cont_service_writable() == 0); + CHECK(ck_cont_service_agent() == 0); + dclose(); + CHECK(load(after) == 0 && memcmp(now, after, T_BYTES) == 0); + ck_cont_service_stop(); + CHECK(ck_cont_service_state() == CK_CONT_NONE); + + unlink(img); + free(now); + free(after); +} + static void test_security(void) { ck_sec_report r; @@ -2258,6 +2340,7 @@ int main(void) test_mmio_stage_report(); test_store(); test_unlock_recovery(); + test_continuity_service(); test_artifact_store(); test_security(); test_nvme_shutdown(); diff --git a/scripts/.crumb b/scripts/.crumb index 94370ada..a8796b00 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T05:32:10Z", + "compiled_at": "2026-10-12T06:35:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:9f409f70dc736ec25cc1fb97a221db84f7ac631b613bf50563740171fabc6983", + "digest": "sha256:87981170f9983b962d7b2c8ea7f2f4811b354e13514dcb6365f0cc7a49cb1e9f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 82, - "generated_at_commit": "a9d120b2e91893bb80a378dc746cf0a274e42878", - "source_tree": "sha256:47a79ad1ca48ece61a18aa7a3fc3d3ad99643f37b67e6e0bd7ec5215fa8c195d" + "generated_at_commit": "101c710b24fad41fc9a8797222e366ed71e6b6f2", + "source_tree": "sha256:d5a697011627c2cead5f4b2c8be6a00698e85d73d7bf8698e575b41ad126783d" }, "owner_lane": "", "provenance": { diff --git a/scripts/qemu_ck_lifecycle_test.sh b/scripts/qemu_ck_lifecycle_test.sh index 20af04d2..e1c99f08 100755 --- a/scripts/qemu_ck_lifecycle_test.sh +++ b/scripts/qemu_ck_lifecycle_test.sh @@ -51,6 +51,16 @@ # Store opened at generation 3 boot_count 1, committed generation 4 # row 170 secret hygiene: the typed secret is echoed as 64 '*' and the hex # never appears in either serial log; no TEST key banner +# row 171 P05 cut 1 continuity GENESIS (unlock boot, after `unlock ok`): the +# production continuity service provisions the identity (AgentRoot, +# AgentState, Manifest incarnation 1) and the ALLEN subject (sequence 1) +# in one transaction (generation 3); `status` reports continuity=provisioned +# row 172 P05 cut 1 continuity RESUME (relock boot): the subject is RESTORED +# (sequence 1), the identity RESUMED at incarnation 2 (generation 6) with +# the same agent id; no second genesis; status continuity=resumed +# row 173 shape: the locked boot prints no continuity line; the test-keys image +# provisions before `Store open`; the service image carries the +# production continuity layer and no TEST mode selection (AIENCONT) # build the default (diagnostic) image carries no lifecycle; CK_SERVICE is # refused with CK_CONSOLE_SESSION, CK_QEMU_UNSAFE_DMA and a CK_TEST_* # flag; CK_SERVICE_TEST_KEYS is refused with CK_HARDWARE_STAGING @@ -198,6 +208,7 @@ m1() { # row: the shared M1 checks read ${work}/serial.txt and set failed # --- build-shape checks --- if grep -aqF "lifecycle: ready" "${default_efi}"; then bad build "default image carries the resident lifecycle"; else ok build "default image carries no resident lifecycle"; fi if grep -aqF "TEST-ONLY service image" "${service_efi}"; then bad build "production service image carries the TEST key banner"; else ok build "production service image carries no TEST key banner"; fi +if grep -aqF "continuity: REFUSED" "${service_efi}" && ! grep -aqF "AIENCONT" "${service_efi}" && ! grep -aqF "RECOVERY_OPERATOR_KEY" "${service_efi}"; then ok 173 "service image carries the production continuity layer and no TEST mode selection"; else bad 173 "service image continuity shape wrong (layer missing, or AIENCONT / TEST operator key present)"; fi for combo in "CK_CONSOLE_SESSION=1" "CK_QEMU_UNSAFE_DMA=1" "CK_TEST_STORE_CRASH=1"; do set +e; msg="$(make -s -n -C native/kernel OUT="${top}/refuse" full CK_SERVICE=1 "${combo}" 2>&1)"; st=$?; set -e if [[ "${st}" != 0 ]] && grep -qE "CK_SERVICE cannot be combined with" <<<"${msg}"; then ok build "refuses CK_SERVICE with ${combo}"; else bad build "did not refuse CK_SERVICE with ${combo} (status ${st})"; fi @@ -224,6 +235,7 @@ before 162 "NVMe revoke < stop order line" '^dma_gate: nvme bus master revoked' before 162 "stop order < stage result" '^lifecycle: stop order' '^stage lifecycle: ok rc=0$' before 162 "stage result < final report" '^stage lifecycle: ok rc=0$' '^report_kind: final' rabsent 162 "no panic or fault" '^report_kind: (panic|fault)' +rabsent 173 "no continuity line while locked" '^(continuity|allen): ' if [[ "${qemu_status}" == 0 ]]; then ok 162 "QEMU exit 0"; else bad 162 "QEMU exit ${qemu_status}"; fi m1 162 @@ -232,6 +244,8 @@ boot testkeys "${testkeys_efi}" drive_ready rcheck 163 "TEST-ONLY banner" '^lifecycle: TEST-ONLY service image \(CK_SERVICE_TEST_KEYS=1: TEST Store keys; QEMU only, never a production boot\)$' rcheck 163 "Store open, NVMe kept bound for the service lifetime" '^store: service lifetime: Store open, NVMe stays bound until the lifecycle stop order$' rcheck 163 "lifecycle ready" '^lifecycle: ready state=ready store=open \(operator input: serial\)$' +rcheck 173 "test-keys image provisions continuity at boot" '^continuity: PROVISIONED agent=[0-9a-f]{64} incarnation=1 sequence=1 cortex=0 branches=1$' +before 173 "PROVISIONED < Store open line" '^continuity: PROVISIONED' '^store: service lifetime: Store open' if [[ -n "$(line_of '^dma_gate: nvme bus master revoked')" && "$(line_of '^dma_gate: nvme bus master revoked')" -lt "$(line_of '^lifecycle: ready state=ready')" ]]; then bad 163 "NVMe revoked before the lifecycle (service lifetime broken)"; else ok 163 "no NVMe revoke before the lifecycle"; fi rcheck 164 "task proposed" '^lifecycle: task pending state=serve proposed="note: draft the plan" \(approve \| deny \| cancel\)$' rcheck 164 "approve committed to the Store" '^lifecycle: approve committed gen=[0-9]+ id=[0-9a-f]{8} state=ready$' @@ -261,7 +275,15 @@ rcheck 168 "unlock ok" '^store: unlock ok source=recovery-keyslot slot=1 genesis rcheck 168 "lifecycle unlocked to ready" '^lifecycle: unlock ok state=ready$' rcheck 168 "status open" '^lifecycle: state=ready store=open pending=- requests=' rcheck 168 "task proposed" '^lifecycle: task pending state=serve proposed="note: write a note" \(approve \| deny \| cancel\)$' -rcheck 168 "approve committed generation 3" '^lifecycle: approve committed gen=3 id=[0-9a-f]{8} state=ready$' +rcheck 168 "approve committed generation 4 (after the continuity genesis at 3)" '^lifecycle: approve committed gen=4 id=[0-9a-f]{8} state=ready$' +rcheck 171 "genesis inputs declared" '^continuity: genesis source=qualification provenance=store-uuid-only \(identity and ALLEN subject in one transaction\)$' +rcheck 171 "identity PROVISIONED incarnation 1" '^continuity: PROVISIONED agent=[0-9a-f]{64} incarnation=1 sequence=1 cortex=0 branches=1$' +rcheck 171 "ALLEN subject GENESIS sequence 1" '^allen: GENESIS subject=[0-9a-f]{64} sequence=1 lineage=[0-9a-f]{64} intents=0 active=0 knowledge=0$' +before 171 "unlock ok < PROVISIONED" '^store: unlock ok' '^continuity: PROVISIONED' +before 171 "PROVISIONED < lifecycle unlock ok" '^continuity: PROVISIONED' '^lifecycle: unlock ok' +rcheck 171 "status reports continuity" '^lifecycle: state=ready store=open pending=- requests=[0-9]+ continuity=provisioned agent=[0-9a-f]{16} incarnation=1 subject_seq=1$' +unlock_agent="$(grep -oE '^continuity: PROVISIONED agent=[0-9a-f]{64}' "${top}/unlock/serial.txt" | head -1 | sed 's/.*agent=//')" +[[ -n "${unlock_agent}" ]] || unlock_agent="NO_AGENT" rcheck 168 "stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=7$' before 168 "stop order < stage result" '^lifecycle: stop order store=closed' '^stage lifecycle: ok rc=0$' rabsent 168 "no panic or fault" '^report_kind: (panic|fault)' @@ -277,12 +299,19 @@ boot relock "${service_efi}" drive_relock "${unlock_img}" rcheck 169 "lifecycle came up locked" '^lifecycle: ready state=locked store=locked' rcheck 169 "wrong secret refused by the keyslot tag" '^store: unlock REFUSED proof=keyed step="recovery secret rejected \(K_vol unwrap tag failed\); disk not opened" rc=-2004 \(RecoverySecretRejected\); still LOCKED, disk not reformatted$' rcheck 169 "lifecycle still locked after the wrong secret" '^lifecycle: REFUSED verb=unlock state=locked reason="production key source refused: still locked"$' -rcheck 169 "status still locked" '^lifecycle: state=locked store=locked pending=- requests=2$' +rcheck 169 "status still locked" '^lifecycle: state=locked store=locked pending=- requests=2 continuity=none$' rabsent 169 "not reformatted" '^store: blank disk' rcheck 169 "key source line: recovery keyslot resume" '^store: key source=recovery-keyslot genesis=0 ' -rcheck 169 "store opened at generation 3 (keyslot + boot record + note), boot_count 1" '^store: opened generation=3 boot_count=1 prev_commit=[0-9a-f]+ anchor=valid-resume$' -rcheck 169 "store committed generation 4 boot 2" '^store: committed generation=4 boot_count=2$' -rcheck 169 "unlock ok, no genesis" '^store: unlock ok source=recovery-keyslot slot=1 genesis=0 generation=4 boot_count=2$' +rcheck 169 "store opened at generation 4 (keyslot + boot record + continuity genesis + note), boot_count 1" '^store: opened generation=4 boot_count=1 prev_commit=[0-9a-f]+ anchor=valid-resume$' +rcheck 169 "store committed generation 5 boot 2" '^store: committed generation=5 boot_count=2$' +rcheck 169 "unlock ok, no genesis" '^store: unlock ok source=recovery-keyslot slot=1 genesis=0 generation=5 boot_count=2$' +rcheck 172 "ALLEN subject RESTORED sequence 1" '^allen: RESTORED subject=[0-9a-f]{64} sequence=1 lineage=[0-9a-f]{64} intents=0 active=0 knowledge=0$' +rcheck 172 "identity RESUMED incarnation 2, same agent as the genesis boot" "^continuity: RESUMED agent=${unlock_agent} incarnation=2 sequence=2 cortex=0 branches=1\$" +rabsent 172 "no second genesis" '^continuity: (PROVISIONED|genesis)' +rabsent 172 "no degraded mount" '^continuity: (degraded|RESUMED_READONLY|REFUSED)' +before 172 "unlock ok < RESUMED" '^store: unlock ok' '^continuity: RESUMED' +before 172 "RESUMED < lifecycle unlock ok" '^continuity: RESUMED' '^lifecycle: unlock ok' +rcheck 172 "status reports resumed" "^lifecycle: state=ready store=open pending=- requests=[0-9]+ continuity=resumed agent=${unlock_agent:0:16} incarnation=2 subject_seq=1\$" rcheck 169 "lifecycle unlocked to ready" '^lifecycle: unlock ok state=ready$' rcheck 169 "evidence: one refused unlock" '^lifecycle: evidence requests=5 refused=1 invalid=0 tasks=0 approved=0' rcheck 169 "stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=6$' @@ -293,7 +322,7 @@ rabsent 170 "secret hex never in the serial log (resume boot)" "${secret_ok}" rabsent 170 "wrong secret hex never in the serial log" "${secret_bad}" if [[ "${fail}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then - for b in service testkeys unlock relock; do echo "---- ${b} serial (lifecycle lines) ----"; grep -E '^(lifecycle|store|stage lifecycle|dma_gate|smmu: nvme|report_kind|mm_usage)' "${top}/${b}/serial.txt" | head -60 || true; done + for b in service testkeys unlock relock; do echo "---- ${b} serial (lifecycle lines) ----"; grep -E '^(lifecycle|store|continuity|allen|stage lifecycle|dma_gate|smmu: nvme|report_kind|mm_usage)' "${top}/${b}/serial.txt" | head -60 || true; done fi if [[ "${fail}" == 0 ]]; then echo "${final_tag}: PASS (QEMU only; hardware NOT_RUN)"; exit 0; fi echo "${final_tag}: FAIL"; exit 1