Documentation
¶
Overview ¶
Package auth provides token, password, and session authentication primitives.
Index ¶
- Constants
- func CSRFToken(secret [32]byte) string
- func FormatToken(id domain.TokenID, raw [32]byte) string
- func HashPassword(pw string) (string, error)
- func HashSecret(raw [32]byte) [32]byte
- func HashSessionID(raw [32]byte) [32]byte
- func NewCSRFSecret() ([32]byte, error)
- func NewSecret() (raw [32]byte, err error)
- func NewSessionID() (raw [32]byte, cookie string, err error)
- func OwnerTokenName(now time.Time) (string, error)
- func ParseSessionCookie(cookie string) ([32]byte, error)
- func ParseToken(s string) (id domain.TokenID, raw [32]byte, err error)
- func ValidateNewPassword(pw string) error
- func VerifyPassword(encoded, pw string) (bool, error)
- type PasswordGate
Constants ¶
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 )
const TokenPrefix = "tkr_"
TokenPrefix identifies Taskronin API tokens.
Variables ¶
This section is empty.
Functions ¶
func FormatToken ¶
FormatToken encodes a token ID and secret in the canonical bearer format.
func HashPassword ¶
HashPassword validates and hashes a new password using a fresh random salt.
func HashSecret ¶
HashSecret returns the SHA-256 digest stored for a token secret.
func HashSessionID ¶
HashSessionID returns the SHA-256 digest stored for a session ID.
func NewCSRFSecret ¶
NewCSRFSecret generates an independent random 32-byte CSRF secret.
func NewSessionID ¶
NewSessionID generates a random session ID and its unpadded base64url cookie.
func OwnerTokenName ¶
OwnerTokenName returns a UTC millisecond timestamp with a random 4-hex suffix.
func ParseSessionCookie ¶
ParseSessionCookie decodes a canonical unpadded base64url session ID.
func ParseToken ¶
ParseToken accepts only canonical tokens with a positive int64 ID.
func ValidateNewPassword ¶
ValidateNewPassword requires valid UTF-8 containing 8 through 1024 bytes.
func VerifyPassword ¶
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.