assets

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 18 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

Overview

Package assets is SSHYard's asset store: the hosts the user saved, with their groups and favorites, and the credentials, proxies and port forwards they use, kept as JSON in the user's data directory. Secrets are never stored here; they live in the system keychain (package keychain), under the ID of the credential, proxy or forward they belong to.

Index

Constants

View Source
const IconPrefix = "icon:"

IconPrefix starts a Host.Icon naming one of the app's icons.

View Source
const SchemaVersion = 2

SchemaVersion is the version of the data file. A file of any other (older) version is discarded, not migrated.

Variables

View Source
var ErrExists = errors.New("assets: ID in use")

ErrExists is AddCredential's or AddProxy's error for an ID in use.

View Source
var ErrJumpLoop = errors.New("assets: the jump chain loops")

ErrJumpLoop reports a jump chain that comes back to a host already on it (A through B, B through A), or reaches one host twice (A through B and C, with C through B too).

View Source
var ErrNotFound = errors.New("assets: not found")

ErrNotFound reports an ID the store does not have.

View Source
var ErrSnapshotChanged = errors.New("assets: snapshot hosts changed")

ErrSnapshotChanged means hosts no longer match the preview baseline.

Functions

func IconText

func IconText(s string) string

IconText is what a host keeps of its icon: one of the app's as it is, else the text trimmed, at most two emoji or four letters wide, whole characters only.

func NewID

func NewID() string

NewID makes a fresh entry ID.

func ValidID

func ValidID(id string) bool

ValidID reports whether id can name an entry: what NewID makes, and no character that would reach into another entry's keychain key.

func ValidateSnippetContent

func ValidateSnippetContent(content string) error

ValidateSnippetContent accepts at most 64 KiB of UTF-8 command text, with CR, LF and TAB as the only allowed C0 controls. Errors never contain the body.

func ValidateSnippetGroup

func ValidateSnippetGroup(group string) error

ValidateSnippetGroup checks a trimmed group name; "" is the default group.

Types

type AIPolicy

type AIPolicy struct {
	Mode          string   `json:"mode,omitempty"`
	WritableRoots []string `json:"writableRoots,omitempty"`
	Sensitive     []string `json:"sensitive,omitempty"`
}

AIPolicy is how an AI pane on this host may act. Paths are remote POSIX paths. Mode empty means inherit.

type AuthMethod

type AuthMethod string

AuthMethod is how a host authenticates.

const (
	// AuthPassword and AuthKey use secrets owned by this host.
	AuthPassword AuthMethod = "password"
	AuthKey      AuthMethod = "key"
	// AuthCredential uses the credential of the host's CredentialID.
	AuthCredential AuthMethod = "credential"
	// AuthAgent signs with the keys of the system's SSH agent.
	AuthAgent AuthMethod = "agent"
	// AuthAsk keeps nothing: the password is asked at each connection
	// and held in memory only.
	AuthAsk AuthMethod = "ask"
)

type Credential

type Credential struct {
	ID   string         `json:"id"`
	Name string         `json:"name"`
	Kind CredentialKind `json:"kind"`
	// User, when set, logs in instead of the host's user.
	User string `json:"user,omitempty"`
	Note string `json:"note,omitempty"`
	// Fingerprint is the SHA256 fingerprint of a key's public half.
	Fingerprint string `json:"fingerprint,omitempty"`
	// KeyType is the key's algorithm, such as ssh-ed25519.
	KeyType string `json:"keyType,omitempty"`
	// Encrypted records that the key has a passphrase; AskPassphrase
	// that it is not saved but asked once per run.
	Encrypted     bool `json:"encrypted,omitempty"`
	AskPassphrase bool `json:"askPassphrase,omitempty"`
	// Certificate is the OpenSSH user certificate of a key, one
	// key-cert.pub line; public, so it is kept here.
	Certificate string    `json:"certificate,omitempty"`
	Created     time.Time `json:"created"`
	Updated     time.Time `json:"updated"`
}

Credential is a password or private key that hosts refer to. Its JSON holds metadata only; the secret is in the keychain under cred/<id>/<kind>.

