passphrase

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoNonInteractiveSource = errors.New("no non-interactive passphrase source available")

ErrNoNonInteractiveSource is returned by AcquireNonInteractive when neither the keyring nor a keyfile can provide a passphrase. Callers that see this error should gracefully degrade (show zero counts, skip DB sections, etc.) instead of propagating the error to the user.

Functions

func ReadKeyfile

func ReadKeyfile(path string) (string, error)

ReadKeyfile reads the passphrase from a keyfile, validating file permissions. Returns the passphrase with trailing whitespace trimmed.

func ReadStdinPipe

func ReadStdinPipe() (string, error)

ReadStdinPipe reads a single line from non-terminal stdin. Returns an error if the line is empty after trimming.

func ShredKeyfile

func ShredKeyfile(path string) error

ShredKeyfile overwrites the keyfile content with zeros, syncs to disk, and removes it. Returns nil if the file does not exist (idempotent).

func ValidatePermissions

func ValidatePermissions(path string) error

ValidatePermissions checks that the file has exactly 0600 permissions.

func WriteKeyfile

func WriteKeyfile(path, passphrase string) error

WriteKeyfile creates a keyfile with 0600 permissions. Parent directories are created with 0700 permissions if needed.

Types

type Options

type Options struct {
	KeyfilePath     string           // default: ~/.lango/keyfile
	AllowCreation   bool             // if true, prompt for confirmation on new passphrase
	KeyringProvider keyring.Provider // if non-nil, try secure keyring first (biometric/TPM)
}

Options configures passphrase acquisition behavior.

type Source

type Source int

Source represents how the passphrase was obtained.

const (
	SourceKeyfile     Source = iota // from ~/.lango/keyfile
	SourceInteractive               // from interactive terminal prompt
	SourceStdin                     // from piped stdin
	SourceKeyring                   // from hardware keyring (Touch ID / TPM)
)

func Acquire

func Acquire(opts Options) (string, Source, error)

Acquire obtains a passphrase from the highest-priority available source. Priority: keyring -> keyfile -> interactive terminal -> stdin pipe -> error

func AcquireNonInteractive added in v0.7.0

func AcquireNonInteractive(opts Options) (string, Source, error)

AcquireNonInteractive obtains a passphrase WITHOUT triggering any interactive terminal prompt or stdin pipe read. It is used by commands that must work in non-interactive environments (e.g. `lango security status` default path) while still being able to read stored state when a passphrase is available.

Priority:

  1. Secure keyring (Touch ID / TPM) — OS-level biometric prompts are permitted because they are not CLI interactive prompts. TPM reads are silent.
  2. Keyfile at opts.KeyfilePath (or the default ~/.lango/keyfile).

If neither source yields a passphrase, the function returns ErrNoNonInteractiveSource. It SHALL NEVER call term.ReadPassword or read from os.Stdin pipe. It SHALL NEVER block on user input beyond whatever the keyring provider itself does (e.g., a Touch ID prompt).

Jump to

Keyboard shortcuts

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