vault

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 16 Imported by: ? 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 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

View Source
const (
	MinSendLifetime = time.Minute
	MaxSendLifetime = 31 * 24 * time.Hour
)
View Source
const (
	ServiceName = "dev.stubbe.lys.Vault1"
	ServicePath = dbus.ObjectPath("/dev/stubbe/lys/Vault")
)

D-Bus identity.

Variables

View Source
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 NewClient

func NewClient(conn *dbus.Conn) *Client

NewClient addresses the vault over conn.

func (*Client) CreateLogin

func (c *Client) CreateLogin(ctx context.Context, l NewLogin) (ItemID, error)

func (*Client) CreateTextSend

func (c *Client) CreateTextSend(ctx context.Context, s NewTextSend) (CreatedSend, error)

func (*Client) DeleteSend

func (c *Client) DeleteSend(ctx context.Context, id SendID) error

func (*Client) Field

func (c *Client) Field(ctx context.Context, id string, f Field, password string) (Value, error)

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) FindLogin

func (c *Client) FindLogin(ctx context.Context, name string, scope FolderScope) (Item, bool, error)

func (*Client) Items

func (c *Client) Items(ctx context.Context) ([]Item, error)

Items lists the open vault, favorites first then by name; ErrLocked while it is not open.

func (*Client) Lock

func (c *Client) Lock(ctx context.Context) error

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

func (c *Client) Logout(ctx context.Context) error

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

func (c *Client) NetworkLogin(ctx context.Context, folder, name string) (NetworkLogin, bool, error)

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.

func (*Client) Sends

func (c *Client) Sends(ctx context.Context) ([]Send, error)

func (*Client) Status

func (c *Client) Status(ctx context.Context) (Status, error)

Status is the vault at a glance.

func (*Client) Sync

func (c *Client) Sync(ctx context.Context) error

Sync refetches the open vault.

func (*Client) Unlock

func (c *Client) Unlock(ctx context.Context, password string) error

Unlock opens a locked vault with the master password.

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, w Watcher) error

Watch reports the vault's signals to w, each on the watch's goroutine, until ctx ends. Only the signals of whoever owns the vault's name as they arrive count, across a restart of the vault; a malformed one is logged and skipped.

type CreatedSend

type CreatedSend struct {
	ID  SendID
	URL string
}

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 NewDaemon

func NewDaemon(life context.Context, host Host) *Daemon

NewDaemon wraps host for export; life bounds the operations callers start.

func (*Daemon) Changed

func (d *Daemon) Changed() error

Changed signals the host's status, after a change of it or of the vault's items.

func (*Daemon) Export

func (d *Daemon) Export(conn *dbus.Conn) (func(), error)

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

func (d *Daemon) SyncFailed(err error) error

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.

const (
	FieldUsername Field = iota
	FieldPassword
	FieldTOTP
	FieldCardNumber
	FieldCardCode
	FieldEmail
	FieldNotes
)

The fields.

func (Field) Secret

func (f Field) Secret() bool

Secret reports whether the field is a secret: behind the item's master password reprompt, and for a client to mark as such where it puts it (a clipboard). A username and an email are not.

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.

func (Item) Match

func (it Item) Match(query string) bool

Match reports whether the item matches every word of query, in its name, username, URIs or folder, ignoring case.

type ItemID

type ItemID string

type ItemType

type ItemType uint32

ItemType is an item's kind, as Bitwarden numbers it.

const (
	ItemLogin      ItemType = 1
	ItemSecureNote ItemType = 2
	ItemCard       ItemType = 3
	ItemIdentity   ItemType = 4
	ItemSSHKey     ItemType = 5
)

The item types.

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

type NetworkLogin struct {
	Username, Password string
	Fields             map[string]string
}

NetworkLogin is the login answering a network connection's secrets: its username and password, and its custom fields by name.

type NewLogin

type NewLogin struct {
	Folder   string
	Name     string
	Username string
	Password string
	URIs     []string
}

func (NewLogin) Validate

func (l NewLogin) Validate() error

type NewTextSend

type NewTextSend struct {
	Name           string
	Text           string
	Deletion       time.Time
	MaxAccessCount uint32
	Password       string
}

func (NewTextSend) Validate

func (s NewTextSend) Validate(now time.Time) error

type Send

type Send struct {
	ID             SendID
	Type           SendType
	Name           string
	AccessCount    uint32
	MaxAccessCount uint32
	HasPassword    bool
	Disabled       bool
	Undecryptable  bool
	Deletion       time.Time
	Expiration     time.Time
}

type SendID

type SendID string

type SendType

type SendType uint32
const (
	SendText SendType = 0
	SendFile SendType = 1
	SendItem SendType = 2
)

type ServerError

type ServerError struct {
	Status  int
	Message string
}

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 State

type State uint32

State is where the vault stands.

const (
	StateLoggedOut State = iota
	StateLocked
	StateUnlocked
)

The vault states: no account, an account whose keys are not in memory, and an open vault.

type Status

type Status struct {
	State    State
	Email    string
	Syncing  bool
	LastSync time.Time
	Items    int
	Err      error
}

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

type Value

type Value struct {
	Text    string
	Expires time.Time
}

Value is one field's value; Expires is when a verification code stops being valid, zero for a value that does not expire.

type Watcher

type Watcher struct {
	// Changed is the status after a change of it or of the items, and
	// the vault's status whenever the vault (re)appears on the bus.
	Changed func(Status)
	// SyncFailed is a periodic sync failing.
	SyncFailed func(error)
}

Watcher is what Watch reports.

Jump to

Keyboard shortcuts

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