httpauth

package
v0.8.22 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package httpauth is the cryptography behind logins in front of apps (http-auth): password hashes, TOTP codes, and signed session cookies and login hand-offs. It keeps no state: a session is valid wherever the cluster's session key is, so any ingress node (an edge included) checks it on its own.

Index

Constants

View Source
const (
	KindUser     = "u"
	KindPassword = "p"
	KindShare    = "s"
)
View Source
const MaxPassword = 72

MaxPassword is bcrypt's limit.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(hash, password string) bool

func CheckTOTP

func CheckTOTP(secret, code string, now time.Time) (uint64, bool)

CheckTOTP accepts the code for the step at now, or the one before or after (clocks drift), and returns the step it matched, so a caller can refuse a code used twice.

func Fingerprint

func Fingerprint(parts ...string) string

Fingerprint identifies a credential (a password hash, a TOTP secret) without revealing it: sessions carry it, so changing the credential ends them.

func HashPassword

func HashPassword(password string) (string, error)

func HashToken

func HashToken(token string) string

HashToken is how share tokens are stored and compared.

func Key

func Key(s string) ([]byte, error)

Key decodes the cluster's session key.

func NewTOTPSecret

func NewTOTPSecret() string

NewTOTPSecret makes a 160-bit secret, base32.

func Sign

func Sign(key []byte, purpose, host string, v any) (string, error)

Sign makes a token for purpose and host carrying v.

func TOTPCode

func TOTPCode(secret string, t time.Time) (string, error)

TOTPCode is the code for the step at t.

func TOTPURI

func TOTPURI(issuer, user, secret string) string

TOTPURI is what authenticator apps scan.

func Token

func Token() string

Token is a random secret for a share link.

func Verify

func Verify(key []byte, purpose, host, token string, v any) bool

Verify checks a token made by Sign for the same purpose and host and reads it into v.

Types

type Session

type Session struct {
	Kind    string `json:"k"`           // KindUser, KindPassword or KindShare
	Name    string `json:"n,omitempty"` // the user, or the share's ID
	App     string `json:"a,omitempty"` // the app it's for (password and share sessions)
	Version string `json:"v,omitempty"` // Fingerprint of the credential it was made with
	Expires int64  `json:"e"`
}

Session is who a cookie lets in, where, and until when.

Jump to

Keyboard shortcuts

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