Documentation
¶
Overview ¶
Package update finds out whether a newer RemoHop release exists and how this copy should be upgraded. It only reads: it downloads nothing but a small version file and never replaces a program.
The version file is https://remohop.com/version.json, a static file of the website ({"version": "v1.2.3"}), built from site/build.py. The request carries no identifier: no machine ID, no account, and the User-Agent is just "RemoHop". Everything the app shows (the download page, the release notes) is an address this package builds from the version number, so a tampered file can at most claim a version, never send the user elsewhere.
Index ¶
- Constants
- Variables
- func Cleanup(p Plan)
- func Download(ctx context.Context, f Fetcher, keys []ed25519.PublicKey, tag string, p Plan, ...) (string, error)
- func DownloadURL(lang string) string
- func Install(p Plan, staged string) error
- func Keys() []ed25519.PublicKey
- func Message(tag string, sums []byte) []byte
- func Newer(latest, current string) bool
- func ParseKey(s string) (ed25519.PublicKey, error)
- func ParseSums(b []byte) (map[string]string, error)
- func Sign(priv ed25519.PrivateKey, tag string, sums []byte) []byte
- func Verify(keys []ed25519.PublicKey, tag string, sums, sig []byte) error
- func VerifyBundle(string) error
- type Env
- type Fetcher
- type Method
- type Plan
- type Progress
- type Release
- type Version
Constants ¶
const ( // AppleTeamID signs the macOS app (checked by VerifyBundle). AppleTeamID = "H7FLAAL9RB" SigContext = "remohop-update-v1" SumsFile = "SHA256SUMS" SigFile = "SHA256SUMS.ed25519" )
In-app upgrades trust a release only through an Ed25519 signature made by the release workflow (secret UPDATE_SIGNING_KEY) over the release's SHA256SUMS. The signed message binds the tag, so the files of an older release cannot be passed off as a newer one:
"remohop-update-v1\n" + tag + "\n" + the bytes of SHA256SUMS
The signature is the release asset SigFile: base64 on one line. The public keys the app accepts are TrustedKeys (keys.go); with none, one-click upgrades are off and the app only opens the download page.
const ( KindDownload = "download" // a download from the website: get the new one there KindHomebrew = "homebrew" KindScoop = "scoop" KindWinget = "winget" KindSnap = "snap" KindPackage = "package" // .deb, .rpm, .apk, AUR: the system's package manager KindNix = "nix" KindStore = "store" // the Microsoft Store (MSIX): the Store updates it )
Kinds of installation.
const Repo = "readori/RemoHop"
Repo is the GitHub repository the release pages are in.
const URL = "https://remohop.com/version.json"
URL is where the version file lives.
Variables ¶
var ErrBadSignature = errors.New("the release signature does not check out")
ErrBadSignature: the signature is not one of a trusted key over these sums for this tag.
var ErrUnsupported = errors.New("this copy cannot upgrade itself")
ErrUnsupported: this copy cannot upgrade itself.
var TrustedKeys = []string{
"EhMAtz32qkaC5xnCXOo6SLO2J/fH6WzxkIV3wvZuUyQ=",
"fdzFU7FhCrIrtD3sTKmcEP4Y1TioJ6LKurOp5fzetSo=",
}
TrustedKeys are the Ed25519 public keys (base64) whose signatures on a release's SHA256SUMS this build accepts for one-click upgrades (sign.go).
- The first is the release workflow's key; its private half is only the repository secret UPDATE_SIGNING_KEY.
- The second, when set, is a spare kept offline by the project's owner: if the first is ever lost or leaked, releases are signed with the spare, and a release that drops the old key goes out signed by it.
Empty: one-click upgrades are off, and the app offers the download page. `go run ./scripts/updsign keygen` makes a key pair.
Functions ¶
func Cleanup ¶
func Cleanup(p Plan)
Cleanup removes what an upgrade left behind (the old program, a staged one that was never installed). It is called at start; failures are harmless (the old program may still be exiting on Windows).
func Download ¶
func Download(ctx context.Context, f Fetcher, keys []ed25519.PublicKey, tag string, p Plan, progress Progress) (string, error)
Download fetches and checks tag's archive for p and unpacks the new program next to p.Target. It returns the staged path, which Install puts in place. Nothing is changed when it fails.
func DownloadURL ¶
DownloadURL is the website's download page in the given language.
func Install ¶
Install swaps the staged program in: the old one becomes Target+".old" (a running program can be renamed, even on Windows), which Cleanup removes at the next start. On failure the old program is put back.
func Keys ¶
Keys returns TrustedKeys parsed. A key that does not parse is a build mistake and panics (TestTrustedKeys catches it first).
func Newer ¶
Newer reports whether latest is a newer version than current. A current version that does not parse (a development build, including one built from source after a tag, such as v1.0.7-3-gabc1234) is never out of date: offering the last release would be a downgrade.
func Sign ¶
func Sign(priv ed25519.PrivateKey, tag string, sums []byte) []byte
Sign signs a release's SHA256SUMS; the result is the content of SigFile.
Types ¶
type Env ¶
type Env struct {
GOOS string
Exe string // the program's path, symbolic links resolved
Getenv func(string) string
Exists func(string) bool
}
Env is what Detect looks at; tests replace it.
type Fetcher ¶
type Fetcher struct {
Client *http.Client
// Base is the release download address with %s for the tag;
// empty means GitHub's.
Base string
}
Fetcher downloads release files; tests replace it.
type Method ¶
type Method struct {
Kind string `json:"kind"`
// Command upgrades it, when there is one command for it.
Command string `json:"command,omitempty"`
}
Method is how this copy is upgraded.
type Plan ¶
type Plan struct {
// Asset is the release file to download.
Asset string `json:"asset"`
// Member is the file (or, for an app bundle, the directory) inside it.
Member string `json:"-"`
// Target is what is replaced: the program, or on macOS the .app.
Target string `json:"-"`
// Bundle: Target is a macOS .app directory.
Bundle bool `json:"-"`
}
Plan is what an upgrade of this program replaces and with which file.
type Progress ¶
Progress reports a stage ("verifying", "downloading", "installing") and, while downloading, the percentage done (-1 when unknown).
type Release ¶
type Release struct {
Version string `json:"version"`
}
Release is what the version file says.
type Version ¶
Version is a parsed vMAJOR.MINOR.PATCH[-PRE].
func ParseVersion ¶
ParseVersion parses "v1.2.3" or "v1.2.3-rc.1". Development builds ("dev", a build from source such as "v1.2.3-4-gabc1234" or "v1.2.3-dirty", or anything else) do not parse.