onionwire/scripts/sign-release.sh
agent 601f640f78
All checks were successful
android-ci / android (pull_request) Successful in 12m34s
ci / test (pull_request) Successful in 13m28s
ci / sdk (pull_request) Successful in 1m13s
release: reproducible builds, and sign every asset
"The source is public" is not a check anyone can run, and against a Tor +
Monero tool the surviving objection is that the released binary might not be
that source. This makes the build checkable instead of trusted.

- scripts/reproducible-build.sh is the single definition of a release build:
  digest-pinned builder image, fixed in-container paths, SOURCE_DATE_EPOCH
  from the released commit, --locked, its own apt build deps, and RUSTFLAGS
  replaced rather than extended. The fixed paths are load-bearing: rustc's
  --remap-path-prefix cannot reach absolute paths compiled in by a C
  toolchain, and this graph always has one (rusqlite compiles OpenSSL from
  vendored sources; the default cuprate-daemon adds RandomX and cmake). It
  also records toolchain versions in build-info, because the apt build deps
  are not digest-pinned the way the image is.
- release.yml pins the image by digest, resolves SOURCE_DATE_EPOCH from the
  tag's commit, runs that recipe, and uploads build-info-<target>.txt beside
  the binary. The cargo target volume is created per run and removed, so the
  published artifact cannot come out of a cache that a verifier does not have.
- scripts/verify-reproducible.sh rebuilds a tag in the same pinned image and
  compares bytes against the release asset. Two fresh builds of the same tree
  in that image produce identical sha256.
- scripts/sign-release.sh signs with minisign and verifies its own signature
  against the committed public key. The publish job signs BEFORE publishing
  and fails closed without MINISIGN_SECRET_KEY, so nothing unsigned reaches
  the release page: an unsigned release is indistinguishable from a signed
  one to anyone who is not checking. Checked: signature accepted by an
  independent minisign -V, a tampered file rejected, a missing key refused,
  a missing public key refused.
- build-release-local.sh runs the same container and the same recipe. A host
  cargo build would publish a hash nobody could reproduce, which is worse
  than having no fallback at all.
- docs/VERIFY.md is the verifier-facing walkthrough: the dependency graph and
  where its HTTP actually comes from, the wallet's real seed-read exposure,
  the rebuild check, the signature check, and an explicit list of what none
  of it proves.
- Cargo.toml repository: point at the Forgejo instance that hosts this and
  builds its releases.

Needs a MINISIGN_SECRET_KEY secret before the next release; without it the
publish job stops by design. docs/RELEASING.md has the keygen procedure.
2026-10-11 12:57:40 -04:00

81 lines
No EOL
3.5 KiB
Shell
Executable file

#!/usr/bin/env bash
# Sign release assets with minisign, and verify our own signatures before
# anything reaches the release page.
#
# Usage: sign-release.sh <file> [<file>...]
#
# 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 <file> [<file>...]" >&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