auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: CC0-1.0 Imports: 19 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 auth provides token, password, and session authentication primitives.

Index

Constants

View Source
const (
	// ArgonTime is the number of passes used for new password hashes.
	ArgonTime = 3
	// ArgonMemoryKiB is the memory cost of new password hashes, in KiB.
	ArgonMemoryKiB = 64 * 1024
	// ArgonThreads is the parallelism of new password hashes.
	ArgonThreads = 1
	// ArgonKeyLen is the derived key length in bytes.
	ArgonKeyLen = 32
	// SaltLen is the random password salt length in bytes.
	SaltLen = 16
)
View Source
const TokenPrefix = "tkr_"

TokenPrefix identifies Taskronin API tokens.

Variables

This section is empty.

Functions

func CSRFToken

func CSRFToken(secret [32]byte) string

CSRFToken computes the unpadded base64url HMAC-SHA256 of "tkr-csrf-v1".

func FormatToken

func FormatToken(id domain.TokenID, raw [32]byte) string

FormatToken encodes a token ID and secret in the canonical bearer format.

func HashPassword

func HashPassword(pw string) (string, error)

HashPassword validates and hashes a new password using a fresh random salt.

func HashSecret

func HashSecret(raw [32]byte) [32]byte

HashSecret returns the SHA-256 digest stored for a token secret.

func HashSessionID

func HashSessionID(raw [32]byte) [32]byte

HashSessionID returns the SHA-256 digest stored for a session ID.

func NewCSRFSecret

func NewCSRFSecret() ([32]byte, error)

NewCSRFSecret generates an independent random 32-byte CSRF secret.

func NewSecret

func NewSecret() (raw [32]byte, err error)

NewSecret generates a cryptographically random 32-byte secret.

func NewSessionID

func NewSessionID() (raw [32]byte, cookie string, err error)

NewSessionID generates a random session ID and its unpadded base64url cookie.

func OwnerTokenName

func OwnerTokenName(now time.Time) (string, error)

OwnerTokenName returns a UTC millisecond timestamp with a random 4-hex suffix.

func ParseSessionCookie

func ParseSessionCookie(cookie string) ([32]byte, error)

ParseSessionCookie decodes a canonical unpadded base64url session ID.

func ParseToken

func ParseToken(s string) (id domain.TokenID, raw [32]byte, err error)

ParseToken accepts only canonical tokens with a positive int64 ID.

func ValidateNewPassword

func ValidateNewPassword(pw string) error

ValidateNewPassword requires valid UTF-8 containing 8 through 1024 bytes.

func VerifyPassword

func VerifyPassword(encoded, pw string) (bool, error)

VerifyPassword derives a key using bounded encoded parameters and compares it in constant time. A password mismatch is false, nil; a malformed hash is an error.

Types

type PasswordGate

type PasswordGate struct {
	// contains filtered or unexported fields
}

PasswordGate rate-limits password attempts and serializes argon2 verification. It is safe for concurrent use and must be constructed with NewPasswordGate.

func NewPasswordGate

func NewPasswordGate(c clock.Clock) *PasswordGate

NewPasswordGate creates a gate with a global 1/s bucket, per-key 1/5s buckets, bursts of five, and at most 1024 cached per-key buckets.

func (*PasswordGate) Verify

func (g *PasswordGate) Verify(ctx context.Context, key, encoded, pw string) (bool, error)

Verify waits at most 15 seconds for both rate buckets, then holds the single verification slot while checking the password. Failed attempts never lock out a key.

Jump to

Keyboard shortcuts

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