Files
ObsidianDragon/scripts/sign-bootstrap-release.sh
T
DanSandClaude Opus 4.8 b79a62b24b fix(security): verify an ed25519 signature on the bootstrap archive (F5)
The chain-bootstrap download was authenticated only by a same-origin SHA-256,
which anyone who can replace the archive (CDN/server compromise or a TLS break)
can also replace. The RCE half of the original report is already closed — extract
skips every *.conf/wallet*/.dat entry, so DRAGONX.conf/blocknotify can't be
overwritten — but the archive itself was unauthenticated.

Verify a detached ed25519 signature over the published .sha256 file (the archive
is multi-GB; its checksum already binds the bytes, so signing the small checksum
authenticates the whole download) against a pinned key. A present-but-invalid
signature always fails closed; a missing one is gated by
kBootstrapRequireSignature (false until bootstrap.dragonx.is publishes .sig
files, then flip to true). Adds scripts/sign-bootstrap-release.sh; the secret key
stays offline.

Also adds regression tests: testBootstrapSignatureInterop (known-answer verify
against the pinned key, fails closed on tamper/wrong-key — F5) and
testEphemeralPortPick (F13).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-08 11:52:57 -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 key pinned in src/util/bootstrap.h (kBootstrapSignaturePublicKeyBase64). 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 (kBootstrapSignaturePublicKeyBase64):"
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 does not match the public key pinned in the wallet (it would then reject every
# signature made with it — expected only when deliberately rotating the pinned key).
pinned="$(grep -oE '"[A-Za-z0-9+/]{43}="' "$PROJECT_ROOT/src/util/bootstrap.h" 2>/dev/null | head -1 | tr -d '"')"
mine="$(pubkey_b64 "$key")"
if [ -n "$pinned" ] && [ "$pinned" != "$mine" ]; then
echo "WARNING: this key's public key does not match the one pinned in bootstrap.h:" >&2
echo " signing key -> $mine" >&2
echo " pinned key -> $pinned" >&2
echo " The wallet will REJECT these signatures unless you are rotating the pinned key." >&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