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 BackupKey(id string) string
- func BackupSecret(id string) string
- func Cred(id string, kind Kind) string
- func ForwardPassword(id string) string
- func Host(id string, kind Kind) string
- func LocalKeyPassphrase(keyID string) 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) CanUsePassword() bool
- func (k *Keychain) ChangePassword(current, next []byte) error
- 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) PasswordProtected() bool
- func (k *Keychain) Seal(purpose string, plain, aad []byte) ([]byte, error)
- func (k *Keychain) Set(key string, value []byte) error
- func (k *Keychain) SetupPassword(password []byte) error
- func (k *Keychain) TryUnlock() error
- func (k *Keychain) Unlock() error
- func (k *Keychain) UnlockPassword(password []byte) error
- func (k *Keychain) Unlocked() bool
- func (k *Keychain) Unseal(purpose string, sealed, aad []byte) ([]byte, error)
- func (k *Keychain) UseSystem(current []byte) error
- type Kind
- type LinuxServiceError
- type LinuxServiceErrorKind
- type Memory
- type OpError
- type OpenOptions
- type Silent
- type System
- type SystemError
Constants ¶
const DefaultBackupKey = "backup/default-key"
DefaultBackupKey is the key derived from the default backup password, which exports and backup targets may seal with instead of their own.
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") // ErrPasswordRequired is an unlock of a store a local master password // protects, which only UnlockPassword opens. ErrPasswordRequired = errors.New("keychain: local master password required") // ErrWrongPassword is a local master password that does not open the // master key. ErrWrongPassword = errors.New("keychain: wrong local master password") // ErrNoPassword is a local master password operation on a store the // system keychain protects. ErrNoPassword = errors.New("keychain: no local master password") // ErrPasswordSetup is a local master password set up for a store that // already has secrets or a master key, which it would orphan. ErrPasswordSetup = errors.New("keychain: local master password needs an empty store") )
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 BackupKey ¶ added in v0.0.7
BackupKey is the key a backup target's backups are sealed with, derived from its backup password: backup/<id>/key.
func BackupSecret ¶ added in v0.0.7
BackupSecret is the password, secret key or token a backup target is reached with: backup/<id>/secret.
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 LocalKeyPassphrase ¶ added in v0.0.12
LocalKeyPassphrase is the remembered passphrase of a key file of this computer, by its session.KeyID: localkey/<keyID>/passphrase. It opens only that file here, so no backup holds it.
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) CanUsePassword ¶ added in v1.0.1
CanUsePassword reports whether SetupPassword may protect the store with a local master password: nothing is stored yet, so no secrets are left behind under a master key of the system keychain.
func (*Keychain) ChangePassword ¶ added in v1.0.1
ChangePassword seals the master key under next in place of current.
func (*Keychain) DeleteCred ¶
func (*Keychain) PasswordProtected ¶ added in v1.0.1
PasswordProtected reports whether a local master password, not the system keychain, protects the master key.
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) SetupPassword ¶ added in v1.0.1
SetupPassword creates the master key of an empty, locked store under a local master password, and unlocks the store with it.
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.
func (*Keychain) UnlockPassword ¶ added in v1.0.1
UnlockPassword opens the master key with the local master password and unlocks the store with it.
func (*Keychain) Unlocked ¶
Unlocked reports whether this open store is ready for secret operations. Explicitly injected test backends do not require unlocking.
type LinuxServiceError ¶ added in v0.0.19
type LinuxServiceError struct {
Kind LinuxServiceErrorKind
Err error
}
LinuxServiceError preserves the original error for errors.Is and errors.As. Kind is diagnostic only and never authorizes creating a new master key.
func (*LinuxServiceError) Error ¶ added in v0.0.19
func (e *LinuxServiceError) Error() string
func (*LinuxServiceError) Unwrap ¶ added in v0.0.19
func (e *LinuxServiceError) Unwrap() error
type LinuxServiceErrorKind ¶ added in v0.0.19
type LinuxServiceErrorKind uint8
LinuxServiceErrorKind identifies only causes retained by MyGo's Linux backend. Unrecognized or stripped GError messages remain LinuxServiceUnknown.
const ( LinuxServiceUnknown LinuxServiceErrorKind = iota LinuxServiceDependency LinuxServiceSessionBus LinuxServiceAccessDenied LinuxServiceStartFailed LinuxServiceLocked // LinuxServiceMissing is a session bus without a Secret Service. LinuxServiceMissing // LinuxServiceTimeout is a Secret Service that did not answer. LinuxServiceTimeout )
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, master-password, master-password-write, file-read, file-decrypt, file-write, or closed.
type OpenOptions ¶
type OpenOptions struct {
Path string
LockPath string
Scope string
System Backend
// KDF is what a new local master password derives with, vault's
// default when zero.
KDF vault.Params
}
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