Expand description
Passki - A WebAuthn/Passkey implementation for Rust
Passki implements the server half of the WebAuthn protocol: the browser holds a private key and signs a challenge with it, this crate issues the challenge and verifies the response.
Registration and authentication are both two-step ceremonies. The first step returns a challenge to send to the browser plus a state value the second step needs; keep that state in a session or cache in between.
§Features
- Support for multiple cryptographic algorithms (EdDSA/Ed25519, ES256/P-256, RS256/RSA)
- Replay attack protection via signature counters
- Flexible authenticator selection and user verification options
- Credential exclusion to prevent duplicate registrations
- Type-safe API with comprehensive error handling
§Example
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");
// Send registration_challenge to the client as JSON, keep registration_state.
// Registration step 2: verify the credential the client created
let stored_passkey = passki.finish_passkey_registration(
®istration_credential,
®istration_state,
)?;
// Save stored_passkey in your database, associated with the user.
// 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;§Security Considerations
- Serve over HTTPS; browsers refuse WebAuthn on insecure origins
- Store the counter returned by each authentication to detect cloned authenticators
- Public keys are not secret, but treat credential IDs as sensitive
- Pass existing passkeys as exclusions so a user cannot register the same one twice
- User IDs must be at least 16 bytes (a UUID or random bytes)
Structs§
- Allow
Credential - A credential the browser may use for this authentication.
- Authentication
Challenge - Challenge sent to the client to begin passkey authentication.
- Authentication
Credential - What the client sends back after
navigator.credentials.get(). - Authentication
Extensions - Extensions included in an authentication challenge.
- Authentication
Options - Options for starting a passkey authentication ceremony.
- Authentication
Result - Result of a successful authentication.
- Authentication
State - Server-side half of an authentication in progress.
- Authenticator
Selection - Constraints on which authenticators the browser may use for registration.
- Client
Data - The client data JSON the browser sent, parsed.
- Client
Extension Results - What
credential.getClientExtensionResults()returned in the browser, one field per extension. - Cred
Props Result - Credential properties returned by the browser after registration.
- Exclude
Credential - An existing credential the authenticator must refuse to register again.
- Large
Blob Registration Input largeBlobextension input included in registration challenges.- Large
Blob Result largeBlobextension result returned by the client.- Passki
- Entry point of the crate: holds the relying party configuration and starts and finishes both ceremonies.
- PrfEval
- The inputs the authenticator derives its PRF outputs from.
- PrfExtension
Result prfextension result returned by the client.- PrfInput
prfextension input included in challenges.- PrfResults
- The secrets the authenticator derived from the PRF inputs.
- PubKey
Cred Param - One signature algorithm the relying party will accept.
- Registration
Challenge - Challenge sent to the client to begin passkey registration.
- Registration
Credential - What the client sends back after
navigator.credentials.create(). - Registration
Extensions - Extensions included in a registration challenge.
- Registration
Options - Options for starting a passkey registration ceremony.
- Registration
State - Server-side half of a registration in progress.
- Relying
Party - The site requesting authentication, as sent to the browser.
- Stored
Passkey - A registered passkey, as it should be saved in the database.
- User
Info - Information about the user account.
Enums§
- Attestation
Conveyance Preference - How much the relying party wants to learn about the authenticator hardware at registration.
- Attestation
Trust Policy - How strictly attestation certificate chains are checked, set together with
the trust anchors by
crate::Passki::with_attestation_trust. - Attestation
Type - What an attestation statement turned out to be worth.
- Authenticator
Attachment - Whether the authenticator is built into the device or a separate one.
- Authenticator
Transport - How an authenticator can be reached.
- Client
Data Type - The type of WebAuthn operation.
- Large
Blob Authentication Input largeBlobextension input included in authentication challenges.- Large
Blob Support - How badly a relying party wants the new credential to support blob storage.
- Passki
Error - Error type for Passki operations.
- Resident
KeyRequirement - Whether the authenticator should store the credential itself.
- User
Verification Requirement - Whether the user must prove who they are, with a PIN or biometric, rather than merely touching the authenticator.
Type Aliases§
- Result
- Convenience type alias for Results returned by Passki operations.