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 / crates / aienos-artifact-tool / fixtures / p2_5 / pack.sh

45 lines · 1902 bytes Raw Blame History
1#!/usr/bin/env bash
2# Pack and sign the P2-5 probes with the TEST ONLY SEED-0B identity into
3# OUT_DIR as P25EXEC.AIEN, P25WX.AIEN, P25SPIN.AIEN, and P25TAMP.AIEN
4# (P25EXEC with one payload byte flipped after signing). Also writes
5# OUT_DIR/ids.txt: "NAME ARTIFACT_ID" per signed probe.
6#
7# TOOL must be a debug aienos-artifact-tool built with
8# --features seed0b-test-signing (release builds refuse that feature).
9set -euo pipefail
10
11here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12tool="${1:?usage: pack.sh TOOL OUT_DIR}"
13out="${2:?usage: pack.sh TOOL OUT_DIR}"
14mkdir -p "${out}"
15: >"${out}/ids.txt"
16
17pack_one() { # probe, output name
18 local probe="$1" name="$2"
19 "${tool}" pack "${here}/${probe}/manifest.json" "${here}/${probe}/code.bin" \
20 "${here}/${probe}/data.bin" "${out}/${probe}.unsigned.aien" >/dev/null
21 "${tool}" sign "${out}/${probe}.unsigned.aien" "${out}/${name}" >/dev/null
22 rm -f "${out}/${probe}.unsigned.aien"
23 "${tool}" verify "${out}/${name}" >/dev/null
24 echo "${name} $("${tool}" id "${out}/${name}")" >>"${out}/ids.txt"
25}
26
27pack_one p25exec P25EXEC.AIEN
28pack_one p25wx P25WX.AIEN
29pack_one p25spin P25SPIN.AIEN
30
31# Tamper: flip the low bit of the first payload byte (first code byte) of
32# the signed P25EXEC. Its ArtifactId changes, so the signature must fail.
33cp "${out}/P25EXEC.AIEN" "${out}/P25TAMP.AIEN"
34payload_offset=$(od -An -tu4 -j56 -N4 "${out}/P25TAMP.AIEN" | tr -d ' ')
35byte=$(od -An -tu1 -j"${payload_offset}" -N1 "${out}/P25TAMP.AIEN" | tr -d ' ')
36printf "$(printf '\\%03o' $((byte ^ 1)))" |
37 dd of="${out}/P25TAMP.AIEN" bs=1 seek="${payload_offset}" conv=notrunc status=none
38if "${tool}" verify "${out}/P25TAMP.AIEN" >/dev/null 2>&1; then
39 echo "FAIL tampered probe still verifies" >&2
40 exit 1
41fi
42if cmp -s "${out}/P25EXEC.AIEN" "${out}/P25TAMP.AIEN"; then
43 echo "FAIL tampering did not change the file" >&2
44 exit 1
45fi