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 ¶
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 )
const ( MaxCredentialIDLen = 1024 MaxAuthDataLen = 512 MaxSignatureLen = 160 )
Size bounds on what an assertion may carry; larger input is refused before any cryptography.
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 ¶
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.
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 ¶
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 ¶
EnrolClientDataHash is the challenge signed (as an attestation) at enrolment: SHA-256( lp(EnrolDomain) || lp(challenge) || lp(name) ).
func IsRefusal ¶
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 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 ¶
NewNonces returns a nonce store. A nonce lives ttl; at most maxUsed accepted nonces are remembered at once.
func (*Nonces) Check ¶
Check reports whether nonce is acceptable on this connection, without spending it.
type Sessions ¶
type Sessions struct {
// contains filtered or unexported fields
}
Sessions holds the short read-only sessions opened by one assertion.
func NewSessions ¶
NewSessions returns a session store.
type Verifier ¶
type Verifier struct {
RPID string
Credentials Credentials
Nonces *Nonces
}
Verifier checks assertions.