3.2 KiB
3.2 KiB
packed attestation verifier
(no submodules)
Purpose
Implements the W3C WebAuthn L3 §8.2 packed attestation format, the most common format on modern authenticators (Yubikey 5, Feitian, every FIDO2-certified platform authenticator that emits non-self-signed attestations). The verifier supports both attestation paths: self-attestation (no x5c, signature made by the credential's own key) and full attestation (with x5c chain, signature made by a manufacturer-issued attestation key).
Features
- Self-attestation detection by
attStmt.x5cabsence; signature verified directly against the embedded credential public key. alg-match check: when the credential public key carries analg, it MUST equalattStmt.algper W3C §8.2 step 3.1.- Full-attestation path: caller-supplied trust binding via
trustPath(the leaf-first DER chain). Chain validation against a trust anchor is intentionally left to the caller; the verifier confirms structural validity and surfaces the chain. - Constant-time
rpIdHashcompare on both paths. - Signature verification delegates to
verifyOverCoseKeyfromverify-assertion, so the same algorithm dispatch (ES256 / ES384 / ES512 / EdDSA / RS256) applies.
Usage: Basic Example
import { verifyPackedAttestation } from "@suaveplan/webauthn/attestation/packed";
const result = await verifyPackedAttestation({
attestationObject,
clientDataHash,
expectedRpIdHash,
});
if (result.attestationType === "self") {
// RP policy: accept self-attestation for low-assurance flows.
} else {
await validateChainAgainstMds(result.trustPath);
}
Usage: Advanced Example
import {
defaultAttestationRegistry,
verifyPackedAttestation,
} from "@suaveplan/webauthn";
const registry = defaultAttestationRegistry();
// Override with a custom packed verifier that also enforces a max chain depth:
registry.set("packed", async (input) => {
const r = await verifyPackedAttestation(input);
if (r.trustPath.length > 3) {
throw new Error("chain too deep");
}
return r;
});
API Reference
verifyPackedAttestation: AttestationFormatVerifier— the format verifier.
Implementation Notes
- The verifier does not perform
x509.validateChainagainst a trust anchor — that requires an out-of-band trust source (FIDO Metadata Service, per-RP attestation-CA allow-list) that the package cannot ship. The caller wires that policy via the returnedtrustPath. - Full-attestation
attestationTypeis reported as"basic"rather than"attCA"because the W3C spec treatspackedwithx5cas basic attestation;attCAis reserved fortpmandandroid-keywhere the chain goes back to a manufacturer-rooted certification authority. - The signed payload is
authData || clientDataHash— concatenated raw — per §8.2 step 2. The signature verifier hashes the message internally per the algorithm (ECDSA hashes inside; Ed25519 signs over the full message; RSA hashes inside). algis read as the COSE numeric label (-7 for ES256, etc.). The credential key'salgfield is read as the named string the COSE_Key decoder produces — we cross-reference via theNAMED_ALG_TO_LABELmap.