core

package
v0.9.4-dev.8 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: GPL-3.0 Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BootstrapConfig

func BootstrapConfig(settings config.Settings) ([]byte, error)

func CompiledAssetDigest added in v0.9.3

func CompiledAssetDigest(ctx context.Context, goos, arch, tag, channel string) (string, error)

CompiledAssetDigest returns the compiled SHA-256 for one supported Unix core.

func DetectVerifiedVersion added in v0.9.3

func DetectVerifiedVersion(ctx context.Context, v *VerifiedCore, x VerifiedExecutor) (string, error)

DetectVerifiedVersion verifies the pair/candidate again immediately before -v.

func DetectVersion

func DetectVersion(ctx context.Context, runner CommandRunner, binaryPath string) (string, error)

func DownloadMigrationCore added in v0.9.3

func DownloadMigrationCore(ctx context.Context, client *http.Client, goos, arch, tag string) (binary, receipt []byte, resultErr error)

DownloadMigrationCore retrieves only the pinned supported asset, then derives a receipt from the independently compiled digest rather than a source receipt.

func EnsureRuntimeConfig

func EnsureRuntimeConfig(path string, settings config.Settings) error

func ParseAlphaSHA added in v0.5.0

func ParseAlphaSHA(name string) string

func ParseVersion

func ParseVersion(output string) (string, error)

func RebuildMigrationCore added in v0.9.3

func RebuildMigrationCore(ctx context.Context, goos, arch, tag string, archive []byte) ([]byte, []byte, error)

RebuildMigrationCore verifies a compressed artifact against the compiled Unix table and derives both core bytes and provenance. It never executes the core.

func RecoverProvenance added in v0.9.3

func RecoverProvenance(ctx context.Context, s ProvenanceStore) error

RecoverProvenance converges the entire pair before any core execution. The caller must hold the daemon/maintenance lifecycle lease with no core running.

func ValidateConfig

func ValidateConfig(ctx context.Context, runner CommandRunner, binaryPath, dataDir, configPath string) error

func ValidateVerifiedConfig added in v0.9.3

func ValidateVerifiedConfig(ctx context.Context, v *VerifiedCore, c *ConfigCapability, x VerifiedExecutor) error

ValidateVerifiedConfig preserves the selected candidate identity and hash.

func VerifyCompiledAssetDigest added in v0.9.3

func VerifyCompiledAssetDigest(ctx context.Context, goos, arch, tag, channel, digestHex string) error

VerifyCompiledAssetDigest checks a digest against the compiled Unix core table. Callers must obtain the digest from an independent TLS checksum or a root-only offline manifest; a user-supplied request hash is not the trust root.

func WriteBootstrapConfig

func WriteBootstrapConfig(path string, settings config.Settings) error

Types

type Asset

type Asset struct {
	ID     int64  `json:"id"`
	Name   string `json:"name"`
	URL    string `json:"browser_download_url"`
	Size   int64  `json:"size"`
	Digest string `json:"digest"`
}

func SelectAsset

func SelectAsset(release Release, goos, goarch, channel string) (Asset, error)

type Candidate

type Candidate struct {
	// contains filtered or unexported fields
}

func (*Candidate) Cleanup

func (c *Candidate) Cleanup()

func (*Candidate) Commit

func (c *Candidate) Commit() (InstallResult, error)

func (*Candidate) Updated

func (c *Candidate) Updated() bool

func (*Candidate) Verified added in v0.9.3

func (c *Candidate) Verified(ctx context.Context) (*VerifiedCore, error)

Verified opens this authenticated candidate, including a green installation where no installed pair exists. Commit/Cleanup revoke all candidate commands.

func (*Candidate) Version

func (c *Candidate) Version() string

type CommandRunner

type CommandRunner interface {
	Run(context.Context, string, ...string) ([]byte, error)
}

type ConfigCapability added in v0.9.3

type ConfigCapability struct {
	// contains filtered or unexported fields
}

ConfigCapability binds a selected generated candidate or committed config.

func BindGeneratedConfig added in v0.9.3

func BindGeneratedConfig(ctx context.Context, data *platform.TrustedRoot, relative string, expectedSHA256 [32]byte) (*ConfigCapability, error)

