All projects

Passki

WebAuthn / Passkey library for Rusthttps://crates.io/crates/passki

Passki is a simple and secure WebAuthn/Passkey implementation for Rust. It lets you add passwordless, phishing-resistant login to your application without reimplementing the FIDO2 protocol yourself.

It follows the two-step, challenge-response model that WebAuthn is built on. For both registration and authentication, the server first issues a challenge, the browser asks the authenticator (a phone, a security key, or the device itself) to sign it, and Passki then verifies the result. Passki is not tied to any web framework - it only takes and returns plain data, so it works with any HTTP server.

Features

  • Simple API - four calls cover the whole passkey lifecycle: start and finish registration, start and finish authentication.
  • Multiple algorithms - EdDSA (Ed25519), ES256/ES384 (P-256/P-384), and RS256/RS384 (RSA).
  • Browser JSON as-is - both ceremonies accept credential.toJSON() exactly as the browser produces it, so the front end does not need to remap anything.
  • Replay protection - signature counters detect cloned authenticators.
  • Extensions - credProps (discoverable credential reporting), PRF (key derivation and end-to-end encryption), largeBlob (blob storage on the authenticator), credProtect (user verification policy on security keys), and minPinLength (PIN policy on managed keys).
  • Hints - steer the browser’s UI toward a security key, this device, or a phone, without ruling any of them out.
  • Related origins - one passkey across several domains, with a helper for the .well-known/webauthn file.
  • Cross-origin iframes - refused by default, with an opt-in allowlist of embedding origins checked against topOrigin.
  • Signal API - tell the browser when a passkey or a username changed, so stale ones stop being offered.
  • Attestation - statement verification for packed, tpm, android-key, and fido-u2f, with optional trust path validation against your own root certificates.
  • Three crypto backends - pure Rust RustCrypto by default, or aws-lc-rs and graviola as faster alternatives. Passki itself contains no unsafe code.

Installation

Add Passki to your Cargo.toml:

[dependencies]
passki = "0.5"

Signatures are verified with the pure Rust RustCrypto crates by default, which need no C toolchain. aws-lc-rs is 3-5x faster at ECDSA and RSA and has a FIPS-validated build:

[dependencies]
passki = { version = "0.5", default-features = false, features = ["aws-lc-rs"] }

graviola is nearly as fast as aws-lc-rs and, like RustCrypto, needs no C toolchain, but it builds only for x86_64 and aarch64:

[dependencies]
passki = { version = "0.5", default-features = false, features = ["graviola"] }
Feature Default Backend
rust-crypto yes p256, p384, ed25519-dalek and rsa
aws-lc-rs no aws-lc-rs
graviola no graviola

If several are enabled, aws-lc-rs wins over graviola, and both win over RustCrypto. The other backends are still compiled in that case, so turn off the default features to drop them.

Quick start

The example below walks through both ceremonies. Between the two steps of each ceremony you send the challenge to the browser as JSON and keep the returned state on the server.

use passki::{AuthenticationOptions, Passki, RegistrationOptions, StoredPasskey};

let passki = Passki::new(
    "example.com",              // relying party ID (the domain)
    &["https://example.com"],   // accepted origins
    "Example Corp"              // name shown in the browser prompt
);

// Registration step 1: issue a challenge
let user_id = b"unique_user_identifier_12345"; // at least 16 bytes
let (registration_challenge, registration_state) = passki.start_passkey_registration(
    user_id,
    "alice@example.com",            // username
    "Alice Smith",                  // display name
    RegistrationOptions::default(),
).expect("user_id must be at least 16 bytes");

// Registration step 2: verify the credential the client created
let mut stored_passkey = passki.finish_passkey_registration(
    &registration_credential,
    &registration_state,
)?;

// Authentication step 1: issue a challenge
let (authentication_challenge, authentication_state) = passki.start_passkey_authentication(
    &user_passkeys,
    AuthenticationOptions::default(),
)?;

// Authentication step 2: verify the signature
let result = passki.finish_passkey_authentication(
    &authentication_credential,
    &authentication_state,
    &stored_passkey,
)?;

// Persist the new counter, or replay detection has nothing to compare against.
stored_passkey.counter = result.counter;

Using it with a web framework

In a real server each step is its own HTTP endpoint. This is how the registration start looks in Axum. It asks for the credProps and PRF extensions:

async fn register_start(
    State(state): State<AppState>,
    Json(req): Json<RegisterStartRequest>,
) -> AppResult<RegistrationChallenge> {
    let user_id = Uuid::new_v4().as_bytes().to_vec();

    let mut extensions = RegistrationExtensions::default();
    extensions.cred_props = Some(true);
    extensions.prf = Some(PrfRegistrationInput::default());

    let mut options = RegistrationOptions::default();
    options.extensions = Some(extensions);

    let (challenge, reg_state) = state.passki.start_passkey_registration(
        &user_id,
        &req.username,
        &req.username,
        options,
    )?;

    // Keyed by the challenge, which is what the finish call brings back.
    state.store.pending_registrations.lock().unwrap()
        .insert(challenge.challenge.clone(), reg_state);

    Ok(Json(challenge))
}

The repository has complete registration and authentication flows for Actix-web, Axum, Poem, Rocket, Salvo, and Warp. Each one also demonstrates credProps, PRF key derivation, and the Signal API. Run one and open http://localhost:3000 in your browser:

cargo run --example axum  # or actix-web, poem, rocket, salvo, warp

Security considerations

  • Always use HTTPS in production - browsers refuse WebAuthn on insecure origins.
  • Store the counter returned by each authentication, or cloned authenticators go undetected.
  • Require user verification for sensitive operations.
  • Keep ceremony timeouts short; the state stored between the two steps expires with them.
  • Allow only the iframe embedders you trust.

Specification coverage

Passki implements WebAuthn Level 1 and Level 2 in full, and nearly all of Level 3: the PRF extension, backup eligibility and state flags, related origin requests, the JSON request shapes, the Signal API, hints, and cross-origin ceremonies in iframes. It also supports the credProtect and minPinLength extensions from CTAP 2.1.

Passki requires Rust 1.85 or later and is licensed under the Apache License 2.0.