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
- func Check(key []byte, token string, gen int, typed string) bool
- func CheckCookie(key []byte, token string, gen int, value string) bool
- func Cookie(key []byte, token string, gen int) string
- func CookieGen(key []byte, token, value string) (gen int, ok bool)
- func Password(key []byte, token string, gen int) string
Constants ¶
const KeyLabel = "sub-page-password"
KeyLabel is the vault.Derive label of the key every function here takes.
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 ¶
Check reports whether typed is the password of the token in the generation (constant time).
func CheckCookie ¶
CheckCookie reports whether a cookie value is the cookie of the token in this generation (constant time).
func Cookie ¶
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 ¶
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).
Types ¶
This section is empty.