Files
ObsidianDragon/scripts/sign-bootstrap-release.sh
T
DanSandClaude Opus 5.5 79aed5462d feat(security): pin two bootstrap signing keys (automated signer + offline backup) (F5)
The single pinned key CbyBk7... has no secret half on record, so it could never
sign anything. Bootstraps are now built, verified and signed weekly by a
dedicated signer box, and an offline backup key covers loss or revocation of
that key. A signature is accepted if it verifies against either pinned key.

- bootstrap.h: kBootstrapSignaturePublicKeysBase64[] = { hot GHgDNfZV..., cold MZi/rTuQ... }
- bootstrap.cpp: Bootstrap::signatureMatchesPinnedKey() checks every pinned key
  (no network, unit-testable); a present signature matching none stays fatal.
- tests: the known answer is now a real signer-box signature over a real weekly
  checksum (height 3449343); covers tamper, garbage, empty and wrong-key cases,
  the two keys being distinct and valid, and CbyBk7 no longer being pinned.
- sign-bootstrap-release.sh: the key check accepts any pinned key.

kBootstrapRequireSignature stays false until every served bootstrap carries a
signature.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 17:26:52 -06:00

114 lines
4.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Sign the DragonX chain-bootstrap archive for the wallet's in-app bootstrap verifier (F5).
#
# The bootstrap archive (DRAGONX.zip) can be multiple GB, so the wallet does NOT sign the archive bytes.
# Instead it verifies a detached ed25519 signature over the published "DRAGONX.zip.sha256" FILE, against a
# public keys pinned in src/util/bootstrap.h (kBootstrapSignaturePublicKeysBase64). The SHA-256 file already
# binds the archive bytes (the wallet computes and matches the archive's hash first), so signing the small
# checksum authenticates the whole download cheaply.
#
# Uses OpenSSL (>= 1.1.1) only. OpenSSL's ed25519 is PureEdDSA (RFC 8032), the same primitive libsodium's
# crypto_sign_verify_detached checks, so the signatures are compatible.
#
# Usage:
# scripts/sign-bootstrap-release.sh keygen [out-prefix] # -> <prefix>.ed25519.{key,pub.b64}
# scripts/sign-bootstrap-release.sh pubkey <secret.key> # print the base64 public key to pin
# scripts/sign-bootstrap-release.sh sign <secret.key> <file>... # sign existing files -> <file>.sig
# scripts/sign-bootstrap-release.sh checksum <secret.key> <DRAGONX.zip>
# # compute <zip>.sha256 (sha256sum format) and sign it -> <zip>.sha256 + <zip>.sha256.sig
#
# Publish BOTH "DRAGONX.zip.sha256" and "DRAGONX.zip.sha256.sig" next to the archive. The wallet verifies
# the signature over the EXACT .sha256 bytes, so upload the same file that was signed. Keep the secret key
# (.ed25519.key) OFFLINE (mode 600). Flip kBootstrapRequireSignature to true in bootstrap.h once every
# served bootstrap publishes a signature, to make a missing signature fail closed.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
die() { echo "error: $*" >&2; exit 1; }
command -v openssl >/dev/null || die "openssl not found (need >= 1.1.1 with ed25519)"
# Raw 32-byte ed25519 public key (base64) from a private key file (DER SPKI = 12-byte prefix + 32-byte key).
pubkey_b64() { openssl pkey -in "$1" -pubout -outform DER | tail -c 32 | openssl base64 -A; }
sha256_of() {
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}';
else shasum -a 256 "$1" | awk '{print $1}'; fi
}
# Detached ed25519 signature over the raw file bytes -> <file>.sig (base64 of the 64-byte sig).
sign_file() {
local key="$1" f="$2" raw
raw="$(mktemp)"
openssl pkeyutl -sign -inkey "$key" -rawin -in "$f" -out "$raw"
openssl base64 -A -in "$raw" > "$f.sig"
printf '\n' >> "$f.sig"
rm -f "$raw"
}
cmd="${1:-}"; shift || true
case "$cmd" in
keygen)
prefix="${1:-dragonx-bootstrap}"
[ -e "$prefix.ed25519.key" ] && die "$prefix.ed25519.key already exists — refusing to overwrite"
openssl genpkey -algorithm ed25519 -out "$prefix.ed25519.key"
chmod 600 "$prefix.ed25519.key"
pub="$(pubkey_b64 "$prefix.ed25519.key")"
printf '%s\n' "$pub" > "$prefix.ed25519.pub.b64"
echo "secret key : $prefix.ed25519.key (KEEP OFFLINE, mode 600)"
echo "public key : $prefix.ed25519.pub.b64"
echo
echo "Pin this in src/util/bootstrap.h (kBootstrapSignaturePublicKeysBase64):"
echo " $pub"
;;
pubkey)
[ $# -ge 1 ] || die "usage: pubkey <secret.key>"
pubkey_b64 "$1"
;;
sign)
[ $# -ge 2 ] || die "usage: sign <secret.key> <file>..."
key="$1"; shift
[ -f "$key" ] || die "no such key: $key"
for f in "$@"; do
[ -f "$f" ] || die "no such file: $f"
sign_file "$key" "$f"
echo "signed: $f -> $f.sig"
done
;;
checksum)
[ $# -ge 2 ] || die "usage: checksum <secret.key> <DRAGONX.zip>"
key="$1"; zip="$2"
[ -f "$key" ] || die "no such key: $key"
[ -f "$zip" ] || die "no such archive: $zip"
# Warn if this key is not one of the public keys pinned in the wallet (it would then reject every
# signature made with it — expected only when deliberately rotating the pinned keys).
pinned="$(grep -oE '"[A-Za-z0-9+/]{43}="' "$PROJECT_ROOT/src/util/bootstrap.h" 2>/dev/null | tr -d '"')"
mine="$(pubkey_b64 "$key")"
if [ -n "$pinned" ] && ! printf '%s\n' "$pinned" | grep -qxF "$mine"; then
echo "WARNING: this key's public key is not pinned in bootstrap.h:" >&2
echo " signing key -> $mine" >&2
echo " pinned keys -> $(echo $pinned)" >&2
echo " The wallet will REJECT these signatures unless you are rotating the pinned keys." >&2
echo >&2
fi
sum="$(sha256_of "$zip")"
printf '%s %s\n' "$sum" "$(basename "$zip")" > "$zip.sha256"
sign_file "$key" "$zip.sha256"
echo "wrote : $zip.sha256 (sha256=$sum)"
echo "signed : $zip.sha256.sig"
echo
echo "Publish both files next to the archive:"
echo " $(basename "$zip").sha256"
echo " $(basename "$zip").sha256.sig"
;;
*)
die "usage: $0 {keygen [prefix] | pubkey <secret.key> | sign <secret.key> <file>... | checksum <secret.key> <DRAGONX.zip>}"
;;
esac