BindGeneratedConfig borrows D and owns a held read descriptor and its parent. expectedSHA256 must be computed by Manager from fresh generated configuration bytes.

func (*ConfigCapability) Close added in v0.9.3

func (c *ConfigCapability) Close() error

func (*ConfigCapability) Path added in v0.9.3

func (c *ConfigCapability) Path(ctx context.Context) (string, error)

Path revalidates and returns this exact config role for the reload adapter.

type CoreCommand added in v0.9.3

type CoreCommand struct {
	Binary, Home, Config string
	Args, Env            []string
}

CoreCommand is the complete command produced by verified capabilities.

type CorePurpose added in v0.9.3

type CorePurpose uint8

CorePurpose selects exactly one supported command shape.

const (
	CoreVersion CorePurpose = iota
	CoreValidate
	CoreRun
)

type GeneratedConfig added in v0.9.3

type GeneratedConfig struct {
	// contains filtered or unexported fields
}

GeneratedConfig retains the exact generated bytes selected for validation.

func (*GeneratedConfig) Close added in v0.9.3

func (g *GeneratedConfig) Close() error

Close retires a generated candidate; identity mismatch leaves the object intact.

func (*GeneratedConfig) Hash added in v0.9.3

func (g *GeneratedConfig) Hash() [32]byte

Hash is the hash of the generated bytes, never a caller-supplied trust root.

func (*GeneratedConfig) Path added in v0.9.3

func (g *GeneratedConfig) Path(ctx context.Context) (string, error)

Path is the selected candidate path, for fixed-path reload adapters only.

type InstallRequest

type InstallRequest struct {
	BinaryPath     string
	DataDir        string
	ConfigPath     string
	StagingDir     string
	CurrentVersion string
	Channel        string
	AlphaSHA       string
}

type InstallResult

type InstallResult struct {
	Version  string
	Updated  bool
	AlphaSHA string
}

type Installer

type Installer struct {
	// Provenance selects the trusted root route; nil preserves legacy platforms.
	Provenance      ProvenanceStore
	GeneratedConfig func(context.Context) (*ConfigCapability, error)
	Executor        VerifiedExecutor
	Reporter        diagnostics.Reporter

	HTTPClient   *http.Client
	APIBase      string
	Repository   string
	GOOS         string
	GOARCH       string
	Runner       CommandRunner
	CheckTimeout time.Duration // 包住"检查最新版"请求,默认 8s;下载仍用 httpClient 超时(design §4.3)
}

func (Installer) DetectVersion added in v0.2.0

func (i Installer) DetectVersion(ctx context.Context, binaryPath string) (string, error)

DetectVersion 报告现有核心二进制的版本(运行 mihomo -v)。供 runtime 侧 setup 本地预检 复用,避免在 runtime.Manager 里另持 Runner;判据复用 DetectVersion(含 ParseVersion 版本 格式校验),与 Prepare 的同版本短路同一判据、DRY(design §4.3 实现位置)。

func (Installer) Download added in v0.2.0

func (i Installer) Download(ctx context.Context, asset Asset, destination string) (resultErr error)

Download 取 asset 并落盘到 destination,校验 asset.Digest 的 sha256:<hex> (bundler 复用入口,design §4.1 export 边界;绝不照 self.go 复刻——其无 Digest 校验)。 以 O_WRONLY|O_TRUNC 写入:调用方需先落盘目标文件(与 Prepare 内 CreateTemp 同契约)。

func (Installer) Install

func (i Installer) Install(ctx context.Context, request InstallRequest) (InstallResult, error)

func (Installer) LatestRelease added in v0.2.0

func (i Installer) LatestRelease(ctx context.Context, channel string) (release Release, resultErr error)

LatestRelease 取 mihomo 最新 release(bundler 复用入口,design §4.1 export 边界)。 channel=="alpha" 走滚动 tag Prerelease-Alpha;其余(含空)走 /releases/latest。

func (Installer) Prepare

func (i Installer) Prepare(ctx context.Context, request InstallRequest) (PreparedCore, error)

type LocalCoreInfo added in v0.4.0

type LocalCoreInfo struct {
	Ready   bool
	Version string
}

LocalCoreInfo reports whether an existing local core binary satisfies setup without a network download. Ready mirrors the Install setup fast-path predicate (DetectVersion success + non-empty version), kept DRY with manager.Install (design §4.3). Read-only; never persists or mutates state.

