Files
makronix/tools/sign-release.sh
T
lotherk 9f5d55dab8 sign-release: the release key of the build host is the default
Without SIGNIFY_SECKEY 'auto' printed 'not signed' and left the previous
.sig next to the new SHA512: a stale signature, which tools/upgrade-verify.sh
and the source DVD check refuse.  Measured twice on 2026-11-17 (release b and
the source set c).  An explicit SIGNIFY_SECKEY still wins.
2026-11-17 20:49:17 +00:00

110 lines
3.8 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
# sign-release.sh -- the signify signature of a release, in a chain.
#
# usage: sign-release.sh sign FILE...
# sign-release.sh auto FILE... (sign what exists, if a key is set)
# sign-release.sh verify FILE...
# sign-release.sh sign-key RELEASE-PUBKEY
#
# The root key signs the release key once; the release key signs the files of
# a release. The root key is offline and never in the tree: sign-key takes
# its path from SIGNIFY_ROOT_SECKEY. The release key takes its path from
# SIGNIFY_SECKEY.
#
# verify checks the chain first: /etc/signify/makronix-root.pub against
# /etc/signify/makronix-0.99.pub.sig (SIGNIFY_ROOT_PUBKEY, SIGNIFY_PUBKEY
# override), then FILE.sig against the release key.
#
# What is signed: RELEASEDIR/source/sets/SHA512 (the SHA512 of the sets) and
# the medium's package list (RELEASEDIR/.../binary/packages/pkg_summary.gz or
# the SHA512 written next to it). The upgrade command verifies them before
# it runs sysupgrade or pkg_add as root (tasksd t0055, t0078).
#
# signify is not part of the NetBSD base: use the host's signify or
# signify-openbsd, or the package security/signify on the target.
set -eu
die()
{
echo "sign-release: $*" >&2
exit 1
}
SIGNIFY=$(command -v signify 2>/dev/null || command -v signify-openbsd 2>/dev/null) \
|| die "no signify (security/signify)"
# The release key of the build host, unless the caller names another: without
# it `auto' left the previous .sig next to a new SHA512 (a stale signature
# that the upgrade check refuses; measured 2026-11-17).
if [ -z "${SIGNIFY_SECKEY:-}" ] &&
[ -r "${HOME:-/nonexistent}/.config/makronix/signify/makronix-0.99.sec" ]; then
SIGNIFY_SECKEY=$HOME/.config/makronix/signify/makronix-0.99.sec
export SIGNIFY_SECKEY
fi
[ $# -ge 2 ] || die "usage: $0 sign|auto|verify|sign-key ARG..."
cmd=$1
shift
case $cmd in
sign)
[ -n "${SIGNIFY_SECKEY:-}" ] || die "SIGNIFY_SECKEY is not set"
[ -r "$SIGNIFY_SECKEY" ] || die "cannot read $SIGNIFY_SECKEY"
for f in "$@"; do
[ -f "$f" ] || die "no $f"
"$SIGNIFY" -S -s "$SIGNIFY_SECKEY" -m "$f" -x "$f.sig" \
|| die "signing $f failed"
echo "sign-release: $f.sig"
done
;;
auto)
# For a build: sign the files that exist when the release key is
# there, say so when it is not. A developer build has no key.
if [ -z "${SIGNIFY_SECKEY:-}" ]; then
echo "sign-release: not signed (SIGNIFY_SECKEY is not set)" >&2
exit 0
fi
[ -r "$SIGNIFY_SECKEY" ] || die "cannot read $SIGNIFY_SECKEY"
for f in "$@"; do
if [ ! -f "$f" ]; then
echo "sign-release: $f: not there, nothing to sign" >&2
continue
fi
"$SIGNIFY" -S -s "$SIGNIFY_SECKEY" -m "$f" -x "$f.sig" \
|| die "signing $f failed"
echo "sign-release: $f.sig"
done
;;
sign-key)
[ $# -eq 1 ] || die "usage: $0 sign-key RELEASE-PUBKEY"
[ -n "${SIGNIFY_ROOT_SECKEY:-}" ] || die "SIGNIFY_ROOT_SECKEY is not set"
[ -r "$SIGNIFY_ROOT_SECKEY" ] || die "cannot read $SIGNIFY_ROOT_SECKEY"
[ -f "$1" ] || die "no $1"
"$SIGNIFY" -S -s "$SIGNIFY_ROOT_SECKEY" -m "$1" -x "$1.sig" \
|| die "signing $1 with the root key failed"
echo "sign-release: $1.sig (signed by the root key)"
;;
verify)
PUB=${SIGNIFY_PUBKEY:-/etc/signify/makronix-0.99.pub}
ROOT=${SIGNIFY_ROOT_PUBKEY:-/etc/signify/makronix-root.pub}
[ -r "$PUB" ] || die "cannot read $PUB (signify release key)"
if [ -r "$ROOT" ] && [ -r "$PUB.sig" ]; then
"$SIGNIFY" -V -p "$ROOT" -m "$PUB" -x "$PUB.sig" \
|| die "the release key $PUB is not signed by the root key"
echo "sign-release: $PUB: signed by the root key"
fi
for f in "$@"; do
[ -f "$f" ] || die "no $f"
[ -f "$f.sig" ] || die "no $f.sig"
"$SIGNIFY" -V -p "$PUB" -m "$f" -x "$f.sig" \
|| die "verifying $f failed"
echo "sign-release: $f: good signature"
done
;;
*)
die "unknown command $cmd"
;;
esac