adminauth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 14 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 adminauth authenticates admin API calls with FIDO2 assertions.

An assertion is valid for exactly one request on exactly one TLS connection: the challenge the authenticator signs commits to a single-use server nonce, the full method name, the bytes of the request as received and a TLS exporter value of the connection. See docs/admin-api.md.

Index

Constants

View Source
const (
	// Domain separates the signed calls of this API from every other use of the
	// key, and versions the encoding.
	Domain = "go-vcs admin v1"
	// EnrolDomain does the same for enrolment challenges.
	EnrolDomain = "go-vcs enrol v1"
	// ExporterLabel is the RFC 9266 label for TLS 1.3 channel binding.
	ExporterLabel = "EXPORTER-Channel-Binding"
	// ExporterLen is the number of exporter bytes used (RFC 9266: 32).
	ExporterLen = 32
	// NonceLen is the length of a server nonce.
	NonceLen = 32
)
View Source
const (
	MaxCredentialIDLen = 1024
	MaxAuthDataLen     = 512
	MaxSignatureLen    = 160
)

Size bounds on what an assertion may carry; larger input is refused before any cryptography.

View Source
const (

	// TokenLen is the length of a nonce.
	TokenLen = 8 + nonceRandLen + nonceMACLen
)

Layout of a stateless nonce: issue time (Unix seconds, big endian), 16 random bytes, then HMAC-SHA-256 over a label, the first two fields and the TLS exporter value of the connection it was issued on.

Variables

View Source
var (
	ErrNonceUnknown     = errors.New("nonce unknown, forged, already used, malformed or issued to another connection")
	ErrNonceExpired     = errors.New("nonce expired")
	ErrNonceStoreFull   = errors.New("too many accepted calls in one nonce lifetime")
	ErrSessionInvalid   = errors.New("session unknown, expired or malformed")
	ErrSessionOtherConn = errors.New("session belongs to another connection")
	ErrTooManySessions  = errors.New("too many open sessions")
)

Errors a nonce or session check returns.

View Source
var (
	ErrUnknownCredential = errors.New("unknown or revoked credential")
	ErrMalformed         = errors.New("malformed assertion")
	ErrRPIDMismatch      = errors.New("authenticator data is for another relying party")
	ErrNotPresent        = errors.New("user presence flag not set")
	ErrNotVerified       = errors.New("user verification flag not set")
	ErrBadSignature      = errors.New("signature does not verify")
	ErrCounterRegression = errors.New("signature counter went backwards")
)

Errors Verify returns. Each is a distinct refusal and each has a test.

Functions

func ClientDataHash

func ClientDataHash(method string, nonce, request, exporter []byte) [32]byte

ClientDataHash is the 32-byte challenge an authenticator signs for one call:

SHA-256( lp(Domain) || lp(method) || lp(nonce) || lp(SHA-256(request)) || lp(exporter) )

where lp prefixes a 4-byte big-endian length. request is hashed exactly as it was received; nothing is re-encoded.

func EnrolClientDataHash

func EnrolClientDataHash(challenge []byte, name string) [32]byte

EnrolClientDataHash is the challenge signed (as an attestation) at enrolment: SHA-256( lp(EnrolDomain) || lp(challenge) || lp(name) ).

func IsRefusal

func IsRefusal(err error) bool

IsRefusal reports whether err is one of this package's refusals: a verdict on what the caller sent, whose reason the caller may be told. Any other error Verify returns is a failure of the server's own storage; it says nothing about the assertion and its text is not for the peer, who at that point has proved nothing.

Types

type Assertion

type Assertion struct {
	CredentialID      []byte
	AuthenticatorData []byte
	Signature         []byte
}

Assertion is what the authenticator returned for one call.

type Credential

type Credential struct {
	ID        []byte
	PublicKey *ecdsa.PublicKey
	SignCount uint32
	AAGUID    string
	Name      string
}

Credential is an enrolled admin credential.

type Credentials

type Credentials interface {
	// ActiveCredential returns the credential, or ErrUnknownCredential when it
	// does not exist or is revoked.
	ActiveCredential(ctx context.Context, id []byte) (Credential, error)
	// AdvanceCounter records the counter of an accepted assertion atomically,
	// and returns ErrCounterRegression unless it is greater than the stored one
	// (both zero is accepted: an authenticator that keeps no counter).
	AdvanceCounter(ctx context.Context, id []byte, count uint32) error
}

Credentials is the storage the verifier needs.

type Input

type Input struct {
	Method   string // full gRPC method name, as the server received the call
	Nonce    []byte
	Request  []byte // the serialized parameters, as received
	Exporter []byte // exporter value of the connection the call arrived on
	Assertion
}

Input is everything one verification depends on.

type Nonces

type Nonces struct {
	// contains filtered or unexported fields
}

Nonces issues and consumes the single-use nonces of signed calls. It stores nothing at issue time, so a peer that has proved nothing, however many connections and nonces it asks for, uses no memory and takes no room from anyone. The only state is the set of nonces of ACCEPTED assertions, kept until they would have expired anyway: it cannot hold more than the number of accepted (physically authorised) calls in one lifetime, and is capped.

The MAC key is random and made when the process starts: nonces do not survive a restart (at most one lifetime of an in-flight call is lost), and no key file exists to protect.

func NewNonces

func NewNonces(now func() time.Time, ttl time.Duration, maxUsed int) *Nonces

NewNonces returns a nonce store. A nonce lives ttl; at most maxUsed accepted nonces are remembered at once.

func (*Nonces) Check

func (n *Nonces) Check(nonce, exporter []byte) error

Check reports whether nonce is acceptable on this connection, without spending it.

func (*Nonces) Issue

func (n *Nonces) Issue(exporter []byte) ([]byte, time.Time)

Issue returns a fresh nonce bound to the connection whose exporter value is given. It never fails and stores nothing.

func (*Nonces) Spend

func (n *Nonces) Spend(nonce, exporter []byte) error

Spend marks the nonce of an accepted assertion as used. It is atomic: of two calls carrying the same nonce, one gets ErrNonceUnknown. Nothing else ever enters the used-set.

type Sessions

type Sessions struct {
	// contains filtered or unexported fields
}

Sessions holds the short read-only sessions opened by one assertion.

func NewSessions

func NewSessions(now func() time.Time, ttl time.Duration, perConn, total int) *Sessions

NewSessions returns a session store.

func (*Sessions) Check

func (s *Sessions) Check(token, exporter []byte) ([]byte, error)

Check accepts a token only on the connection it was opened on, and returns the id of the credential that opened it, which the caller must still find active.

func (*Sessions) Open

func (s *Sessions) Open(exporter, credentialID []byte) ([]byte, time.Time, error)

Open returns a session token bound to the connection and to the credential that opened it.

type Verifier

type Verifier struct {
	RPID        string
	Credentials Credentials
	Nonces      *Nonces
}

Verifier checks assertions.

func (*Verifier) Verify

func (v *Verifier) Verify(ctx context.Context, in Input) (Credential, error)

Verify accepts the assertion only if every check passes, and returns the credential that signed. The nonce is checked first and spent last: only an accepted assertion spends it.

Jump to

Keyboard shortcuts

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