interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / docs / adr / 0017-m5-key-hierarchy-and-encrypted-store.md

275 lines · 19229 bytes Raw Blame History Rendered
1# ADR 0017: M5 Key Hierarchy, Encrypted Envelopes, and Storage Security Roots
2
3Status: **Proposed.** Normative specification for Milestone M5 (Encryption and Identity).
4Related: [ADR 0006](0006-deterministic-recovery-core-and-offline-operator-authority.md) (Recovery Core), [ADR 0007](0007-continuous-existence-provisioning-once.md) (Provisioning Once), [ADR 0015](0015-system-store-v1-format.md) (System Store v1), [ADR 0016](0016-continuity-objects-over-store-v1.md) (Continuity Objects), [TRUST-1-IMPLEMENTATION-PLAN.md](../TRUST-1-IMPLEMENTATION-PLAN.md).
5
6---
7
8## 1. Context
9
10Milestone M4 established persistent agent continuity across cold restarts in QEMU over System Store v1 ([ADR 0015](0015-system-store-v1-format.md), [ADR 0016](0016-continuity-objects-over-store-v1.md)) and qualified deterministic Recovery Core inspection and offline repair ([ADR 0006](0006-deterministic-recovery-core-and-offline-operator-authority.md)). However, Store v1 provides only structural crash integrity over raw NVMe; all application payloads currently reside in plaintext on disk, and Store v1 explicitly disclaims anti-rollback protection against a malicious raw-disk adversary.
11
12Milestone M5 establishes the cryptographic security architecture of AIENOS:
131. **Confidentiality at rest**: Agent state, Cortex memories, checkpoints, credentials, and artifacts must be unreadable without authorization.
142. **Hardware-sealed unattended boot**: Unattended boots unseal storage keys strictly when firmware and kernel measurements satisfy an authorized TPM 2.0 policy.
153. **Attended break-glass recovery**: An offline operator must retain cryptographic recovery capability without compromising unattended boot security or relying on vendor backdoors.
164. **Hardware anti-rollback**: Replay of a valid earlier raw disk image must be detected and halted.
175. **Preservation of recovery invariants**: Storage encryption must never prevent unkeyed Recovery Core diagnosis of a degraded or corrupted physical store.
18
19---
20
21## 2. Decision
22
23### 2.1 The Separation of Proofs
24
25AIENOS strictly decouples physical consistency, keyed authorization, and hardware freshness into three independent verification stages:
26
27```text
281. Store v1 Structural Validation (Unkeyed)
29 "These on-disk bytes form a self-consistent Store v1 transaction history."
30 Evaluates: Dual superblocks, active generation, CommitRecords, Catalogs, CRC32C checksums.
31 Guarantees: Crash safety, tear closure, degraded peer recovery.
32 ↓
332. M5 Keyed Authentication (Requires K_vol)
34 "This Store history was committed by an authorized holder of K_vol."
35 Evaluates: KeySlotManifest (kind 21) unwrap, SecurityManifest (kind 22) HMAC-SHA256 root tag,
36 AES-256-GCM-SIV per-object chunk authentication.
37 Guarantees: Authenticity and confidentiality of application payloads.
38 ↓
393. Anti-Rollback Freshness Validation (Requires AntiRollbackSource)
40 "This authorized Store history is not an older replay."
41 Evaluates: Hardware off-disk anchor {store_uuid, epoch, security_root_digest}.
42 Guarantees: Replay protection bounded to the last anchored security epoch.
43```
44
45Store v1 superblocks, CommitRecords, Catalogs, CRC32C, and generation semantics remain 100% frozen and unmutated as defined in [ADR 0015](0015-system-store-v1-format.md).
46
47---
48
49### 2.2 Key Hierarchy & Separation of Authority
50
511. **Volume Master Secret (`K_vol`)**:
52 - An independent, high-entropy 256-bit random secret generated once during initial store provisioning.
53 - `K_vol` is never written to persistent media in plaintext.
542. **Keyslots**:
55 - `Slot 0 (Automated TPM Boot)`: `K_vol` wrapped under `K_tpm_kek` via AES-256-GCM-SIV. `K_tpm_kek` is sealed to the TPM 2.0 Storage Root Key (SRK) under an authorized PCR policy.
56 - `Slot 1 (Operator Break-Glass)`: `K_vol` wrapped under `K_recovery_kek` via AES-256-GCM-SIV. `K_recovery_kek` is derived from an offline recovery secret or passphrase.
573. **Subkey Derivation via HKDF-SHA256**:
58 All operational keys derive deterministically from `K_vol` with strict domain separation:
59 ```text
60 K_cortex = HKDF-Expand(K_vol, "AIENOS/M5/CORTEX-V1", 32)
61 K_agent = HKDF-Expand(K_vol, "AIENOS/M5/AGENT-STATE-V1", 32)
62 K_artifact = HKDF-Expand(K_vol, "AIENOS/M5/ARTIFACT-V1", 32)
63 K_root_auth = HKDF-Expand(K_vol, "AIENOS/M5/ROOT-AUTH-V1", 32)
64 ```
654. **Three Independent Cryptographic Roles**:
66 - `K_operator_auth`: Proves operator authority to execute Recovery Core commands ([ADR 0006](0006-deterministic-recovery-core-and-offline-operator-authority.md)).
67 - `K_recovery`: Cryptographic break-glass secret used to derive `K_recovery_kek` and unwrap storage.
68 - `K_vol`: Internal volume master key protecting encrypted Store objects.
69 Possessing one credential never grants automatic possession of the others.
70
71---
72
73### 2.3 Cipher Suite: AES-256-GCM-SIV Chunked Envelopes
74
75To prevent catastrophic confidentiality failure under power loss, retries, cold boots, and branch-native execution incarnations, AIENOS standardizes on **AES-256-GCM-SIV** (RFC 8452) as its primary at-rest AEAD suite.
76
77#### Envelope Framing
78Each encrypted object payload is wrapped in a chunked envelope:
79```text
80Offset Size Field
810 8 magic = "AIENENV1"
828 2 envelope_version = 1
8310 2 cipher_suite = 0x0001 (AES_256_GCM_SIV)
8412 4 flags = 0
8516 4 chunk_size = 65536 (64 KiB)
8620 8 total_plaintext_len (u64le)
8728 16 envelope_id (128-bit random identifier)
8844 8 nonce_prefix (64-bit random prefix)
8952 8 key_epoch (u64le)
9060 4 reserved = 0
91```
92
93Followed sequentially by $N$ encrypted chunks:
94```text
95[Chunk 0 Ciphertext][Chunk 0 Tag: 16 B] ... [Chunk N Ciphertext][Chunk N Tag: 16 B]
96```
97
98#### Deterministic Nonce Derivation
99For each chunk index $i \in [0, N]$:
100$$\text{nonce}_i = \text{nonce\_prefix}[8] \parallel i\text{:u32le}$$
101
102#### Per-Chunk Additional Authenticated Data (AAD)
103To prevent cross-object splicing, chunk reordering, truncation, and cross-store replay:
104$$\text{AAD}_i = \text{"AIENOS-M5-CHUNK-V1\0"} \parallel \text{store\_uuid} \parallel \text{object\_kind:u16le} \parallel \text{object\_version:u16le} \parallel \text{header\_64B} \parallel i\text{:u32le} \parallel \text{chunk\_plaintext\_len}_i\text{:u32le}$$
105
106Store v1 content-addresses the object by computing its standard `ObjectId = SHA-256(complete_ciphertext_envelope)`.
107
108**Security Invariant**: The kernel must verify each 64 KiB chunk's 16-byte authentication tag in a private scratchpad before releasing decrypted plaintext to callers. The scratchpad is securely zeroed on tag verification failure.
109
110---
111
112### 2.4 KeySlotManifest (`kind = 21`)
113
114`KeySlotManifest` is a plaintext Store v1 system object that bootstraps storage decryption. It is not encrypted under `K_vol`.
115
116```text
117Offset Size Field
1180 8 magic = "AIENKSL1"
1198 2 format_version = 1
12010 2 flags = 0
12112 16 store_uuid
12228 8 manifest_sequence (u64le)
12336 32 previous_keyslot_manifest_id (ObjectId, 0 for genesis)
12468 8 active_key_epoch (u64le)
12576 4 slot_count (u32le, max 4)
12680 48 reserved = 0
127128 4×128 KeySlotDescriptors (512 B total)
128640 var Payload Arena (max 32 KiB)
129```
130
131Each 128-byte `KeySlotDescriptor`:
132```text
133slot_type (u8): 0=Empty, 1=TPM2_PolicyAuthorize, 2=Recovery_Argon2id, 3=Recovery_RawSecret
134wrap_suite (u8): 0x01 = AES_256_GCM_SIV
135kdf_suite (u8): 0x00 = None, 0x01 = KDF_ARGON2ID_V1, 0x02 = HKDF_SHA256
136flags (u8)
137slot_id (u32le)
138key_epoch (u64le)
139salt (16 B)
140argon_m_kib (u32le)
141argon_t_cost (u32le)
142argon_p_cost (u32le)
143wrap_nonce (12 B)
144wrapped_k_vol (32 B)
145wrap_tag (16 B)
146payload_offset (u32le, relative to start of Payload Arena)
147payload_length (u32le)
148reserved (16 B)
149```
150
151#### Recovery KDF Profiles
1521. **Passphrase Profile (`KDF_ARGON2ID_V1`)**:
153 - $m = 65536\text{ KiB}$ (64 MiB), $t = 3$, $p = 4$, salt = 16 bytes, output = 32 bytes (RFC 9106).
154 - Executed inside a reserved Recovery Core memory arena; memory is explicitly zeroed immediately after derivation.
155 - Decoders strictly validate that $m \le 131072\text{ KiB}$ and $t \le 10$ to prevent denial-of-service.
1562. **High-Entropy / WebAuthn PRF Profile**:
157 $$\text{K\_recovery\_kek} = \text{HKDF-SHA256}(\text{salt} = \text{slot.salt}, \text{ikm} = \text{raw\_secret}, \text{info} = \text{"AIENOS/M5/RECOVERY-KEK-V1"}, \text{len} = 32)$$
158
159---
160
161#### 2.4.1 Implementation note (C kernel, P04 cut 1, 2026-10-12)
162
163- The manifest is committed as a plaintext kind-21 object **inside a sealed transaction** (`native/store/store_sealed.c`): the keyed transaction record binds its SHA-256, exactly one manifest may be bound at a time, and an unkeyed bootstrap read (`ss_keyslot_bootstrap`) returns the bytes before any key exists. The keyed open re-checks the same bytes. A manifest that is present but unclaimed, duplicated, or whose digest changed is refused.
164- Codec: `native/m5` `m5_ksm_encode` / `m5_ksm_decode` (fixed 640 bytes + arena; every descriptor through `m5_keyslot_decode`; unused descriptors must be Empty).
165- Recovery KEK (raw-secret profile): `m5_recovery_kek` = HKDF-SHA256(salt = slot.salt, ikm = 32-byte secret, info = `AIENOS/M5/RECOVERY-KEK-V1`, 32). HKDF-Extract is `HMAC(salt || 0^16, ikm)`, bit-identical to RFC 5869 for a 16-byte salt (test vector in `m5_test.c`).
166- Keyslot AAD in C binds `store_uuid, slot_id, slot_type, key_epoch` (`AIENOS-M5-KEYSLOT-V2`), a superset of the Rust reference; C is authoritative.
167- The kernel (`ck_store_unlock_boot`) creates the manifest at genesis in the same first transaction as the boot record (index 0 reserved Empty for the TPM slot, index 1 = Recovery_RawSecret, slot_id 1, `active_key_epoch` 1), and derives PRODUCTION-class subkeys with owner hierarchy generation = `active_key_epoch`.
168- Not yet: TPM Slot 0 (BLOCKED_HARDWARE), Argon2id profile. The `keyslot_manifest_id` binding into the SecurityManifest is P04 cut 2a (section 2.5.1); recovery secret rotation is P04 cut 2b (section 2.7.1).
169
170### 2.5 SecurityManifest (`kind = 22`)
171
172`SecurityManifest` is a 256-byte fixed-size Store v1 object that authenticates authorized logical state under `K_root_auth`:
173
174```text
175Offset Size Field
1760..8 8 magic = "AIENSEC1"
1778..10 2 format_version = 1
17810..12 2 flags = 0
17912..16 4 reserved = 0
18016..32 16 store_uuid
18132..40 8 generation (u64le, equals Store superblock generation)
18240..48 8 security_sequence (u64le, strictly monotonic)
18348..56 8 epoch (u64le, anti-rollback security epoch)
18456..64 8 key_epoch (u64le)
18564..96 32 previous_security_manifest_id (ObjectId, 0 for first)
18696..128 32 keyslot_manifest_id (ObjectId)
187128..160 32 agent_root_id (ObjectId)
188160..192 32 continuity_manifest_id (ObjectId)
189192..224 32 migration_manifest_id (ObjectId, 0 if unmigrated)
190224..256 32 root_mac (HMAC-SHA256)
191```
192
193$$\text{root\_mac} = \text{HMAC-SHA256}(K_{\text{root\_auth}}, \text{"AIENOS-M5-ROOT-AUTH-V1\0"} \parallel \text{bytes}[0..224])$$
194
195To break the content-addressing dependency cycle, `SecurityManifest` intentionally omits the current generation's `commit_record_id`. The Store transaction engine links `SecurityManifest` into the Catalog, whose root is referenced by the CommitRecord.
196
197#### 2.5.1 Implementation note (C kernel, P04 cut 2a, 2026-10-12)
198
199- Codec: `native/m5` `m5_secman_seal` / `m5_secman_open` (256 bytes, Rust v1 layout, `root_mac` under `k_root_auth`; identity class and owner hierarchy generation are bound through the key, not wire fields).
200- The kernel boot stage (`native/kernel/svc/store_boot.c`, `run_policy_ex`) commits one SecurityManifest in **every boot transaction**, next to the boot record (and the KeySlotManifest at genesis). In the C sealed store it is a kind-22 **sealed envelope** (the store admits only the KeySlotManifest in plaintext), so the transaction record binds it and `root_mac` authenticates it a second time under `k_root_auth`.
201- Fields as written: `generation` = the generation the transaction creates; `security_sequence` = previous + 1 (1 at genesis); `previous_security_manifest_id` = the Store ObjectId of the manifest it supersedes (zero at genesis); `key_epoch` = the owner hierarchy generation of the open keys (`active_key_epoch`, 1); `keyslot_manifest_id` = the KeySlotManifest ObjectId (`sv1_object_id` of the kind-21 bytes at genesis, the keyed open's bound `keyslot_sid` later; zero on a TEST-key Store, which has none); `epoch` = `generation`, because the C sealed store's anti-rollback anchor (`torn_slot`, section 2.6 step 3) counts Store generations; `agent_root_id`, `continuity_manifest_id`, `migration_manifest_id` = zero (not yet linked).
202- On every open the newest manifest is read back and must: verify under the open keys; name this Store; bind exactly the keyslot the keyed open bound; carry the open keys' epoch; carry the generation of the transaction that committed it; carry a `security_sequence` equal to the number of manifests on the Store. A Store with history but no manifest, or any failed check, is refused (`CK_SB_E_SECMAN`, "SecurityManifestRefused") before the boot record is written, and the keys are wiped. Evidence: `svc/tests/stage_test.c` `test_secman`, LIFECYCLE gate rows 182-183.
203- Limits: only the boot transaction writes a manifest (approve, continuity and journal commits do not advance `security_sequence`); rotation (section 2.7) and TPM Slot 0 (section 2.8) remain open.
204
205---
206
207### 2.6 Anti-Rollback Semantics & Security Epochs
208
209**Theorem**: *To detect replay of committed state against a malicious raw-disk adversary, trusted state outside the replayable disk must advance for every protected commit boundary.*
210
2111. **Security Epoch**: The smallest group of Class-A commits that AIENOS permits to become externally authoritative before their root is anchored outside replayable storage.
2122. **Commit Ordering**:
213 ```text
214 Step 1: Commit Store v1 generation G with epoch E+1 and SecurityManifest digest H.
215 Step 2: Flush Store v1 durably to media (NVMe FLUSH).
216 Step 3: Advance AntiRollbackSource to {store_uuid, E+1, H}.
217 Step 4: Release external effects (Effect Broker dispatch, external observation).
218 ```
2193. **Boot Validation Protocol**:
220 - $\text{disk\_epoch} == \text{anchor\_epoch} \land \text{disk\_digest} == \text{anchor\_digest} \implies \text{Normal resume}$.
221 - $\text{disk\_epoch} == \text{anchor\_epoch} + 1 \implies \text{Prepared unanchored epoch; freeze external observation, complete anchor update}$.
222 - $\text{disk\_epoch} < \text{anchor\_epoch} \implies \text{Halt with RecoveryRequired::RollbackDetected}$.
223 - $\text{disk\_epoch} == \text{anchor\_epoch} \land \text{disk\_digest} \ne \text{anchor\_digest} \implies \text{Halt with RecoveryRequired::RollbackDetected}$.
224 - $\text{disk\_epoch} > \text{anchor\_epoch} + 1 \implies \text{Halt with RecoveryRequired::InconsistentEpoch}$.
225
226Replay detection halts into `RecoveryRequired::RollbackDetected`, strictly prohibiting automatic agent continuation.
227
228---
229
230### 2.7 Key Rotation vs. Store Migration
231
2321. **Policy / Credential Rotation ($O(1)$)**:
233 Updating PCR policy or changing operator passphrases unwraps `K_vol`, writes a new `KeySlotManifest` with updated wrapped keyslots, increments `security_sequence`, and commits a new `SecurityManifest`. No encrypted application objects are re-encrypted.
2342. **`K_vol` Compromise (Out-of-Band Migration)**:
235 In-place re-encryption cannot revoke confidentiality because Store v1's append-only design leaves historical ciphertext on disk. When `K_vol` is compromised:
236 - Live state is decrypted from the source Store.
237 - Transferred to a fresh Store container with a new `store_uuid` and new $K_{\text{vol}}'$.
238 - An authorized `MigrationManifest` (kind = 23) is signed by the TRUST-1 offline Owner Authority.
239 - The target Store imports the identical `AgentRoot` (`genesis_store_uuid` preserved) and resumes continuity at `migration_parent_id`.
240
241#### 2.7.1 Implementation note (C kernel, P04 cut 2b, 2026-10-12)
242
243Item 1 is implemented for the recovery secret (`native/kernel/svc/store_boot.c` `ck_store_rotate_recovery`, serial verb `rotate <current 64-hex> <new 64-hex>` while READY):
244
245- Store v1 is append-only, so a KeySlotManifest is never replaced: manifests form a chain (`native/store/store_sealed.c`). Sequences 1..n appear exactly once, sequence 1 carries a zero `previous_keyslot_manifest_id`, every later manifest names the Store ObjectId of its predecessor, and the newest is the bound one. A transaction may add at most one manifest, only as sequence n+1 naming the bound manifest. The unkeyed bootstrap read walks the same chain and returns the newest; a broken, duplicated or forged chain is `SS_E_KEYSLOT` both unkeyed and keyed.
246- Rotation first unwraps `K_vol` with the current secret from the bound manifest (proof of possession; a wrong secret writes nothing). One sealed transaction then commits the next KeySlotManifest (same `K_vol`, `active_key_epoch` unchanged, slot 1 re-wrapped under the new secret with a fresh salt and nonce from the entropy service) together with the SecurityManifest of section 2.5 (`security_sequence` + 1, linked to the previous one, `keyslot_manifest_id` = the new manifest). `K_vol` is wiped before the transaction is written and is never kept resident between unlock and rotation.
247- Afterwards the old secret fails the AES-GCM-SIV tag of the newest manifest (`RecoverySecretRejected`). Superseded manifests stay on disk and readable, as the append-only design requires; they cannot open the Store because the keyed open binds only the newest.
248- Not in this cut: a change of `K_vol` (item 2, out-of-band migration), TPM Slot 0 (BLOCKED_HARDWARE), the Argon2id profile, the owner-root path. Evidence: `native/kernel/GATES.md` LIFECYCLE rows 184 and 185, host `stage-test` test_rotate and `store_sealed_test` chain tests.
249
250---
251
252### 2.8 TPM 2.0 `PolicyAuthorize` Integration
253
254Slot 0 unsealing uses TPM 2.0 `PolicyAuthorize` to allow firmware and kernel measurements to evolve without invalidating the sealed key:
255
2561. **Dedicated Policy Signing Key**:
257 The offline TRUST-1 Owner Root issues an authorized credential for a dedicated TPM Policy Authorization Key whose public area Name is pinned in Slot 0.
2582. **Offline Authorization**:
259 The operator computes the approved `PolicyPCR` digest for an update bundle, signs the policy digest with the Policy Authorization Key, and embeds the signature, approved policy digest, and `policyRef` (`"AIENOS/M5/STORE-UNLOCK/POLICY-V1" || store_uuid || slot_id`).
2603. **Runtime Verification**:
261 ```text
262 TPM Policy Session Started
263 ↓
264 TPM2_PolicyPCR(actual PCRs)
265 ↓
266 TPM2_VerifySignature(keySign, approvedPolicy, signature) → checkTicket
267 ↓
268 TPM2_PolicyAuthorize(approvedPolicy, policyRef, keySign, checkTicket)
269 ↓
270 TPM2_Unseal(Slot 0) → K_tpm_kek
271 ↓
272 AES-256-GCM-SIV unwrap K_vol
273 ```
2744. **Empirical PCR Policy**:
275 The exact PCR selection mask is not hard-coded; it is determined empirically by the TRUST-1 Gate 2 measurement campaign on Machine 1 hardware.