Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/patches/18cdbbd4c89820f4 # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/aienux#377 (code only) closed derived `18cdbbd4c89820f4` #377 Imported from GitHub aien-dev/aienux#377 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `8f42b7cd1abefd5cd3a8db7c1e42d721831f752a` · Head `a59a76bf193d0fe9c8e39665d682d49dd35b9f7e` ### Apply it ``` git checkout -b patch-18cdbbd4c89820f4 8f42b7cd1abefd5cd3a8db7c1e42d721831f752a curl -fsSL https://interplane.io/drakestapleton/aienux/patches/18cdbbd4c89820f4.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/aienux 377 a59a76bf193d0fe9c8e39665d682d49dd35b9f7e ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aienux","number":377,"url":"https://github.com/aien-dev/aienux/pull/377","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:18Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index ff408632..fd7870c7 100644 --- a/.crumb +++ b/.crumb @@ -22,38 +22,38 @@ "children": [ { "digest": "8371189e943a695a50a5e06a13e1826dc479747bda53357bcdb98f632065156e", - "last_commit": "384171b", + "last_commit": "8f42b7c", "name": "crates", "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "4415112fa64d6a11e562de8d452287e1e51ceb08362c2200d37f05016a2b741e", - "last_commit": "384171b", + "digest": "bab9e0a60e846bd9392efe8c6d8d7ce40f53855c7b428587c22b75decdb80958", + "last_commit": "2a5d40f", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "10e9c2e0ebceb8e60113783dfa5c83ddaf7ef3fef3d700d6c489cae331117f11", - "last_commit": "e12e6f6", + "digest": "8d8b584b803ad58093160f159c4e02e90362ade480b066b0275b196471e59535", + "last_commit": "2a5d40f", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "ee6e3d66e3e3a4f85001de67fad6b5243b02c522a046f630b720feaf16d7822c", - "last_commit": "384171b", + "digest": "3acf9d9879c2376b99d9c9c569702af2c32c3bf8141334d034bedbca5599d5b0", + "last_commit": "2a5d40f", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:fcbf212859f600237624648892c23ea832edf50f1248e4c0f91c86cec675022b", - "compiled_at": "2026-10-14T02:42:53Z", + "children_root": "sha256:171dc60231d373593f5980a9f287b84913981201b52fc51d496a403809df6b55", + "compiled_at": "2026-10-14T02:50:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:47be77e2b25e75933a65368d45fcaaa1e9a0caf8b359ca31c286268a576ded35", + "digest": "sha256:ce1fbacef2ad2f1aa7a680de9256af1fdeb2c27dc81e3ca5f48f4111411df75c", "evidence_files": 156, "evidence_root": "sha256:cd53ab119be9de6ce28c4f5949b106c9622f1fe105611de3de21c3bce7932694", - "files": 3240, - "generated_at_commit": "384171b3fd2b66f08e15ec67cf0fa5dd5935ec16", - "source_tree": "sha256:6992cec0e6bbbd9b95042afd90aa45f5e011fb5f9f7e45563e1da885c329df4a" + "files": 3245, + "generated_at_commit": "2a5d40fb8714e3917e82215388e08865a579ecbb", + "source_tree": "sha256:11e41d280e8be4a8dacf8d0baea785dae7e79bdd9c0678b4f795b05366ea6b46" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 832793a6..3db6b129 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:491e93c09b6185b662afda8b29d24bb3ee81bc2aed9009757fdf4674d197be31", - "compiled_at": "2026-10-14T02:42:53Z", + "compiled_at": "2026-10-14T02:50:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:4415112fa64d6a11e562de8d452287e1e51ceb08362c2200d37f05016a2b741e", + "digest": "sha256:bab9e0a60e846bd9392efe8c6d8d7ce40f53855c7b428587c22b75decdb80958", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 87, - "generated_at_commit": "384171b3fd2b66f08e15ec67cf0fa5dd5935ec16", - "source_tree": "sha256:6afdbd5bf5f90e4a8d8496fdc81202d9b3e6471f24326042e5a03366ee0d3d85" + "files": 88, + "generated_at_commit": "2a5d40fb8714e3917e82215388e08865a579ecbb", + "source_tree": "sha256:0e9765d592810977a376de2074ea500f6b498fc2c65008283a59a34b2682ec89" }, "owner_lane": "", "provenance": { diff --git a/docs/native/PI5-8-OWNER-CEREMONY.md b/docs/native/PI5-8-OWNER-CEREMONY.md new file mode 100644 index 00000000..1a5475e2 --- /dev/null +++ b/docs/native/PI5-8-OWNER-CEREMONY.md @@ -0,0 +1,144 @@ +# PI5-8 Q2: the owner-key ceremony (prepared, NOT performed) + +Status: prepared and rehearsed with software keys only. No owner key exists. Nothing was written to any YubiKey. The real +ceremony is run once, by Drake, on the Spark with the network down. + +## What this is + +The OWNER key is an Ed25519 key made inside Drake's YubiKey (PIV application, slot 9c, YubiKey 5C NFC, firmware 5.7.4). The +private half never leaves the device. It does two jobs: + +1. It signs the PI5-8 receipts manifest (`scripts/pi5_receipts_manifest.sh`), so anyone can check the Pi test evidence + was approved by the owner. +2. Its public half is the owner public key built into images: `make -C native/kernel full CK_HARDWARE_STAGING=1 + CK_OWNER_PUBKEYS= CK_MACHINE_ID=` (see `native/kernel/README.md`, "Owner provisioning"). + +It is NOT the public-release signing key. That key is generated only at the first public release and is not touched here. + +## Tools (installed on the Spark, verified) + +Ubuntu 24.04's packages are too old: yubico-piv-tool 2.2.0 and yubikey-manager 5.2.1. Yubico's own yubico-piv-tool NEWS lists +"Add support for ED25519 and X25519 key types. Available in firmware 5.7.0 and newer" in 2.5.0 (2024-01-31), so Ed25519 needs +yubico-piv-tool 2.5.0 or newer and a YubiKey with firmware 5.7 or newer. Drake's key is 5.7.4. + +| Tool | Version | Source | sha256 | +| --- | --- | --- | --- | +| yubico-piv-tool | 2.7.3 (2026-01-20, newest release) | https://developers.yubico.com/yubico-piv-tool/Releases/yubico-piv-tool-2.7.3.tar.gz, built from source | fcb25c42f54298ece8b20684fb3c581ed9195a162cbc55180a4161501be93181 | +| tarball signature | good, key A8CE 1679 14EE E232 B923 7B54 10CA C496 2E03 C7CC, a subkey of 1D73 08B0 055F 5AEF 3694 4A8F 27A9 C24D 9588 EA0F, which is on https://developers.yubico.com/Software_Projects/Software_Signing.html | | | +| yubikey-manager (ykman) | 5.9.2 (2026-06-30) | PyPI, in a private virtual environment (used for read-only status and checks) | wheel 19a1173106b104bea37722e61ce748fb2d39c87a02880c1964461837ddaa7fba | +| pcscd | 2.0.3 (Ubuntu) | apt | | + +`scripts/pi5-8/install_owner_tools.sh` repeats the whole install and refuses if the tarball sha256 or the OpenPGP signature +does not match. It installs under `~/.local`. The smart card service on this Spark also needed one small permission rule so a +non-graphical login may talk to the card reader: `/etc/polkit-1/rules.d/49-aienos-pcsc-drake.rules` (allows user drakestapleton +only the two pcsc actions). + +## Signing design: what exact bytes the YubiKey signs + +PIV Ed25519 is pure Ed25519 (RFC 8032): the YubiKey signs the message it is sent, with no hash wrapper, and returns the 64-byte +signature. `yubico-piv-tool --sign -A ED25519` sends the raw input file and refuses input of 3072 bytes or more +(`YKPIV_OBJ_MAX_SIZE`, "File too big"). A real manifest is longer than that, and the card's own limit is not documented in +what we could read. So the key signs a small FIXED STATEMENT that binds the manifest. Exactly four lines, each ending in LF: + +``` +AIENOS-OWNER-STATEMENT-V1 +purpose pi5-8-receipts-manifest +manifest_bytes +manifest_sha256 <64 lowercase hex, sha256 of the manifest bytes> +``` + +`native/kernel/tools/ck_manifest_sig.c` builds and checks these bytes: + +- `statement MANIFEST OUT` writes the statement (this is the file the YubiKey signs). +- `verify MANIFEST SIG PUBKEYHEX` rebuilds the statement from the manifest it is given and checks a plain Ed25519 + signature over it with the in-tree verifier. Change one manifest byte and the statement changes, so the signature fails. +- `sign-test` signs the statement with the public RFC 8032 TEST 1 key (output says TEST ONLY). + +A signature over the raw manifest bytes (the Q6 scheme) is no longer accepted. `scripts/ck_pi5_manifest_check.sh` proves: +statement bytes equal the spec and an independent `sha256sum`; TEST key round trip; tampered manifest, tampered signature, +wrong key and a raw-manifest signature all fail; an openssl Ed25519 software key (TEST, standing in for the YubiKey) +signs the statement and the in-tree verifier accepts it. That is two independent Ed25519 implementations agreeing. + +UNVERIFIED until the real ceremony: that this YubiKey firmware returns exactly the pure Ed25519 signature over those bytes. +The ceremony checks it in step 6 and stops if the two verifiers do not agree. + +## Owner public key file + +The YubiKey exports the public key as PEM (SubjectPublicKeyInfo). For Ed25519 the DER form is 12 fixed bytes +`30 2a 30 05 06 03 2b 65 70 03 21 00` followed by the 32 key bytes. `scripts/pi5-8/owner_pubkey_file.sh PUBKEY.pem OUTFILE +["comment"]` checks those 12 bytes exactly (anything else, such as RSA, P-256, X25519 or an all-equal key, is refused), takes the +32 bytes and writes the file the image build reads: + +``` +# AIENOS owner public key. PUBLIC material only ... +owner_root_ed25519 <64 lowercase hex> +``` + +It prints the sha256 of the file. The ceremony then runs the same checker the image build uses (`ck_owner_gen`), which also +refuses the RFC 8032 TEST keys. + +Pi images: the Makefile deliberately refuses `CK_HARDWARE_STAGING` together with any `CK_PI5*` flag, so there is no Pi image with +an owner key today (every Pi image is a TEST-key qualification tier). `scripts/ck_pi5_owner_check.sh` therefore proves the owner +file on the hardware staging image (`make full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS=...`): the image carries the owner public +key; it has no `artifact_trust: seed0b-test qualification build ... TEST ONLY` banner, no TEST Store label, no TEST machine id; +the TEST-anchor image is the positive control (has the banner, not the key); and the Makefile refuses a TEST key as owner key and +refuses mixing the owner image with the Pi or TEST-anchor tiers. + +## Drake's step list (real ceremony), about 25 minutes + +Before (can be done days earlier, 10 minutes, network may be up): + +1. On paper, write three things: the new PIN (6 to 8 characters, letters and digits allowed), the new PUK (6 to 8 characters) and + a management key. For the management key open a terminal and type `openssl rand -hex 32`; it prints 64 letters and digits + (0-9 and a-f). Copy it onto the paper by hand. Keep the paper in a safe place. (It prints a secret on screen once; that is + the only time.) +2. Rehearse: in a terminal in the repository type `scripts/pi5-8/owner_ceremony.sh --dry-run`. It uses a software key, never + touches the YubiKey, and ends with `CEREMONY_DRY_RUN: PASS`. + +The ceremony (sit at the Spark keyboard and screen, not over a remote login): + +3. Plug the YubiKey into the Spark. Unplug the network cable and turn Wi-Fi off. Wait ten seconds. +4. Type `scripts/pi5-8/owner_ceremony.sh --real` and press Enter. If you see `REFUSED: the Spark is still online`, the network is + not fully down: nothing was touched, fix it and run it again. +5. The screen shows the YubiKey model, serial number and firmware. Compare the serial with the one on your key. Type `YES`. +6. It asks for the new PIN twice, the new PUK twice, and the new management key twice (type from your paper; nothing shows on + screen while you type). It stops if any of them is still the factory value afterwards. +7. It asks for the management key once more and creates the key inside the YubiKey. You see `Successfully generated a new private key.` +8. It shows the public key, the owner file hash, and then says the key will sign a test text: type the PIN and TOUCH the metal + contact of the key when it blinks. +9. You see `Signature verified two ways`, `A changed manifest is refused, as it must be.` and `CEREMONY_REAL: PASS`. +10. Reconnect the network. Copy `owner-pubkeys.txt` and `owner-pubkeys.txt.sha256` from the folder it names (under + `~/aienos-owner-ceremony/`). They are public. Write the sha256 on the paper too. + +Later, to sign the PI5-8 manifest with the YubiKey: `scripts/pi5_receipts_manifest.sh --all > manifest.txt`, then +`scripts/pi5-8/owner_ceremony.sh --sign-manifest manifest.txt manifest.sig owner-pubkeys.txt` (PIN, then touch). It first checks +that the key in the slot is the owner key in the file, and verifies the signature before finishing. + +What the real mode writes to the YubiKey: new PIN, new PUK, new management key, and one key in slot 9c. It refuses if slot 9c +already holds a key and never overwrites one. It never receives, shows or stores a PIN, PUK or management key: the YubiKey tool +asks for them on the terminal. The only values it passes itself are the public factory defaults (PIN 123456, PUK 12345678), and +only while the YubiKey still reports the factory values. + +State of Drake's YubiKey when this was prepared (read-only checks on 2026-10-13): PIV PIN tries 3 of 3, PUK tries 3 of 3, PIN, PUK and +management key all still the FACTORY defaults (management key algorithm AES192), no certificates, and every key slot empty. + +## If something goes wrong + +- Wrong PIN three times: the PIN is blocked. Unblock it with the PUK: `yubico-piv-tool -a unblock-pin` (asks for the PUK, then a + new PIN). Do not guess further. +- Wrong PUK three times as well: the PIV application can only be reset (`ykman piv reset`), which ERASES the owner key. Do that + only on Drake's say. A new ceremony then makes a NEW owner key, so images and signatures made with the old key stop being trusted. +- Lost or broken YubiKey: the owner key is gone; run a new ceremony with a new key and rebuild what carries the public key. +- Touch missed: the signing step fails; run it again. Nothing was damaged. +- The management key typed wrong once is harmless; there is no retry counter on it. If it is truly lost, the only remedy is the + reset above, so keep the paper. +- The PAPER RECOVERY SECRET is a different thing. It is the Store backup (PD1: paper backup plus YubiKey unlock) and is not in the + YubiKey and not made here. Losing the YubiKey does not lose it; losing the YubiKey does mean the owner key must be redone. + +## What is NOT done + +- No owner key exists yet. Nothing was written to Drake's YubiKey (only read-only commands were run: `ykman info`, `ykman piv info`, + `yubico-piv-tool -a list-readers`, `-a version`, `-a status`). +- No release signing key: it is generated only at the first public release. +- No machine id or Store uuid file, no image built with a real owner key, no manifest signed for real. +- No Pi run. The real mode and the YubiKey signing bytes are UNVERIFIED on hardware; the dry run and the tests use software keys only. diff --git a/docs/native/PI5-8-QUALIFICATION.md b/docs/native/PI5-8-QUALIFICATION.md index 0522266e..994fd7f1 100644 --- a/docs/native/PI5-8-QUALIFICATION.md +++ b/docs/native/PI5-8-QUALIFICATION.md @@ -50,13 +50,16 @@ lines picked by the checked-in table `scripts/pi5_receipts_verdicts.tsv` (PI5-3 PI5-6 infer and G1-G3, PI5-7 L1-L3, power cut P1, artifact a1 and a2, pi5-pcie-1, pi5-net-1, pi5-net-3-r1). It refuses to print anything if a folder is missing, a field is absent or a table row matches no line. Plain ASCII, LF only, no timestamps or paths. -Signing design: the signature is a detached Ed25519 signature (RFC 8032, 64 raw bytes) over the exact manifest bytes. -`native/kernel/tools/ck_manifest_sig.c verify MANIFEST SIG PUBKEYHEX` checks it with the in-tree verifier; its only signing -command, `sign-test`, uses the public RFC 8032 TEST 1 key and says TEST ONLY. `scripts/ck_pi5_manifest_check.sh` proves the -round trip (and that a tampered manifest, a tampered signature and a different key all fail). +Signing design (updated for the owner YubiKey, see `docs/native/PI5-8-OWNER-CEREMONY.md`): PIV Ed25519 signs only a small message, +so the owner signs a fixed four-line ASCII statement that binds the manifest by its length and sha256; the signature is a plain +Ed25519 signature (RFC 8032, 64 raw bytes) over those statement bytes. `native/kernel/tools/ck_manifest_sig.c verify MANIFEST SIG +PUBKEYHEX` rebuilds the statement from the manifest and checks it with the in-tree verifier; its only signing command, +`sign-test`, uses the public RFC 8032 TEST 1 key and says TEST ONLY. `scripts/ck_pi5_manifest_check.sh` proves the round trip (a +tampered manifest, a tampered signature, a different key and a signature over the raw manifest all fail; an openssl TEST key +signature verifies too). ## Limits -- All Pi evidence is one Pi, one card, TEST keys. The manifest is unsigned for real: only a TEST signature was made. +- All Pi evidence is one Pi, one card, TEST keys. The manifest is unsigned for real: only a TEST signature was made. The owner-key ceremony is prepared and rehearsed (software keys) but not performed. - Run folders live on the Spark (`~/workspace/pi5-runs`), not in the repository; the manifest records their hashes. - The Pi image tier change affects every Pi image that links the artifact loader (none of the other Pi images presents candidates). diff --git a/native/.crumb b/native/.crumb index 83857bfa..1cc34eae 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "48357362d2e3f9fa0d22b866d4503fa63953378c4841d5c87c64797bc77932c6", - "last_commit": "c31f632", + "digest": "4b6595e55bb546c4d40de5188663a10b77dd3dd9932b57f17f839f8096836383", + "last_commit": "2a5d40f", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, @@ -109,15 +109,15 @@ "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:6a6528f2ebd9224370f98ec6bb454dfcdf6e3adddb0c32966ff52acea7bb1c64", - "compiled_at": "2026-10-14T02:20:15Z", + "children_root": "sha256:58b7ad9498fde99882d542de6809e662d076a5680abbb6446d673b3de0ee1db3", + "compiled_at": "2026-10-14T02:50:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:10e9c2e0ebceb8e60113783dfa5c83ddaf7ef3fef3d700d6c489cae331117f11", + "digest": "sha256:8d8b584b803ad58093160f159c4e02e90362ade480b066b0275b196471e59535", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", "files": 562, - "generated_at_commit": "7cd74cbbd0a45def4384618e7f82513c76021aad", - "source_tree": "sha256:df21964cda544ea6321f93e03355d98405d1626fd8d1876096e71b65c9ffaede" + "generated_at_commit": "2a5d40fb8714e3917e82215388e08865a579ecbb", + "source_tree": "sha256:3bbd01bb70304e837f00086ca0b2646f4a113ac759671ce6db8753053a7cd28b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 71c59069..bf8a9f7a 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -52,13 +52,13 @@ }, { "digest": "29a3372d4ab6170718cb870e8d586c94f9828a20755277bf052588376e47333e", - "last_commit": "c31f632", + "last_commit": "e12e6f6", "name": "artifact", "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { "digest": "9333ad224a18c87c3e0e241c69209b761a27f72d7f2067354f0658b917cd77ef", - "last_commit": "c31f632", + "last_commit": "e12e6f6", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, @@ -88,26 +88,26 @@ }, { "digest": "67f43d00adce9780c2ae75ece209ac453a1b9debc74d735d9acdb72f36e6df77", - "last_commit": "c31f632", + "last_commit": "e12e6f6", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { - "digest": "f3d6c345756daa6db11e27a2f19d4c1f3ff0101cb999ff08a6c938a7cc031969", - "last_commit": "c31f632", + "digest": "8c9d6edb01cdf61cdbeb1399e07e4bf4e506dc841c798db8a03e4ef86efb0a8e", + "last_commit": "2a5d40f", "name": "tools", "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin" } ], - "children_root": "sha256:a54967a5384a7acacb8b4f5532afdcd4be6c0e5b0eb1af9b693bfbb688a81574", - "compiled_at": "2026-10-14T02:20:15Z", + "children_root": "sha256:07df85f4c5f2c7c519b2d0c0e9a94cdabf029ba6935c68d7af30c1076a8dcbec", + "compiled_at": "2026-10-14T02:50:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:48357362d2e3f9fa0d22b866d4503fa63953378c4841d5c87c64797bc77932c6", + "digest": "sha256:4b6595e55bb546c4d40de5188663a10b77dd3dd9932b57f17f839f8096836383", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 381, - "generated_at_commit": "7cd74cbbd0a45def4384618e7f82513c76021aad", - "source_tree": "sha256:2f910836a1405c22674d09861b8b357f0f25cb41dd1a4ac35176e583005c331d" + "generated_at_commit": "2a5d40fb8714e3917e82215388e08865a579ecbb", + "source_tree": "sha256:ca852832288b60fe1665cd76bdac4a08f2ed10eb59b3c7c53b7509d808a9bf4c" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/README.md b/native/kernel/README.md index 7b1bab7c..e03588fe 100644 --- a/native/kernel/README.md +++ b/native/kernel/README.md @@ -58,6 +58,8 @@ of them: refuses the RFC 8032 TEST 1/2/3 public keys, the TEST machine id, the TEST store uuid, all-equal bytes, wrong lengths, non-hex, duplicates and unknown names. Real owner files are never committed. + The owner file for a YubiKey-held owner key is made by `scripts/pi5-8/owner_pubkey_file.sh` from the exported PIV public key + (`docs/native/PI5-8-OWNER-CEREMONY.md`, gate `scripts/ck_pi5_owner_check.sh`). - What the image uses: the machine id becomes the ARGUS machine id, the store uuid the boot Store uuid, and the boot log prints a SHA-256 fingerprint of the owner root key. Nothing in the kernel verifies with the owner root key diff --git a/native/kernel/tools/.crumb b/native/kernel/tools/.crumb index a55976d6..ba4ab79d 100644 --- a/native/kernel/tools/.crumb +++ b/native/kernel/tools/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-14T01:54:45Z", + "compiled_at": "2026-10-14T02:50:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:f3d6c345756daa6db11e27a2f19d4c1f3ff0101cb999ff08a6c938a7cc031969", + "digest": "sha256:8c9d6edb01cdf61cdbeb1399e07e4bf4e506dc841c798db8a03e4ef86efb0a8e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 23, - "generated_at_commit": "8307a68a2eedcc5c8d6c2a6ffbf7c12f398c094b", - "source_tree": "sha256:a756674e9c3048b930ddacd4151b5812999d5fefa5a19ea392a860a63d372bf1" + "generated_at_commit": "2a5d40fb8714e3917e82215388e08865a579ecbb", + "source_tree": "sha256:a4088fd76a9a7a60a880a119738e4ff7f51d2cc47e03122366510f2f0d6d6352" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tools/ck_manifest_sig.c b/native/kernel/tools/ck_manifest_sig.c index 46a6a433..d8bbf0e9 100644 --- a/native/kernel/tools/ck_manifest_sig.c +++ b/native/kernel/tools/ck_manifest_sig.c @@ -1,17 +1,31 @@ -/* ck_manifest_sig.c -- PI5-8 Q6: detached Ed25519 signature over the exact bytes of a Pi receipts manifest - * (scripts/pi5_receipts_manifest.sh), using the in-tree Ed25519 (native/sig, RFC 8032 pure Ed25519). +/* ck_manifest_sig.c -- PI5-8: owner signature over a Pi receipts manifest (scripts/pi5_receipts_manifest.sh), + * using the in-tree Ed25519 (native/sig, RFC 8032 pure Ed25519) and SHA-256 (native/argus). * - * ck_manifest_sig verify MANIFEST SIG PUBKEYHEX exit 0 only if SIG (64 raw bytes) is valid over MANIFEST - * ck_manifest_sig sign-test MANIFEST SIGOUT signs with the PUBLIC RFC 8032 TEST 1 secret key + * ck_manifest_sig statement MANIFEST OUT writes the fixed signed statement for MANIFEST + * ck_manifest_sig verify MANIFEST SIG PUBKEYHEX exit 0 only if SIG (64 raw bytes) is a valid Ed25519 + * signature over the statement rebuilt from MANIFEST + * ck_manifest_sig sign-test MANIFEST SIGOUT signs that statement with the PUBLIC RFC 8032 TEST 1 secret key * - * There is deliberately no way to sign with any other key: no key file, no key argument. An owner or release - * signature will be made by the owner's own signing tool; this tool only verifies those. "sign-test" exists to - * prove the manifest bytes are signable and verifiable, and its output says TEST ONLY. */ + * WHAT IS SIGNED (design, docs/native/PI5-8-OWNER-CEREMONY.md): the owner key lives in a YubiKey PIV slot. The PIV + * Ed25519 operation signs the message it is handed (pure Ed25519) but the tool and the card take only a small + * message (yubico-piv-tool: under 3072 bytes), and a manifest can be longer. So the owner signs a fixed ASCII + * statement of four LF-terminated lines that binds the manifest by its length and sha256: + * + * AIENOS-OWNER-STATEMENT-V1 + * purpose pi5-8-receipts-manifest + * manifest_bytes + * manifest_sha256 <64 lowercase hex> + * + * The verifier rebuilds those bytes from the manifest it is given and checks a plain Ed25519 signature over them, + * so any change to the manifest changes the statement and the signature fails. There is deliberately no way to + * sign with any other key: no key file, no key argument. An owner signature is made by the YubiKey; this tool only + * verifies it. "sign-test" exists to prove the statement is signable and verifiable, and its output says TEST ONLY. */ #include #include #include #include #include "aienos_sig.h" +#include "sha256.h" /* RFC 8032 section 7.1 TEST 1 (public, published in the RFC; protects nothing). */ static const char *const TEST1_SK = "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"; @@ -63,10 +77,44 @@ static uint8_t *readf(const char *path, size_t *n) return p; } +/* Rebuild the signed statement for a manifest. Returns its length (fixed size for a given manifest length class). */ +static size_t statement_of(const uint8_t *m, size_t mn, char *out, size_t cap) +{ + uint8_t d[SHA256_DIGEST_SIZE]; + char hex[2 * SHA256_DIGEST_SIZE + 1]; + sha256_hash(m, mn, d); + for (size_t i = 0; i < SHA256_DIGEST_SIZE; i++) + snprintf(hex + 2 * i, 3, "%02x", d[i]); + int n = snprintf(out, cap, + "AIENOS-OWNER-STATEMENT-V1\npurpose pi5-8-receipts-manifest\nmanifest_bytes %zu\nmanifest_sha256 %s\n", mn, + hex); + if (n <= 0 || (size_t)n >= cap) { + fprintf(stderr, "error: statement does not fit\n"); + exit(2); + } + return (size_t)n; +} + +static int writef(const char *path, const void *p, size_t n) +{ + FILE *f = fopen(path, "wb"); + if (!f || fwrite(p, 1, n, f) != n || fclose(f)) { + fprintf(stderr, "error: cannot write %s\n", path); + return -1; + } + return 0; +} + int main(int argc, char **argv) { uint8_t sig[64], pk[32], sk[32]; size_t mn, sn; + char st[256]; + if (argc == 4 && !strcmp(argv[1], "statement")) { + uint8_t *m = readf(argv[2], &mn); + size_t n = statement_of(m, mn, st, sizeof st); + return writef(argv[3], st, n) ? 2 : 0; + } if (argc == 5 && !strcmp(argv[1], "verify")) { uint8_t *m = readf(argv[2], &mn); uint8_t *s = readf(argv[3], &sn); @@ -75,11 +123,12 @@ int main(int argc, char **argv) return 2; } memcpy(sig, s, 64); - if (aienos_ed25519_verify(sig, m, mn, pk) != AIENOS_SIG_OK) { - printf("MANIFEST_SIG: FAIL signature does not verify (%zu manifest bytes)\n", mn); + size_t n = statement_of(m, mn, st, sizeof st); + if (aienos_ed25519_verify(sig, (const uint8_t *)st, n, pk) != AIENOS_SIG_OK) { + printf("MANIFEST_SIG: FAIL signature does not verify over the statement for these %zu manifest bytes\n", mn); return 1; } - printf("MANIFEST_SIG: PASS signature verifies over %zu manifest bytes, public key %s%s\n", mn, + printf("MANIFEST_SIG: PASS signature verifies over the statement binding %zu manifest bytes, public key %s%s\n", mn, argv[4], strcmp(argv[4], TEST1_PK) ? "" : " (RFC 8032 TEST 1 key: TEST ONLY, not an owner or release key)"); return 0; } @@ -91,19 +140,17 @@ int main(int argc, char **argv) fprintf(stderr, "error: RFC 8032 TEST 1 key self-check failed\n"); return 2; } - if (aienos_ed25519_sign(sig, m, mn, sk) != AIENOS_SIG_OK) { + size_t n = statement_of(m, mn, st, sizeof st); + if (aienos_ed25519_sign(sig, (const uint8_t *)st, n, sk) != AIENOS_SIG_OK) { fprintf(stderr, "error: sign failed\n"); return 2; } - FILE *f = fopen(argv[3], "wb"); - if (!f || fwrite(sig, 1, 64, f) != 64 || fclose(f)) { - fprintf(stderr, "error: cannot write %s\n", argv[3]); + if (writef(argv[3], sig, 64)) return 2; - } - printf("MANIFEST_SIGN: TEST ONLY, signed %zu manifest bytes with the public RFC 8032 TEST 1 key %s " + printf("MANIFEST_SIGN: TEST ONLY, signed the statement for %zu manifest bytes with the public RFC 8032 TEST 1 key %s " "(not an owner or release key)\n", mn, TEST1_PK); return 0; } - fprintf(stderr, "usage: ck_manifest_sig verify MANIFEST SIG PUBKEYHEX | sign-test MANIFEST SIGOUT\n"); + fprintf(stderr, "usage: ck_manifest_sig statement MANIFEST OUT | verify MANIFEST SIG PUBKEYHEX | sign-test MANIFEST SIGOUT\n"); return 2; } diff --git a/scripts/.crumb b/scripts/.crumb index 1bfff038..2037d48c 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-14T02:42:53Z", + "compiled_at": "2026-10-14T02:50:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:ee6e3d66e3e3a4f85001de67fad6b5243b02c522a046f630b720feaf16d7822c", + "digest": "sha256:3acf9d9879c2376b99d9c9c569702af2c32c3bf8141334d034bedbca5599d5b0", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 108, - "generated_at_commit": "384171b3fd2b66f08e15ec67cf0fa5dd5935ec16", - "source_tree": "sha256:79826a61372ffaa6c49f90f9adc677b5dcae75287f6f78dfbfd824059494322b" + "files": 112, + "generated_at_commit": "2a5d40fb8714e3917e82215388e08865a579ecbb", + "source_tree": "sha256:ca8e818343594e297f2add42a2e75332d5c54147e7f997f61562dd844fd906a9" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_pi5_manifest_check.sh b/scripts/ck_pi5_manifest_check.sh index 16f9b6b5..e06208bb 100755 --- a/scripts/ck_pi5_manifest_check.sh +++ b/scripts/ck_pi5_manifest_check.sh @@ -2,8 +2,10 @@ # ck_pi5_manifest_check.sh -- PI5-8 Q6 gate: the receipts manifest tool and its TEST-key signature round trip. # 1. synthetic run folders -> manifest; second run gives identical bytes; order of arguments does not matter; # 2. a missing run folder, an absent verdict line and an unknown run tag each make the tool fail with no output; -# 3. sign the manifest with the public RFC 8032 TEST 1 key (TEST ONLY) and verify with the in-tree Ed25519; -# a flipped manifest byte, a flipped signature byte and a different public key must all fail to verify. +# 3. the owner signs a fixed statement binding the manifest length and sha256 (PIV Ed25519 takes a small message only); +# sign with the public RFC 8032 TEST 1 key (TEST ONLY) and verify with the in-tree Ed25519; a flipped manifest byte, +# a flipped signature byte, a different public key and a signature over the raw manifest must all fail to verify; +# 4. an openssl Ed25519 SOFTWARE key (TEST, stands in for the YubiKey) signs the statement and the tool verifies it. # No owner or release key is generated or used. Set PI5_RUNS= to also build the manifest of real runs. set -euo pipefail root="$(cd "$(dirname "$0")/.." && pwd)" @@ -11,8 +13,8 @@ tmp="$(mktemp -d)"; trap 'rm -rf "${tmp}"' EXIT fail=0 ok() { echo "PASS $*"; } bad() { echo "FAIL $*"; fail=1; } -cc -std=gnu11 -O1 -Wall -Wextra -Werror -I"${root}/native/sig" -o "${tmp}/sig" \ - "${root}/native/kernel/tools/ck_manifest_sig.c" "${root}/native/sig/ed25519.c" "${root}/native/sig/sha512.c" "${root}/native/sig/ct.c" +cc -std=gnu11 -O1 -Wall -Wextra -Werror -I"${root}/native/sig" -I"${root}/native/argus" -o "${tmp}/sig" \ + "${root}/native/kernel/tools/ck_manifest_sig.c" "${root}/native/sig/ed25519.c" "${root}/native/sig/sha512.c" "${root}/native/sig/ct.c" "${root}/native/argus/sha256.c" mk() { # tag efi commit log-lines... local t="$1" e="$2" c="$3"; shift 3 mkdir -p "${tmp}/runs/${t}" @@ -36,8 +38,13 @@ if "${M}" -t "${tmp}/t2.tsv" "${tmp}/runs/pi5-x1" > "${tmp}/o" 2>"${tmp}/e"; the if "${M}" -t "${tmp}/t.tsv" "${tmp}/runs/pi5-x1" "${tmp}/runs/pi5-x2" "${tmp}/runs/pi5-x1" > "${tmp}/o3" 2>/dev/null && cmp -s "${tmp}/o3" "${tmp}/m1"; then ok "duplicate folder argument is folded"; else bad "duplicate folder"; fi mkdir -p "${tmp}/runs/pi5-x3"; cp "${tmp}/runs/pi5-x1/"* "${tmp}/runs/pi5-x3/" if "${M}" -t "${tmp}/t.tsv" "${tmp}/runs/pi5-x3" > "${tmp}/o" 2>/dev/null; then bad "run tag without table rows accepted"; else ok "run tag without table rows refused"; fi -# TEST-key signature round trip over the exact manifest bytes +# TEST-key signature round trip over the statement that binds the manifest TPK=d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a +# the statement is exactly four LF lines and agrees with an independent sha256sum +"${tmp}/sig" statement "${tmp}/m1" "${tmp}/m1.st" +want="$(printf 'AIENOS-OWNER-STATEMENT-V1\npurpose pi5-8-receipts-manifest\nmanifest_bytes %s\nmanifest_sha256 %s\n' "$(wc -c < "${tmp}/m1")" "$(sha256sum < "${tmp}/m1" | cut -d' ' -f1)"; echo x)" +got="$(cat "${tmp}/m1.st"; echo x)" +if [ "${want}" = "${got}" ] && [ "$(wc -l < "${tmp}/m1.st")" = 4 ]; then ok "statement bytes match the spec and sha256sum"; else bad "statement bytes"; fi "${tmp}/sig" sign-test "${tmp}/m1" "${tmp}/m1.sig" | tee "${tmp}/s.out" grep -q "TEST ONLY" "${tmp}/s.out" && ok "sign-test says TEST ONLY" || bad "sign-test label" "${tmp}/sig" verify "${tmp}/m1" "${tmp}/m1.sig" "${TPK}" | tee "${tmp}/v.out" && grep -q "^MANIFEST_SIG: PASS" "${tmp}/v.out" && ok "signature verifies with the in-tree Ed25519" || bad "verify" @@ -46,6 +53,16 @@ if "${tmp}/sig" verify "${tmp}/m1.bad" "${tmp}/m1.sig" "${TPK}" >/dev/null; then cp "${tmp}/m1.sig" "${tmp}/s.bad"; printf 'Z' | dd of="${tmp}/s.bad" bs=1 seek=10 conv=notrunc 2>/dev/null if "${tmp}/sig" verify "${tmp}/m1" "${tmp}/s.bad" "${TPK}" >/dev/null; then bad "tampered signature verified"; else ok "tampered signature fails to verify"; fi if "${tmp}/sig" verify "${tmp}/m1" "${tmp}/m1.sig" 3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c >/dev/null; then bad "wrong key verified"; else ok "wrong public key fails to verify"; fi +# a signature over the raw manifest (the old, pre-statement scheme) must not verify +openssl genpkey -algorithm ED25519 -out "${tmp}/sw.pem" 2>/dev/null +SWPK="$(openssl pkey -in "${tmp}/sw.pem" -pubout -outform DER | tail -c 32 | od -An -v -tx1 | tr -d ' \n')" +openssl pkeyutl -sign -rawin -inkey "${tmp}/sw.pem" -in "${tmp}/m1" -out "${tmp}/raw.sig" +if "${tmp}/sig" verify "${tmp}/m1" "${tmp}/raw.sig" "${SWPK}" >/dev/null; then bad "raw-manifest signature verified"; else ok "signature over the raw manifest is refused"; fi +# TEST software key standing in for the YubiKey: sign the statement bytes, verify through the tool +openssl pkeyutl -sign -rawin -inkey "${tmp}/sw.pem" -in "${tmp}/m1.st" -out "${tmp}/sw.sig" +"${tmp}/sig" verify "${tmp}/m1" "${tmp}/sw.sig" "${SWPK}" | tee "${tmp}/sv.out" +grep -q "^MANIFEST_SIG: PASS" "${tmp}/sv.out" && ok "openssl software key (TEST) signature over the statement verifies" || bad "software key verify" +if "${tmp}/sig" verify "${tmp}/m1.bad" "${tmp}/sw.sig" "${SWPK}" >/dev/null; then bad "software signature verified a tampered manifest"; else ok "software signature fails on a tampered manifest"; fi if [ -n "${PI5_RUNS:-}" ]; then "${M}" --all "${PI5_RUNS}" > "${tmp}/real" && echo "real manifest: $(grep -c '^run ' "${tmp}/real") runs, $(wc -c < "${tmp}/real") bytes, sha256 $(sha256sum < "${tmp}/real" | cut -d' ' -f1)" || bad "real runs manifest" fi diff --git a/scripts/ck_pi5_owner_check.sh b/scripts/ck_pi5_owner_check.sh new file mode 100755 index 00000000..e325aef9 --- /dev/null +++ b/scripts/ck_pi5_owner_check.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +# ck_pi5_owner_check.sh -- PI5-8 Q2 gate: the owner-key ceremony tooling, proven with SOFTWARE keys only (TEST). +# 1. PIV public key (PEM) -> CK_OWNER_PUBKEYS file conversion is exact; anything that is not an Ed25519 key is refused; +# 2. the ceremony dry run (software key, labelled TEST) runs end to end and never calls a YubiKey tool (tripwire); +# 3. real mode refuses when the machine looks online, and with no terminal, before any YubiKey tool is called; +# 4. an image built with that owner file (make full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS=) carries the owner key +# and none of the TEST anchors (no "seed0b-test ... TEST ONLY" banner, no TEST Store identity); the TEST-anchor image +# is the positive control (it has the banner and not the owner key); Pi image flags are refused with CK_HARDWARE_STAGING. +# No YubiKey is touched. No owner or release key is generated: every key here is a throw-away openssl key. +set -euo pipefail +root="$(cd "$(dirname "$0")/.." && pwd)" +tmp="$(mktemp -d)"; trap 'rm -rf "${tmp}"' EXIT +fail=0 +ok() { echo "PASS $*"; } +bad() { echo "FAIL $*"; fail=1; } +C="${root}/scripts/pi5-8/owner_ceremony.sh"; CONV="${root}/scripts/pi5-8/owner_pubkey_file.sh" +hexof() { od -An -v -tx1 "$1" | tr -d ' \n'; } + +# 1. conversion +openssl genpkey -algorithm ED25519 -out "${tmp}/k.pem" 2>/dev/null +openssl pkey -in "${tmp}/k.pem" -pubout -out "${tmp}/k.pub" +want="$(openssl pkey -in "${tmp}/k.pem" -pubout -outform DER | tail -c 32 | od -An -v -tx1 | tr -d ' \n')" +got="$("${CONV}" "${tmp}/k.pub" "${tmp}/owner.txt" "TEST conversion" 2>/dev/null)" +if [ "${got}" = "${want}" ] && grep -qx "owner_root_ed25519 ${want}" "${tmp}/owner.txt" && [ "$(grep -vc '^#' "${tmp}/owner.txt")" = 1 ]; then ok "conversion gives the 32 raw key bytes in the CK_OWNER_PUBKEYS format"; else bad "conversion"; fi +openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out "${tmp}/rsa.pem" 2>/dev/null; openssl pkey -in "${tmp}/rsa.pem" -pubout -out "${tmp}/rsa.pub" +openssl genpkey -algorithm X25519 -out "${tmp}/x.pem" 2>/dev/null; openssl pkey -in "${tmp}/x.pem" -pubout -out "${tmp}/x.pub" +openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out "${tmp}/ec.pem" 2>/dev/null; openssl pkey -in "${tmp}/ec.pem" -pubout -out "${tmp}/ec.pub" +printf 'not a key\n' > "${tmp}/junk.pub" +{ echo "-----BEGIN PUBLIC KEY-----"; { printf '\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00'; head -c 32 /dev/zero | tr '\0' '\021'; } | base64; echo "-----END PUBLIC KEY-----"; } > "${tmp}/same.pub" +for b in rsa x ec junk same; do + if "${CONV}" "${tmp}/${b}.pub" "${tmp}/o.${b}" >/dev/null 2>&1; then bad "conversion accepted ${b}"; else ok "conversion refuses ${b} (not a plain Ed25519 key)"; fi +done +for b in rsa x ec junk same; do [ ! -e "${tmp}/o.${b}" ] || bad "refused input ${b} still wrote a file"; done + +# 2. dry run with a tripwire in place of both YubiKey tools +printf '#!/bin/sh\necho "$0" >> "%s/tripwire"\nexit 99\n' "${tmp}" > "${tmp}/trip"; chmod +x "${tmp}/trip" +AIENOS_PIV_TOOL="${tmp}/trip" AIENOS_YKMAN="${tmp}/trip" "${C}" --dry-run --out "${tmp}/dry" > "${tmp}/dry.log" 2>&1 || { cat "${tmp}/dry.log"; bad "dry run failed"; } +if grep -q "^CEREMONY_DRY_RUN: PASS" "${tmp}/dry.log"; then ok "dry run passes end to end"; else bad "dry run verdict"; fi +[ ! -e "${tmp}/tripwire" ] && ok "dry run called no YubiKey tool" || bad "dry run called a YubiKey tool" +for f in slot-9c-public.pem owner-pubkeys.txt owner-pubkeys.txt.sha256 ceremony-statement ceremony-signature ceremony-report.txt; do + [ -s "${tmp}/dry/${f}" ] || bad "dry run output lacks ${f}" +done +grep -q "DRY RUN, TEST software key, not an owner key" "${tmp}/dry/ceremony-report.txt" && ok "dry run report is labelled TEST" || bad "dry run label" +( cd "${tmp}/dry" && sha256sum -c owner-pubkeys.txt.sha256 >/dev/null ) && ok "owner file sha256 file matches" || bad "owner sha256" +if grep -rqE "PRIVATE KEY|TEST-software-key" "${tmp}/dry"; then bad "dry run output holds a private key"; else ok "dry run output holds public material only"; fi + +# 3. real mode refusals (a pseudo-terminal is needed to get past the terminal check) +mkdir -p "${tmp}/fakebin" "${tmp}/net/eth0" "${tmp}/offline/eth0" +printf '#!/bin/sh\n[ "$*" = "-o route show default" ] && echo "default via 192.0.2.1 dev eth0"\nexit 0\n' > "${tmp}/fakebin/ip-online" +printf '#!/bin/sh\nexit 0\n' > "${tmp}/fakebin/ip-offline"; chmod +x "${tmp}/fakebin/ip-"* +echo up > "${tmp}/net/eth0/operstate"; echo down > "${tmp}/offline/eth0/operstate" +shimdir() { mkdir -p "${tmp}/p-$1"; cp "${tmp}/fakebin/ip-$1" "${tmp}/p-$1/ip"; for t in bash env sed cat sort head grep readlink basename dirname date cc mktemp rm; do ln -sf "$(command -v ${t})" "${tmp}/p-$1/${t}" 2>/dev/null || true; done; echo "${tmp}/p-$1"; } +online_path="$(shimdir online)"; offline_path="$(shimdir offline)" +run_pty() { script -qec "$1" /dev/null &1)"; rc_on=$? +out_nic="$(AIENOS_SYSFS_NET="${tmp}/net" AIENOS_PIV_TOOL="${tmp}/trip" AIENOS_YKMAN="${tmp}/trip" run_pty "PATH='${offline_path}':\$PATH '${C}' --real --out '${tmp}/real2'" 2>&1)"; rc_nic=$? +out_tty="$(PATH="${offline_path}:${PATH}" AIENOS_SYSFS_NET="${tmp}/offline" AIENOS_PIV_TOOL="${tmp}/trip" AIENOS_YKMAN="${tmp}/trip" "${C}" --real --out "${tmp}/real3" &1)"; rc_tty=$? +PATH="${offline_path}:${PATH}" AIENOS_SYSFS_NET="${tmp}/offline" "${C}" --check-network > "${tmp}/cn.off" 2>&1; rc_cn_off=$? +PATH="${online_path}:${PATH}" AIENOS_SYSFS_NET="${tmp}/offline" "${C}" --check-network > "${tmp}/cn.on" 2>&1; rc_cn_on=$? +set -e +if [ "${rc_on}" != 0 ] && grep -q "still online" <<<"${out_on}"; then ok "real mode refuses with a default route (online)"; else bad "real mode online refusal (rc=${rc_on})"; fi +if [ "${rc_nic}" != 0 ] && grep -q "network card eth0 is up" <<<"${out_nic}"; then ok "real mode refuses with a physical network card up"; else bad "real mode nic refusal (rc=${rc_nic})"; fi +if [ "${rc_tty}" = 2 ] && grep -q "keyboard of the Spark" <<<"${out_tty}"; then ok "real mode refuses without a terminal"; else bad "real mode tty refusal (rc=${rc_tty})"; fi +if [ "${rc_cn_off}" = 0 ] && grep -q OFFLINE "${tmp}/cn.off" && [ "${rc_cn_on}" = 1 ] && grep -q ONLINE "${tmp}/cn.on"; then ok "network check: offline passes, online fails"; else bad "network check controls (${rc_cn_off} ${rc_cn_on})"; fi +[ ! -e "${tmp}/tripwire" ] && ok "no refused real run called a YubiKey tool" || bad "a refused real run called a YubiKey tool" +[ ! -e "${tmp}/real1" ] && [ ! -e "${tmp}/real2" ] && [ ! -e "${tmp}/real3" ] && ok "refused real runs wrote nothing" || bad "refused real run wrote output" + +# 4. images +own="${tmp}/dry/owner-pubkeys.txt"; ohex="$(sed -n 's/^owner_root_ed25519 //p' "${own}")" +printf 'machine_id %s\nstore_uuid %s\n' "$(openssl rand -hex 32)" "$(openssl rand -hex 16)" > "${tmp}/machine.txt" +K="${root}/native/kernel" +make -s -C "${K}" OUT="${tmp}/img-own" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${own}" CK_MACHINE_ID="${tmp}/machine.txt" > "${tmp}/img-own.log" 2>&1 || { tail -5 "${tmp}/img-own.log"; bad "owner image build"; } +make -s -C "${K}" OUT="${tmp}/img-test" full CK_SEED0B_TEST_ANCHOR=1 > "${tmp}/img-test.log" 2>&1 || { tail -5 "${tmp}/img-test.log"; bad "TEST-anchor image build"; } +eo="${tmp}/img-own/full-hardware-staging/aienos-ck.elf"; et="${tmp}/img-test/aienos-ck.elf" +[ -s "${eo}" ] || eo="$(find "${tmp}/img-own" -name aienos-ck.elf | head -n 1)" +[ -s "${et}" ] || et="$(find "${tmp}/img-test" -name aienos-ck.elf | head -n 1)" +if hexof "${eo}" | grep -q "${ohex}"; then ok "owner image carries the owner public key"; else bad "owner image lacks the owner key"; fi +if hexof "${et}" | grep -q "${ohex}"; then bad "TEST-anchor image carries the owner key"; else ok "TEST-anchor control image has no owner key"; fi +so="$(strings -a "${eo}")"; st="$(strings -a "${et}")" +if grep -q "seed0b-test qualification build" <<<"${st}"; then ok "control: TEST-anchor image carries the TEST ONLY artifact_trust banner"; else bad "control banner missing, the check below would prove nothing"; fi +if grep -qE "seed0b-test qualification build|TEST ONLY|TEST-ONLY|AIEN-TEST-BOOT|LANE18-TEST-KVOL|TEST machine id" <<<"${so}"; then bad "owner image carries a TEST anchor/banner: $(grep -E 'seed0b-test qualification build|TEST ONLY|TEST-ONLY|AIEN-TEST-BOOT|LANE18-TEST-KVOL|TEST machine id' <<<"${so}" | head -n 3)"; else ok "owner image has no TEST anchor banner, TEST Store label or TEST machine id"; fi +if grep -q "no TEST Store label, uuid or key code" "${tmp}/img-own.log" || make -s -C "${K}" -n OUT="${tmp}/x" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${own}" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1; then ok "Makefile owner_check accepts the owner image"; else bad "owner_check"; fi +for flag in CK_PI5=1 CK_PI5_ARTIFACT=1 CK_SEED0B_TEST_ANCHOR=1; do + if make -n -C "${K}" ${flag} full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${own}" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1; then bad "Makefile accepts ${flag} with CK_HARDWARE_STAGING"; else ok "Makefile refuses ${flag} with CK_HARDWARE_STAGING (TEST tier and owner image never mix)"; fi +done +if make -n -C "${K}" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${own}" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1; then ok "positive control: owner image build is accepted"; else bad "positive control"; fi +cp "${tmp}/machine.txt" "${tmp}/machine.copy"; printf 'owner_root_ed25519 d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a\n' > "${tmp}/t1.txt" +if make -n -C "${K}" OUT="${tmp}/x2" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${tmp}/t1.txt" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1 && make -s -C "${K}" OUT="${tmp}/x2" full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS="${tmp}/t1.txt" CK_MACHINE_ID="${tmp}/machine.txt" >/dev/null 2>&1; then bad "an RFC 8032 TEST key was accepted as owner key"; else ok "an RFC 8032 TEST key is refused as owner key"; fi +[ "${fail}" = 0 ] && echo "PASS ck_pi5_owner_check" || { echo "FAIL ck_pi5_owner_check"; exit 1; } diff --git a/scripts/pi5-8/install_owner_tools.sh b/scripts/pi5-8/install_owner_tools.sh new file mode 100755 index 00000000..5d337b14 --- /dev/null +++ b/scripts/pi5-8/install_owner_tools.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# install_owner_tools.sh -- PI5-8 Q2: install the YubiKey tools the owner-key ceremony needs. Host only; never touches a YubiKey. +# +# scripts/pi5-8/install_owner_tools.sh +# +# Why not the Ubuntu packages: Ubuntu 24.04 ships yubico-piv-tool 2.2.0 and yubikey-manager 5.2.1. PIV Ed25519 keys need +# yubico-piv-tool >= 2.5.0 (its NEWS: "Add support for ED25519 and X25519 key types. Available in firmware 5.7.0 and newer") +# and a YubiKey with firmware >= 5.7. This script builds the newest released yubico-piv-tool from Yubico's official source tarball +# and installs yubikey-manager (ykman, read-only status and checks) into a private virtual environment. +# +# Checks before anything is built: the tarball sha256 is pinned below, and the detached OpenPGP signature must verify against +# Yubico's signing key (primary key 1D73 08B0 055F 5AEF 3694 4A8F 27A9 C24D 9588 EA0F, listed on +# https://developers.yubico.com/Software_Projects/Software_Signing.html), fetched from keys.openpgp.org into a throw-away keyring. +# Needs (apt): pcscd libpcsclite-dev libssl-dev cmake gcc pkg-config check zlib1g-dev gengetopt help2man swig python3-venv gnupg. +# The smart card daemon also needs a polkit rule when you run from a non-graphical login; see docs/native/PI5-8-OWNER-CEREMONY.md. +set -euo pipefail +ver=2.7.3 +url="https://developers.yubico.com/yubico-piv-tool/Releases/yubico-piv-tool-${ver}.tar.gz" +sha=fcb25c42f54298ece8b20684fb3c581ed9195a162cbc55180a4161501be93181 +primary=1D7308B0055F5AEF36944A8F27A9C24D9588EA0F +ykman_ver=5.9.2 +ykman_whl_sha=19a1173106b104bea37722e61ce748fb2d39c87a02880c1964461837ddaa7fba +prefix="${AIENOS_OWNER_TOOLS:-$HOME/.local}" +work="$(mktemp -d)"; trap 'rm -rf "${work}"' EXIT +mkdir -p "${work}/dl" "${work}/src" "${work}/build" "${work}/gnupg"; chmod 700 "${work}/gnupg" +curl -fsSL -o "${work}/dl/t.tar.gz" "${url}" +curl -fsSL -o "${work}/dl/t.tar.gz.sig" "${url}.sig" +[ "$(sha256sum < "${work}/dl/t.tar.gz" | cut -d' ' -f1)" = "${sha}" ] || { echo "REFUSED: tarball sha256 differs from the pinned value" >&2; exit 1; } +export GNUPGHOME="${work}/gnupg" +gpg --batch --quiet --keyserver hkps://keys.openpgp.org --recv-keys "${primary}" +st="$(gpg --batch --status-fd 1 --verify "${work}/dl/t.tar.gz.sig" "${work}/dl/t.tar.gz" 2>/dev/null || true)" +grep -q '^\[GNUPG:\] GOODSIG' <<<"${st}" && grep -q "^\[GNUPG:\] VALIDSIG .* ${primary}\$" <<<"${st}" \ + || { echo "REFUSED: signature does not verify against Yubico's key ${primary}" >&2; exit 1; } +echo "tarball sha256 and Yubico OpenPGP signature verified (${ver})" +tar -xzf "${work}/dl/t.tar.gz" -C "${work}/src" +cmake -S "${work}/src/yubico-piv-tool-${ver}" -B "${work}/build" -DCMAKE_INSTALL_PREFIX="${prefix}/yubico-piv-tool" >/dev/null +make -C "${work}/build" -j"$(nproc)" >/dev/null +make -C "${work}/build" install >/dev/null +python3 -m venv "${prefix}/ykman-venv" +"${prefix}/ykman-venv/bin/pip" download -q --no-deps "yubikey-manager==${ykman_ver}" -d "${work}/dl" +[ "$(sha256sum < "${work}/dl/yubikey_manager-${ykman_ver}-py3-none-any.whl" | cut -d' ' -f1)" = "${ykman_whl_sha}" ] \ + || { echo "REFUSED: ykman wheel sha256 differs from the pinned value" >&2; exit 1; } +"${prefix}/ykman-venv/bin/pip" install -q "yubikey-manager==${ykman_ver}" +LD_LIBRARY_PATH="${prefix}/yubico-piv-tool/lib" "${prefix}/yubico-piv-tool/bin/yubico-piv-tool" --version +"${prefix}/ykman-venv/bin/ykman" --version diff --git a/scripts/pi5-8/owner_ceremony.sh b/scripts/pi5-8/owner_ceremony.sh new file mode 100755 index 00000000..80d0c23f --- /dev/null +++ b/scripts/pi5-8/owner_ceremony.sh @@ -0,0 +1,233 @@ +#!/usr/bin/env bash +# owner_ceremony.sh -- PI5-8 Q2: the AIENOS owner-key ceremony on Drake's YubiKey (PIV, Ed25519, slot 9c). +# +# owner_ceremony.sh --dry-run [--out DIR] rehearsal with a SOFTWARE key (openssl). Labelled TEST. Never touches a YubiKey. +# owner_ceremony.sh --real [--out DIR] the ceremony. Writes to the YubiKey. Run it only when the Spark is offline. +# owner_ceremony.sh --sign-manifest MANIFEST SIGOUT OWNERFILE +# after the ceremony: the YubiKey signs the statement that binds MANIFEST +# (PIN once, then touch). Checks the signature against OWNERFILE before it finishes. +# owner_ceremony.sh --check-network exit 0 only if the machine looks offline (what --real checks first) +# +# Decisions (PI5-8 Q2, Drake): the owner key is an Ed25519 key generated ON the YubiKey (PIV, slot 9c, touch policy always, PIN +# policy once). The private key never leaves the device. The Spark is offline while the key is made. Drake types the PIV PIN, +# PUK and management key himself; this script never receives, echoes, stores or logs them: the YubiKey tools ask for them on +# the terminal. The owner key is NOT the public-release signing key (that one is generated only at the first public release). +# +# What is signed: a small fixed statement that binds the manifest (ck_manifest_sig.c, docs/native/PI5-8-OWNER-CEREMONY.md). +# Real mode writes (and only ever reads from the YubiKey the public parts): slot 9c key, PIN, PUK, management key. +# It refuses to run if slot 9c is already occupied. Output folder (default ~/aienos-owner-ceremony/) holds PUBLIC +# files only: slot-9c-public.pem, owner-pubkeys.txt, owner-pubkeys.txt.sha256, ceremony-statement, ceremony-signature, +# ceremony-report.txt. +set -euo pipefail +export LC_ALL=C +case $- in *x*) echo "REFUSED: shell tracing (set -x) would print secrets and commands; run without it" >&2; exit 2;; esac +here="$(cd "$(dirname "$0")" && pwd)" +root="$(cd "${here}/../.." && pwd)" +PIV="${AIENOS_PIV_TOOL:-${HOME}/.local/yubico-piv-tool/bin/yubico-piv-tool}" +YKMAN="${AIENOS_YKMAN:-${HOME}/.local/ykman-venv/bin/ykman}" +export LD_LIBRARY_PATH="$(dirname "$(dirname "${PIV}")")/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" +SLOT=9c +mode="" out="" tmp="" +say() { printf '%s\n' "$*"; } +die() { printf 'REFUSED: %s\n' "$*" >&2; exit "${2:-1}"; } +cleanup() { [ -z "${tmp}" ] || rm -rf "${tmp}"; } +trap cleanup EXIT + +# ---- network check (real mode): refuse unless the machine is offline ---------------------------------------------- +network_state() { # prints reasons the machine is online, nothing when offline (refuses to guess without ip) + command -v ip >/dev/null || { echo "cannot check: the ip tool is missing"; return 0; } + ip -o route show default 2>/dev/null | sed 's/^/default route: /' + ip -o -6 route show default 2>/dev/null | sed 's/^/default route (v6): /' + local d n + for d in "${AIENOS_SYSFS_NET:-/sys/class/net}"/*; do + n="$(basename "${d}")" + case "$(readlink -f "${d}")" in /sys/devices/virtual/*) continue;; esac + [ "$(cat "${d}/operstate" 2>/dev/null || echo unknown)" = up ] && echo "network card ${n} is up" + done + return 0 +} +require_offline() { + local s; s="$(network_state)" + if [ -n "${s}" ]; then + printf '%s\n' "${s}" >&2 + die "the Spark is still online. Unplug the network cable and turn Wi-Fi off, wait ten seconds, run this again." 3 + fi +} + +# ---- tools ------------------------------------------------------------------------------------------------------------- +vge() { [ "$(printf '%s\n%s\n' "$2" "$1" | sort -V | head -n 1)" = "$2" ]; } # vge A B: A >= B +need_tools() { + [ -x "${PIV}" ] || die "yubico-piv-tool not found at ${PIV}; run scripts/pi5-8/install_owner_tools.sh" 2 + [ -x "${YKMAN}" ] || die "ykman not found at ${YKMAN}; run scripts/pi5-8/install_owner_tools.sh" 2 + local v; v="$("${PIV}" --version 2>&1 | awk '{print $2}')" + vge "${v}" 2.5.0 || die "yubico-piv-tool ${v} is too old for PIV Ed25519 (needs 2.5.0 or newer; installed script builds 2.7.3)" 2 +} +build_host_tools() { # in-tree verifier and owner-file checker, built from the repo + cc -std=gnu11 -O1 -Wall -Wextra -Werror -I"${root}/native/sig" -I"${root}/native/argus" -o "${tmp}/ck_manifest_sig" \ + "${root}/native/kernel/tools/ck_manifest_sig.c" "${root}/native/sig/ed25519.c" "${root}/native/sig/sha512.c" \ + "${root}/native/sig/ct.c" "${root}/native/argus/sha256.c" + cc -std=gnu11 -O1 -Wall -Wextra -Werror -o "${tmp}/ck_owner_gen" "${root}/native/kernel/tools/ck_owner_gen.c" +} + +# ---- backends: software (dry run) and YubiKey (real) -------------------------------------------------------------------- +sw_generate() { # PUBPEM + openssl genpkey -algorithm ED25519 -out "${tmp}/TEST-software-key.pem" 2>/dev/null + openssl pkey -in "${tmp}/TEST-software-key.pem" -pubout -out "$1" +} +sw_sign() { openssl pkeyutl -sign -rawin -inkey "${tmp}/TEST-software-key.pem" -in "$1" -out "$2"; } +yk_info() { + say "YubiKey seen by the smart card service:" + "${PIV}" -a list-readers + local n; n="$("${PIV}" -a list-readers | grep -ci yubikey || true)" + [ "${n}" = 1 ] || die "need exactly one YubiKey plugged in, found ${n}" 2 + "${YKMAN}" info | grep -E '^(Device type|Serial number|Firmware version|Form factor)' + local fw; fw="$("${PIV}" -a version 2>&1 | sed -n 's/^Firmware version \([0-9.]*\) found.*/\1/p')" + vge "${fw:-0}" 5.7.0 || die "firmware ${fw:-unknown} cannot hold PIV Ed25519 keys (needs 5.7.0 or newer)" 2 +} +yk_slot_must_be_empty() { + if "${PIV}" -a status 2>/dev/null | grep -qi "^Slot ${SLOT}"; then die "slot ${SLOT} already holds a key; this script never overwrites a key" 2; fi + say "Slot ${SLOT} is empty." +} +yk_is_default() { "${YKMAN}" piv info 2>/dev/null | grep -q "WARNING: Using default $1"; } # $1: PIN | PUK | Management key +yk_set_secrets() { + # The YubiKey tool asks for each new secret twice, so a typing slip cannot lock you out. Factory values are public + # (PIN 123456, PUK 12345678, management key 0102...08 x3) and are passed only while the device still reports them. + local ok + if yk_is_default PIN; then + say "STEP 3a: choose your new PIV PIN (6 to 8 characters). Type it, then type it again." + "${PIV}" -a change-pin -P 123456 + else + say "The PIN is no longer the factory PIN. Change it again only if you want to." + read -r -p "Change the PIN now? [y/N] " ok; if [ "${ok}" = y ]; then "${PIV}" -a change-pin; fi + fi + if yk_is_default PUK; then + say "STEP 3b: choose your new PUK (6 to 8 characters). It unblocks the PIN if the PIN gets blocked. Type it, then again." + "${PIV}" -a change-puk -P 12345678 + else + say "The PUK is no longer the factory PUK; keeping it." + fi + if yk_is_default "Management key"; then + say "STEP 3c: choose your new management key: 64 hexadecimal characters (0-9, a-f), the one you wrote on paper. Type it, then again." + "${PIV}" -a set-mgm-key -m AES256 + else + say "The management key is no longer the factory one; keeping it." + fi + "${YKMAN}" piv info | grep -E 'tries remaining|Management key algorithm' || true + if "${YKMAN}" piv info | grep -q "WARNING: Using default"; then die "something is still set to the factory value; stopping" 1; fi +} +yk_generate() { # PUBPEM + say "STEP: the YubiKey now makes the owner key inside itself (Ed25519, slot ${SLOT}, touch always, PIN once). Type the management key when asked." + "${PIV}" -k -a generate -s "${SLOT}" -A ED25519 --pin-policy=once --touch-policy=always -o "$1" +} +yk_sign() { # IN OUT + say "STEP: the YubiKey signs. Type the PIN when asked, then TOUCH the metal contact on the key when it blinks." + "${PIV}" -a verify-pin --sign -s "${SLOT}" -A ED25519 -i "$1" -o "$2" +} +yk_check_policy() { + local info; info="$("${YKMAN}" piv keys info "${SLOT}")" + say "${info}" + grep -qi "Algorithm:.*ED25519" <<<"${info}" || die "slot ${SLOT} is not an Ed25519 key" 1 + grep -qi "Origin:.*GENERATED" <<<"${info}" || die "slot ${SLOT} key was not generated on the YubiKey" 1 + grep -qi "PIN required for use:.*ONCE" <<<"${info}" || die "PIN policy is not ONCE" 1 + grep -qi "Touch required for use:.*ALWAYS" <<<"${info}" || die "touch policy is not ALWAYS" 1 +} + +# ---- shared steps ------------------------------------------------------------------------------------------------------ +write_and_check_owner_file() { # PUBPEM OUTDIR LABEL + local hex + hex="$("${here}/owner_pubkey_file.sh" "$1" "$2/owner-pubkeys.txt" "$3")" || die "could not convert the public key" 1 + ( cd "$2" && sha256sum owner-pubkeys.txt > owner-pubkeys.txt.sha256 ) + # ck_owner_gen is the same checker the image build uses; it also refuses RFC 8032 TEST keys and all-equal keys. + printf 'machine_id %s\nstore_uuid %s\n' "$(openssl rand -hex 32)" "$(openssl rand -hex 16)" > "${tmp}/placeholder-machine.txt" # random placeholder, only checks the owner line + "${tmp}/ck_owner_gen" "$2/owner-pubkeys.txt" "${tmp}/placeholder-machine.txt" "${tmp}/owner_prov.h" || die "the image build would refuse this owner file" 1 + OWNER_HEX="${hex}" + say "Owner public key (PUBLIC): ${hex}" + say "Owner file sha256: $(cut -d' ' -f1 "$2/owner-pubkeys.txt.sha256")" +} +sign_and_verify() { # SIGN_FN MANIFEST SIGOUT HEX LABEL + local fn="$1" man="$2" sig="$3" hex="$4" st="${tmp}/statement" + "${tmp}/ck_manifest_sig" statement "${man}" "${st}" + "${fn}" "${st}" "${sig}" + [ "$(wc -c < "${sig}")" = 64 ] || die "signature is not 64 bytes" 1 + "${tmp}/ck_manifest_sig" verify "${man}" "${sig}" "${hex}" || die "the signature does not verify with the in-tree Ed25519" 1 + # second, independent verifier: openssl over the same statement bytes (plain Ed25519, no hashing wrapper) + local pem="${tmp}/v.pem" + # SPKI DER = fixed 12-byte prefix + the 32 key bytes, written as raw bytes (not through $(...), which drops NUL) + printf "$(printf '%s' "302a300506032b6570032100${hex}" | sed 's/../\\x&/g')" | openssl pkey -pubin -inform DER -out "${pem}" 2>/dev/null \ + || die "could not rebuild the public key for the second check" 1 + openssl pkeyutl -verify -rawin -pubin -inkey "${pem}" -in "${st}" -sigfile "${sig}" >/dev/null || die "openssl does not verify the signature" 1 + say "Signature verified two ways (in-tree Ed25519 and openssl)." + cp "${man}" "${tmp}/m.bad"; printf 'X' | dd of="${tmp}/m.bad" bs=1 seek=3 conv=notrunc 2>/dev/null + if "${tmp}/ck_manifest_sig" verify "${tmp}/m.bad" "${sig}" "${hex}" >/dev/null; then die "a changed manifest still verified" 1; fi + say "A changed manifest is refused, as it must be." +} +test_manifest() { printf 'AIENOS-OWNER-CEREMONY-TEST-MANIFEST-V1\nthis is a fixed test text, not a receipts manifest\n' > "$1"; } + +ceremony() { # dry|real + local kind="$1" label + if [ -z "${out}" ]; then if [ "${kind}" = real ]; then out="${HOME}/aienos-owner-ceremony/$(date -u +%Y%m%dT%H%M%SZ)"; else out="$(mktemp -d /tmp/aienos-owner-dryrun.XXXXXX)"; fi; fi + build_host_tools + if [ "${kind}" = dry ]; then + say "DRY RUN (TEST): a software key stands in for the YubiKey. No YubiKey is touched, nothing real is created." + say "Steps 1 to 4 of the real ceremony (offline check, YubiKey, PIN/PUK/management key, key generation) are replaced by a software key." + label="TEST software key (dry run), not an owner key" + mkdir -p "${out}"; chmod 700 "${out}" + sw_generate "${out}/slot-9c-public.pem" + else + [ -t 0 ] && [ -t 1 ] || die "run this at the keyboard of the Spark (it asks you to type secrets)" 2 + say "STEP 1: checking the Spark is offline."; require_offline; say "Offline: OK." + say "STEP 2: checking the tools and the YubiKey."; need_tools; yk_info + read -r -p "Does that serial number match your YubiKey (type YES to go on)? " ans; [ "${ans}" = YES ] || die "stopped by you" 1 + yk_slot_must_be_empty + mkdir -p "${out}"; chmod 700 "${out}" + say "STEP 3: PIN, PUK and management key (typed by you, never shown here)."; yk_set_secrets + say "STEP 4: making the owner key inside the YubiKey."; yk_generate "${out}/slot-9c-public.pem" + "${PIV}" -a read-public-key -s "${SLOT}" -o "${tmp}/read-back.pem" + cmp -s "${tmp}/read-back.pem" "${out}/slot-9c-public.pem" || die "the key read back from slot ${SLOT} differs from the generated one" 1 + yk_check_policy + label="Ed25519 key generated on YubiKey serial $("${YKMAN}" info | sed -n 's/^Serial number: *//p'), PIV slot ${SLOT}" + fi + say "STEP 5: owner public key file."; write_and_check_owner_file "${out}/slot-9c-public.pem" "${out}" "${label}" + test_manifest "${out}/ceremony-test-manifest" + say "STEP 6: signing and checking a fixed test statement." + if [ "${kind}" = dry ]; then sign_and_verify sw_sign "${out}/ceremony-test-manifest" "${out}/ceremony-signature" "${OWNER_HEX}" TEST + else sign_and_verify yk_sign "${out}/ceremony-test-manifest" "${out}/ceremony-signature" "${OWNER_HEX}" real; fi + cp "${tmp}/statement" "${out}/ceremony-statement" + { + echo "AIENOS owner ceremony report (${kind}); PUBLIC data only" + echo "kind: $([ "${kind}" = dry ] && echo 'DRY RUN, TEST software key, not an owner key' || echo 'REAL, key generated on the YubiKey')" + echo "utc: $(date -u +%Y-%m-%dT%H:%M:%SZ)" + echo "key: ${label}" + echo "owner_root_ed25519: ${OWNER_HEX}" + echo "owner_file_sha256: $(cut -d' ' -f1 "${out}/owner-pubkeys.txt.sha256")" + echo "signed_statement_sha256: $(sha256sum < "${out}/ceremony-statement" | cut -d' ' -f1)" + echo "checks: network offline $([ "${kind}" = dry ] && echo n/a || echo ok); owner file accepted by ck_owner_gen; signature verified by in-tree Ed25519 and openssl; changed manifest refused" + } > "${out}/ceremony-report.txt" + say "" + if [ "${kind}" = dry ]; then say "DRY RUN COMPLETE (TEST). Files in ${out}"; say "CEREMONY_DRY_RUN: PASS" + else say "CEREMONY COMPLETE. Public files in ${out}. You may reconnect the network now."; say "CEREMONY_REAL: PASS"; fi +} + +sign_manifest() { # MANIFEST SIGOUT OWNERFILE (real YubiKey) + local man="$1" sigout="$2" ofile="$3" hex + [ -r "${man}" ] || die "cannot read manifest ${man}" 2 + hex="$(sed -n 's/^owner_root_ed25519 \([0-9a-f]\{64\}\)$/\1/p' "${ofile}")"; [ -n "${hex}" ] || die "no owner_root_ed25519 line in ${ofile}" 2 + need_tools; build_host_tools + "${PIV}" -a read-public-key -s "${SLOT}" -o "${tmp}/slot.pem" || die "cannot read the public key of slot ${SLOT}" 1 + "${here}/owner_pubkey_file.sh" "${tmp}/slot.pem" "${tmp}/slot-owner.txt" >/dev/null 2>&1 || die "slot ${SLOT} does not hold an Ed25519 key" 1 + grep -qx "owner_root_ed25519 ${hex}" "${tmp}/slot-owner.txt" || die "the key in slot ${SLOT} is not the owner key in ${ofile}" 1 + sign_and_verify yk_sign "${man}" "${tmp}/sig.out" "${hex}" real + cp "${tmp}/sig.out" "${sigout}" + say "Wrote ${sigout}. MANIFEST_OWNER_SIGNED: PASS" +} + +tmp="$(mktemp -d)" +case "${1:-}" in + --dry-run) mode=dry; shift;; + --real) mode=real; shift;; + --check-network) s="$(network_state)"; if [ -n "${s}" ]; then printf '%s\n' "${s}"; echo "ONLINE"; exit 1; fi; echo "OFFLINE"; exit 0;; + --sign-manifest) [ $# = 4 ] || die "usage: --sign-manifest MANIFEST SIGOUT OWNERFILE" 2; sign_manifest "$2" "$3" "$4"; exit 0;; + *) sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//' >&2; exit 2;; +esac +while [ $# -gt 0 ]; do case "$1" in --out) out="${2:?--out DIR}"; shift 2;; *) die "unknown argument $1" 2;; esac; done +ceremony "${mode}" diff --git a/scripts/pi5-8/owner_pubkey_file.sh b/scripts/pi5-8/owner_pubkey_file.sh new file mode 100755 index 00000000..1e6fda28 --- /dev/null +++ b/scripts/pi5-8/owner_pubkey_file.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# owner_pubkey_file.sh -- PI5-8 Q2: turn an exported Ed25519 public key into the CK_OWNER_PUBKEYS file (PUBLIC material only). +# +# scripts/pi5-8/owner_pubkey_file.sh PUBKEY.pem OUTFILE ["comment text"] +# +# PUBKEY.pem is what the YubiKey tool exports (`yubico-piv-tool -a read-public-key -s 9c`, or the output of `-a generate`): +# 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. +# The conversion takes the last 32 bytes after checking those 12 bytes exactly, and writes the file format that +# native/kernel/tools/ck_owner_gen.c reads (native/kernel/README.md "Owner provisioning"): +# owner_root_ed25519 <64 lowercase hex> +# Prints the 64 hex digits on stdout and the sha256 of the file on stderr. Refuses anything that is not exactly an Ed25519 +# public key and an all-equal-bytes key. Never reads or writes secret material. Real owner files are never committed. +set -euo pipefail +pem="${1:?usage: owner_pubkey_file.sh PUBKEY.pem OUTFILE [comment]}"; out="${2:?outfile}"; comment="${3:-}" +case "${comment}" in *$'\n'*|*$'\r'*) echo "REFUSED: comment must be one line" >&2; exit 2;; esac +der="$(openssl pkey -pubin -in "${pem}" -outform DER 2>/dev/null | od -An -v -tx1 | tr -d ' \n')" \ + || { echo "REFUSED: ${pem} is not a PEM public key" >&2; exit 1; } +prefix=302a300506032b6570032100 +if [ "${#der}" != 88 ] || [ "${der:0:24}" != "${prefix}" ]; then + echo "REFUSED: ${pem} is not exactly an Ed25519 public key (SPKI prefix/length mismatch)" >&2; exit 1 +fi +hex="${der:24}" +if [ "$(fold -w2 <<<"${hex}" | sort -u | wc -l)" = 1 ]; then echo "REFUSED: all bytes equal (placeholder, not a key)" >&2; exit 1; fi +tmp="${out}.tmp.$$" +{ + echo "# AIENOS owner public key. PUBLIC material only (the private key never leaves the YubiKey)." + [ -z "${comment}" ] || echo "# ${comment}" + echo "owner_root_ed25519 ${hex}" +} > "${tmp}" +mv "${tmp}" "${out}" +echo "owner file sha256 $(sha256sum < "${out}" | cut -d' ' -f1)" >&2 +echo "${hex}" diff --git a/scripts/pi5_receipts_manifest.sh b/scripts/pi5_receipts_manifest.sh index 6f9d562c..fd5ff45a 100755 --- a/scripts/pi5_receipts_manifest.sh +++ b/scripts/pi5_receipts_manifest.sh @@ -9,11 +9,11 @@ # kernel.log, and the verdict lines picked by the checked-in table (scripts/pi5_receipts_verdicts.tsv). # Output is plain ASCII, LF line endings, no timestamps, no absolute paths: same inputs, same bytes. # -# SIGNING (not done here): the manifest bytes on stdout are the message. A signature is an Ed25519 detached -# signature over exactly those bytes (RFC 8032 pure Ed25519), checked with the in-tree verifier -# (native/sig/ed25519.c) by native/kernel/tools/ck_manifest_sig.c ("verify MANIFEST SIG PUBKEYHEX"). -# No owner or release key exists yet; scripts/ck_pi5_manifest_check.sh proves sign+verify with the public -# RFC 8032 TEST 1 key only. +# SIGNING (not done here): the owner signs a fixed four-line statement that binds these manifest bytes by length and +# sha256 (PIV Ed25519 takes only a small message), as plain Ed25519 (RFC 8032), checked with the in-tree verifier +# (native/sig/ed25519.c) by native/kernel/tools/ck_manifest_sig.c ("verify MANIFEST SIG PUBKEYHEX"). The statement and the +# YubiKey ceremony are in docs/native/PI5-8-OWNER-CEREMONY.md. No owner or release key exists yet; +# scripts/ck_pi5_manifest_check.sh proves sign+verify with the public RFC 8032 TEST 1 key and an openssl TEST key only. # # Exit 0 and a manifest on stdout only when every run folder exists, every field was found and every table # row matched at least one line. Otherwise nothing goes to stdout; problems go to stderr (exit 1 evidence ```