Documentation
¶
Overview ¶
Package secrets keeps account credentials out of the database (docs/design/storage.md#credentials): the Secret Service over D-Bus on Linux, a file sealed with DPAPI on Windows, and a plain File for development.
Index ¶
Constants ¶
const ( // CredentialName is the systemd credential that holds the key of the // sealed store (ADR-0044): the unit's // LoadCredentialEncrypted=frostmail-secrets-key puts it in // $CREDENTIALS_DIRECTORY. CredentialName = "frostmail-secrets-key" // SealedFileName is the sealed store's file in maild's data directory. SealedFileName = "secrets.sealed" )
Variables ¶
var ErrDismissed = errors.New("secrets: the unlock prompt was dismissed")
ErrDismissed means the user dismissed the service's unlock prompt.
var ErrNotFound = errors.New("secrets: not found")
ErrNotFound means no secret is stored under the key.
var ErrReadOnly = errors.New("secrets: read-only store")
ErrReadOnly is what a store from OpenReader answers to Set and Delete.
ErrUnavailable means no Secret Service answered on the bus.
Functions ¶
func AccountPassword ¶
AccountPassword is the key of an account's password.
func Credential ¶
Credential is the key of the secret an account signs in with.
func LoadKey ¶
LoadKey reads the sealing key from the credential CredentialName in credDir ($CREDENTIALS_DIRECTORY). It must be exactly 32 raw bytes. An error names the credential and never holds the key.
func OAuthClientSecret ¶
OAuthClientSecret is the key of a provider's OAuth client secret.
func RefreshToken ¶
RefreshToken is the key of an oauth2 account's refresh token.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a Store kept in one JSON object ({"key": "value", ...}) in a file with mode 0600. It is the M1 development store: plain text on disk, guarded only by file permissions. On Windows, NewDPAPIFile seals the same object for the user (ADR-0038).
func NewFile ¶
NewFile returns a File store at path. The file is created on first Set; its directory must exist.
func NewSealedFile ¶
NewSealedFile returns a File store at path whose bytes are sealed with AES-256-GCM under key, which must be 32 bytes (ADR-0044). A file is the magic "FMSEAL01", a fresh random 12-byte nonce, then the ciphertext with its tag; the magic is also the additional data. The rest is File's: the atomic write, mode 0600, a missing file is an empty store.
func (*File) Delete ¶
Delete removes key, rewriting the file atomically like Set. A missing key or a missing file is not an error.
func (*File) Get ¶
Get returns the secret stored under key, or ErrNotFound. A missing file holds no secrets. A file whose mode allows group or other access is refused with an error naming the file and its mode.
type SecretService ¶
type SecretService struct {
// contains filtered or unexported fields
}
SecretService is a Store in the desktop's Secret Service.
func OpenSecretService ¶
OpenSecretService opens a plain session with the Secret Service on conn, or returns an error wrapping ErrUnavailable.
func (*SecretService) Delete ¶
func (s *SecretService) Delete(ctx context.Context, key string) error
Delete removes key; a missing key is not an error.
type Store ¶
type Store interface {
// Get returns the secret, or ErrNotFound.
Get(ctx context.Context, key string) (string, error)
// Set stores the secret, replacing any previous value.
Set(ctx context.Context, key, value string) error
// Delete removes the secret; a missing key is not an error.
Delete(ctx context.Context, key string) error
}
Store keeps string secrets by key.
func Open ¶
Open picks maild's secret store by FROSTMAIL_SECRETS:
- "file": the plain file at file, with a warning (CI, development, a server with no systemd credentials);
- "sealed": the file beside it sealed with the key of the systemd credential frostmail-secrets-key, never a fallback (ADR-0044); a plain file moves in once and is removed;
- empty: the Secret Service on the session bus, or, when no service answers, the plain file with a warning. With the Secret Service, secrets still in the file are moved over and the file is removed;
- anything else is an error.
func OpenReader ¶
OpenReader opens the store Open would pick, to read it and nothing else (mailctl export, with maild stopped): it never moves a secret out of the file and never writes. With the Secret Service or the sealed file, a key it does not hold is also looked up in the plain file, a leftover Open has not migrated yet. With "sealed" it needs the credential's key.