Documentation
¶
Overview ¶
Package auth104 is the server side of BRC-103 mutual authentication over HTTP (BRC-104), as a provider's routes need it: the handshake at /.well-known/auth, and each authenticated request checked and its answer signed, the way the SDK's clients (authhttp in Go, AuthFetch in TypeScript) send and check them. It holds the hardening every bstore route shares: a handshake budget per address and for the route, checked before any signature work; bounded sessions; a budget of signed answers per session, taken before a request is verified; and a request sent twice refused before any work. go-sdk carries the client and the Peer but no HTTP server, so this is that server, built on the SDK's own payload encoding (authpayload) and nonce rules.
Index ¶
Constants ¶
const ( DefaultMaxSessions = 10000 DefaultSessionTTL = 10 * time.Minute DefaultMaxRemembered = 1 << 18 DefaultMaxHandshake = 16 << 10 )
const HandshakePath = "/.well-known/auth"
HandshakePath is where the SDK's clients send a handshake: the origin's /.well-known/auth.
const MaxAddresses = 10000
MaxAddresses is the most addresses with a bucket of their own.
Variables ¶
var ( DefaultHandshakes = Budget{Rate: 4, Burst: 8} DefaultPerAddress = Budget{Rate: 1, Burst: 4} DefaultResponses = Budget{Rate: 5, Burst: 20} )
The defaults, as the bstore host's terms route has them.
Functions ¶
func AddressKey ¶
AddressKey is the key a remote address is budgeted under: an IPv4 address as it is (an IPv4-mapped IPv6 address as its IPv4 address), an IPv6 address by its /64, which is what one host is usually given. A port is dropped.
Types ¶
type Caller ¶
Caller is who sent a request: the identity key BRC-103 authenticated, or nil for a request without authentication.
type Config ¶
type Config struct {
Wallet Wallet
// MaxSessions bounds the sessions kept, SessionTTL how long one idle is
// kept, and MaxRemembered the request identifiers remembered across all
// sessions (past it the least recently used session is forgotten whole).
MaxSessions int
SessionTTL time.Duration
MaxRemembered int
// Handshakes and PerAddress are the handshake budget; Responses the
// signed answers one session is given.
Handshakes Budget
PerAddress Budget
Responses Budget
// MaxHandshake bounds a handshake's body.
MaxHandshake int64
Now func() time.Time
// ClientAddr, when set, is the remote address a request is budgeted
// under (a client behind a trusted proxy); RemoteAddr otherwise.
ClientAddr func(*http.Request) string
// Count, when set, is told each outcome: "handshake" with accepted,
// failed, limited_address or limited_global; "request" with replayed,
// limited, failed or accepted; "session_evicted" with cap, idle or
// requests.
Count func(what, result string)
}
Config is a server's settings. Zero fields take the defaults below.
type Handshakes ¶
type Handshakes struct {
// contains filtered or unexported fields
}
Handshakes is the handshake budget: a bucket for the route and one for each remote address, an address's checked first so that one address that floods spends its own budget and not the route's.
func NewHandshakes ¶
func NewHandshakes(global, perAddress Budget, now func() time.Time) (*Handshakes, error)
NewHandshakes is a handshake budget.
type Keyed ¶
type Keyed struct {
// contains filtered or unexported fields
}
Keyed is token buckets by key, at most Max of them: past it the least recently used is forgotten, which only ever gives a forgotten key a full bucket again, never more than Burst at once.
type Reply ¶
Reply is an answer before it is written, signed when its request was authenticated.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server answers BRC-104 handshakes and authenticated requests.
func (*Server) Handshake ¶
func (s *Server) Handshake(w http.ResponseWriter, r *http.Request)
Handshake answers a POST to /.well-known/auth. The budget is taken before the body is read and before any signature work.
type Wallet ¶
type Wallet interface {
wallet.KeyOperations
}
Wallet is what the server signs and checks with: the SDK's ProtoWallet, or any BRC-100 wallet.