#!/usr/bin/env bash # Sign release assets with minisign, and verify our own signatures before # anything reaches the release page. # # Usage: sign-release.sh [...] # # Env: # MINISIGN_SECRET_KEY contents of the secret key file (required). # A CI secret; never committed, never passed as an arg. # MINISIGN_PUBKEY_FILE default scripts/onionwire-signing.pub # RELEASE_TAG optional; recorded in the trusted comment # # Fail closed by design. If the key is missing or a signature we just made does # not verify, this exits non-zero and the publish job stops — an unsigned # release is worse than a missing one, because it looks identical to a signed # one to anyone who is not checking. # # The key must be generated WITHOUT a password (`minisign -G -W`): CI cannot # answer a prompt, and a passphrase that has to sit next to the key in the same # secret store protects nothing. The secret lives only in Forgejo Actions # secrets; the public half is committed so verifiers have it out-of-band from # the release page. See docs/VERIFY.md. set -euo pipefail [ "$#" -ge 1 ] || { echo "usage: sign-release.sh [...]" >&2; exit 1; } root="$(cd "$(dirname "$0")/.." && pwd)" pub_file="${MINISIGN_PUBKEY_FILE:-$root/scripts/onionwire-signing.pub}" command -v minisign >/dev/null 2>&1 || { echo "sign-release: minisign is not installed (apt-get install -y minisign)" >&2 exit 1 } [ -s "$pub_file" ] || { echo "sign-release: no public key at $pub_file" >&2 echo " Generate the pair once, on a machine you control:" >&2 echo " minisign -G -W -p scripts/onionwire-signing.pub -s onionwire-signing.key" >&2 echo " Commit the .pub file, store the .key file's contents as the Forgejo" >&2 echo " Actions secret MINISIGN_SECRET_KEY, then delete the .key file." >&2 echo " Procedure: docs/VERIFY.md, \"Maintainer: the signing key\"." >&2 exit 1 } : "${MINISIGN_SECRET_KEY:?MINISIGN_SECRET_KEY is not set — add it as a Forgejo Actions secret; see docs/VERIFY.md}" tmp="$(mktemp -d)" cleanup() { # The secret key is on disk for the length of this script and no longer. if [ -f "$tmp/onionwire-signing.key" ]; then shred -uz "$tmp/onionwire-signing.key" 2>/dev/null || rm -f "$tmp/onionwire-signing.key" fi rm -rf "$tmp" } trap cleanup EXIT umask 077 printf '%s\n' "$MINISIGN_SECRET_KEY" > "$tmp/onionwire-signing.key" chmod 600 "$tmp/onionwire-signing.key" # Warm the signature with the same secret we just wrote: an unreadable or # truncated secret fails here rather than after three files are half-signed. [ -s "$tmp/onionwire-signing.key" ] || { echo "sign-release: the secret key is empty" >&2; exit 1; } comment="OnionWire ${RELEASE_TAG:-release}" for f in "$@"; do [ -f "$f" ] || { echo "sign-release: no such file: $f" >&2; exit 1; } bytes=$(wc -c < "$f") [ "$bytes" -gt 0 ] || { echo "sign-release: refusing to sign empty file $f" >&2; exit 1; } minisign -S -W -s "$tmp/onionwire-signing.key" -m "$f" -x "$f.minisig" \ -t "$comment" -c "signature for $(basename "$f")" [ -s "$f.minisig" ] || { echo "sign-release: minisign produced no signature for $f" >&2; exit 1; } # Verify with the public half, not with the secret we just used: this is the # check a user will run, so it is the check we run. minisign -V -p "$pub_file" -m "$f" -x "$f.minisig" -q \ || { echo "sign-release: our own signature for $f does not verify against $pub_file" >&2; exit 1; } echo "sign-release: signed and verified $(basename "$f") -> $(basename "$f").minisig" done