Documentation
¶
Overview ¶
Package bitwarden is an in-process Bitwarden client: the key hierarchy (master key, user key, RSA private key, organization keys), the EncString envelope, TOTP codes, and the identity and sync API, so lys-secrets reads a vault with no external daemon and wipes its keys on lock. Its Service is the vault package's Host.
Index ¶
- Variables
- type APIError
- type Card
- type Client
- func (c *Client) APIKeyLogin(ctx context.Context, id, secret string, now time.Time) (Token, error)
- func (c *Client) CreateCipher(ctx context.Context, accessToken string, req cipherRequest) (SyncCipher, error)
- func (c *Client) CreateSend(ctx context.Context, accessToken string, req sendRequest) (SyncSend, error)
- func (c *Client) DeleteSend(ctx context.Context, accessToken string, id vault.SendID) error
- func (c *Client) PasswordLogin(ctx context.Context, email, passwordHash string, tf *vault.TwoFactor, ...) (Token, error)
- func (c *Client) Prelogin(ctx context.Context, email string) (Prelogin, error)
- func (c *Client) Refresh(ctx context.Context, refreshToken, loginClientID string, now time.Time) (Token, error)
- func (c *Client) Revoke(ctx context.Context, refreshToken, loginClientID string) error
- func (c *Client) SendLoginEmail(ctx context.Context, email, passwordHash string) error
- func (c *Client) Sync(ctx context.Context, accessToken string) (SyncResponse, error)
- type Device
- type EncString
- type EncType
- type Field
- type FolderLogin
- type Identity
- type Item
- type Kdf
- type KdfType
- type Keychain
- type Keyring
- type Policy
- type Prelogin
- type Service
- func (s *Service) CreateLogin(ctx context.Context, l vault.NewLogin) (vault.ItemID, error)
- func (s *Service) CreateTextSend(ctx context.Context, n vault.NewTextSend) (vault.CreatedSend, error)
- func (s *Service) DeleteSend(ctx context.Context, id vault.SendID) error
- func (s *Service) Field(id string, f vault.Field, password string) (vault.Value, error)
- func (s *Service) FindLogin(name string, scope vault.FolderScope) (vault.Item, bool, error)
- func (s *Service) FolderLogins(folder string) (logins []FolderLogin, open bool)
- func (s *Service) FolderPassword(folder, id string) ([]byte, error)
- func (s *Service) Items() ([]vault.Item, error)
- func (s *Service) Keep(ctx context.Context, p Policy, failed func(error))
- func (s *Service) Lock()
- func (s *Service) Login(ctx context.Context, req vault.LoginRequest) error
- func (s *Service) LoginAPIKey(ctx context.Context, req vault.APIKeyRequest) error
- func (s *Service) Logout(ctx context.Context) error
- func (s *Service) NetworkLogin(folder, name string) (vault.NetworkLogin, bool)
- func (s *Service) SendLoginEmail(ctx context.Context, req vault.LoginRequest) error
- func (s *Service) Sends() ([]vault.Send, error)
- func (s *Service) Status() vault.Status
- func (s *Service) Sync(ctx context.Context) error
- func (s *Service) Unlock(ctx context.Context, password string) error
- type SymmetricKey
- func (k SymmetricKey) Decrypt(e EncString) ([]byte, error)
- func (k SymmetricKey) DecryptString(s string) (string, error)
- func (k SymmetricKey) Encrypt(plain []byte) (EncString, error)
- func (k SymmetricKey) EncryptString(s string) (string, error)
- func (k SymmetricKey) GoString() string
- func (k SymmetricKey) String() string
- func (k SymmetricKey) Wipe()
- type SyncCard
- type SyncCipher
- type SyncCollection
- type SyncField
- type SyncFolder
- type SyncIdentity
- type SyncLogin
- type SyncOrganization
- type SyncProfile
- type SyncResponse
- type SyncSend
- type TOTP
- type TOTPAlgorithm
- type Token
- type UnlockInput
- type Vault
Constants ¶
This section is empty.
Variables ¶
var ErrInsufficientKdf = errors.New("bitwarden: insufficient KDF parameters")
ErrInsufficientKdf reports KDF parameters under Bitwarden's floors.
var ErrMAC = errors.New("bitwarden: EncString MAC mismatch")
ErrMAC reports an EncString whose MAC does not verify: the wrong key, or tampered data.
var ErrMissingSecret = errors.New("bitwarden: TOTP without a secret")
ErrMissingSecret reports an otpauth URI without a secret.
var ErrUnsupportedEncType = errors.New("bitwarden: unsupported EncString type")
ErrUnsupportedEncType reports an EncString of a type this client does not open.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Op string
vault.ServerError
}
APIError is a server answer the flow does not handle: the operation and the server's status and message.
type Card ¶
type Card struct {
Cardholder, Brand, Number, ExpMonth, ExpYear, Code string
}
Card is a decrypted card.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one server as one device. Every request carries the caller's context and a timeout.
func NewClient ¶
func NewClient(server vaultserver.Server, device Device) *Client
NewClient is a client for server as device.
func (*Client) APIKeyLogin ¶
APIKeyLogin logs in with the account's personal API key: no second factor or device check, for the factors this client does not speak.
func (*Client) CreateCipher ¶
func (*Client) CreateSend ¶
func (*Client) DeleteSend ¶
func (*Client) PasswordLogin ¶
func (c *Client) PasswordLogin(ctx context.Context, email, passwordHash string, tf *vault.TwoFactor, newDeviceOTP string, now time.Time) (Token, error)
PasswordLogin exchanges the master password hash for tokens. A second factor or a new device's emailed code, when the server asks, comes as TwoFactorRequiredError or ErrNewDeviceVerification; retry with it.
func (*Client) Prelogin ¶
Prelogin asks how the account derives its master key. The password endpoint answers either the current shape, KDF settings and a salt, or, as bitwarden.com does, the original one; older servers (Vaultwarden among them) answer only the original endpoint. Without a salt it is the email.
func (*Client) Refresh ¶
func (c *Client) Refresh(ctx context.Context, refreshToken, loginClientID string, now time.Time) (Token, error)
Refresh trades the refresh token for a new access token, under the client id that logged in.
func (*Client) Revoke ¶
Revoke asks the server to revoke refreshToken (RFC 7009). The token endpoint's client id needs no secret for a first-party client. A server saying it cannot is vault.ErrRevocationUnsupported; any other answer but 200 is an APIError.
func (*Client) SendLoginEmail ¶
SendLoginEmail asks the server to email the login's second-factor code.
type Device ¶
type Device struct {
ID, Name string
}
Device is how this client registers with the server: its stable identifier and the name the account's device list shows.
type EncString ¶
EncString is Bitwarden's encrypted value, "type.part|part|...": AES-CBC (iv, data[, mac]) or RSA-OAEP (data).
func ParseEncString ¶
ParseEncString parses s, checking the part count and the IV and MAC lengths its type requires.
type FolderLogin ¶
type FolderLogin struct {
ID, Name, Username, URI, Folder string
}
FolderLogin is a login the Secret Service shows: its id, name, username, first URI and folder.
type Identity ¶
type Identity struct {
Title, First, Middle, Last, Email, Phone, Username, Company string
}
Identity is a decrypted identity's shown fields.
type Item ¶
type Item struct {
ID string
Type vault.ItemType
Name string
Notes string
Folder string
Organization string
Favorite bool
Reprompt bool
Username string
Password string
TOTP string
URIs []string
Card Card
Identity Identity
Fields []Field
Undecryptable bool
}
Item is a decrypted vault item. Undecryptable marks one any of whose fields failed to open (a key it was not shared with, an EncString type this client does not speak); the rest still shows.
type Keyring ¶
type Keyring struct {
User SymmetricKey
Orgs map[string]SymmetricKey
// contains filtered or unexported fields
}
Keyring is an unlocked account's keys: the user key, the RSA private key, and each organization's key. Wipe zeroes them all.
func Unlock ¶
func Unlock(in UnlockInput) (*Keyring, error)
Unlock derives the master key and opens the key hierarchy. A user key that does not verify is vault.ErrWrongPassword; any other key that does not open is an error naming it.
func (*Keyring) SetOrgKeys ¶
SetOrgKeys replaces the organization keys with orgKeys, each opened with the private key: a sync after a membership change brings new ones and drops old ones. On an error the previous keys stay.
type Policy ¶
Policy is how the open vault is kept: locked once unused for LockAfter (0 never), synced every SyncInterval (0 only on unlock and when asked).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns the vault: the session, the keys while unlocked, and the decrypted items. Operations run one at a time; no lock is held across a network call except the operation lock that serializes them.
func Open ¶
Open loads the session in dir (created 0700), registering a device id on first use: an account there starts locked, none logged out. Its credential is read from keychain at the first unlock. changed runs after every status or vault change.
func (*Service) CreateLogin ¶
func (*Service) CreateTextSend ¶
func (s *Service) CreateTextSend(ctx context.Context, n vault.NewTextSend) (vault.CreatedSend, error)
func (*Service) DeleteSend ¶
func (*Service) Field ¶
Field is item id's field f, a verification code the one current now. A secret of an item behind the master password reprompt needs the master password; otherwise password is ignored. It counts as use.
func (*Service) FolderLogins ¶
func (s *Service) FolderLogins(folder string) (logins []FolderLogin, open bool)
FolderLogins is the open vault's shareable logins in folder, in vault order; open is false (and the list empty) while the vault is not open.
func (*Service) FolderPassword ¶
FolderPassword is the password of login id, one of FolderLogins' for folder. It counts as use.
func (*Service) Keep ¶
Keep upholds p until ctx ends. A periodic sync that fails is reported to failed once per run of failures, and every time it logs the account out.
func (*Service) Lock ¶
func (s *Service) Lock()
Lock wipes the keys and the plaintext; the session stays for Unlock.
func (*Service) Login ¶
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 (*Service) LoginAPIKey ¶
LoginAPIKey logs in with the personal API key and opens the vault with the master password. The server issues no refresh token for it, so the keyring keeps the API key, and an unlock or a sync after the access token expired logs in with it again, as Bitwarden's clients do.
func (*Service) Logout ¶
Logout locks and forgets the session here first, then asks the server to revoke its refresh token, so a server that does not answer never keeps a session here. A server with no way to revoke is logged once and returned as vault.ErrRevocationUnsupported, with no error in the status, since that logout did all it can. An attempt that failed is vault.ErrSessionNotRevoked, in the status as well, and so is a keyring that could not say which refresh token to revoke. A session without a refresh token (an API key login) has nothing to revoke. It waits for a running operation, which may rotate the token or save the session.
func (*Service) NetworkLogin ¶
func (s *Service) NetworkLogin(folder, name string) (vault.NetworkLogin, bool)
NetworkLogin is the login answering the network connection named name from folder (networkLogin); none from an empty folder or a vault that is not open.
func (*Service) SendLoginEmail ¶
SendLoginEmail asks the server to email the second-factor code for a login that needs it.
func (*Service) Sync ¶
Sync refetches the open vault: new and changed items, organization memberships, folder names.
func (*Service) Unlock ¶
Unlock opens a locked vault with the master password: the credential from the keyring after a restart, a fresh token, a sync, the keys. A wrong password leaves it locked; a session that can no longer refresh, or one the keyring does not keep, logs out with vault.ErrLoginRequired.
type SymmetricKey ¶
type SymmetricKey struct {
// contains filtered or unexported fields
}
SymmetricKey is an AES-256-CBC key with its HMAC-SHA256 key; a legacy key has no MAC key and opens only type 0 EncStrings. It formats as [redacted].
func (SymmetricKey) Decrypt ¶
func (k SymmetricKey) Decrypt(e EncString) ([]byte, error)
Decrypt opens an AES EncString. A MAC-carrying string needs a key with a MAC key and verifies before decrypting; a legacy type 0 string opens only with a legacy key, so a type 0 string can never stand in for an authenticated one.
func (SymmetricKey) DecryptString ¶
func (k SymmetricKey) DecryptString(s string) (string, error)
DecryptString opens s as a UTF-8 string.
func (SymmetricKey) EncryptString ¶
func (k SymmetricKey) EncryptString(s string) (string, error)
func (SymmetricKey) String ¶
func (k SymmetricKey) String() string
String and GoString keep the key out of logs and %v output.
type SyncCard ¶
type SyncCard struct {
CardholderName, Brand, Number, ExpMonth, ExpYear, Code string
}
SyncCard is a card's encrypted fields.
type SyncCipher ¶
type SyncCipher struct {
ID string
OrganizationID string
FolderID string
Type vault.ItemType
Name string
Notes string
Favorite bool
Key string
Reprompt int
DeletedDate *string
Login *SyncLogin
Card *SyncCard
Identity *SyncIdentity
Fields []SyncField
}
SyncCipher is one encrypted vault item.
type SyncCollection ¶
type SyncCollection struct {
ID, OrganizationID, Name string
}
SyncCollection is an organization collection, its name encrypted under the organization key.
type SyncField ¶
SyncField is a custom field; its type says whether the value is hidden (1) or plain (0, 2 boolean, 3 linked).
type SyncFolder ¶
type SyncFolder struct {
ID, Name string
}
SyncFolder is a folder, its name encrypted under the user key.
type SyncIdentity ¶
type SyncIdentity struct {
Title, FirstName, MiddleName, LastName, Email, Phone, Username, Company string
}
SyncIdentity is an identity's encrypted fields this client shows.
type SyncOrganization ¶
type SyncOrganization struct {
ID, Name, Key string
}
SyncOrganization is a membership: the organization and its wrapped key.
type SyncProfile ¶
type SyncProfile struct {
Email string
Key string
PrivateKey string
Organizations []SyncOrganization
}
SyncProfile carries the wrapped keys: the user key under the master key, the private key under the user key, each organization's key under the private key.
type SyncResponse ¶
type SyncResponse struct {
Profile SyncProfile
Folders []SyncFolder
Collections []SyncCollection
Ciphers []SyncCipher
Sends []SyncSend
}
SyncResponse is /sync's answer, the encrypted account.
type TOTP ¶
type TOTP struct {
Secret []byte
Algorithm TOTPAlgorithm
Digits int
Period int
Issuer string
Account string
}
TOTP is a parsed authenticator key: the secret and the code's shape.
type TOTPAlgorithm ¶
type TOTPAlgorithm int
TOTPAlgorithm is a code's HMAC; Steam is SHA-1 with Steam's alphabet.
const ( TOTPSHA1 TOTPAlgorithm = iota TOTPSHA256 TOTPSHA512 TOTPSteam )
The algorithms an otpauth URI or a steam:// key names.
type Token ¶
type Token struct {
AccessToken string
RefreshToken string
Expires time.Time
Key string
PrivateKey string
}
Token is a login's answer: the access and refresh tokens, when the access token expires, and the account's wrapped keys.
type UnlockInput ¶
type UnlockInput struct {
Password, Email string
Kdf Kdf
UserKey string
PrivateKey string
OrgKeys map[string]string
}
UnlockInput is what unlocking needs: the master password, the account email and KDF, the master-key-wrapped user key, the user-key-wrapped private key, and the organization keys wrapped for the private key.
type Vault ¶
type Vault struct {
Items []Item
Folders map[string]string
Sends []vault.Send
// contains filtered or unexported fields
}
Vault is the decrypted account: its items, favorites first then by name, and folder names by id. Deleted items (the trash) are left out.
func DecryptVault ¶
func DecryptVault(kr *Keyring, s SyncResponse) Vault
DecryptVault opens a sync under the keyring. A field that does not open marks its item Undecryptable rather than failing the sync.