Documentation
¶
Overview ¶
Package release holds everything about WHERE ccdad releases live: how a tag is spelled and ordered, what this machine's asset is called, how the published sha256sums.txt is read, and the HTTP client that reads them.
It exists because both installers hard-code those rules — install.sh in shell, install.ps1 in PowerShell — and a third, divergent copy in Go would be a verification hole rather than a duplication. `ccdad update` and the daemon's version check share this one.
Index ¶
Constants ¶
const MinAssetBytes = 1_000_000
MinAssetBytes is the floor a downloaded asset has to clear.
Every released ccdad is over three megabytes on all six targets, and nothing under a megabyte is one — it is a proxy's error page, a captive-portal login, or a truncated transfer. install.sh applies the same figure for the same reason, and the two must not drift: a floor here that is lower than the installer's would let `update` accept what a fresh install refuses.
Variables ¶
This section is empty.
Functions ¶
func Asset ¶
func Asset() string
Asset names the release asset for the build this binary IS.
runtime.GOOS and runtime.GOARCH, with one consequence worth stating: an amd64 binary running under Rosetta or Windows-on-ARM updates to amd64 forever, while install.ps1's own detection would pick arm64. So `update` and the installer disagree exactly on the machines emulation exists for; getting off the wrong architecture means re-running the installer instead of running `update`, and nothing in this repository writes that down yet.
func BaseURL ¶
func BaseURL() string
BaseURL is where releases are fetched from, honouring the variable install.sh and install.ps1 already read. It is one seam and not two: the command and the daemon's version check both go through here, so a daemon cannot ignore a test origin the CLI was pointed at.
A trailing slash is trimmed rather than tolerated, because every caller joins a path onto this and a doubled separator is a 404 nobody can explain.
func DownloadBase ¶
DownloadBase is where one release's assets live.
func ExpectedHash ¶
ExpectedHash returns the lowercase hex digest sums records for asset.
Anchored at BOTH ends, and the asset name quoted. A missing trailing anchor lets ccdad-linux-amd64 match the ccdad-linux-amd64.exe row — a different platform's binary, with a digest that would then verify. Quoting matters because the asset name is data here and not a pattern.
Comparison downstream is case-sensitive against this value, never EqualFold: the class above is lowercase, and a fold would accept a row an attacker re-cased.
A CRLF file does not match, and that is the answer rather than a gap. Neither sha256sum nor shasum emits one, and accepting it would mean accepting a row whose asset name ends in a carriage return.
ok=false is "not listed" and is a DIFFERENT refusal from a file that fails SumsLookLikeSums. The caller must ask both questions, in that order.
func SumsLookLikeSums ¶
SumsLookLikeSums reports whether b contains at least one checksum row.
It is the check that catches a proxy's HTML error page BEFORE the bytes are treated as data. Per line rather than over the whole file, because the release's sums file also covers LICENSE, NOTICE and THIRD-PARTY-LICENSES.txt — a release is a binary distribution and those notices are part of it — so nothing here may depend on the line count or the ordering.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client fetches release metadata and assets.
func NewClient ¶
func NewClient() *Client
NewClient builds a client pinned to the configured origin.
func (*Client) Download ¶
func (c *Client) Download(ctx context.Context, rawURL, dest string, limit int64) (string, int64, error)
Download streams a URL into dest, returning the lowercase hex sha256 of what arrived and how many bytes it was.
The body goes through the hasher on its way to disk rather than being buffered and hashed afterwards: the asset is megabytes, and a version that read it into memory first would hold the whole thing twice.
This step owns the file's durability and its mode, because it is the code holding the open handle. Sync before close, then Chmod EXPLICITLY after the close — a create mode is masked by umask, and install.sh's bare chmod 0755 defeats umask deliberately. Whatever renames this file afterwards therefore does renames and nothing else.
A failed download removes dest. A partial file left in a directory on the user's PATH under a plausible name is worse than no file.
func (*Client) Get ¶
Get reads a whole small body.
limit is a REFUSAL, not a truncation. An io.LimitReader on its own hands back a prefix of an over-long body, and every caller here goes on to parse what it got as though it were the whole file.
func (*Client) Latest ¶
Latest resolves the published latest release to its tag.
GET <base>/latest with redirects NOT followed: the Location header is the answer. api.github.com/repos/.../releases/latest is deliberately not used, and the reason is already written down in install.sh — sixty unauthenticated requests an hour turns a corporate NAT or a CI runner into a mystery failure. Reintroducing it here would need that argument re-made, not merely forgotten.
The Location is remote-controlled input that ends up in a status document and on a terminal. Only a …/tag/<version> shape is accepted, it is re-parsed, and the canonical re-stringified tag is what comes back — never the bytes the origin sent.
The tag arriving over an unauthenticated channel is safe ONLY because the signature's trusted comment names the release too: the origin chooses the name, and the signature decides whether the bytes are the ones published under it. Neither half stands alone.
type StatusError ¶
StatusError is a non-200 answer, carrying the code because one of them means something specific: a 404 on sha256sums.txt.minisig is a release that genuinely carries no signature, which is a refusal a user can act on, while a 500, a timeout or a DNS failure says nothing about the release at all. Reporting the second as a tamper verdict would let a flaky origin manufacture a permanent-looking one.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
type Version ¶
type Version struct {
Major, Minor, Patch int
// Pre keeps its leading '-', so String can append it unconditionally.
Pre string
}
Version is a release version. Only the three numbers are ordered; Pre is carried so a prerelease tag round-trips and sorts below the release of the same numbers.
func ParseTag ¶
ParseTag reads a release tag. It accepts "1.2.3", "v1.2.3" and surrounding whitespace, so that `--version 1.2.3` and `--version v1.2.3` are the same request. Without that, a user's missing v fails later as "this signature is for a different release" — the tamper remedy, for a typo.