applock

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 16 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 applock is the lock in front of SSHYard's windows: what opens it (a password, a time-based one-time code of an authenticator app, or both), when it locks by itself, and how long wrong attempts make the next one wait.

It keeps the host list and the sessions from whoever sits down at an unlocked computer; it does not encrypt the metadata on disk, which anyone reading the data folder reads anyway. Its file, applock.json, stays on this computer, and no backup takes it. What opens the lock is also a Record in the encrypted local store (keychain.AppLock), which wins over the file once the store is unlocked: deleting or replacing the file does not remove the lock. The password itself is never stored, only a vault-sealed check that opens with it; the one-time code's secret is a secret of the encrypted store too (keychain.AppLockTOTP).

Index

Constants

View Source
const (
	Digits = 6
)

Time-based one-time codes (RFC 6238) as authenticator apps make them by default: HMAC-SHA1, six digits, a new code every 30 seconds.

View Source
const File = "applock.json"

File is the name of the lock's file in the data folder.

Variables

View Source
var IdleChoices = []int{1, 5, 15, 30, 60, 0}

IdleChoices are the minutes of inactivity the lock may wait before it locks, 0 for never.

View Source
var Methods = []Method{Password, TOTP, Both}

Methods are the methods to choose from, in the order they are offered.

Functions

func CheckPassword

func CheckPassword(verifier, password []byte) (bool, error)

CheckPassword reports whether password opens verifier. An error is a verifier that cannot be opened at all.

func Code

func Code(secret []byte, step int64) string

Code is the code of secret at time step step.

func EncodeSecret

func EncodeSecret(secret []byte) string

EncodeSecret is secret as it is typed into an authenticator app.

func NewSecret

func NewSecret() []byte

NewSecret is a random secret for a new authenticator.

func NewVerifier

func NewVerifier(password []byte, p vault.Params) ([]byte, error)

NewVerifier seals the check a password opens, deriving with p.

func Save

func Save(path string, c Config) error

Save writes the lock to path atomically.

func Step

func Step(t time.Time) int64

Step is the time step of t.

func URI

func URI(secret []byte, issuer, account string) string

URI is the otpauth URI a QR code gives an authenticator app.

func Verify

func Verify(secret []byte, code string, t time.Time, last int64) (step int64, ok bool)

Verify reports whether code is secret's at t, within the skew, and at a step after last, which no code may be taken at again; step is the one it was taken at.

Types

type Config

type Config struct {
	Method Method `json:"method,omitempty"`
	// Verifier is a vault sealed with the password, for a method asking
	// for it.
	Verifier []byte `json:"verifier,omitempty"`
	// IdleMinutes of no input in SSHYard lock it; 0 never does.
	IdleMinutes int `json:"idleMinutes"`
	// LockOnSleep locks as the screen locks or the computer sleeps.
	LockOnSleep bool `json:"lockOnSleep"`
	// LastStep is the time step of the last one-time code taken, which
	// no code may reuse.
	LastStep int64 `json:"lastStep,omitempty"`
	// Failures is how many attempts in a row failed, RetryAt when the
	// next may be made: kept so that quitting does not start them over.
	Failures int       `json:"failures,omitempty"`
	RetryAt  time.Time `json:"retryAt,omitzero"`
}

Config is the lock as applock.json keeps it.

func Default

func Default() Config

Default is the lock before one is set up.

func Load

func Load(path string) (Config, error)

Load reads the lock at path; a missing file is Default. A file that cannot be read is an error, which the caller keeps locked.

func (*Config) Adopt

func (c *Config) Adopt(rec []byte) (bool, error)

Adopt makes what the store's record opens with the way c opens, and reports whether c opened another way: the store wins over the file.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether the lock is on.

func (*Config) Fail

func (c *Config) Fail(now time.Time)

Fail counts a failed attempt at now.

func (Config) Record

func (c Config) Record() []byte

Record is what opens c, for the encrypted store.

func (*Config) Succeed

func (c *Config) Succeed()

Succeed forgets the failed attempts.

func (Config) Wait

func (c Config) Wait(now time.Time) time.Duration

Wait is how long until the next attempt may be made at now: never more than maxWait, so that a clock set back does not lock the user out.

type Method

type Method string

Method is what opens the lock.

const (
	// Off is no lock.
	Off      Method = ""
	Password Method = "password"
	TOTP     Method = "totp"
	// Both asks for the password and a one-time code.
	Both Method = "both"
)

func (Method) NeedsCode

func (m Method) NeedsCode() bool

NeedsCode reports whether m asks for a one-time code.

func (Method) NeedsPassword

func (m Method) NeedsPassword() bool

NeedsPassword reports whether m asks for the password.

Jump to

Keyboard shortcuts

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