type OSCommandRunner

type OSCommandRunner struct{}

func (OSCommandRunner) Run

func (OSCommandRunner) Run(ctx context.Context, name string, args ...string) ([]byte, error)

type OSVerifiedExecutor added in v0.9.3

type OSVerifiedExecutor struct{}

OSVerifiedExecutor explicitly assigns the allowlisted environment.

func (OSVerifiedExecutor) Execute added in v0.9.3

func (OSVerifiedExecutor) Execute(ctx context.Context, c CoreCommand) ([]byte, error)

type PreparedCore

type PreparedCore interface {
	Version() string
	Updated() bool
	Commit() (InstallResult, error)
	Cleanup()
}

type ProvenanceMutation added in v0.9.3

type ProvenanceMutation struct {
	Role, Source             ProvenanceRole
	Transaction              string
	Expected, SourceExpected ProvenanceObject
}

ProvenanceMutation replaces/removes one observed fixed-role object.

type ProvenanceObject added in v0.9.3

type ProvenanceObject struct {
	Present  bool   `json:"present"`
	SHA256   string `json:"sha256,omitempty"`
	Identity string `json:"identity,omitempty"`
	BootID   string `json:"boot_id,omitempty"`
}

ProvenanceObject is an observation, not authority to bypass store checks.

type ProvenanceReceipt added in v0.9.3

type ProvenanceReceipt struct {
	Schema       string `json:"schema"`
	PolicyID     string `json:"policy_id"`
	AssetSHA256  string `json:"asset_sha256"`
	BinarySHA256 string `json:"binary_sha256"`
	OS           string `json:"os"`
	Arch         string `json:"arch"`
	Tag          string `json:"tag"`
}

ProvenanceReceipt records a binary derived from an immutable supported asset. Receipts are accepted only from the private store, never from a caller or migration tree.

type ProvenanceRole added in v0.9.3

type ProvenanceRole string

ProvenanceRole identifies a fixed object within the private data root.

const (
	InstalledBinary   ProvenanceRole = "binary"
	InstalledReceipt  ProvenanceRole = "receipt"
	CandidateBinary   ProvenanceRole = "candidate_binary"
	CandidateReceipt  ProvenanceRole = "candidate_receipt"
	BackupBinary      ProvenanceRole = "backup_binary"
	BackupReceipt     ProvenanceRole = "backup_receipt"
	RestoreBinary     ProvenanceRole = "restore_binary"
	RestoreReceipt    ProvenanceRole = "restore_receipt"
	QuarantineBinary  ProvenanceRole = "quarantine_binary"
	QuarantineReceipt ProvenanceRole = "quarantine_receipt"
	PairJournal       ProvenanceRole = "journal"
	TransactionMarker ProvenanceRole = "transaction_marker"
)

type ProvenanceStore added in v0.9.3

type ProvenanceStore interface {
	Load(context.Context, ProvenanceRole, string) ([]byte, error)
	Save(context.Context, ProvenanceRole, string, []byte) error
	Apply(context.Context, ProvenanceMutation) error
	Inspect(context.Context, ProvenanceRole, string) (ProvenanceObject, error)
	Sync(context.Context) error
	// contains filtered or unexported methods
}

ProvenanceStore is implemented by the core-owned Unix capability adapter. Its private method prevents callers from supplying an untrusted path/hash store.

func NewProvenanceStore added in v0.9.3

func NewProvenanceStore(ctx context.Context, data *platform.TrustedRoot) (ProvenanceStore, error)

NewProvenanceStore borrows a root-owned 0700 D capability. The caller keeps D and its lifecycle lease alive until all store/config/core capabilities close.

type Release

type Release struct {
	ID      int64   `json:"id"`
	TagName string  `json:"tag_name"`
	Assets  []Asset `json:"assets"`
}

type TrustedExecution added in v0.9.3

type TrustedExecution struct {
	// contains filtered or unexported fields
}

TrustedExecution binds core and generated configuration IO to one trusted D. Unix construction borrows D; no public fields can replace its authorities.

func NewTrustedExecution added in v0.9.3

func NewTrustedExecution(ctx context.Context, data *platform.TrustedRoot, executor VerifiedExecutor) (*TrustedExecution, error)

