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 / scripts / ck_pi5_owner_check.sh

105 lines · 10901 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# ck_pi5_owner_check.sh -- PI5-8 Q2 gate: the owner-key ceremony tooling, proven with SOFTWARE keys only (TEST).
18# 1. PIV public key (PEM) -> CK_OWNER_PUBKEYS file conversion is exact; anything that is not an Ed25519 key is refused;
19# 2. the ceremony dry run (software key, labelled TEST) runs end to end and never calls a YubiKey tool (tripwire);
20# 3. real mode refuses when the machine looks online, and with no terminal, before any YubiKey tool is called;
21# 4. an image built with that owner file (make full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS=<file>) carries the owner key
22# and none of the TEST anchors (no "seed0b-test ... TEST ONLY" banner, no TEST Store identity); the TEST-anchor image
23# is the positive control (it has the banner and not the owner key); Pi image flags are refused with CK_HARDWARE_STAGING.
24# No YubiKey is touched. No owner or release key is generated: every key here is a throw-away openssl key.
25set -euo pipefail
26root="$(cd "$(dirname "$0")/.." && pwd)"
27tmp="$(mktemp -d)"; trap 'rm -rf "${tmp}"' EXIT
28fail=0
29ok() { echo "PASS $*"; }
30bad() { echo "FAIL $*"; fail=1; }
31C="${root}/scripts/pi5-8/owner_ceremony.sh"; CONV="${root}/scripts/pi5-8/owner_pubkey_file.sh"
32hexof() { od -An -v -tx1 "$1" | tr -d ' \n'; }
33
34# 1. conversion
35openssl genpkey -algorithm ED25519 -out "${tmp}/k.pem" 2>/dev/null
36openssl pkey -in "${tmp}/k.pem" -pubout -out "${tmp}/k.pub"
37want="$(openssl pkey -in "${tmp}/k.pem" -pubout -outform DER | tail -c 32 | od -An -v -tx1 | tr -d ' \n')"
38got="$("${CONV}" "${tmp}/k.pub" "${tmp}/owner.txt" "TEST conversion" 2>/dev/null)"
39if [ "${got}" = "${want}" ] && grep -qx "owner_root_ed25519 ${want}" "${tmp}/owner.txt" && [ "$(grep -vc '^#' "${tmp}/owner.txt")" = 1 ]; then ok "conversion gives the 32 raw key bytes in the CK_OWNER_PUBKEYS format"; else bad "conversion"; fi
40openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out "${tmp}/rsa.pem" 2>/dev/null; openssl pkey -in "${tmp}/rsa.pem" -pubout -out "${tmp}/rsa.pub"
41openssl genpkey -algorithm X25519 -out "${tmp}/x.pem" 2>/dev/null; openssl pkey -in "${tmp}/x.pem" -pubout -out "${tmp}/x.pub"
42openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out "${tmp}/ec.pem" 2>/dev/null; openssl pkey -in "${tmp}/ec.pem" -pubout -out "${tmp}/ec.pub"
43printf 'not a key\n' > "${tmp}/junk.pub"
44{ echo "-----BEGIN PUBLIC KEY-----"; { printf '\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00'; head -c 32 /dev/zero | tr '\0' '\021'; } | base64; echo "-----END PUBLIC KEY-----"; } > "${tmp}/same.pub"
45for b in rsa x ec junk same; do
46 if "${CONV}" "${tmp}/${b}.pub" "${tmp}/o.${b}" >/dev/null 2>&1; then bad "conversion accepted ${b}"; else ok "conversion refuses ${b} (not a plain Ed25519 key)"; fi
47done
48for b in rsa x ec junk same; do [ ! -e "${tmp}/o.${b}" ] || bad "refused input ${b} still wrote a file"; done
49
50# 2. dry run with a tripwire in place of both YubiKey tools
51printf '#!/bin/sh\necho "$0" >> "%s/tripwire"\nexit 99\n' "${tmp}" > "${tmp}/trip"; chmod +x "${tmp}/trip"
52AIENOS_PIV_TOOL="${tmp}/trip" AIENOS_YKMAN="${tmp}/trip" "${C}" --dry-run --out "${tmp}/dry" > "${tmp}/dry.log" 2>&1 || { cat "${tmp}/dry.log"; bad "dry run failed"; }
53if grep -q "^CEREMONY_DRY_RUN: PASS" "${tmp}/dry.log"; then ok "dry run passes end to end"; else bad "dry run verdict"; fi
54[ ! -e "${tmp}/tripwire" ] && ok "dry run called no YubiKey tool" || bad "dry run called a YubiKey tool"
55for f in slot-9c-public.pem owner-pubkeys.txt owner-pubkeys.txt.sha256 ceremony-statement ceremony-signature ceremony-report.txt; do
56 [ -s "${tmp}/dry/${f}" ] || bad "dry run output lacks ${f}"
57done
58grep -q "DRY RUN, TEST software key, not an owner key" "${tmp}/dry/ceremony-report.txt" && ok "dry run report is labelled TEST" || bad "dry run label"
59( cd "${tmp}/dry" && sha256sum -c owner-pubkeys.txt.sha256 >/dev/null ) && ok "owner file sha256 file matches" || bad "owner sha256"
60if grep -rqE "PRIVATE KEY|TEST-software-key" "${tmp}/dry"; then bad "dry run output holds a private key"; else ok "dry run output holds public material only"; fi
61
62# 3. real mode refusals (a pseudo-terminal is needed to get past the terminal check)
63mkdir -p "${tmp}/fakebin" "${tmp}/net/eth0" "${tmp}/offline/eth0"
64printf '#!/bin/sh\n[ "$*" = "-o route show default" ] && echo "default via 192.0.2.1 dev eth0"\nexit 0\n' > "${tmp}/fakebin/ip-online"
65printf '#!/bin/sh\nexit 0\n' > "${tmp}/fakebin/ip-offline"; chmod +x "${tmp}/fakebin/ip-"*
66echo up > "${tmp}/net/eth0/operstate"; echo down > "${tmp}/offline/eth0/operstate"
67shimdir() { mkdir -p "${tmp}/p-$1"; cp "${tmp}/fakebin/ip-$1" "${tmp}/p-$1/ip"; for t in bash env sed cat sort head grep readlink basename dirname date cc mktemp rm; do ln -sf "$(command -v ${t})" "${tmp}/p-$1/${t}" 2>/dev/null || true; done; echo "${tmp}/p-$1"; }
68online_path="$(shimdir online)"; offline_path="$(shimdir offline)"
69run_pty() { script -qec "$1" /dev/null </dev/null; }
70set +e
71out_on="$(PATH="${online_path}:${PATH}" AIENOS_SYSFS_NET="${tmp}/offline" AIENOS_PIV_TOOL="${tmp}/trip" AIENOS_YKMAN="${tmp}/trip" run_pty "PATH='${online_path}':\$PATH '${C}' --real --out '${tmp}/real1'" 2>&1)"; rc_on=$?
72out_nic="$(AIENOS_SYSFS_NET="${tmp}/net" AIENOS_PIV_TOOL="${tmp}/trip" AIENOS_YKMAN="${tmp}/trip" run_pty "PATH='${offline_path}':\$PATH '${C}' --real --out '${tmp}/real2'" 2>&1)"; rc_nic=$?
73out_tty="$(PATH="${offline_path}:${PATH}" AIENOS_SYSFS_NET="${tmp}/offline" AIENOS_PIV_TOOL="${tmp}/trip" AIENOS_YKMAN="${tmp}/trip" "${C}" --real --out "${tmp}/real3" </dev/null 2>&1)"; rc_tty=$?
74PATH="${offline_path}:${PATH}" AIENOS_SYSFS_NET="${tmp}/offline" "${C}" --check-network > "${tmp}/cn.off" 2>&1; rc_cn_off=$?
75PATH="${online_path}:${PATH}" AIENOS_SYSFS_NET="${tmp}/offline" "${C}" --check-network > "${tmp}/cn.on" 2>&1; rc_cn_on=$?
76set -e
77if [ "${rc_on}" != 0 ] && grep -q "still online" <<<"${out_on}"; then ok "real mode refuses with a default route (online)"; else bad "real mode online refusal (rc=${rc_on})"; fi
78if [ "${rc_nic}" != 0 ] && grep -q "network card eth0 is up" <<<"${out_nic}"; then ok "real mode refuses with a physical network card up"; else bad "real mode nic refusal (rc=${rc_nic})"; fi
79if [ "${rc_tty}" = 2 ] && grep -q "keyboard of the Spark" <<<"${out_tty}"; then ok "real mode refuses without a terminal"; else bad "real mode tty refusal (rc=${rc_tty})"; fi
80if [ "${rc_cn_off}" = 0 ] && grep -q OFFLINE "${tmp}/cn.off" && [ "${rc_cn_on}" = 1 ] && grep -q ONLINE "${tmp}/cn.on"; then ok "network check: offline passes, online fails"; else bad "network check controls (${rc_cn_off} ${rc_cn_on})"; fi
81[ ! -e "${tmp}/tripwire" ] && ok "no refused real run called a YubiKey tool" || bad "a refused real run called a YubiKey tool"
82[ ! -e "${tmp}/real1" ] && [ ! -e "${tmp}/real2" ] && [ ! -e "${tmp}/real3" ] && ok "refused real runs wrote nothing" || bad "refused real run wrote output"
83
84# 4. images
85own="${tmp}/dry/owner-pubkeys.txt"; ohex="$(sed -n 's/^owner_root_ed25519 //p' "${own}")"
86printf 'machine_id %s\nstore_uuid %s\n' "$(openssl rand -hex 32)" "$(openssl rand -hex 16)" > "${tmp}/machine.txt"
87K="${root}/native/kernel"
88make -s -C "${K}" OUT="${tmp}/img-own" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${own}" CK_MACHINE_ID="${tmp}/machine.txt" > "${tmp}/img-own.log" 2>&1 || { tail -5 "${tmp}/img-own.log"; bad "owner image build"; }
89make -s -C "${K}" OUT="${tmp}/img-test" full CK_SEED0B_TEST_ANCHOR=1 > "${tmp}/img-test.log" 2>&1 || { tail -5 "${tmp}/img-test.log"; bad "TEST-anchor image build"; }
90eo="${tmp}/img-own/full-hardware-staging/aienos-ck.elf"; et="${tmp}/img-test/aienos-ck.elf"
91[ -s "${eo}" ] || eo="$(find "${tmp}/img-own" -name aienos-ck.elf | head -n 1)"
92[ -s "${et}" ] || et="$(find "${tmp}/img-test" -name aienos-ck.elf | head -n 1)"
93if hexof "${eo}" | grep -q "${ohex}"; then ok "owner image carries the owner public key"; else bad "owner image lacks the owner key"; fi
94if hexof "${et}" | grep -q "${ohex}"; then bad "TEST-anchor image carries the owner key"; else ok "TEST-anchor control image has no owner key"; fi
95so="$(strings -a "${eo}")"; st="$(strings -a "${et}")"
96if grep -q "seed0b-test qualification build" <<<"${st}"; then ok "control: TEST-anchor image carries the TEST ONLY artifact_trust banner"; else bad "control banner missing, the check below would prove nothing"; fi
97if grep -qE "seed0b-test qualification build|TEST ONLY|TEST-ONLY|AIEN-TEST-BOOT|LANE18-TEST-KVOL|TEST machine id" <<<"${so}"; then bad "owner image carries a TEST anchor/banner: $(grep -E 'seed0b-test qualification build|TEST ONLY|TEST-ONLY|AIEN-TEST-BOOT|LANE18-TEST-KVOL|TEST machine id' <<<"${so}" | head -n 3)"; else ok "owner image has no TEST anchor banner, TEST Store label or TEST machine id"; fi
98if grep -q "no TEST Store label, uuid or key code" "${tmp}/img-own.log" || make -s -C "${K}" -n OUT="${tmp}/x" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${own}" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1; then ok "Makefile owner_check accepts the owner image"; else bad "owner_check"; fi
99for flag in CK_PI5=1 CK_PI5_ARTIFACT=1 CK_SEED0B_TEST_ANCHOR=1; do
100 if make -n -C "${K}" ${flag} full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${own}" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1; then bad "Makefile accepts ${flag} with CK_HARDWARE_STAGING"; else ok "Makefile refuses ${flag} with CK_HARDWARE_STAGING (TEST tier and owner image never mix)"; fi
101done
102if make -n -C "${K}" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${own}" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1; then ok "positive control: owner image build is accepted"; else bad "positive control"; fi
103cp "${tmp}/machine.txt" "${tmp}/machine.copy"; printf 'owner_root_ed25519 d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a\n' > "${tmp}/t1.txt"
104if make -n -C "${K}" OUT="${tmp}/x2" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${tmp}/t1.txt" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1 && make -s -C "${K}" OUT="${tmp}/x2" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${tmp}/t1.txt" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1; then bad "an RFC 8032 TEST key was accepted as owner key"; else ok "an RFC 8032 TEST key is refused as owner key"; fi
105[ "${fail}" = 0 ] && echo "PASS ck_pi5_owner_check" || { echo "FAIL ck_pi5_owner_check"; exit 1; }