Documentation
¶
Overview ¶
Package keychain stores business secrets in a local encrypted file, with only its random master key in the operating system keychain.
Index ¶
- Constants
- Variables
- func AIAgentEnv(agentID, name string) string
- func AIKey(profileID string) string
- func Cred(id string, kind Kind) string
- func ForwardPassword(id string) string
- func Host(id string, kind Kind) string
- func ProxyPassword(id string) string
- func SnippetContent(id string) string
- type Backend
- type Change
- type Keychain
- func (k *Keychain) Apply(changes []Change) error
- func (k *Keychain) Backend() Backend
- func (k *Keychain) Close() error
- func (k *Keychain) Delete(key string) error
- func (k *Keychain) DeleteCred(id string) error
- func (k *Keychain) Exists(key string) (bool, error)
- func (k *Keychain) Get(key string) ([]byte, error)
- func (k *Keychain) Has(key string) bool
- func (k *Keychain) Seal(purpose string, plain, aad []byte) ([]byte, error)
- func (k *Keychain) Set(key string, value []byte) error
- func (k *Keychain) TryUnlock() error
- func (k *Keychain) Unlock() error
- func (k *Keychain) Unlocked() bool
- func (k *Keychain) Unseal(purpose string, sealed, aad []byte) ([]byte, error)
- type Kind
- type Memory
- type OpError
- type OpenOptions
- type Silent
- type System
- type SystemError
Constants ¶
const MCPToken = "mcp/token"
MCPToken is the bearer token of the MCP endpoint.
const MasterKey = "master/v1"
Variables ¶
var ( ErrNotFound = errors.New("keychain: secret not found") ErrLocked = errors.New("keychain: secret store locked") ErrBusy = errors.New("keychain: secret store in use") ErrMasterMissing = errors.New("keychain: master key missing") ErrMasterInvalid = errors.New("keychain: invalid master key") ErrCorrupt = errors.New("keychain: encrypted store damaged or key mismatched") ErrVersion = errors.New("keychain: unsupported encrypted store version") // ErrInteractionRequired is a silent unlock that needs system authorization. ErrInteractionRequired = errors.New("keychain: system authorization required") )
var Kinds = []Kind{Password, PrivateKey, Passphrase}
Kinds are every kind of secret a credential has.
Functions ¶
func AIAgentEnv ¶
AIAgentEnv is an environment variable injected into an external agent from the keychain: ai/<agentID>/env/<NAME>. A3 reads it; nothing here puts the value into a process.
func ForwardPassword ¶
ForwardPassword is the entry of the password a dynamic forward's clients authenticate with: forward/<id>/password.
func Host ¶
Cred is the entry of a credential's secret: cred/<id>/<kind>. Host is a host-owned secret entry.
func ProxyPassword ¶
ProxyPassword is the entry of a proxy's password: proxy/<id>/password.
func SnippetContent ¶
SnippetContent is the encrypted body of a saved command: snippet/<id>/content.
Types ¶
type Backend ¶
type Backend interface {
Set(key string, value []byte) error
Get(key string) ([]byte, error)
Delete(key string) error
}
Backend is the operating system secret store, or an explicitly injected test store.
type Keychain ¶
type Keychain struct {
// contains filtered or unexported fields
}
Keychain is the secret store facade. New is only for explicit test injection; production must use OpenLocked or Open, which never fall back to memory.
func Open ¶
func Open(o OpenOptions) (*Keychain, error)
Open acquires the lifetime lock and immediately unlocks the store. A failure never replaces existing ciphertext or regenerates a missing master.
func OpenLocked ¶
func OpenLocked(o OpenOptions) (_ *Keychain, err error)
OpenLocked acquires the lifetime lock and reads ciphertext without accessing the system keychain or creating a master key or encrypted file.
func (*Keychain) Apply ¶
Apply commits production changes once. Explicit test backends keep their own Get/Set/Delete hooks, including injected failures, with best-effort rollback.
func (*Keychain) DeleteCred ¶
func (*Keychain) Seal ¶
Seal encrypts plain for purpose, bound to aad, which Unseal must be given again. It fails with ErrLocked while the store is locked, and with ErrUnavailable on a backend without a master key.
func (*Keychain) TryUnlock ¶
TryUnlock unlocks an existing store only when the system keychain hands over the master key without asking, as after the user always allowed SSHYard. Otherwise it fails and the store stays locked for Unlock.
func (*Keychain) Unlock ¶
Unlock explicitly accesses the system keychain and verifies the encrypted store, retaining the master key only after successful verification.
type Memory ¶
type Memory struct {
// Fail, when set, is returned by every call.
Fail error
// contains filtered or unexported fields
}
Memory is an explicitly injected test Backend; production never falls back to it.
type OpError ¶
OpError identifies the failed stage without requiring UI to render raw errors. Op is lock, master-read, master-write, master-verify, file-read, file-decrypt, file-write, or closed.
type OpenOptions ¶
OpenOptions separates the per-app lifetime lock from an overridden data path.
type System ¶
type System struct{}
System is the Backend of the operating system's keychain, mygo.Secrets, under the app's identifier (com.sshyard.desktop).
func (System) GetSilently ¶
GetSilently reads key without any system authorization prompt: where one would be needed, the read fails.
type SystemError ¶
SystemError preserves a structured OSStatus and its original error chain.
func (*SystemError) Error ¶
func (e *SystemError) Error() string
func (*SystemError) Is ¶
func (e *SystemError) Is(target error) bool
func (*SystemError) Unwrap ¶
func (e *SystemError) Unwrap() error