NewTrustedExecution borrows the root-owned data capability and an optional test executor. The daemon closes all capabilities before releasing its lease.

func (*TrustedExecution) CheckPaths added in v0.9.3

func (t *TrustedExecution) CheckPaths(root, binary, configuration string) error

CheckPaths prevents a root assembly from mixing capabilities with another tree.

func (*TrustedExecution) CommittedConfig added in v0.9.3

func (t *TrustedExecution) CommittedConfig(ctx context.Context) (*ConfigCapability, error)

CommittedConfig requires the hash accepted by initialization or publication.

func (*TrustedExecution) InitializeConfig added in v0.9.3

func (t *TrustedExecution) InitializeConfig(ctx context.Context, generated []byte) error

InitializeConfig validates and publishes already-generated startup bytes. A bootstrap may be accepted only when both installed provenance roles are absent.

func (*TrustedExecution) InstalledAvailable added in v0.9.3

func (t *TrustedExecution) InstalledAvailable(ctx context.Context) (bool, error)

InstalledAvailable distinguishes a true green install from a broken pair.

func (*TrustedExecution) Installer added in v0.9.3

func (t *TrustedExecution) Installer() Installer

Installer returns the root installer; path/args Runner is never used.

func (*TrustedExecution) PrepareGenerated added in v0.9.3

func (t *TrustedExecution) PrepareGenerated(ctx context.Context, generated []byte) (*GeneratedConfig, error)

PrepareGenerated receives fresh generated bytes from Manager's generator. The caller's revision check remains in the mutation coordinator.

func (*TrustedExecution) PreviousConfig added in v0.9.3

func (t *TrustedExecution) PreviousConfig(ctx context.Context) ([]byte, error)

PreviousConfig captures the last bound bytes for rollback under the mutation lease.

func (*TrustedExecution) Provenance added in v0.9.3

func (t *TrustedExecution) Provenance() ProvenanceStore

Provenance returns the fixed-role store for startup recovery under the lease.

func (*TrustedExecution) Publish added in v0.9.3

func (t *TrustedExecution) Publish(ctx context.Context, g *GeneratedConfig, expected [32]byte) (*ConfigCapability, error)

Publish verifies the selected candidate again and atomically writes those same bytes. Manager invokes this only after its mutation/revision check, then reloads.

func (*TrustedExecution) RestoreConfig added in v0.9.3

func (t *TrustedExecution) RestoreConfig(ctx context.Context, previous []byte) (*ConfigCapability, error)

RestoreConfig reinstalls bytes captured through PreviousConfig, then rebinds.

func (*TrustedExecution) RunCommand added in v0.9.3

func (t *TrustedExecution) RunCommand(ctx context.Context) (CoreCommand, func() error, error)

RunCommand obtains a fresh installed pair plus committed configuration for Start. release must run after OS Start, including any failed Start path.

func (*TrustedExecution) SetDiagnosticReporter added in v0.9.4

func (t *TrustedExecution) SetDiagnosticReporter(reporter diagnostics.Reporter)

SetDiagnosticReporter borrows the daemon's existing file diagnostic outlet. Assembly calls it before the trusted execution is published to concurrent users.

type VerifiedCore added in v0.9.3

type VerifiedCore struct {
	// contains filtered or unexported fields
}

VerifiedCore holds the installed pair or a private, authenticated candidate. Its zero value is unusable; callers cannot fill in trust identities.

func OpenInstalledCore added in v0.9.3

func OpenInstalledCore(ctx context.Context, s ProvenanceStore) (*VerifiedCore, error)

OpenInstalledCore verifies the recovered installed receipt and binary before opening an execution capability. It never recovers while a process may run.

func (*VerifiedCore) Close added in v0.9.3

func (c *VerifiedCore) Close() error

func (*VerifiedCore) Command added in v0.9.3

func (c *VerifiedCore) Command(ctx context.Context, purpose CorePurpose, configuration *ConfigCapability) (CoreCommand, error)

type VerifiedExecutor added in v0.9.3

type VerifiedExecutor interface {
	Execute(context.Context, CoreCommand) ([]byte, error)
}

VerifiedExecutor consumes only a complete capability-generated command. Injected executors in tests record calls without starting an actual core.

Jump to

Keyboard shortcuts

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