Files
LithosAnanke/kernel/include/starkernel/capsule_sig.h
T
Claude 9db364f7c7 capsule trust: a signed kernel refuses an unsigned capsule; the intermediate is the anchor (#139)
capsule_sig_refused(), the one decision at v4's boot and v3's three
births: INVALID always; MISSING and NO_ROOT_KEY on a signed build
(CAPSULE_SIGNED_BUILD, set exactly when the Makefiles sign). A
developer build warns and boots. test_capsule_sig, built both ways,
did not build without it; 4 checks each way now. nightly.sh
capsule-trust, a nightly step: signed, v4:centre.4th left unsigned
(test only), amd64 must refuse it -- CI's, as ruled, since only CI has
the key. No root check, as ruled; the step-4 trust model (blobs signed
by their authors, MANIFEST.md hashes, contributors' intermediates,
snakeoil) recorded as given. FABRIC-3 XLIX. Gates pass, POST 992/992.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-20 22:37:25 +00:00

80 lines
3.9 KiB
C

/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/*
* capsule_sig.h -- per-capsule Ed25519 signature verification
* (Milestone 6, Phase 8). Deliberately kept separate from
* capsule_validate.c: that function is already tested and its
* signature/behavior stays untouched; this is a new, additive check
* called alongside it, not folded into it.
*
* Which results are refused is capsule_sig_refused()'s, the one decision every caller asks (#139,
* docs/v4.0.0/plans/2026-11-20-capsule-trust.md, ruled 2026-11-20): INVALID on every build; MISSING
* and NO_ROOT_KEY as well on a signed build (CAPSULE_SIGNED_BUILD 1, set by kernel/Makefile and
* v4/Makefile exactly when they sign the capsules). A developer build, without the key, warns of them
* and boots. The anchor is the signing certificate in the image (FABRIC-3 XLVI): it is not checked
* against the root CA (ruled 2026-11-20). Corrected 2026-11-20: until then, as below, only INVALID
* was refused on any build.
*
* Enforced ONLY on CAPSULE_SIG_INVALID (2026-08-26, after landing
* WARN-only and proving correct on all three architectures against both
* a valid and a deliberately-corrupted capsule -- see FABRIC-2.md's
* Milestone 6 writeup). CAPSULE_SIG_MISSING and CAPSULE_SIG_NO_ROOT_KEY
* stay WARN-only, deliberately: MISSING is the normal state on every
* machine without access to the offline signing key (CI, any other
* checkout) -- refusing on it would brick boot everywhere but the one
* machine that minted the key, not catch anything real. Only INVALID
* (a signature that IS present but does not verify) is unambiguous
* tampering/corruption evidence, safe to refuse on regardless of who's
* building.
*/
#ifndef STARKERNEL_CAPSULE_SIG_H
#define STARKERNEL_CAPSULE_SIG_H
#include "starkernel/capsule.h"
/* The certificate whose key the capsules are signed with: "StarshipOS
* Capsule Signing", issued by the StarshipOS Root CA (ci/pki/make-ca.sh;
* FABRIC-3.md XLVI), replacing the snakeoil intermediate of Milestone 6.
* mkcapsule refuses to sign with a key that is not this certificate's. */
#define CAPSULE_SIGNING_CERT_NAME "pki:starshipos-intermediate.der"
/* 1 when the kernel is built with the signing key (kernel/Makefile, v4/Makefile): its capsules are
* signed, so an unsigned one, or no certificate to check by, is refused (#139). */
#ifndef CAPSULE_SIGNED_BUILD
#define CAPSULE_SIGNED_BUILD 0
#endif
typedef enum {
CAPSULE_SIG_OK = 0, /* has_sig=1, and it verifies */
CAPSULE_SIG_MISSING, /* has_sig=0 -- not signed at all */
CAPSULE_SIG_INVALID, /* has_sig=1 but verification failed */
CAPSULE_SIG_NO_ROOT_KEY, /* couldn't find/parse the embedded intermediate cert */
} CapsuleSigResult;
/*
* Verify capsule descs[index]'s Ed25519 signature against the embedded
* capsule-signing certificate's public key (CAPSULE_SIGNING_CERT_NAME,
* found and parsed once, cached for every later call this boot -- the
* cert doesn't change mid-boot).
*
* descs/names/sigs must be the same three parallel arrays
* (capsule_get_descriptors()/capsule_get_names()/capsule_get_signatures()),
* desc_count their shared length, arena_base the payload arena
* (capsule_get_arena()). index must be < desc_count.
*/
CapsuleSigResult capsule_verify_signature(
const CapsuleDesc *descs, const CapsuleNameEntry *names,
const CapsuleSigEntry *sigs, const uint8_t *arena_base,
uint32_t desc_count, int index);
/* Human-readable string for logging, mirroring
* capsule_validate_result_str()'s existing shape. */
const char *capsule_sig_result_str(CapsuleSigResult result);
/* 1 if a capsule with this result is refused (#139): INVALID always; MISSING and NO_ROOT_KEY on a
* signed build (CAPSULE_SIGNED_BUILD). Every caller asks this rather than testing a result itself. */
int capsule_sig_refused(CapsuleSigResult result);
#endif /* STARKERNEL_CAPSULE_SIG_H */