func (*Credential) Normalize

func (c *Credential) Normalize()

Normalize trims the credential's fields.

func (Credential) Validate

func (c Credential) Validate() error

Validate checks a normalized credential.

type CredentialKind

type CredentialKind string

CredentialKind is what a credential holds.

const (
	// CredPassword is a password.
	CredPassword CredentialKind = "password"
	// CredKey is a private key, kept in OpenSSH form (a PuTTY key is
	// converted when imported), maybe with a passphrase.
	CredKey CredentialKind = "key"
)

type FieldError

type FieldError struct {
	Field  string // "name", "address", "port", "user", "auth", "credential", "kind", "target", …
	Reason string
}

FieldError reports an invalid field of a host.

func (*FieldError) Error

func (e *FieldError) Error() string

type Forward

type Forward struct {
	ID     string      `json:"id"`
	Name   string      `json:"name"`
	Kind   ForwardKind `json:"kind"`
	HostID string      `json:"hostId"`
	// Listen is where connections come in: on this computer for local
	// and dynamic forwards, on the server for remote ones.
	ListenAddr string `json:"listenAddr"`
	ListenPort int    `json:"listenPort"`
	// Target is where they go: seen from the server for local
	// forwards, from this computer for remote ones; none for dynamic.
	TargetAddr string          `json:"targetAddr,omitempty"`
	TargetPort int             `json:"targetPort,omitempty"`
	Protocol   ForwardProtocol `json:"protocol,omitempty"`
	// User, when set, is the username a dynamic forward's clients
	// authenticate with (HTTP and SOCKS5).
	User      string    `json:"user,omitempty"`
	AutoStart bool      `json:"autoStart,omitempty"`
	Note      string    `json:"note,omitempty"`
	Created   time.Time `json:"created"`
	Updated   time.Time `json:"updated"`
}

Forward is a port forwarding rule through a host. Its listener's password (dynamic forwards) is in the keychain under forward/<id>/password.

func (Forward) Exposed

func (f Forward) Exposed() bool

Exposed reports whether the forward listens beyond the loopback address, where others on the network may reach it.

func (Forward) Label

func (f Forward) Label() string

Label is the name shown for the forward.

func (Forward) Listen

func (f Forward) Listen() string

Listen is ListenAddr:ListenPort.

func (*Forward) Normalize

func (f *Forward) Normalize()

Normalize trims the forward's fields and fills defaults: it listens on 127.0.0.1 unless told otherwise.

func (Forward) Target

func (f Forward) Target() string

Target is TargetAddr:TargetPort.

func (Forward) Validate

func (f Forward) Validate() error

Validate checks a normalized forward.

type ForwardKind

type ForwardKind string

ForwardKind is the kind of a port forward.

const (
	ForwardLocal   ForwardKind = "local"   // ssh -L
	ForwardRemote  ForwardKind = "remote"  // ssh -R
	ForwardDynamic ForwardKind = "dynamic" // ssh -D
)

type ForwardProtocol

type ForwardProtocol string

ForwardProtocol is what a dynamic forward's proxy speaks.

const (
	ProtoAuto   ForwardProtocol = "" // tell from the first bytes
	ProtoHTTP   ForwardProtocol = "http"
	ProtoSOCKS4 ForwardProtocol = "socks4" // and 4a
	ProtoSOCKS5 ForwardProtocol = "socks5"
)

type Host

