A pure Rust
implementation of FIDO2/WebAuthn CTAP 2.0/2.1 protocol for virtual authenticators.
soft-fido2 provides virtual FIDO2 authenticator capabilities for testing and development, enabling developers to implement WebAuthn authentication flows without physical security keys.
Features
- ๐ Full CTAP 2.0/2.1 Protocol - Complete implementation of FIDO2 Client-to-Authenticator Protocol
- ๐ซ no_std Support - Core protocol and cryptography work in embedded environments
- ๐ Multiple Transports - USB HID and Linux UHID virtual device support
- ๐งช Testing-First - Designed for WebAuthn integration testing and development
- ๐ฏ Callback-Based - Flexible user interaction model with customizable callbacks
- ๐ฆ Modular Architecture - Separate crates for crypto, protocol, and transport layers
- ๐ Well-Audited Crypto - Uses industry-standard cryptographic libraries (p256, sha2, aes)
Basic Example
use ;
// Create an in-memory authenticator with default callbacks
let callbacks = new
.up // User presence
.uv // User verification
.build;
let mut auth = new?;
// Enumerate available transports (USB HID or UHID)
let mut transport_list = enumerate?;
let mut transport = transport_list.get?;
transport.open?;
// Get authenticator info
let info = authenticator_get_info?;
println!;
Architecture
soft-fido2 is organized into four main crates:
soft-fido2/
โโโ soft-fido2 # High-level API and examples
โโโ soft-fido2-crypto # Cryptographic primitives (ECDSA, ECDH, PIN protocols)
โโโ soft-fido2-ctap # CTAP 2.0/2.1 protocol implementation
โโโ soft-fido2-transport # Transport layers (USB HID, UHID)
Crate Overview
| Crate | Description | no_std |
|---|---|---|
soft-fido2 |
High-level API combining all components | โ ๏ธ Core only |
soft-fido2-crypto |
P-256 ECDSA/ECDH, PIN protocols V1/V2 | โ Yes |
soft-fido2-ctap |
CTAP command handlers and authenticator logic | โ Yes |
soft-fido2-transport |
USB HID and UHID transport implementations | โ Requires std |
Usage
Creating a Virtual Authenticator
use ;
use ;
use HashMap;
// Setup credential storage
let credentials = new;
// Build callbacks for user interaction
let creds_write = credentials.clone;
let creds_read = credentials.clone;
let callbacks = new
.up
.uv
.write
.read_credentials
.build;
// Create authenticator with custom configuration
let config = builder
.aaguid
.max_credentials
.extensions
.build;
let auth = with_config?;
WebAuthn Registration Flow
use ;
use ;
// 1. Create client data hash (normally from browser)
let client_data_json = r#"{"type":"webauthn.create","challenge":"...","origin":"https://example.com"}"#;
let mut hasher = new;
hasher.update;
let client_data_hash = from;
// 2. Setup relying party and user
let rp = RelyingParty ;
let user = User ;
// 3. Create credential
let request = builder
.client_data_hash
.rp
.user
.resident_key
.user_verification
.build;
let response = make_credential?;
println!;
WebAuthn Authentication Flow
use ;
// 1. Get assertion (authentication)
let request = builder
.rp_id
.client_data_hash
.allow_list
.user_verification
.build;
let response = get_assertion?;
println!;
PIN Protocol
use ;
// Establish PIN protocol
let mut pin_encapsulation = new?;
// Get PIN token for operations
let pin_token = pin_encapsulation.get_pin_uv_auth_token_using_pin_with_permissions?;
// Use PIN token for authenticated operations
let pin_auth = from_pin_token;
no_std Support
The core protocol and cryptographic components support no_std environments:
[]
= { = "0.2", = false }
Available in no_std:
- โ CTAP protocol logic
- โ Cryptographic operations (ECDSA, ECDH)
- โ PIN protocols V1 and V2
- โ Authenticator state management
- โ CBOR encoding/decoding
Requires std:
- โ Transport layers (USB HID, UHID)
- โ Client API
- โ Time-based PIN token expiration (uses timestamp = 0 in no_std)
Examples
The soft-fido2/examples directory contains several complete examples:
- authenticator.rs - Virtual authenticator with UHID
- client.rs - CTAP client communicating with authenticators
- webauthn_flow.rs - Complete WebAuthn registration and authentication
- pin_protocol.rs - PIN protocol demonstration
- credential_management.rs - Managing stored credentials
Run examples:
# List available FIDO2 devices
# Run virtual authenticator (requires UHID permissions)
# Complete WebAuthn flow
Building
Standard Build
Build without USB Support
Useful on systems without libudev:
Build for no_std
Testing
# Run all tests
# Run integration tests only
# Run with all features
Supported CTAP Commands
soft-fido2 implements the following CTAP 2.0/2.1 commands:
| Command | Support | Description |
|---|---|---|
authenticatorMakeCredential |
โ | Create new credential (registration) |
authenticatorGetAssertion |
โ | Get authentication assertion (login) |
authenticatorGetInfo |
โ | Get authenticator metadata |
authenticatorClientPIN |
โ | PIN protocol operations (V1, V2) |
authenticatorReset |
โ | Factory reset |
authenticatorGetNextAssertion |
โ | Get next assertion in batch |
authenticatorCredentialManagement |
โ | Manage stored credentials |
authenticatorSelection |
โ | User verification and selection |
Security
โ ๏ธ Important: This library is designed for testing and development purposes. While it implements the FIDO2 specification correctly and uses well-audited cryptographic libraries, it is not intended for production use as a real security key.
Cryptographic Dependencies
All cryptographic operations use well-maintained, audited libraries:
- p256 (v0.13) - NIST P-256 elliptic curve operations
- sha2 (v0.10) - SHA-256 hashing
- aes (v0.8) - AES-256 encryption
- hmac (v0.12) - HMAC authentication
- rand (v0.8) - Cryptographically secure RNG
Credential Storage
Credentials are stored in memory by default. For persistent storage, implement custom callback functions that write to secure storage (encrypted filesystem, TPM, etc.).
Platform Support
| Platform | USB HID | UHID Virtual Device |
|---|---|---|
| Linux | โ Yes | โ Yes |
| macOS | โ Yes | โ No |
| Windows | โ Yes | โ No |
| Embedded | โ No | โ No |
UHID Requirements (Linux only):
- UHID kernel module loaded:
sudo modprobe uhid - User permissions: Add user to
fidogroup or configure udev rules
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
# Clone repository
# Install pre-commit hooks
# Run tests
# Run formatting and linting
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
References
Acknowledgments
Built with โค๏ธ using Rust
Note: This is a community project and is not affiliated with the FIDO Alliance.