aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / scripts / pi5-8 / owner_pubkey_file.sh
| 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 | # owner_pubkey_file.sh -- PI5-8 Q2: turn an exported Ed25519 public key into the CK_OWNER_PUBKEYS file (PUBLIC material only). |
| 18 | # |
| 19 | # scripts/pi5-8/owner_pubkey_file.sh PUBKEY.pem OUTFILE ["comment text"] |
| 20 | # |
| 21 | # PUBKEY.pem is what the YubiKey tool exports (`yubico-piv-tool -a read-public-key -s 9c`, or the output of `-a generate`): |
| 22 | # a PEM SubjectPublicKeyInfo, DER = 12 fixed bytes 30 2a 30 05 06 03 2b 65 70 03 21 00 followed by the 32 raw key bytes. |
| 23 | # The conversion takes the last 32 bytes after checking those 12 bytes exactly, and writes the file format that |
| 24 | # native/kernel/tools/ck_owner_gen.c reads (native/kernel/README.md "Owner provisioning"): |
| 25 | # owner_root_ed25519 <64 lowercase hex> |
| 26 | # Prints the 64 hex digits on stdout and the sha256 of the file on stderr. Refuses anything that is not exactly an Ed25519 |
| 27 | # public key and an all-equal-bytes key. Never reads or writes secret material. Real owner files are never committed. |
| 28 | set -euo pipefail |
| 29 | pem="${1:?usage: owner_pubkey_file.sh PUBKEY.pem OUTFILE [comment]}"; out="${2:?outfile}"; comment="${3:-}" |
| 30 | case "${comment}" in *$'\n'*|*$'\r'*) echo "REFUSED: comment must be one line" >&2; exit 2;; esac |
| 31 | der="$(openssl pkey -pubin -in "${pem}" -outform DER 2>/dev/null | od -An -v -tx1 | tr -d ' \n')" \ |
| 32 | || { echo "REFUSED: ${pem} is not a PEM public key" >&2; exit 1; } |
| 33 | prefix=302a300506032b6570032100 |
| 34 | if [ "${#der}" != 88 ] || [ "${der:0:24}" != "${prefix}" ]; then |
| 35 | echo "REFUSED: ${pem} is not exactly an Ed25519 public key (SPKI prefix/length mismatch)" >&2; exit 1 |
| 36 | fi |
| 37 | hex="${der:24}" |
| 38 | if [ "$(fold -w2 <<<"${hex}" | sort -u | wc -l)" = 1 ]; then echo "REFUSED: all bytes equal (placeholder, not a key)" >&2; exit 1; fi |
| 39 | tmp="${out}.tmp.$$" |
| 40 | { |
| 41 | echo "# AIENOS owner public key. PUBLIC material only (the private key never leaves the YubiKey)." |
| 42 | [ -z "${comment}" ] || echo "# ${comment}" |
| 43 | echo "owner_root_ed25519 ${hex}" |
| 44 | } > "${tmp}" |
| 45 | mv "${tmp}" "${out}" |
| 46 | echo "owner file sha256 $(sha256sum < "${out}" | cut -d' ' -f1)" >&2 |
| 47 | echo "${hex}" |