config

package
v0.0.44 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: BSD-3-Clause Imports: 12 Imported by: 2

Documentation

Overview

Package config handles keyfish configuration settings. Configurations are typically stored as JSON on disk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilePath added in v0.0.35

func FilePath() string

FilePath returns the effective configuration file path. If KEYFISH_CONFIG is defined in the environment, that is used; otherwise the compiled-in default is used.

func SiteCandidates added in v0.0.40

func SiteCandidates(base string) []string

SiteCandidates returns a slice of candidate site names from base. If base is structured like a host name, the candidates are the suffixes of the hostname having length at least 2. For example, given "x.y.z" the candidates are "x.y.z" and "x.y". A salt prefix (salt@x.y) is preserved on each candidate, so "s@x.y.z" yields "s@x.y.z" and "s@y.z" as candidates.

If base does not look like a hostname, the slice contains it alone.

Types

type Config

type Config struct {
	// A map from site names to site configurations.
	Sites map[string]Site `json:"sites,omitempty"`

	// A default site, overrides empty fields of a named config.
	Default Site `json:"default,omitempty"`

	// Default values for flags.
	Flags struct {
		Copy    bool `json:"copy,omitempty"`
		OTP     bool `json:"otp,omitempty"`
		Strict  bool `json:"strict,omitempty"`
		Verbose bool `json:"verbose,omitempty"`
	} `json:"flags,omitempty"`
}

A Config represents the contents of a keyfish config file.

func (*Config) Load

func (c *Config) Load(path string) error

Load loads the contents of the specified path into c. If path does not exist, the reported error satisfies os.IsNotExist and c is unmodified.

func (*Config) Site

func (c *Config) Site(name string) (Site, bool)

Site returns a site configuration for the given name, which has the form host.name or salt@host.name, and reports whether the config arose from a matching entry in the config. If a matching entry was found, the corresponding Site is returned; otherwise a default Site is built using the name to derive the host (and possibly the salt).

type OTP

type OTP struct {
	Key    OTPKey `json:"key"`
	Digits int    `json:"digits,omitempty"`
}

An OTP represents the settings for an OTP generator.

type OTPKey added in v0.0.33

type OTPKey []byte

OTPKey is the JSON encoding of an OTP secret.

func (OTPKey) MarshalJSON added in v0.0.33

func (o OTPKey) MarshalJSON() ([]byte, error)

MarshalJSON encodes an OTPKey to a base32 string.

func (*OTPKey) UnmarshalJSON added in v0.0.33

func (o *OTPKey) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes an OTPKey from a base32 string.

type Site

type Site struct {
	// The hostname that identifies this site (required).
	// This can be any non-empty string, but conventionally is the domain name
	// of the site, e.g. "dartmouth.edu".
	Host string `json:"host"`

	// The hash key used to generate passwords for this site.  If empty, the
	// hostname is used.
	Key string `json:"key,omitempty"`

	// If set, this defines the alphabet used for key generation on this site.
	// This overrides the Punct setting. The entries in the slice define which
	// components to include:
	//
	//    "upper"     : uppercase letters (A..Z)
	//    "lower"     : lowercase letters (a..z)
	//    "letter"    : upper + lower
	//    "digit"     : decimal digits (0..9)
	//    "nopunct"   : upper + lower + digit
	//    "punct"     : punctuation (the built-in set)
	//    "all"       : upper + lower + digit + punct
	//    "chars:..." : the literal characters ... (order matters)
	//
	// Order is significant: For example ["digit", "chars:x"] means
	// "0123456789x"; whereas ["chars:x", "digit"] means "x0123456789".
	Alphabet []string `json:"alphabet,omitempty"`

	// If set, this defines the exact layout of the password.
	// See the Format method of hashpass.Context for details.
	Format string `json:"format,omitempty"`

	// If set, generate passwords with this many characters.
	// If zero, uses the default.
	Length int `json:"length,omitempty"`

	// If true, include punctuation in the password alphabet.  This is ignored
	// if Alphabet or Format is set.
	Punct *bool `json:"punct,omitempty"`

	// Use this string as a salt for password generation.  This can be used to
	// rotate passwords.
	Salt string `json:"salt,omitempty"`

	// The login name to use for this site.
	Login string `json:"login,omitempty"`

	// The e-mail address associated with this login.
	EMail string `json:"email,omitempty"`

	// OTP configurations for this site. The map key is the salt value for which
	// each configuration applies. Use "" as the key for an unsalted host.
	OTP map[string]*OTP `json:"otp,omitempty"`

	// Alternative hostnames that should be considered aliases for this site.
	// This is useful for sites that use a different domain for authentication.
	// Aliases are only examined if there is no primary host match.
	Aliases []string `json:"aliases,omitempty"`

	// User-defined password hints, security questions, and other metadata that
	// do not affect the password but the user may need to log in.
	Hints map[string]interface{} `json:"hints,omitempty"`
}

A Site represents the non-secret configuration for a single site.

func (Site) Context

func (s Site) Context(secret string) hashpass.Context

Context returns a password generation context from s.

func (Site) String

func (s Site) String() string

Jump to

Keyboard shortcuts

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