Skip to main content

Crate webauthn_kit

Crate webauthn_kit 

Source
Expand description

§webauthn-kit

Standalone WebAuthn / FIDO2 passkey verification kit: real CTAP2/COSE cryptographic verification with zero framework coupling. This is not a wrapper around navigator.credentials server emulation — it implements the server side of the protocol directly on ring.

§What it does

  • Full CTAP2 authenticator data parsing (rpIdHash, flags, signCount, attested credential data) — protocol
  • verify_registration / verify_authentication ceremonies — protocol
  • COSE public key parsing and signature verification for ES256 (ECDSA P-256 + SHA-256) and RS256 (RSA PKCS#1 v1.5 + SHA-256) via ring — crypto
  • Challenge generation from the OS CSPRNG, single-use consumption (replay protection), freshness/expiry enforcement, and the sign-count clone-detection state machine — challenge
  • Storage-free credential record + browser wire DTOs — credential

§Quick start

use webauthn_kit::{
    check_sign_count, verify_authentication, verify_registration, AuthenticationParams,
    ChallengeStore, WebauthnConfig,
};

let config = WebauthnConfig {
    rp_id: "example.com".into(),
    rp_name: "Example".into(),
    rp_origins: vec!["https://example.com".into()],
    allowed_algorithms: vec![-7, -257],
    challenge_timeout_secs: 300,
};

// 1. Issue a challenge (single-use; store the (id, bytes) pair).
let store = ChallengeStore::new();
let (challenge_b64, create_options) =
    store.generate_registration_challenge(&config, "alice", "Alice", &[]);
// ... send `create_options` to the browser, receive RegistrationResponse ...

// 2. Verify a registration response (see tests/vectors.rs for a full
//    roundtrip with a synthetic keypair).
// let result = verify_registration(&challenge, &client_data_json_b64, &attestation_object_b64, "", &config.rp_id, &config.rp_origins)?;

// 3. Verify an assertion; persist result.new_sign_count afterwards.
// let result = verify_authentication(&AuthenticationParams { ... })?;

§Storage contract (what this crate does NOT do)

This crate is deliberately storage-free. The integrator owns:

§Security notes

  • #![forbid(unsafe_code)]; all cryptography via ring.
  • Every parser accepts hostile input and returns Err instead of panicking (property/fuzz-tested in tests/fuzz.rs).
  • Challenge bytes are 32 bytes from the OS CSPRNG; consumption is single-use and freshness-bounded.
  • Attestation is parsed, not verified: the attestation object is decoded to extract authenticator data, but attestation statement signatures are not checked. Supported attestation formats: any fmt value is tolerated (“none”, “packed”, “fido-u2f”, …) and recorded informationally — registration proves key possession, not device provenance. If you need verified device provenance, add an attestation verifier on top.
  • Supported algorithms: ES256 (COSE -7) and RS256 (COSE -257) only. Other algorithms (including OKP/Ed25519) are rejected with WebauthnError::UnsupportedAlgorithm.
  • Sign-count policy: a stored counter of 0 disables the check (authenticators without counters); otherwise a strictly decreasing counter is rejected. Equal counters are allowed by design.
  • The UV (user verification) flag is reported, never required; enforce your own policy per ceremony.

Re-exports§

pub use challenge::check_sign_count;
pub use challenge::ChallengeStore;
pub use config::WebauthnConfig;
pub use credential::AllowCredential;
pub use credential::AuthenticationOptions;
pub use credential::AuthenticationResponse;
pub use credential::AuthenticationResult;
pub use credential::AuthenticatorSelection;
pub use credential::ExcludeCredential;
pub use credential::PubKeyCredParam;
pub use credential::RegistrationOptions;
pub use credential::RegistrationResponse;
pub use credential::RegistrationResult;
pub use credential::RelyingParty;
pub use credential::WebauthnCredential;
pub use credential::WebauthnUser;
pub use crypto::alg_to_name;
pub use crypto::base64_decode_urlsafe;
pub use crypto::base64_encode_urlsafe;
pub use crypto::cbor_bytes;
pub use crypto::cbor_map_entries;
pub use crypto::generate_challenge_bytes;
pub use crypto::parse_cose_key;
pub use crypto::verify_cose_signature;
pub use crypto::CosePublicKey;
pub use crypto::COSE_ALG_ES256;
pub use crypto::COSE_ALG_RS256;
pub use crypto::COSE_KTY_EC2;
pub use crypto::COSE_KTY_OKP;
pub use crypto::COSE_KTY_RSA;
pub use error::WebauthnError;
pub use protocol::verify_authentication;
pub use protocol::verify_registration;
pub use protocol::AuthenticationParams;

Modules§

challenge
Challenge generation, single-use consumption (replay protection), freshness/expiry enforcement, and the sign-count clone-detection state machine.
config
Relying-party configuration.
credential
WebAuthn credential descriptor and protocol DTOs (options, responses, results).
crypto
COSE key parsing and signature verification (ES256 / RS256) via ring, plus base64url helpers and CSPRNG challenge generation.
error
Error type for all webauthn-kit operations.
protocol
CTAP2 protocol parsing and ceremony verification.