1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//! Kernel boot path: gate the PQ signing key load on a self-quote.
//!
//! The PQ signing key load is gated on a verified self-quote that binds the
//! `expect_report_data` and hybrid-signing paths. Boot order:
//!
//! 1. The kernel comes up with its classical Ed25519 keypair already
//! materialized. No PQ key has been touched.
//! 2. The kernel requests its own TEE quote from the surrounding
//! `chio-tee` container and feeds the bytes into a
//! verifier-side [`KernelSelfQuoteVerifier`]. The quote
//! MUST commit to `expect_report_data(kernel_classical_pk,
//! receipt_root_genesis)` where `receipt_root_genesis` is the all-zero
//! 32-byte sentinel `[0u8; 32]` representing the empty receipt-tree root
//! at boot.
//! 3. Only after the verifier returns success does the kernel derive the
//! [`MlDsa65Backend`](chio_core_types::pq::MlDsa65Backend) from the
//! operator-supplied seed and compose the
//! [`HybridBackend`](chio_core_types::pq::HybridBackend). Any failure in
//! step 2 leaves the kernel running classical-only and the boot path
//! returns an error: under `crypto_floor=allow_hybrid` or
//! `crypto_floor=pq_required` the operator MUST refuse to start signing.
//!
//! ## Why a port trait rather than a hard `chio-attest-verify` dep
//!
//! `chio-kernel` does not depend on `chio-attest-verify` and this module
//! preserves that boundary. The verifier crate today carries TDX/SEV-SNP/
//! Nitro backends each pulled in behind a cargo feature; the kernel does
//! not need any of them at boot time. The port trait below is small enough
//! to implement against `chio-attest-verify`'s `QuoteVerifier` by a
//! one-line shim in the operator binary that wires the two crates together,
//! and small enough to implement against an in-memory mock for the
//! integration test.
//!
//! ## Trust-boundary discipline
//!
//! - Fail-closed: every error path returns
//! [`KernelBootError`] without producing a [`HybridBackend`].
//! - The kernel signing key (the classical Ed25519 key plus the PQ
//! composition) is never returned partially. Callers that ask for a
//! hybrid backend either get one fully gated by a verified self-quote
//! or they get an error.
//! - `receipt_root_genesis` is the [`RECEIPT_ROOT_GENESIS`] constant.
//! Production callers MUST NOT thread their current receipt root in;
//! the genesis quote binds to the empty tree so the chain has a fixed
//! cryptographic anchor independent of the first receipt's contents.
use ;
use crate;
/// Receipt-root sentinel used for the kernel self-quote.
///
/// The first signed receipt advances the root, but the genesis-quote
/// binds to the empty tree so the chain has a fixed cryptographic anchor
/// independent of the first receipt's contents (per the self-quote
/// boot-gate contract).
pub const RECEIPT_ROOT_GENESIS: = ;
/// Outcome reported by a [`KernelSelfQuoteVerifier`].
///
/// The verifier carries the actual collateral chain validation and TCB
/// freshness check; the kernel boot path only inspects the boolean
/// success flag and the diagnostic message. A successful verification
/// MUST mean that:
///
/// - the quote envelope parsed and matched the configured TEE family,
/// - the collateral chained to its trusted root,
/// - the TCB status was acceptable per the verifier's policy,
/// - and the 64-byte `report_data` slot byte-matched
/// `expect_report_data(kernel_classical_pk, RECEIPT_ROOT_GENESIS)`.
///
/// Any failure produces [`KernelSelfQuoteOutcome::rejected`]. Verifiers
/// MUST NOT report success on partial verification.
/// Port the kernel boot path consults to verify its own TEE quote.
///
/// Implementations live in operator binaries (which compose
/// `chio-attest-verify` backends) or in
/// integration tests (which inject a mock with a captured expected
/// `report_data`). The port trait deliberately does not return the full
/// `VerifiedQuote` shape: the kernel boot path only needs a yes/no
/// answer plus a diagnostic message, and keeping the interface narrow
/// preserves the no-`chio-attest-verify`-dep boundary on `chio-kernel`.
/// Errors the boot path raises while gating the PQ key load.
///
/// Distinct from [`KernelSigningBackendError`] so the operator log can
/// distinguish "the policy floor was misconfigured" from "the self-quote
/// did not bind". Both still fail the kernel start.
/// Load the kernel signing backend, gating the PQ half on a verified
/// self-quote.
///
/// Boot logic:
///
/// - Under [`KernelCryptoFloor::AllowClassical`] the self-quote step is
/// skipped: there is no PQ key to gate, and a classical-only deployment
/// may not even ship a TEE container. The function returns the
/// classical-only backend produced by [`kernel_signing_backend`].
/// - Under [`KernelCryptoFloor::AllowHybrid`] or
/// [`KernelCryptoFloor::PqRequired`] the function consults the
/// verifier port FIRST. Only on
/// [`KernelSelfQuoteOutcome::verified`] does it construct the hybrid
/// backend. A rejected outcome returns
/// [`KernelBootError::SelfQuoteRejected`] without ever materializing
/// the [`MlDsa65Backend`](chio_core_types::pq::MlDsa65Backend).
///
/// `quote_bytes` is the on-the-wire self-quote produced by the TEE
/// container. For tests, an empty slice combined with a mock verifier
/// is fine; for production the bytes come from `chio-tee`.
///
/// # Errors
///
/// - [`KernelBootError::SelfQuoteRejected`] when the verifier rejects
/// the self-quote and the floor mandates a PQ key.
/// - [`KernelBootError::SigningBackend`] when the floor or PQ seed is
/// misconfigured (forwarded from
/// [`KernelSigningBackendError::HybridFloorRequiresPqKey`] or
/// [`KernelSigningBackendError::PqKeyImportFailed`]).