update

package
v0.1.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package update implements the signed, fail-closed CodeSampleX binary updater. It deliberately uses only the Go standard library so the updater does not add another executable supply-chain dependency of its own.

Index

Constants

View Source
const (
	ManifestSchema     = 1
	DefaultChannel     = "stable"
	DefaultManifestURL = "https://github.com/r2cuerdame/CodeSampleX/releases/latest/download/csx-update-stable.json"
)

Variables

View Source
var ErrPolicyDisabled = errors.New("update: automatic update policy was disabled")
View Source
var PublicKeyBase64 string

PublicKeyBase64 is stamped into release binaries from the protected release signing secret. Development builds intentionally have no update trust root.

Functions

func AcknowledgeActivation

func AcknowledgeActivation(home, currentVersion string) error

AcknowledgeActivation clears a restart notice only from a newly launched binary that matches the installed target (or the first process after a rollback). It never removes the preserved previous executable.

func AdoptStandalone

func AdoptStandalone(home, executable string) error

func AutoEnabled

func AutoEnabled(mode, policy string) bool

func BootstrapLauncher

func BootstrapLauncher(ctx context.Context, root, staged, legacy, currentVersion string) (launcher.Active, error)

BootstrapLauncher is the one-time Windows installer bridge. It verifies the signed stable manifest with the key embedded in the payload, then lets the shared launcher commit code durably promote that running staged payload.

func CompareVersions

func CompareVersions(a, b string) (int, error)

CompareVersions compares strict numeric release versions, ignoring one leading v. It rejects ranges, aliases, and prerelease text.

func EmbeddedPublicKey

func EmbeddedPublicKey() (ed25519.PublicKey, error)

func InstallPath

func InstallPath(home string) string

func IsCanonicalReleaseVersion

func IsCanonicalReleaseVersion(v string) bool

func OwnsExecutable

func OwnsExecutable(home, executable string) (bool, error)

func Rollback

func Rollback(home, executable string) (string, error)

func SaveState

func SaveState(home string, st State) error

func StableExecutable

func StableExecutable(home, executable string) (string, error)

func StatePath

func StatePath(home string) string

func WithLock

func WithLock(home string, fn func() error) error

WithLock serializes a consent/config write with update checks. When it returns, no check that observed the old policy can begin a later request.

Types

type Asset

type Asset struct {
	OS                 string `json:"os"`
	Arch               string `json:"arch"`
	URL                string `json:"url"`
	Size               int64  `json:"size"`
	SHA256             string `json:"sha256"`
	MinLauncherVersion string `json:"minLauncherVersion,omitempty"`
}

func CurrentAsset

func CurrentAsset(m Manifest) (Asset, error)

type Client

type Client struct {
	Home              string
	CurrentVersion    string
	Executable        string
	ManifestURL       string
	Channel           string
	PublicKey         ed25519.PublicKey
	HTTP              *http.Client
	Now               func() time.Time
	SelfTest          func(context.Context, string, string) error
	Replace           func(string, string, string) error
	ValidateTarget    func(string) error
	SyncDir           func(string) error
	LoadState         func(string) (State, error)
	SaveState         func(string, State) error
	CheckApplySupport func() error
	Preflight         func() error
	Automatic         bool
	// contains filtered or unexported fields
}

func (*Client) Check

func (c *Client) Check(ctx context.Context, apply bool) (res Result, retErr error)

func (*Client) Due

func (c *Client) Due() bool

type Envelope

type Envelope struct {
	Payload   string `json:"payload"`
	Signature string `json:"signature"`
}

type Install

type Install struct {
	Schema         int    `json:"schema"`
	Kind           string `json:"kind"`
	ExecutablePath string `json:"executablePath"`
	InstallRoot    string `json:"installRoot,omitempty"`
	LauncherPath   string `json:"launcherPath,omitempty"`
}

func LoadInstall

func LoadInstall(home string) (Install, error)

func ResolveInstall

func ResolveInstall(home, executable string) (Install, error)

ResolveInstall uses the per-profile marker when present, then falls back to the stable launcher's verified environment. The latter is install-scoped, so a second CSX_HOME/profile still resolves the same trusted launcher.

type Manifest

type Manifest struct {
	Schema            int       `json:"schema"`
	Channel           string    `json:"channel"`
	Sequence          uint64    `json:"sequence"`
	Version           string    `json:"version"`
	PublishedAt       time.Time `json:"publishedAt"`
	ExpiresAt         time.Time `json:"expiresAt"`
	MinUpdaterVersion string    `json:"minUpdaterVersion,omitempty"`
	Assets            []Asset   `json:"assets"`
}

func VerifyEnvelope

func VerifyEnvelope(raw []byte, publicKey ed25519.PublicKey, now time.Time, channel string) (Manifest, error)

VerifyEnvelope authenticates the raw payload before parsing it. Signing the exact bytes avoids any dependence on JSON canonicalization rules.

func (Manifest) AssetFor

func (m Manifest) AssetFor(osName, arch string) (Asset, error)

type Result

type Result struct {
	CurrentVersion        string
	LatestVersion         string
	Available             bool
	Applied               bool
	RestartRequired       bool
	ManualInstallRequired bool
	RollbackHeld          bool
	PreviousPath          string
	NextCheck             time.Time
}

type State

type State struct {
	Schema              int       `json:"schema"`
	HighestSequence     uint64    `json:"highestSequence,omitempty"`
	HighestVersion      string    `json:"highestVersion,omitempty"`
	LastCheck           time.Time `json:"lastCheck,omitempty"`
	NextCheck           time.Time `json:"nextCheck,omitempty"`
	ConsecutiveFailures int       `json:"consecutiveFailures,omitempty"`
	PendingRestart      string    `json:"pendingRestart,omitempty"`
	PreviousPath        string    `json:"previousPath,omitempty"`
	LastError           string    `json:"lastError,omitempty"`
}

func LoadState

func LoadState(home string) (State, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL