Documentation
¶
Overview ¶
Package vault is the dev.stubbe.lys.Vault1 contract: lys-secrets' Bitwarden vault on the session bus, so the one process that holds the vault's keys serves every surface that shows or uses it (lys-shell's bar module, dropdown and launcher mode, its NetworkManager secret agent). It holds the types both sides speak, the errors a call fails with, the Host a vault implements, the Daemon serving one and the Client calling it.
Secret values leave the vault one field at a time (Client.Field), only to a caller running as the vault's own user, and an item behind Bitwarden's master password reprompt gives up its secrets only with the master password.
Index ¶
- Constants
- Variables
- type APIKeyRequest
- type Client
- func (c *Client) CreateLogin(ctx context.Context, l NewLogin) (ItemID, error)
- func (c *Client) CreateTextSend(ctx context.Context, s NewTextSend) (CreatedSend, error)
- func (c *Client) DeleteSend(ctx context.Context, id SendID) error
- func (c *Client) Field(ctx context.Context, id string, f Field, password string) (Value, error)
- func (c *Client) FindLogin(ctx context.Context, name string, scope FolderScope) (Item, bool, error)
- func (c *Client) Items(ctx context.Context) ([]Item, error)
- func (c *Client) Lock(ctx context.Context) error
- func (c *Client) Login(ctx context.Context, r LoginRequest) error
- func (c *Client) LoginAPIKey(ctx context.Context, r APIKeyRequest) error
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) NetworkLogin(ctx context.Context, folder, name string) (NetworkLogin, bool, error)
- func (c *Client) SendLoginEmail(ctx context.Context, r LoginRequest) error
- func (c *Client) Sends(ctx context.Context) ([]Send, error)
- func (c *Client) Status(ctx context.Context) (Status, error)
- func (c *Client) Sync(ctx context.Context) error
- func (c *Client) Unlock(ctx context.Context, password string) error
- func (c *Client) Watch(ctx context.Context, w Watcher) error
- type CreatedSend
- type Daemon
- type Field
- type FolderScope
- type Host
- type Item
- type ItemID
- type ItemType
- type LoginRequest
- type NetworkLogin
- type NewLogin
- type NewTextSend
- type Send
- type SendID
- type SendType
- type ServerError
- type State
- type Status
- type TwoFactor
- type TwoFactorProvider
- type TwoFactorRequiredError
- type Value
- type Watcher
Constants ¶
const ( MinSendLifetime = time.Minute MaxSendLifetime = 31 * 24 * time.Hour )
const ( ServiceName = "dev.stubbe.lys.Vault1" ServicePath = dbus.ObjectPath("/dev/stubbe/lys/Vault") )
D-Bus identity.
Variables ¶
var ( ErrWrongPassword = errors.New("vault: wrong master password") ErrInvalidCredentials = errors.New("vault: invalid credentials") ErrLoginRequired = errors.New("vault: login required") ErrNewDeviceVerification = errors.New("vault: new device verification required") ErrLocked = errors.New("vault: the vault is not open") ErrNoSuchItem = errors.New("vault: no such item") ErrNoSuchField = errors.New("vault: the item has no such field") ErrRepromptRequired = errors.New("vault: the item asks for the master password") ErrUnreachable = errors.New("vault: the server is unreachable") ErrSessionNotRevoked = errors.New("vault: logged out here, but revoking the session on the server failed, so its refresh token may still work; deauthorize the account's sessions if it may have leaked") // ErrRevocationUnsupported is a logout that did all it can: the session // is gone here and the server has no way to revoke it. A caller shows // it as a completed logout, not as a failure. ErrRevocationUnsupported = errors.New("vault: logged out here; this server cannot revoke a session, so its refresh token stays valid until it expires or the account's sessions are deauthorized") ErrAccessDenied = errors.New("vault: only the vault's own user may use it") ErrInvalidInput = errors.New("vault: invalid input") ErrNoSuchFolder = errors.New("vault: no such folder") ErrAmbiguous = errors.New("vault: more than one match") ErrItemExists = errors.New("vault: a login of that name exists in that folder") ErrNoSuchSend = errors.New("vault: no such Send") )
The errors a call fails with. A Client returns them wrapped with the vault's own message, so errors.Is tells them apart.
Functions ¶
This section is empty.
Types ¶
type APIKeyRequest ¶
type APIKeyRequest struct {
Server vaultserver.Server
Email string
ClientID, Secret string
Password string
}
APIKeyRequest is a login with the account's personal API key; the master password still opens the keys.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the vault. A login or an unlock derives the master key and talks to the server, so the calls are bounded only by ctx.
func (*Client) CreateLogin ¶
func (*Client) CreateTextSend ¶
func (c *Client) CreateTextSend(ctx context.Context, s NewTextSend) (CreatedSend, error)
func (*Client) Field ¶
Field is item id's field f. A secret of an item behind the reprompt needs the master password as password; otherwise it is ignored.
func (*Client) Items ¶
Items lists the open vault, favorites first then by name; ErrLocked while it is not open.
func (*Client) Lock ¶
Lock wipes the vault's keys and plaintext. A vault that is not running holds no keys: Lock does not start it, and finds nothing to lock.
func (*Client) Login ¶
func (c *Client) Login(ctx context.Context, r LoginRequest) error
Login logs in with the master password and opens the vault. A second factor or a new device's code comes back as TwoFactorRequiredError or ErrNewDeviceVerification: ask for it and call Login again with it.
func (*Client) LoginAPIKey ¶
func (c *Client) LoginAPIKey(ctx context.Context, r APIKeyRequest) error
LoginAPIKey logs in with the personal API key and opens the vault with the master password.
func (*Client) Logout ¶
Logout locks, forgets the session here, and asks the server to revoke it. An error matching ErrRevocationUnsupported is a completed logout on a server that cannot revoke, so its refresh token stays valid until it expires or the account's sessions are deauthorized. One matching ErrSessionNotRevoked means revoking was tried and failed.
func (*Client) NetworkLogin ¶
NetworkLogin is the login in folder answering the network connection named name; false when there is none or the vault is not open.
func (*Client) SendLoginEmail ¶
func (c *Client) SendLoginEmail(ctx context.Context, r LoginRequest) error
SendLoginEmail asks the server to email a login's second-factor code.
type CreatedSend ¶
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon serves a Host as dev.stubbe.lys.Vault1 to callers running as this process's user.
func (*Daemon) Changed ¶
Changed signals the host's status, after a change of it or of the vault's items.
func (*Daemon) Export ¶
Export serves the interface under its name on conn; the returned release drops the name. A name another process owns is dbusx.ErrNameTaken, and leaves nothing exported.
func (*Daemon) SyncFailed ¶
SyncFailed signals a periodic sync failing with err.
type Field ¶
type Field uint32
Field is one value an item gives out: a login's or identity's username, a login's password and verification code, a card's number and code, an identity's email, a secure note's text.
type FolderScope ¶
type FolderScope struct {
// contains filtered or unexported fields
}
func AnyFolder ¶
func AnyFolder() FolderScope
func InFolder ¶
func InFolder(name string) FolderScope
func (FolderScope) Contains ¶
func (s FolderScope) Contains(folder string) bool
func (FolderScope) Folder ¶
func (s FolderScope) Folder() (string, bool)
type Host ¶
type Host interface {
// Status is the vault at a glance.
Status() Status
// Items lists the open vault, favorites first then by name;
// ErrLocked while it is not open.
Items() ([]Item, error)
// Field is item id's field f, a verification code as of now. A
// secret of an item behind the reprompt needs the master password
// (ErrRepromptRequired without, ErrWrongPassword for another);
// otherwise password is ignored. It counts as use of the vault.
Field(id string, f Field, password string) (Value, error)
// Login logs in with the master password and opens the vault.
Login(ctx context.Context, r LoginRequest) error
// SendLoginEmail asks the server to email a login's second-factor
// code.
SendLoginEmail(ctx context.Context, r LoginRequest) error
// LoginAPIKey logs in with the personal API key and opens the vault
// with the master password.
LoginAPIKey(ctx context.Context, r APIKeyRequest) error
// Unlock opens a locked vault with the master password.
Unlock(ctx context.Context, password string) error
// Lock wipes the keys and the plaintext; the session stays.
Lock()
// Logout locks, forgets the session here, and asks the server to
// revoke it. The session is gone here whatever the server does. A
// server with no way to revoke it is ErrRevocationUnsupported, and an
// attempt that failed is ErrSessionNotRevoked.
Logout(ctx context.Context) error
// Sync refetches the open vault.
Sync(ctx context.Context) error
// NetworkLogin is the login answering the network connection named
// name from folder; false when there is none or the vault is not
// open.
NetworkLogin(folder, name string) (NetworkLogin, bool)
CreateLogin(ctx context.Context, l NewLogin) (ItemID, error)
FindLogin(name string, scope FolderScope) (Item, bool, error)
Sends() ([]Send, error)
CreateTextSend(ctx context.Context, s NewTextSend) (CreatedSend, error)
DeleteSend(ctx context.Context, id SendID) error
}
Host is a vault the Daemon serves. Each call blocks until done; a failing one returns the contract's errors.
type Item ¶
type Item struct {
ID string
Type ItemType
Name string
Folder string
Organization string
Favorite bool
Reprompt bool
Undecryptable bool
Username string
URIs []string
CardBrand string
Fields []Field
}
Item is what a listing shows of a vault item, no secret among it: its names, the login's username and URIs, the card's brand, and the fields it gives out, its primary one first. Undecryptable marks an item any of whose fields did not open; Reprompt one behind the master password reprompt.
type LoginRequest ¶
type LoginRequest struct {
Server vaultserver.Server
Email string
Password string
TwoFactor *TwoFactor
NewDeviceOTP string
}
LoginRequest is a password login: the server, the account, the master password, and the second factor or new device code when a previous attempt asked for one.
type NetworkLogin ¶
NetworkLogin is the login answering a network connection's secrets: its username and password, and its custom fields by name.
type NewTextSend ¶
type ServerError ¶
ServerError is a server answer the vault does not handle: its HTTP status and the server's message.
func (*ServerError) Error ¶
func (e *ServerError) Error() string
func (*ServerError) Retryable ¶
func (e *ServerError) Retryable() bool
Retryable reports a rate limit or a server-side failure, worth trying again later; a client error is not.
type Status ¶
Status is the vault at a glance: the state, the account, whether a sync runs, when the last one landed (zero for none), how many items the open vault holds, and the last operation's error (nil once one succeeds).
type TwoFactor ¶
type TwoFactor struct {
Provider TwoFactorProvider
Code string
}
TwoFactor is a second factor answering a TwoFactorRequiredError.
type TwoFactorProvider ¶
type TwoFactorProvider uint32
TwoFactorProvider is a second factor, as Bitwarden numbers it.
const ( TwoFactorAuthenticator TwoFactorProvider = 0 TwoFactorEmail TwoFactorProvider = 1 )
The providers a login completes; the server may list others (Duo, WebAuthn, YubiKey) that the API key login gets around.
type TwoFactorRequiredError ¶
type TwoFactorRequiredError struct{ Providers []TwoFactorProvider }
TwoFactorRequiredError asks for a second factor: the providers the account has.
func (*TwoFactorRequiredError) Error ¶
func (e *TwoFactorRequiredError) Error() string