Documentation
¶
Overview ¶
Package auth holds credential primitives: password hashing, random tokens and the one-time setup token.
Index ¶
- Constants
- Variables
- func CheckSetupToken(ctx context.Context, st *store.Store, token string, now time.Time) (bool, error)
- func EnsureSetupToken(ctx context.Context, st *store.Store, now time.Time) (string, error)
- func HashPassword(password string) (string, error)
- func HashToken(token string) string
- func NewAccessKey() (id, secret string)
- func NewID(prefix string) string
- func NewTOTPSecret() string
- func NewToken(prefix string) string
- func NewUserCode() string
- func TOTPCode(secret string, t time.Time) (string, error)
- func TOTPURI(secret, issuer, account string) string
- func TokenMatches(token, storedHash string) bool
- func VerifyPassword(password, encoded string) (bool, error)
- func VerifyTOTP(secret, code string, t time.Time) bool
Constants ¶
const MinPasswordLen = 12
const SetupTokenTTL = time.Hour
SetupTokenTTL is how long the one-time setup token printed at install stays valid (§5.0).
const TempKeyPrefix = "SYNAS"
TempKeyPrefix starts the key IDs of temporary credentials (STS).
Variables ¶
var ErrWeakPassword = fmt.Errorf("password must be at least %d characters", MinPasswordLen)
Functions ¶
func CheckSetupToken ¶
func CheckSetupToken(ctx context.Context, st *store.Store, token string, now time.Time) (bool, error)
CheckSetupToken reports whether token is the current, unexpired setup token.
func EnsureSetupToken ¶
EnsureSetupToken issues a fresh setup token if no account exists yet. It returns the plain token (to print once) or "" when setup is already done. A new token is issued on every controller start until setup completes, so a lost or expired token is recovered by restarting the controller.
func HashPassword ¶
HashPassword returns a PHC-format argon2id hash.
func NewAccessKey ¶
func NewAccessKey() (id, secret string)
NewAccessKey returns a new access key ID ("SYNAK" + 16 chars) and secret (40 chars).
func NewTOTPSecret ¶
func NewTOTPSecret() string
NewTOTPSecret returns a random 160-bit secret, base32 encoded.
func NewToken ¶
NewToken returns a random token with the given prefix, e.g. "syn_sess_…". 20 random bytes = 160 bits of entropy.
func NewUserCode ¶
func NewUserCode() string
NewUserCode is a short code a person types to approve a device login: two groups of four letters without ambiguous ones (XXXX-XXXX).
func TokenMatches ¶
TokenMatches compares a presented token with a stored hash in constant time.
func VerifyPassword ¶
VerifyPassword checks password against a hash produced by HashPassword, using the parameters stored in the hash.
Types ¶
This section is empty.