interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tests / checker2 / owner_receipt.sh

84 lines · 5377 bytes Raw Blame History
1#!/bin/sh
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# Positive production case for OWNER receipts (spec/one-layer-receipts.md section 11, omega#446):
18# one receipt signed on Drake's YubiKey (owner root, PIV slot 9c) must be accepted by
19# `checker2 receipt verify --production`, and its tampered copies refused.
20#
21# Fixtures (tests/checker2/fixtures/owner-receipt, PROVENANCE.txt):
22# a01.ir, a01.code program and executable bytes of aienos osc_unit/vectors/a01_valid_min.unit
23# a01.owner-draft.rcpt `receipt issue --owner-draft` output: OWNER class, all-zero signature
24# a01.owner-draft.tbs `receipt tbs` output: the 65 bytes the YubiKey signs
25# a01.owner.sig the 64-byte Ed25519 signature made on the YubiKey (Drake)
26# a01.owner.rcpt `receipt attach` output: the signed receipt
27# Checks: the draft and the message are rebuilt by this checker2 and must be byte-identical (a changed
28# checker identity changes them, and the signed receipt must then be made again); the signed receipt is
29# the draft with exactly the committed signature in bytes [352, 416); production verify says VALID;
30# controls: a changed signature byte, a changed program hash, a wrong target, an expired epoch, a
31# revoked owner key and a wrong executable are each refused with their named reason.
32# Until the signature is committed the test FAILS with OWNER-RECEIPT PENDING: the gap stays visible.
33# Usage: owner_receipt.sh <checker2> <fixture-dir> <work-dir>
34set -u
35C2=$1 F=$2 W=$3
36TARGET=aienos-ck-aarch64-el0 EPOCH=20 EXPIRY=100 FLOOR=10
37OWNER_FP=$(od -An -tx1 -j320 -N32 "$F/a01.owner-draft.rcpt" | tr -d ' \n') # key fingerprint written by issue
38rm -rf "$W" && mkdir -p "$W" || exit 2
39fail=0 ctl=0
40bad() { echo "owner_receipt: FAIL $*"; fail=$((fail + 1)); }
41
42"$C2" receipt issue "$F/a01.ir" "$F/a01.code" --target $TARGET --epoch $EPOCH --expiry $EXPIRY \
43 --owner-draft "$W/draft.rcpt" || bad "issue --owner-draft"
44cmp -s "$W/draft.rcpt" "$F/a01.owner-draft.rcpt" || bad "owner draft is not byte-identical to the committed draft"
45"$C2" receipt tbs "$F/a01.owner-draft.rcpt" "$W/tbs" || bad "tbs"
46cmp -s "$W/tbs" "$F/a01.owner-draft.tbs" || bad "signed message is not byte-identical to the committed one"
47
48if [ ! -f "$F/a01.owner.rcpt" ] || [ ! -f "$F/a01.owner.sig" ]; then
49 echo "owner_receipt: OWNER-RECEIPT PENDING: no YubiKey-signed receipt committed yet (~/bin/owner-sign-receipt-test.sh)"
50 exit 1
51fi
52[ "$(wc -c <"$F/a01.owner.rcpt")" = 416 ] || bad "signed receipt is not 416 bytes"
53[ "$(wc -c <"$F/a01.owner.sig")" = 64 ] || bad "signature is not 64 bytes"
54head -c 352 "$F/a01.owner.rcpt" >"$W/head.signed"
55head -c 352 "$F/a01.owner-draft.rcpt" >"$W/head.draft"
56cmp -s "$W/head.signed" "$W/head.draft" || bad "signed receipt differs from the draft in the signed bytes"
57tail -c 64 "$F/a01.owner.rcpt" | cmp -s - "$F/a01.owner.sig" || bad "signed receipt does not carry the committed signature"
58# attach again from the committed draft and signature: verifies against the compiled-in owner root
59mkdir -p "$W/store"
60"$C2" receipt attach "$F/a01.owner-draft.rcpt" "$F/a01.owner.sig" --out-dir "$W/store" >"$W/attach.out" || bad "attach refuses the committed signature"
61cmp -s "$(sed -n 's/^receipt=//p' "$W/attach.out" | cut -d' ' -f1)" "$F/a01.owner.rcpt" || bad "attach does not rebuild the committed receipt"
62
63v() { "$C2" receipt verify "$1" "$F/a01.ir" "${2:-$F/a01.code}" --target "${3:-$TARGET}" --epoch "${4:-$EPOCH}" --floor $FLOOR $5; }
64out=$(v "$F/a01.owner.rcpt" "" "" "" --production)
65[ "$out" = receipt=VALID ] || bad "production verify: $out"
66out=$(v "$F/a01.owner.rcpt" "" "" "" "")
67[ "$out" = receipt=VALID ] || bad "default (production) verify: $out"
68
69# expect NAME WANT RECEIPT EXE TARGET EPOCH EXTRA (empty: the default)
70expect() {
71 n=$1 want=$2; shift 2
72 got=$(v "$@")
73 if [ "$got" = "receipt=$want" ]; then ctl=$((ctl + 1)); else bad "control $n: want $want, got $got"; fi
74}
75flip() { cat "$F/a01.owner.rcpt" >"$2"; printf '\377' | dd of="$2" bs=1 seek="$1" conv=notrunc status=none; }
76flip 400 "$W/sig.flip"; expect signature-byte BAD_SIGNATURE "$W/sig.flip" "" "" "" --production
77flip 48 "$W/prog.flip"; expect program-hash BAD_SIGNATURE "$W/prog.flip" "" "" "" --production
78expect wrong-target WRONG_TARGET "$F/a01.owner.rcpt" "" aarch64-linux-host "" --production
79expect expired EXPIRED "$F/a01.owner.rcpt" "" "" $((EXPIRY + 1)) --production
80expect revoked-key REVOKED "$F/a01.owner.rcpt" "" "" "" "--production --revoked-key $OWNER_FP"
81expect wrong-executable EXECUTABLE_MISMATCH "$F/a01.owner.rcpt" "$F/a01.ir" "" "" --production
82
83if [ "$fail" -ne 0 ]; then echo "owner_receipt: FAIL ($fail)"; exit 1; fi
84echo "owner_receipt: PASS owner-signed receipt VALID in production, $ctl controls refused"