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 / pi5_unlock_req.sh

48 lines · 2346 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# pi5_unlock_req.sh -- write a THROWAWAY unlock request file for the PI5-4 qualification image
18# (make pi5-unlock-card). QUALIFICATION ONLY. Layout: native/kernel/core/unlock_req.h
19# (512 bytes: magic AIENUNQ1, version 1, flags 0, tag QUALIF-THROWAWAY, 32-byte secret, zero padding).
20#
21# pi5_unlock_req.sh <out file> [<secret file, exactly 32 bytes>]
22#
23# With no secret file, 32 random bytes come from /dev/urandom. Refuses an output path inside a git
24# checkout (a secret must never be committed) and an existing output file. The secret is never printed.
25# Use a different secret file to make a "wrong secret" request, or the same one to reopen.
26set -euo pipefail
27out="${1:?output file}"
28sec="${2:-}"
29[[ ! -e "${out}" ]] || { echo "refusing: ${out} exists" >&2; exit 1; }
30dir="$(cd "$(dirname "${out}")" && pwd)"
31if git -C "${dir}" rev-parse --git-dir >/dev/null 2>&1; then echo "refusing: ${dir} is inside a git checkout" >&2; exit 1; fi
32tmp="$(mktemp)"; trap 'rm -f "${tmp}"' EXIT
33if [[ -n "${sec}" ]]; then
34 [[ "$(stat -c %s "${sec}")" == 32 ]] || { echo "secret file must be exactly 32 bytes" >&2; exit 1; }
35 cp "${sec}" "${tmp}"
36else
37 head -c 32 /dev/urandom > "${tmp}"
38fi
39# not all zero, not one repeated byte (the kernel refuses those too)
40[[ "$(od -An -v -tx1 "${tmp}" | tr -s ' \n' '\n\n' | sort -u | grep -c .)" -gt 1 ]] || { echo "weak secret refused" >&2; exit 1; }
41umask 077
42{
43 printf 'AIENUNQ1\x01\x00\x00\x00\x00\x00\x00\x00QUALIF-THROWAWAY'
44 cat "${tmp}"
45 head -c 448 /dev/zero
46} > "${out}"
47[[ "$(stat -c %s "${out}")" == 512 ]] || { rm -f "${out}"; echo "internal error: size" >&2; exit 1; }
48echo "wrote ${out} (512 bytes, throwaway secret not shown)"