banger/internal/updater
Thales Maciel 8ed351ea47
updater: cosign-blob signature verification on SHA256SUMS
Closes the v0.1.0 cosign requirement. Every banger update download
now goes through ECDSA-P256 verification before any binary is
trusted: SHA256SUMS.sig is fetched, base64-decoded, and verified
against the embedded BangerReleasePublicKey.

  * BangerReleasePublicKey: PEM-encoded ECDSA public key embedded
    at compile time. The current value is a sentinel PLACEHOLDER —
    the maintainer must replace it with the output of
    `cosign generate-key-pair`'s cosign.pub before cutting v0.1.0,
    and re-cut. Until they do, every `banger update` refuses with
    ErrSignatureRequired ("the maintainer must replace it and
    re-cut a release before update can proceed"). Loud refusal
    beats silent acceptance.
  * VerifyBlobSignature: parses the embedded public key, base64-
    decodes the signature, computes SHA256(body), runs ecdsa
    .VerifyASN1. cosign sign-blob produces the format
    VerifyASN1 verifies natively (ASN.1-DER encoded ECDSA over
    a SHA256 digest), so no third-party crypto deps needed.
  * FetchAndVerifySignature: pulls the signature URL from the
    release manifest entry, fetches it (1 KiB cap), and verifies
    against sumsBody. Refuses outright when sha256sums_sig_url is
    empty — v0.1.0 contract requires every release to be signed,
    and an unsigned release is a manifest publishing bug we'd
    rather catch loudly than silently accept.
  * Wired into banger update: sumsBody captured from
    DownloadRelease, immediately fed into FetchAndVerifySignature.
    A failed verification removes the staged tarball before
    returning so it can't be reused.
  * BangerReleasePublicKey is var (not const) only to support tests
    that swap in a generated keypair; production sets it at compile
    time and never mutates it.

Tests: placeholder-key path returns ErrSignatureRequired; happy
path with a fresh in-test ECDSA keypair verifies a real
sign-then-verify; tampered body, wrong key, and three malformed
signature shapes (not-base64, empty, garbage-DER) all reject.

Maintainer-cut workflow documented in BangerReleasePublicKey's
comment: cosign generate-key-pair → paste cosign.pub into the
constant → at release time, cosign sign-blob --key cosign.key
SHA256SUMS > SHA256SUMS.sig and publish.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 12:37:53 -03:00
..
download.go updater: download/stage/swap/rollback flow steps 2026-04-29 12:30:22 -03:00
flow_test.go updater: download/stage/swap/rollback flow steps 2026-04-29 12:30:22 -03:00
manifest.go updater: manifest + SHA256SUMS parsing scaffolding 2026-04-29 12:24:36 -03:00
manifest_test.go updater: manifest + SHA256SUMS parsing scaffolding 2026-04-29 12:24:36 -03:00
sha256sums.go updater: manifest + SHA256SUMS parsing scaffolding 2026-04-29 12:24:36 -03:00
sha256sums_test.go updater: manifest + SHA256SUMS parsing scaffolding 2026-04-29 12:24:36 -03:00
stage.go updater: download/stage/swap/rollback flow steps 2026-04-29 12:30:22 -03:00
swap.go updater: download/stage/swap/rollback flow steps 2026-04-29 12:30:22 -03:00
verify_signature.go updater: cosign-blob signature verification on SHA256SUMS 2026-04-29 12:37:53 -03:00
verify_signature_test.go updater: cosign-blob signature verification on SHA256SUMS 2026-04-29 12:37:53 -03:00