type Host struct {
	ID       string     `json:"id"`
	Name     string     `json:"name"`
	Address  string     `json:"address"`
	Port     int        `json:"port"`
	User     string     `json:"user"`
	Group    string     `json:"group,omitempty"`
	Favorite bool       `json:"favorite,omitempty"`
	Auth     AuthMethod `json:"auth"`
	// Icon is the host's icon: one of the app's own, by its key after
	// IconPrefix ("icon:database"), or a short text the user typed, as
	// an emoji. Empty picks one from the address.
	Icon string `json:"icon,omitempty"`
	// Color is the tint behind the icon, a name of theme.TintNames.
	// Empty picks one from the address.
	Color string `json:"color,omitempty"`
	// CredentialID is the credential of AuthCredential.
	CredentialID  string `json:"credentialId,omitempty"`
	AskPassphrase bool   `json:"askPassphrase,omitempty"`
	// Certificate is the OpenSSH user certificate of an AuthKey host's
	// key, one key-cert.pub line; public, so it is kept here.
	Certificate string `json:"certificate,omitempty"`
	// JumpChain are the hosts connected through, in order, before this
	// one (ProxyJump); each with its own credential and host key check.
	JumpChain []string `json:"jumpChain,omitempty"`
	// ProxyID is the proxy the first hop is dialed through.
	ProxyID string `json:"proxyId,omitempty"`
	// CwdFollow lets a Files pane follow the directory the terminal of
	// the same tab reports (OSC 7). New hosts have it on.
	CwdFollow bool `json:"cwdFollow"`
	// OSC52 overrides the global OSC 52 write policy (allow, ask or
	// deny). Empty follows the global setting.
	OSC52 string `json:"osc52,omitempty"`
	// Metrics is whether this host shows the metrics bar: follow the
	// global setting, always, or never.
	Metrics MetricsMode `json:"metrics,omitempty"`
	// AIPolicy is the host's AI permission override. An empty mode
	// inherits the global default.
	AIPolicy AIPolicy  `json:"aiPolicy,omitempty"`
	Created  time.Time `json:"created"`
	Updated  time.Time `json:"updated"`
	LastUsed time.Time `json:"lastUsed,omitzero"`
}

Host is a saved SSH host: where it is and how to reach it. It holds no secret; host-owned and reusable secrets live in the encrypted store.

func (Host) Addr

func (h Host) Addr() string

Addr is address:port for dialing.

func (Host) Label

func (h Host) Label() string

Label is the name shown for the host.

func (*Host) Normalize

func (h *Host) Normalize()

Normalize trims the host's fields and fills defaults.

func (Host) Target

func (h Host) Target() string

Target is user@address, with :port when it is not 22.

func (Host) Validate

func (h Host) Validate() error

Validate checks a normalized host.

type InUseError

type InUseError struct {
	Hosts    []string // IDs
	Forwards []string // IDs
}

InUseError reports an entry other entries still use, so it can not be deleted: the hosts (and forwards) using it.

func (*InUseError) Error

func (e *InUseError) Error() string

type MetricsMode

type MetricsMode string

MetricsMode is a host's metrics bar: follow the global setting, on, or off. Off hides the bar while the global setting is on. The global setting off hides every host, including one set to on.

const (
	// MetricsFollow uses the global metrics setting.
	MetricsFollow MetricsMode = ""
	// MetricsOn shows the bar while the global setting is on.
	MetricsOn MetricsMode = "on"
	// MetricsOff never collects or shows the bar for this host.
	MetricsOff MetricsMode = "off"
)

type Proxy

type Proxy struct {
	ID      string    `json:"id"`
	Name    string    `json:"name"`
	Kind    ProxyKind `json:"kind"`
	Address string    `json:"address"`
	Port    int       `json:"port"`
	// User, when set, authenticates (Basic for HTTP, username and
	// password for SOCKS5) with the password in the keychain.
	User    string    `json:"user,omitempty"`
	Note    string    `json:"note,omitempty"`
	Created time.Time `json:"created"`
	Updated time.Time `json:"updated"`
}

Proxy is an HTTP or SOCKS5 proxy the first hop to a host is dialed through. Its password is in the keychain under proxy/<id>/password.

func (Proxy) Addr

func (p Proxy) Addr() string

Addr is address:port for dialing.

func (*Proxy) Normalize

func (p *Proxy) Normalize()

Normalize trims the proxy's fields and fills defaults.

func (Proxy) Validate

func (p Proxy) Validate() error

Validate checks a normalized proxy.

type ProxyKind

type ProxyKind string

ProxyKind is the protocol of a proxy.

const (
	ProxyHTTP   ProxyKind = "http"   // HTTP CONNECT
	ProxySOCKS5 ProxyKind = "socks5" // SOCKS5, names resolved by the proxy
)

type Snapshot

