Documentation
¶
Overview ¶
Package sumverify answers one question about an installed Go binary: was every module compiled into it checked against sum.golang.org?
The answer comes from the RESULT, not from how the binary was installed. A Go binary records, for its main module and every dependency, the h1: hash of the module zip it was built from (runtime/debug.BuildInfo, read here with debug/buildinfo). The checksum database is an append-only, signed Merkle tree (https://go.dev/design/25530-sumdb) holding the h1: hash of every public module version. If the two agree the binary was built from the bytes the whole world sees; if they disagree it was built from something else. An install made with GONOSUMDB, GOSUMDB=off, GOFLAGS=-insecure, a replace directive or a working tree cannot produce a VERIFIED binary, however the environment was set or hidden.
Lookups go through golang.org/x/mod/sumdb.Client, which verifies the signed tree head with the built-in key and the inclusion of the record; a plain HTTP GET of the record would be believing the transport.
Index ¶
- Constants
- func ParseHookInput(r io.Reader) (string, error)
- func Programs(command, binDir, home string) []string
- type DBSource
- type Decision
- type Ops
- func (o *Ops) Log(string)
- func (o *Ops) ReadCache(name string) ([]byte, error)
- func (o *Ops) ReadConfig(name string) ([]byte, error)
- func (o *Ops) ReadRemote(path string) ([]byte, error)
- func (o *Ops) SecurityError(msg string)
- func (o *Ops) WriteCache(name string, data []byte)
- func (o *Ops) WriteConfig(name string, old, new []byte) error
- type Result
- type Source
- type Status
- type StatusError
- type Verdict
- type Verifier
Constants ¶
const ( DefaultBase = "https://sum.golang.org" DefaultKey = "sum.golang.org+033de0ae+Ac4zctda0e5eza+HJyk9SxEdh+s3Ux18htTTAD8OuAn8" )
DefaultBase and DefaultKey are the checksum database the Go toolchain trusts. The key is cmd/go/internal/modfetch/key.go, copied from the go1.27.4 source tree; every record and tree head is verified against it by golang.org/x/mod/sumdb, so the transport (and any proxy in between) is not trusted.
const MaxFile = 512 << 20
MaxFile bounds what is hashed.
Variables ¶
This section is empty.
Functions ¶
func ParseHookInput ¶
ParseHookInput reads a Claude Code PreToolUse payload and returns the Bash command, or "" when it is not a Bash call. It never panics, whatever it is given (fuzzed).
func Programs ¶
Programs returns the files under binDir that the command would run: the first word of every simple command, looking through env assignments, launchers (env, sudo, command, exec, nohup, time, nice, xargs, sh -c ...), pipes, lists and $( ) / backtick substitutions. No shell is run.
It is a best-effort reading of what the command LINE runs. It cannot see a program started by another program; the cache, not this parser, is what makes an installed binary trustworthy.
Types ¶
type DBSource ¶
type DBSource struct {
// contains filtered or unexported fields
}
DBSource is the production Source: a tlog-verifying sumdb.Client.
type Decision ¶
type Decision struct {
Deny bool
Reason string // shown to the model when Deny
Notes []string // for stderr: NOSUM reports, cannot-read allowances
}
Decision is a hook answer.
type Ops ¶
type Ops struct {
Base string // no trailing slash
Key string // verifier key
Dir string // durable directory (config/ and cache/)
HTTP *http.Client
// contains filtered or unexported fields
}
Ops implements sumdb.ClientOps over HTTP with durable files under Dir.
It is deliberately NOT configurable from the environment: GOPROXY, GOSUMDB, GONOSUMDB and friends are exactly the knobs this package exists to be immune to.
func (*Ops) ReadConfig ¶
ReadConfig implements sumdb.ClientOps: the key, and the latest tree head.
func (*Ops) ReadRemote ¶
ReadRemote implements sumdb.ClientOps.
func (*Ops) SecurityError ¶
SecurityError implements sumdb.ClientOps: the database lied, or a cached tree head contradicts it. Recorded, so the verdict can say so.
func (*Ops) WriteCache ¶
WriteCache implements sumdb.ClientOps. A failure only costs a re-fetch.
type Result ¶
type Result struct {
Path string
Verdict Verdict
// SHA is the SHA-256 of the file content (empty for NotGo).
SHA string
// Main is "module@version" of the main module, when known.
Main string
// Unreachable is set when Unverified because the database could not be
// asked at all (as opposed to answering "no").
Unreachable bool
// Cached is set when the answer came from the verdict cache.
Cached bool
// Detail is one line of explanation; Bad names the modules at fault.
Detail string
Bad []string
}
Result is the verdict for one file.
type Source ¶
Source looks a module version up in the checksum database. The returned lines are go.sum lines ("path version h1:...").
type Status ¶
type Status int
Status classifies a failed lookup.
const ( // OK: the database answered with a verified record. OK Status = iota // NotFound: HTTP 404/410, the version is not (yet) in the database. NotFound // Unreachable: the database could not be asked (transport error, 5xx...). Unreachable // Failed: the database answered and the answer did not verify. Failed )
type StatusError ¶
StatusError is a non-200 answer from the database.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) NotYetPublished ¶
func (e *StatusError) NotYetPublished() bool
NotYetPublished reports the answers that mean "the database does not know this module version (yet)", as opposed to "the database could not be asked".
type Verdict ¶
type Verdict string
Verdict is the answer for one file.
const ( // Verified: every module in the binary carries an h1: hash that // sum.golang.org confirms. Verified Verdict = "VERIFIED" // Mismatch: the database knows a module version with a DIFFERENT hash. The // binary was built from other bytes than the published ones: tampered. Mismatch Verdict = "MISMATCH" // Unverified: the database could not confirm it (not yet published, 404, // unreachable, misbehaving, or a dependency without a recorded hash). An // unreadable answer is never Verified. Unverified Verdict = "UNVERIFIED" // NoSum: built from a working tree (main module "(devel)"): there is no // published hash to compare with. NoSum Verdict = "NOSUM" // NotGo: not a Go binary. NotGo Verdict = "NOTGO" )
type Verifier ¶
type Verifier struct {
Source Source
CacheDir string
// Info reads the build info; nil means debug/buildinfo.Read. A seam for
// tests, which cannot make the go tool stamp arbitrary dependency hashes.
Info func(io.ReaderAt) (*debug.BuildInfo, error)
// MaxSize bounds what is hashed; 0 means MaxFile.
MaxSize int64
}
Verifier verifies binaries. CacheDir holds VERIFIED verdicts keyed by the SHA-256 of the file content; nothing else is cached, so an unverified binary is asked again every time.