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_imac_security_test.sh

60 lines · 3394 bytes Raw Blame History
1#!/usr/bin/env bash
2# ck_imac_security_test.sh -- regression tests for the iMac security fixes (L872):
3# F1 the wizard's API key must never be queued on, nor stay in, the unencrypted Ethernet courier;
4# F2 the kernel must verify the owner's signature before it writes a boot section;
5# F3 nor may it install an owner-signed kernel below the installed kernel's policy_generation
6# (an old kernel replayed over the unauthenticated network loader).
7# Three small programs are built from the REAL production sources and run:
8# courier_secret_test x86/courier_udp_x86.c (host build, mocked clock, link and frames)
9# setup_secret_test svc/setup_wizard.c plus x86/setup_x86.c (the adapter), mocked kernel services
10# boot_verify_test x86/memory_x86.c boot_section, mocked disk and GPT, real ck_slot_verify and Ed25519
11# The last two are x86-64 code (rdtsc, cpuid): cross-built static and run under qemu-x86_64
12# (run natively on an x86-64 host). No full-model QEMU, no disk, no network, no private key
13# (RFC 8032 public test vectors only).
14# PROD_ROOT=<checkout> builds the production sources from another tree (for the red run at the
15# commit before the fix, e.g. a worktree of e3f1c6ac); the tests always come from this tree.
16# Ends with "AIENOS_IMAC_SECURITY: PASS" or "AIENOS_IMAC_SECURITY: FAIL <why>".
17set -u -o pipefail
18cd "$(dirname "$0")/.."
19HERE=$PWD
20P=$(cd "${PROD_ROOT:-.}" && pwd)
21K=native/kernel
22tag=AIENOS_IMAC_SECURITY
23bad=
24fail() { echo "${tag}: FAIL $*"; exit 1; }
25W=$(mktemp -d "${TMPDIR:-/tmp}/ck_imac_security.XXXXXX")
26trap 'rm -rf "$W"' EXIT
27T=$HERE/$K/x86/tests
28HCC=${HOSTCC:-cc}
29XCC=${X86CC:-x86_64-linux-gnu-gcc}
30run_x86() {
31 if [ "$(uname -m)" = x86_64 ]; then "$@"; else qemu-x86_64 "$@"; fi
32}
33# nice 19 on the shared Spark; the builds are small
34nice_() { nice -n 19 "$@"; }
35
36# 1. the courier (F1)
37nice_ $HCC -std=gnu11 -O2 -Wall -Wextra -Werror -DCK_COURIER_HOST -DCOURIER_X86_C="\"$P/$K/x86/courier_udp_x86.c\"" \
38 -I$P/$K/x86 -I$P/native/net -o "$W/courier" $T/courier_secret_test.c $P/native/net/aienos_net.c ||
39 fail "courier_secret_test does not build"
40"$W/courier" | grep -v '^courier: Ethernet' || bad="$bad courier_secret_test"
41
42# 2. the wizard and its adapter (F1)
43nice_ $XCC -std=gnu11 -O1 -static -Wall -Wextra -Werror -ffunction-sections -fdata-sections -Wl,--gc-sections \
44 -DSETUP_X86_C="\"$P/$K/x86/setup_x86.c\"" -I$P/$K/x86 -I$P/$K/svc -I$P/$K -I$P/$K/core -I$P/native/boot \
45 -I$P/native/disk -I$P/native/argus -I$P/$K/dev -I$P/$K/include -I$P/$K/ui \
46 -o "$W/setup" $T/setup_secret_test.c $P/$K/svc/setup_wizard.c $P/$K/svc/setup_inv.c ||
47 fail "setup_secret_test does not build"
48run_x86 "$W/setup" || bad="$bad setup_secret_test"
49
50# 3. the boot section (F2)
51nice_ $XCC -std=gnu11 -O1 -static -Wall -Wextra -Werror -ffunction-sections -fdata-sections -Wl,--gc-sections \
52 -DMEMORY_X86_C="\"$P/$K/x86/memory_x86.c\"" -I$P/$K/x86 -I$P/$K/svc -I$P/$K -I$P/$K/core -I$P/native/boot \
53 -I$P/native/disk -I$P/native/sig -I$P/native/argus -I$P/$K/dev -I$P/$K/include \
54 -o "$W/boot" $T/boot_verify_test.c $T/boot_verify_keys.c $P/native/boot/slot_select.c \
55 $P/native/sig/ed25519.c $P/native/sig/sha512.c $P/native/sig/ct.c $P/native/argus/sha256.c ||
56 fail "boot_verify_test does not build"
57run_x86 "$W/boot" || bad="$bad boot_verify_test"
58
59[ -z "$bad" ] || fail "red:$bad"
60echo "${tag}: PASS"