service

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT, MIT Imports: 30 Imported by: 0 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 service serves the freedesktop Secret Service API (org.freedesktop.secrets) over keyring collections stored encrypted in a directory: sessions with plain and DH transport, collections and items with their properties and signals, aliases, and prompts that ask the user through a Prompter.

Every client on the user's bus may read an unlocked collection, as with gnome-keyring, unless reads are confirmed: then a program reading an item it does not own sees it locked, and its Unlock prompt asks the user. Sandboxed apps reach their secrets through the portal instead, which identifies them.

Index

Constants

View Source
const (
	BusName = "org.freedesktop.secrets"
)

D-Bus names of the API.

View Source
const LoginID = "login"

LoginID is the collection the login password unlocks; the default alias points at it unless set otherwise.

View Source
const VaultID = "bitwarden"

VaultID is the collection the Bitwarden vault shows as: the logins of one vault folder, read-only, locked while the vault is.

Variables

This section is empty.

Functions

This section is empty.

Types

type Access

type Access int

Access is the user's answer to a program reading an item it does not own.

const (
	Denied Access = iota
	AllowedOnce
	AllowedAlways
)

The answers to ConfirmRead.

type Config

type Config struct {
	// Dir holds the collection files.
	Dir string
	KDF keyring.KDF
	// Stretch derives keys from passwords, off the service's lock.
	Stretch  keyring.Stretch
	Prompter Prompter
	Now      func() time.Time
	// Vault, when set, locks with LockService, and shows as a collection
	// if it says so.
	Vault Vault
	// LockAfter locks a collection once no secret was read from it and
	// nothing in it changed for this long; 0 never does.
	LockAfter time.Duration
	// ConfirmForeignReads asks the user before a program reads an item it
	// does not own.
	ConfirmForeignReads bool
	// Locked, when set, runs each time a collection locks, with its id, under
	// the service's lock: it must not call back into the Service.
	Locked func(id string)
}

Config is what Start needs.

type Prompter

type Prompter interface {
	// Password asks for an existing collection's password; retry says
	// the previous attempt was wrong.
	Password(ctx context.Context, collection string, retry bool) (password []byte, ok bool, err error)
	// NewPassword asks for a new password for a collection, typed twice.
	NewPassword(ctx context.Context, collection string) (password []byte, ok bool, err error)
	// MasterPassword asks for the Bitwarden vault's master password;
	// retry says the previous attempt was wrong.
	MasterPassword(ctx context.Context, retry bool) (password []byte, ok bool, err error)
	// ConfirmRead asks whether a program may read an item it does not own.
	ConfirmRead(ctx context.Context, r ReadRequest) (Access, error)
	// PreviousLoginPassword asks for the login password from before it
	// changed, to move the login collection to the new one; ok is false
	// when the user keeps the old password apart. retry says the previous
	// attempt was wrong.
	PreviousLoginPassword(ctx context.Context, retry bool) (password []byte, ok bool, err error)
}

Prompter asks the user for passwords. ok is false when they dismissed the prompt; ctx ends when the client dismisses it.

type ReadRequest

type ReadRequest struct {
	// Program is who asks, "" for a program that could not be identified,
	// which can only be allowed once.
	Program keyring.Owner
	PID     uint32
	// Item and Collection are the item's and its collection's labels.
	Item, Collection string
	Owners           []keyring.Owner
}

ReadRequest is what ConfirmRead shows: the program asking, the item and who owns it.

type Secret

type Secret struct {
	Session     dbus.ObjectPath
	Parameters  []byte
	Value       []byte
	ContentType string
}

Secret is the API's Secret struct, (oayays).

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a running Secret Service.

func Start

func Start(conn *dbus.Conn, cfg Config) (*Service, error)

Start loads the collections in cfg.Dir, exports them on conn and takes the bus name. A name another provider holds is dbusx.ErrNameTaken: the service never queues for it or replaces the owner. A failed Start leaves nothing exported or watched on conn.

func (*Service) Close

func (s *Service) Close()

Close destroys every collection's key, gives up the bus name and unexports everything Start exported. Every change is on disk already, so nothing is sealed on the way out.

func (*Service) Lock

func (s *Service) Lock()

Lock locks every collection and the vault, whether or not the vault shows as a collection.

func (*Service) LockCollections

func (s *Service) LockCollections()

LockCollections locks every collection, leaving the vault as it is.

func (*Service) LoginSecret

func (s *Service) LoginSecret(attrs map[string]string) (secret []byte, found bool, err error)

LoginSecret is the secret of the first item of the login collection holding attrs, for lys-secrets' own use; found is false with none. A locked login collection is keyring.ErrLocked: it is not unlocked for this. The caller clears the secret.

func (*Service) RekeyLogin

func (s *Service) RekeyLogin(old, next []byte) error

RekeyLogin moves the login collection from the password old to next, as a password change does, unlocking it on the way. A collection next opens already is left as it is, so running it twice is safe, and with no login collection there is nothing to move. An old password that opens nothing matches both control.ErrWrongPassword and keyring.ErrWrongPassword.

func (*Service) StoreLoginSecret

func (s *Service) StoreLoginSecret(label string, attrs map[string]string, secret []byte) error

StoreLoginSecret stores secret under attrs in the unlocked login collection, replacing an item with the same attributes, owned by lys-secrets itself.

func (*Service) UnlockLogin

func (s *Service) UnlockLogin(password []byte) error

UnlockLogin unlocks the login collection with the password the user logged in or unlocked the session with, creating it with that password on first use and pointing the default alias at it when none is set. A wrong password matches both control.ErrWrongPassword and keyring.ErrWrongPassword, and leaves it locked: the login password changed, so the user is asked once for the previous one, to move the collection to this one.

func (*Service) VaultChanged

func (s *Service) VaultChanged()

VaultChanged follows a change of the vault: the collection's lock state and items, with their signals.

type Vault

type Vault interface {
	// Shown reports whether the vault shows as the read-only VaultID
	// collection.
	Shown() bool
	// Logins are the logins the collection shows; open is false while
	// the vault is not open.
	Logins() (logins []VaultLogin, open bool)
	// Password is login id's password.
	Password(id string) ([]byte, error)
	// Unlock opens the vault with the master password; a wrong one
	// matches vault.ErrWrongPassword.
	Unlock(ctx context.Context, password string) error
	// Lock locks the vault.
	Lock()
}

Vault is the Bitwarden vault: it locks with the service, and Shown says whether it also shows as the vault collection.

type VaultLogin

type VaultLogin struct {
	ID, Name, Username, URI, Folder string
}

VaultLogin is one login the vault collection shows.

Jump to

Keyboard shortcuts

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