pagepass

package
v0.2.0-dev.7 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: AGPL-3.0 Imports: 5 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 pagepass is the password of a user's page and the cookie that remembers it. Both are computed, never stored: HMAC-SHA256 under a key the panel derives from its master key (vault.Derive(KeyLabel)), over the user's current subscription token and a small number, the generation of the password. The database holds that number (and whether the password was removed) and nothing else: no password, no hash of one.

Generation 0 is the password every person has had since the page was protected; "change" adds one, so the password is new, the link stays and the cookies of the old one stop working; a new link (a rotated token) is a new password too.

The password only keeps the page and its self-service calls from whoever happens to hold the link; the subscription itself, which apps fetch from the same address, never asks for it.

Index

Constants

View Source
const KeyLabel = "sub-page-password"

KeyLabel is the vault.Derive label of the key every function here takes.

View Source
const MaxGen = 1_000_000

MaxGen is the largest generation a cookie may claim; far beyond what changes by hand reach.

Variables

This section is empty.

Functions

func Check

func Check(key []byte, token string, gen int, typed string) bool

Check reports whether typed is the password of the token in the generation (constant time).

func CheckCookie

func CheckCookie(key []byte, token string, gen int, value string) bool

CheckCookie reports whether a cookie value is the cookie of the token in this generation (constant time).

func Cookie(key []byte, token string, gen int) string

Cookie is the value of the cookie that remembers an entered password: an HMAC over the token and the generation, so the server keeps no state, and under another purpose than the password, so it does not reveal it. Generation 0 is the bare HMAC (what browsers already hold); a later one is "<gen>.<HMAC>", so the server can tell which generation a cookie claims before it knows the current one.

func CookieGen

func CookieGen(key []byte, token, value string) (gen int, ok bool)

CookieGen is the generation a cookie value claims and whether it is genuine for that generation (its HMAC is right for the token). It does not know the current generation: the caller compares the two. It is how a call that has not read the person's row yet tells a forged cookie (refused at once) from one that was once earned (judged when the row is read).

func Password

func Password(key []byte, token string, gen int) string

Password is the page password of a token in a generation as it is shown and typed: "xxxx-xxxx".

Types

This section is empty.

Jump to

Keyboard shortcuts

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