Documentation
¶
Overview ¶
Package session is turnd's own login: an OpenID Connect login through go-authn/rp in a popup window, and a short-lived bearer token turnd signs itself, which the playground then presents to the credential and rendezvous endpoints.
The token is "t1.<payload>.<mac>" (both base64url): payload is the expiry (8 bytes, big endian Unix seconds), a 16-byte random nonce, then the subject; mac is HMAC-SHA256 over a domain-separation label and the payload, under a server key that never leaves turnd. It is compared in constant time and is refused when expired or altered.
Index ¶
Constants ¶
const ( // MinKeyLen is the shortest session key accepted (the HMAC-SHA256 output size). MinKeyLen = 32 // MaxSubjectLen bounds the subject of a token. MaxSubjectLen = 128 // MaxTokenLen bounds a token Verify reads; anything longer is refused unread. MaxTokenLen = 512 )
Variables ¶
var ( // ErrInvalid is a token that is malformed, signed by no key of ours, or altered. ErrInvalid = errors.New("session: invalid token") // ErrExpired is a genuine token whose time is over. ErrExpired = errors.New("session: token expired") )
ErrUnauthorized is the one refusal Subject gives, whatever the cause: a client that sent a bad token is not owed which check caught it.
Functions ¶
func Subject ¶
Subject is the opaque, stable identifier turnd uses for a person: a hash of issuer and "sub", never a name. It ends up in TURN usernames, which an eavesdropper sees (draft-uberti-behave-turn-rest-00 §6).
func ValidSubject ¶
ValidSubject says whether s can be a token's subject: non-empty, UTF-8, at most MaxSubjectLen bytes, no control or space characters.
Types ¶
type Auth ¶
type Auth struct {
Signer *Signer
// AccessTokens, when non-nil, accepts issuer access tokens. Build it with
// oidc.Config{Type: "at+jwt"} so an ID token is never taken for one.
AccessTokens *oidc.Verifier
Now func() time.Time
// Logf receives the real reason for a refusal (never sent to the client).
Logf func(format string, args ...any)
}
Auth authenticates an API request from its Authorization: Bearer header: a turnd session token, or (when AccessTokens is set) an access token of the configured issuer, verified by go-authn/oidc.
func (*Auth) Authenticate ¶
Authenticate returns the opaque subject of a token: a turnd session token or an issuer access token. It is what a gRPC service calls with the token of its "authorization: Bearer" metadata.
type Login ¶
type Login struct {
// contains filtered or unexported fields
}
Login serves /login and /callback.
type LoginConfig ¶
type LoginConfig struct {
Client *rp.Client
Signer *Signer
// Origins is the allowlist of origins ("https://go-tex.github.io") that may
// open /login and receive the token by postMessage. Compared exactly; the
// popup's return target comes from here and nowhere else.
Origins []string
// Secure marks the flow cookie Secure (set it when the public URL is https).
Secure bool
// FlowTTL is how long a login may take (default 10 minutes); MaxFlows bounds
// the logins in progress (default 4096).
FlowTTL time.Duration
MaxFlows int
Now func() time.Time
}
LoginConfig configures NewLogin.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer issues and verifies tokens. Issue signs with the first key; Verify accepts any of them, so a key can be rotated without logging everybody out.
func NewSigner ¶
NewSigner is a signer with the given lifetime for tokens it issues. A key shorter than MinKeyLen, a non-positive ttl or a duplicate key is refused.