webauthntest

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Request

func Request(body string) *http.Request

Request wraps a credential JSON body as the handlers receive it.

Types

type Device

type Device struct {
	SignCount uint32
	// userVerified controls the UV flag — a fingerprint or PIN, as opposed to mere
	// possession.
	UserVerified bool
	// UserHandle is what a DISCOVERABLE credential reports back: the account the
	// authenticator stored beside the key. Empty for a second-factor assertion,
	// where the server already knows whose login it is.
	UserHandle []byte
	// contains filtered or unexported fields
}

Package webauthntest provides a virtual authenticator: enough of a security key to exercise the real thing.

It lives in its own package rather than in a _test.go file because both the auth service tests and the HTTP pentests need it, and a harness duplicated in two places is a harness that drifts.

A virtual authenticator: enough of a security key to exercise the real thing.

WebAuthn cannot be tested by mocking the library — the library IS the check. So this builds what a real authenticator sends: a COSE ES256 public key, an authenticator data blob with the RP id hash and flags, a client data JSON bound to the challenge and origin, and an ECDSA signature over the two. Everything the server rejects, it rejects because one of those does not add up, which is what makes these tests worth having: they fail for the same reasons a real attack would.

It is deliberately dumb about state: the sign counter is a field the test moves by hand, because moving it backwards is exactly how a cloned key behaves.

func New

func New(t *testing.T) *Device

func (*Device) Assert

func (a *Device) Assert(t *testing.T, rpID, origin, challenge string) string

assert produces the JSON a browser posts after navigator.credentials.get.

The counter moves first, because a real authenticator increments it on every assertion — that movement is the whole clone-detection signal, and a harness that left it still would make an ordinary login look like a cloned key.

func (*Device) Register

func (a *Device) Register(t *testing.T, rpID, origin, challenge string) string

register produces the JSON a browser posts after navigator.credentials.create.

Jump to

Keyboard shortcuts

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