Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/svc/store_boot.h # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / svc / store_boot.h` 196 lines ยท 12192 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* store_boot.h -- the Store boot stage: mount the sealed C Store 18 * (native/store store_sealed, M5 keyed, torn_slot anchor) on the boot disk, 19 * read the boot record, bump boot_count, commit, flush. 20 * 21 * Proof separation (AGENTS.md section 1). A refusal names which proof 22 * failed and never reformats a non-blank disk: 23 * structural unkeyed Store::open (st_open) refused the region 24 * keyed M5 identity/records/envelopes refused under the given keys 25 * rollback the anti-rollback anchor refused the Store's generation 26 * io the disk failed 27 * Only an all-zero anchor + Store head counts as blank and is formatted. 28 * 29 * KEYS. Default (QEMU) build: ck_store_test_keys gives TEST identity 30 * (M5_ID_TEST) keys derived from a public label. They protect nothing and 31 * every line printed with them says TEST. 32 * Hardware staging build (CK_HARDWARE_STAGING; built with CK_OWNER_PUBKEYS= 33 * and CK_MACHINE_ID= files, see README "Owner provisioning"): the TEST keys 34 * and TEST uuid are not compiled; the store uuid comes from the generated 35 * owner provisioning header; keys come from ck_store_production_keys, the 36 * BLOCKED_OPERATOR seam (K_vol is secret and needs the TRUST-1 key 37 * ceremony), so the stage refuses before reading the disk. store_boot_run 38 * refuses TEST-identity keys in that build before any disk access, so it 39 * never formats a blank disk with them. 40 * 41 * RECOVERY KEYSLOT UNLOCK (P04 cut 1, ADR 0017 section 2.4 Slot 1). 42 * ck_store_unlock_boot takes the operator's 32-byte raw recovery secret and 43 * never any key material from the image: on a blank disk it draws K_vol, 44 * salt and nonce from the kernel entropy service (RNDR; refused when RNDR 45 * is), wraps K_vol into a Recovery_RawSecret descriptor (slot_id 1, HKDF 46 * KEK) and commits the KeySlotManifest (kind 21, plaintext, bound by the 47 * sealed transaction record) in the same first transaction as the boot 48 * record. On a non-blank disk it reads the manifest before any key exists 49 * (ss_keyslot_bootstrap), derives the KEK, unwraps K_vol and opens the Store 50 * with PRODUCTION-class keys (owner hierarchy generation = active_key_epoch). 51 * A wrong secret is refused by the AES-GCM-SIV tag before the Store is 52 * touched. K_vol lives in a stack buffer for the unwrap only and is wiped. 53 * 54 * SECURITY MANIFEST (P04 cut 2a, ADR 0017 section 2.5). Every boot 55 * transaction also commits one SecurityManifest (kind 22, a sealed envelope 56 * whose root_mac is under k_root_auth): generation = the generation the 57 * transaction creates, security_sequence = previous + 1 (1 at genesis), 58 * previous_security_manifest_id = the ObjectId of the manifest it 59 * supersedes (zero at genesis), key_epoch = the owner hierarchy generation 60 * of the open keys, keyslot_manifest_id = the KeySlotManifest ObjectId (zero 61 * for a TEST-key Store, which has none), epoch = generation (the sealed 62 * Store's anti-rollback anchor counts Store generations). On every open the 63 * newest manifest is read back and must verify under the open keys, name 64 * this Store, bind exactly the keyslot the keyed open bound, carry the open 65 * keys' epoch, the generation that committed it and a security_sequence 66 * equal to the number of manifests on the Store. A Store with history but 67 * no manifest, or a manifest failing any check, is refused (CK_SB_E_SECMAN) 68 * before the boot record is written and the keys are wiped. 69 * 70 * KEY ROTATION (P04 cut 2b, ADR 0017 section 2.7 item 1, credential 71 * rotation). ck_store_rotate_recovery takes the current and the new raw 72 * recovery secret while the production Store is open: the current secret 73 * must unwrap K_vol from the bound manifest (proof of possession, nothing is 74 * written otherwise), a fresh salt and nonce come from the entropy service, 75 * and one transaction commits the next KeySlotManifest of the chain 76 * (manifest_sequence + 1, previous_keyslot_manifest_id = the bound manifest, 77 * same K_vol and active_key_epoch, the Recovery_RawSecret descriptor 78 * re-wrapped under the new KEK) together with a SecurityManifest 79 * (security_sequence + 1) that binds the new manifest. The sealed store 80 * admits a manifest only as the next link of the chain and binds the newest 81 * one, so the next unlock accepts the new secret only: the old descriptor is 82 * superseded, its ciphertext stays on the append-only Store (ADR 0017 83 * section 2.7 item 2: a K_vol compromise needs migration, not rotation). 84 * K_vol lives in a stack buffer for the rewrap only and is wiped. 85 * Limits (cut 2b): TPM Slot 0 stays BLOCKED_HARDWARE (slot 0 Empty); 86 * active_key_epoch stays 1 (K_vol never changes in place); only the boot 87 * and rotation transactions write a SecurityManifest (approve, continuity 88 * and journal commits do not advance security_sequence); agent_root_id, 89 * continuity_manifest_id and migration_manifest_id stay zero (not yet 90 * linked). */ 91 #ifndef AIENOS_CK_STORE_BOOT_H 92 #define AIENOS_CK_STORE_BOOT_H 93 #include 94 #include "disk.h" 95 #include "store_sealed.h" 96 97 #define CK_BOOT_KIND 0x0B00u /* application kind of the boot record */ 98 #define CK_BOOT_VERSION 1u 99 #define CK_BOOT_COMMIT_MAX 64u 100 #define CK_BOOT_RECORD_LEN 88u /* "AIENBOOT" u32 ver u32 0 u64 boot_count char commit[64] */ 101 #define CK_SECMAN_KIND 22u /* ADR 0017 section 2.5 SecurityManifest, M5_SECMAN_LEN bytes */ 102 103 enum { CK_SB_COMMITTED = 0, CK_SB_REFUSED = 1 }; 104 105 typedef struct { 106 int verdict; /* CK_SB_* */ 107 int formatted; /* this run formatted a blank disk */ 108 int rc; /* first failing rc (ST_* / SS_* / disk), 0 if committed */ 109 const char *proof; /* "structural" "keyed" "rollback" "io" "geometry" "record" "commit" */ 110 const char *step; /* what was being done */ 111 int rb; /* SS_RB_* from the open */ 112 uint64_t gen_open, gen_commit; 113 uint64_t boot_count_prev, boot_count_new; 114 char prev_commit[CK_BOOT_COMMIT_MAX + 1]; 115 uint64_t store_base_lba, store_units, anchor_lba; 116 uint8_t identity_class; /* identity class of the keys given (M5_ID_*) */ 117 int unlocked_genesis; /* ck_store_unlock_boot: this run created the keyslot manifest */ 118 const char *key_source; /* ck_store_unlock_boot: "recovery-keyslot" */ 119 uint64_t secman_seq; /* security_sequence of the SecurityManifest this boot committed */ 120 uint64_t keyslot_seq; /* manifest_sequence of the KeySlotManifest bound (unlock) or committed (rotate) */ 121 int secman_keyslot; /* 1: it binds the KeySlotManifest ObjectId (production Store) */ 122 int secman_prev; /* 1: it links the manifest it supersedes (0 at genesis) */ 123 } ck_store_report; 124 125 #define CK_SB_E_TEST_KEYS (-2001) /* TEST identity keys refused (hardware staging) */ 126 #define CK_SB_E_BLOCKED_OPERATOR (-2002) /* production key source needs the operator */ 127 #define CK_SB_E_NO_KEYSLOT (-2003) /* non-blank disk carries no KeySlotManifest (not a production Store) */ 128 #define CK_SB_E_SECRET_REJECTED (-2004) /* recovery secret did not unwrap K_vol (tag failed) */ 129 #define CK_SB_E_ENTROPY (-2005) /* genesis refused: kernel entropy service refused */ 130 #define CK_SB_E_KEYSLOT_BAD (-2006) /* manifest decoded but has no usable recovery descriptor / wrong uuid */ 131 #define CK_SB_E_CONTINUITY (-2007) /* service: continuity refused after the Store opened (lifecycle stays LOCKED) */ 132 #define CK_SB_E_SECMAN (-2008) /* SecurityManifest missing, malformed, unbound, stale or under other keys */ 133 #define CK_SB_SECRET_LEN 32u 134 135 /* TEST keys and store uuid. Public, not secret, never production. Not 136 * compiled in a CK_HARDWARE_STAGING build. */ 137 void ck_store_test_keys(ss_keys *k); 138 extern const uint8_t ck_store_test_uuid[16]; 139 140 /* Production Store keys. BLOCKED_OPERATOR: always zeroes k and returns 141 * CK_SB_E_BLOCKED_OPERATOR until the TRUST-1 ceremony provides a K_vol source 142 * (Gate 6 TPM Slot 0 unwrap or Slot 1 recovery KEK). Never falls back. */ 143 int ck_store_production_keys(ss_keys *k); 144 145 /* 1 if keys of this identity class may open/format a Store in this build: 146 * PRODUCTION always; TEST only when hardware_staging is 0. */ 147 int ck_store_keys_admissible(const ss_keys *k, int hardware_staging); 148 149 /* One boot against disk d (the AIENOS partition view of dev/disk_part.h in the 150 * kernel, a whole file in host tests; layout of dev/disk_layout.h, relative to d). 151 * commit is the image commit string recorded in the new boot record. 152 * Prints nothing; ck_stage_store prints. */ 153 int store_boot_run(const disk_dev *d, const ss_keys *keys, const uint8_t uuid[16], const char *commit, 154 ck_store_report *r); 155 /* Same with the build policy explicit (store_boot_run passes 1 in a 156 * CK_HARDWARE_STAGING build, else 0); the host test drives both. */ 157 int store_boot_run_policy(const disk_dev *d, const ss_keys *keys, const uint8_t uuid[16], const char *commit, 158 int hardware_staging, ck_store_report *r); 159 /* Recovery keyslot unlock + boot (see the header comment). secret is the 160 * operator's raw 32-byte recovery secret. expect_uuid (optional) must equal 161 * the manifest's store_uuid and is the uuid of a formatted blank disk; when 162 * NULL a blank disk gets a random uuid and any manifest uuid is accepted. 163 * hardware_staging as store_boot_run_policy. Prints nothing. */ 164 int ck_store_unlock_boot(const disk_dev *d, const uint8_t secret[CK_SB_SECRET_LEN], const uint8_t *expect_uuid, 165 const char *commit, int hardware_staging, ck_store_report *r); 166 /* Recovery secret rotation on the open production Store (see the header 167 * comment): current must unwrap K_vol from the bound KeySlotManifest, next is 168 * the new raw secret. One transaction (next manifest + SecurityManifest) or 169 * nothing. Prints nothing. */ 170 int ck_store_rotate_recovery(const disk_dev *d, const uint8_t current[CK_SB_SECRET_LEN], 171 const uint8_t next[CK_SB_SECRET_LEN], ck_store_report *r); 172 #ifdef CK_PI5_UNLOCK 173 /* Pi unlock image only. The board glue (core/pi5.c) supplies the recovery secret source: returns 0 and 174 * fills out with the 32-byte secret, naming the source in *source (printed by the Store stage, never the 175 * secret); nonzero = no secret. ck_store_pi5_unlock_run: NULL secret refuses before any disk read; else the 176 * Slot 1 path with the hardware policy (TEST keys and TEST uuid do not exist in this image). Prints nothing. */ 177 int ck_pi5_unlock_secret(uint8_t out[CK_SB_SECRET_LEN], const char **source); 178 int ck_store_pi5_unlock_run(const disk_dev *d, const uint8_t *secret, const char *commit, ck_store_report *r); 179 #ifdef CK_PI5_FACT 180 /* PI5-5 (QUALIFICATION ONLY): the Cortex fact stage after the Store stage. r: the report of the Store boot. The 181 * Store is passed on only when it committed; a refused Store (wrong secret) recalls nothing. */ 182 int ck_store_pi5_fact_stage(const ck_store_report *r); 183 #endif 184 #ifdef CK_PI5_AGENT 185 /* PI5-6 (QUALIFICATION ONLY): the agent stage after the Store stage: recover the persisted reply, or generate and commit it. 186 * Same rule as the fact stage: the Store is passed on only when it committed, so a refused Store (wrong secret) never reaches the 187 * model. */ 188 int ck_store_pi5_agent_stage(const ck_store_report *r); 189 #endif 190 #endif 191 /* Print the report lines (also used by the host test). */ 192 void store_boot_print(const ck_store_report *r); 193 /* The open Store of the last store_boot_run (valid only after it returned 0; 194 * host image tool and tests write further objects through it). */ 195 ss_store *store_boot_store(void); 196 #endif