type Snapshot struct {
	Hosts       []Host       `json:"hosts"`
	Credentials []Credential `json:"credentials"`
	Proxies     []Proxy      `json:"proxies"`
	Forwards    []Forward    `json:"forwards"`
	Groups      []string     `json:"groups,omitempty"`
	GroupOrder  []string     `json:"groupOrder,omitempty"`
	Snippets    []Snippet    `json:"snippets,omitempty"`
}

Snapshot is everything the store holds, for a backup. Like the store, it holds no secret.

type Snippet

type Snippet struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Group     string `json:"group,omitempty"`
	SendEnter bool   `json:"sendEnter"`
}

Snippet holds metadata only; its command body belongs in the encrypted store.

func (*Snippet) Normalize

func (s *Snippet) Normalize()

Normalize trims metadata without altering the separately stored command body.

func (Snippet) Validate

func (s Snippet) Validate() error

Validate checks normalized metadata.

type Store

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

Store keeps hosts, credentials, proxies and port forwards in a JSON file. It is safe for concurrent use.

func Open

func Open(path string) (*Store, error)

Open reads the store at path; a missing file is an empty store. A file of an older schema version is discarded and an empty store written in its place: there is no migration. An empty path keeps the store in memory only.

func (*Store) Add

func (s *Store) Add(h Host) (Host, error)

Add validates and adds a host, giving it an ID.

func (*Store) AddCredential

func (s *Store) AddCredential(c Credential) (Credential, error)

AddCredential adds a credential under the ID it has (from NewID), so its secrets can be stored before it is.

func (*Store) AddForward

func (s *Store) AddForward(f Forward) (Forward, error)

AddForward adds a port forward under the ID it has, when it has one (made with NewID, so that its keychain entry can be written first).

func (*Store) AddGroup

func (s *Store) AddGroup(name string) error

AddGroup makes an empty group, for hosts to be moved into. The name is trimmed; a group of that name, in any case, is a "taken" FieldError.

func (*Store) AddHost

func (s *Store) AddHost(h Host) (Host, error)

AddHost adds a host with a preallocated ID for its encrypted secrets.

func (*Store) AddProxy

func (s *Store) AddProxy(p Proxy) (Proxy, error)

AddProxy adds a proxy under the ID it has (from NewID), so its password can be stored before it is.

func (*Store) AddSnippet

func (s *Store) AddSnippet(n Snippet) (Snippet, error)

AddSnippet adds an entry under its supplied ID so its body can be saved first.

func (*Store) Credential

func (s *Store) Credential(id string) (Credential, bool)

Credential returns the credential of id.

func (*Store) CredentialUsers

func (s *Store) CredentialUsers(id string) []Host

CredentialUsers are the hosts that use the credential of id, sorted.

func (*Store) Credentials

func (s *Store) Credentials() []Credential

Credentials returns every credential, sorted by name.

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete removes the host of id. A host other hosts jump through, or port forwards enter by, is in use and not deleted (an *InUseError).

func (*Store) DeleteCredential

func (s *Store) DeleteCredential(id string) error

DeleteCredential removes a credential no host uses; one in use is an *InUseError listing the hosts.

func (*Store) DeleteForward

func (s *Store) DeleteForward(id string) error

DeleteForward removes a port forward.

func (*Store) DeleteGroup

func (s *Store) DeleteGroup(name string) error

DeleteGroup removes a group. Its hosts stay, in no group.

func (*Store) DeleteProxy

func (s *Store) DeleteProxy(id string) error

DeleteProxy removes a proxy no host uses; one in use is an *InUseError listing the hosts.

func (*Store) DeleteSnippet

func (s *Store) DeleteSnippet(id string) error

DeleteSnippet removes metadata; the app coordinates encrypted body deletion.

func (*Store) Discarded

func (s *Store) Discarded() []string

Discarded are the IDs of the hosts of an older data file Open threw away, so that the caller can drop what it kept for them elsewhere.

func (*Store) Favorites

func (s *Store) Favorites() []Host

Favorites returns the favorite hosts, sorted.

func (*Store) Forward

func (s *Store) Forward(id string) (Forward, bool)

