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/omega-mv/blob/main/tests/searchtrace/test_st_holdout_sig_cli.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / searchtrace / test_st_holdout_sig_cli.sh` 102 lines ยท 6059 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 # test_st_holdout_sig_cli.sh - end-to-end check of `searchtrace holdout sign` 18 # and `verify --strict` with freshly generated random TEST keys (never an 19 # owner key; the keys are deleted at the end). If openssl is installed, an 20 # OpenSSL-made Ed25519 TEST key (PKCS#8/SPKI DER, the owner ceremony's 21 # format) is also used, and OpenSSL independently checks the signature. 22 # Usage: bash tests/searchtrace/test_st_holdout_sig_cli.sh 23 set -u 24 tool="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" 25 umask 077 26 w="$(mktemp -d /tmp/st_holdout_sig_cli_XXXXXX)" 27 trap 'rm -rf "$w"' EXIT 28 fail=0 29 ok() { echo "PASS $1"; } 30 bad() { echo "FAIL $1"; fail=1; } 31 expect() { # expect 32 local want="$1" name="$2"; shift 2 33 "$@" >"$w/out" 2>"$w/err"; local rc=$? 34 if [[ $rc -eq $want ]]; then ok "$name"; else bad "$name (exit $rc, want $want: $(head -c 200 "$w/err"))"; fi 35 } 36 hex2bin() { local h; h="$(cat)"; printf "$(printf '%s' "$h" | sed 's/../\\x&/g')"; } 37 38 printf 'task alpha\ntask beta\ntask gamma\n' >"$w/taskset.txt" 39 head -c 32 /dev/urandom >"$w/salt.bin" 40 head -c 32 /dev/urandom >"$w/TEST-ONLY-random-key-1.sk" 41 head -c 32 /dev/urandom >"$w/TEST-ONLY-random-key-2.sk" 42 head -c 32 /dev/urandom >"$w/random-public-key.pk" 43 mkdir "$w/rec" "$w/k2" 44 45 rec="$("$tool" holdout commit g3-cli-test "$w/taskset.txt" "$w/salt.bin" "$w/rec")" \ 46 && ok "commit" || bad "commit" 47 d="$(basename "$rec" .txt)"; d="${d#g3-commit-}" 48 sig="$w/rec/g3-sig-$d.txt" 49 50 expect 2 "strict verify refuses an unsigned record" "$tool" holdout verify --strict "$w/random-public-key.pk" "$rec" 51 expect 0 "sign with random TEST key 1" "$tool" holdout sign "$rec" "$w/TEST-ONLY-random-key-1.sk" "$w/rec" 52 [[ -f "$sig" ]] && ok "signature file is g3-sig-.txt" || bad "signature file name" 53 expect 0 "plain verify of the record unchanged" "$tool" holdout verify "$rec" 54 expect 2 "sign with key 2 refuses to replace key 1's signature" "$tool" holdout sign "$rec" "$w/TEST-ONLY-random-key-2.sk" "$w/rec" 55 chmod 644 "$w/TEST-ONLY-random-key-2.sk" 56 expect 2 "sign refuses a world-readable key file" "$tool" holdout sign "$rec" "$w/TEST-ONLY-random-key-2.sk" "$w/k2" 57 chmod 600 "$w/TEST-ONLY-random-key-2.sk" 58 mkfifo "$w/fifo.sk" && chmod 600 "$w/fifo.sk" 59 expect 2 "sign refuses a named pipe as key file (no hang)" timeout 20 "$tool" holdout sign "$rec" "$w/fifo.sk" "$w/k2" 60 61 if command -v openssl >/dev/null 2>&1; then 62 openssl genpkey -algorithm `ed25519` -out "$w/TEST-ONLY-openssl.pem" 2>/dev/null 63 openssl pkey -in "$w/TEST-ONLY-openssl.pem" -outform DER -out "$w/TEST-ONLY-openssl.der.sk" 2>/dev/null 64 openssl pkey -in "$w/TEST-ONLY-openssl.pem" -pubout -outform DER -out "$w/TEST-ONLY-openssl.der.pk" 2>/dev/null 65 mkdir "$w/o" 66 expect 0 "sign with an OpenSSL-made PKCS#8 TEST key" "$tool" holdout sign "$rec" "$w/TEST-ONLY-openssl.der.sk" "$w/o" 67 osig="$w/o/g3-sig-$d.txt" 68 expect 0 "strict verify with the SPKI public key" "$tool" holdout verify --strict "$w/TEST-ONLY-openssl.der.pk" "$rec" "$osig" 69 expect 2 "strict verify of key 1's signature under the OpenSSL key refused" "$tool" holdout verify --strict "$w/TEST-ONLY-openssl.der.pk" "$rec" "$sig" 70 # Independent check: OpenSSL verifies the same signature over 71 # "omega.g3.holdout.sig.v1" 0x00 || record. 72 { printf 'omega.g3.holdout.sig.v1\0'; cat "$rec"; } >"$w/msg.bin" 73 sed -n 's/^signature //p' "$osig" | hex2bin >"$w/sig.bin" 74 if [[ $(stat -c %s "$w/sig.bin") -eq 64 ]] && openssl pkeyutl -verify -pubin -inkey "$w/TEST-ONLY-openssl.der.pk" -keyform DER \ 75 -rawin -in "$w/msg.bin" -sigfile "$w/sig.bin" >/dev/null 2>&1; then 76 ok "OpenSSL independently verifies the signature" 77 else 78 bad "OpenSSL independently verifies the signature" 79 fi 80 printf 'x' >>"$w/msg.bin" 81 if openssl pkeyutl -verify -pubin -inkey "$w/TEST-ONLY-openssl.der.pk" -keyform DER \ 82 -rawin -in "$w/msg.bin" -sigfile "$w/sig.bin" >/dev/null 2>&1; then 83 bad "OpenSSL refuses a changed message" 84 else 85 ok "OpenSSL refuses a changed message" 86 fi 87 kid="$(tail -c 32 "$w/TEST-ONLY-openssl.der.pk" | sha256sum | cut -c1-64)" 88 grep -qx "key_id $kid" "$osig" && ok "key_id is sha256 of the public key" || bad "key_id is sha256 of the public key" 89 # tamper: one signature hex digit changed (end line now stale) 90 awk '/^signature /{c=substr($2,1,1); $2=(c=="0"?"1":"0") substr($2,2)} {print}' "$osig" >"$w/tampered.txt" 91 expect 2 "strict verify refuses a tampered signature file" "$tool" holdout verify --strict "$w/TEST-ONLY-openssl.der.pk" "$rec" "$w/tampered.txt" 92 head -c 100 "$osig" >"$w/trunc.txt" 93 expect 2 "strict verify refuses a truncated signature file" "$tool" holdout verify --strict "$w/TEST-ONLY-openssl.der.pk" "$rec" "$w/trunc.txt" 94 cp "$rec" "$w/o/rec.txt"; printf 'x' >>"$w/o/rec.txt" 95 expect 2 "strict verify refuses a tampered commitment record" "$tool" holdout verify --strict "$w/TEST-ONLY-openssl.der.pk" "$w/o/rec.txt" "$osig" 96 rm -f "$osig" 97 expect 2 "strict verify refuses once the signature is removed" "$tool" holdout verify --strict "$w/TEST-ONLY-openssl.der.pk" "$rec" "$osig" 98 else 99 echo "NOTE openssl not found: OpenSSL interop cross-check NOT_RUN (the C unit test still covers sign/verify)" 100 fi 101 102 if [[ $fail -eq 0 ]]; then echo "ST_HOLDOUT_SIG_CLI: PASS"; else echo "ST_HOLDOUT_SIG_CLI: FAIL"; exit 1; fi