Forward returns the port forward of id.

func (*Store) Forwards

func (s *Store) Forwards() []Forward

Forwards returns every port forward, sorted by label.

func (*Store) Get

func (s *Store) Get(id string) (Host, bool)

Get returns the host of id.

func (*Store) Groups

func (s *Store) Groups() []string

Groups returns the names of the groups in display order: those of the hosts and those made with AddGroup, empty or not. Hosts without a group are in none of them.

func (*Store) InGroup

func (s *Store) InGroup(group string) []Host

InGroup returns the hosts of a group, "" for those without one.

func (*Store) JumpPath

func (s *Store) JumpPath(id string) ([]Host, error)

JumpPath is the hosts dialed through to reach id, first hop first, each jump host's own chain expanded before it.

func (*Store) Len

func (s *Store) Len() int

Len is the number of hosts.

func (*Store) List

func (s *Store) List() []Host

List returns every host, sorted by label.

func (*Store) MoveGroup added in v0.0.8

func (s *Store) MoveGroup(name, target string, after bool) error

MoveGroup places name immediately before or after target, saving the full display order without making implicit groups into permanent empty groups.

func (*Store) Proxies

func (s *Store) Proxies() []Proxy

Proxies returns every proxy, sorted by name.

func (*Store) Proxy

func (s *Store) Proxy(id string) (Proxy, bool)

Proxy returns the proxy of id.

func (*Store) ProxyUsers

func (s *Store) ProxyUsers(id string) []Host

ProxyUsers are the hosts that use the proxy of id, sorted.

func (*Store) RenameGroup

func (s *Store) RenameGroup(old, name string) error

RenameGroup renames a group, and moves its hosts with it.

func (*Store) Restore

func (s *Store) Restore(in Snapshot) error

Restore merges a snapshot into the store: each entry replaces the one of its ID, or is added, and nothing else is removed. A credential or proxy whose name another one here has is renamed "name (2)". Everything is checked first: when an entry is invalid, or refers to one that is neither here nor in the snapshot, nothing changes.

func (*Store) RestoreIfHostsUnchanged added in v0.0.9

func (s *Store) RestoreIfHostsUnchanged(in Snapshot, expected []Host) error

RestoreIfHostsUnchanged merges only while hosts still equal a prior List result. The comparison and persistence share the store lock with other writers.

func (*Store) SaveCredential

func (s *Store) SaveCredential(c Credential) (Credential, error)

SaveCredential adds a credential (no ID) or replaces the one of its ID. Names are unique, ignoring case.

func (*Store) SaveForward

func (s *Store) SaveForward(f Forward) (Forward, error)

SaveForward adds a port forward (no ID) or replaces the one of its ID.

func (*Store) SaveProxy

func (s *Store) SaveProxy(p Proxy) (Proxy, error)

SaveProxy adds a proxy (no ID) or replaces the one of its ID.

func (*Store) SaveSnippet

func (s *Store) SaveSnippet(n Snippet) (Snippet, error)

SaveSnippet creates an entry with an empty ID or updates an existing one.

func (*Store) Search

func (s *Store) Search(q string) []Host

Search returns the hosts whose name, address, user or group contain every word of q, ignoring case.

func (*Store) SetFavorite

func (s *Store) SetFavorite(id string, fav bool) error

SetFavorite marks or unmarks a host as a favorite.

func (*Store) SetGroup

func (s *Store) SetGroup(id, group string) error

SetGroup moves a host into a group, "" for none.

func (*Store) Snapshot

func (s *Store) Snapshot() Snapshot

Snapshot returns a copy of every entry.

func (*Store) Snippet

func (s *Store) Snippet(id string) (Snippet, bool)

Snippet returns metadata for id.

func (*Store) Snippets

func (s *Store) Snippets() []Snippet

Snippets returns a copy sorted by group, then name, ignoring case.

func (*Store) Touch

func (s *Store) Touch(id string) error

Touch records that the host was just connected to.

func (*Store) Update

func (s *Store) Update(h Host) (Host, error)

Update replaces the host with h's ID.

Jump to

Keyboard shortcuts

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