Expand description
Rust SDK for interacting with YubiKey devices.
yubikit provides a complete API for communicating with YubiKeys over USB (CCID/SmartCard, FIDO HID, OTP HID) and NFC. It covers the full range of YubiKey applications: OATH, PIV, OpenPGP, FIDO2/CTAP2, WebAuthn, YubiOTP, HSM Auth, and device management.
§Getting started
Most workflows follow the same pattern: discover devices, open a connection over the desired transport, then create a session for the application you want to use.
use yubikit::platform::device::list_devices;
use yubikit::management::UsbInterface;
use yubikit::oath::OathSession;
// 1. Discover connected YubiKeys
let all = UsbInterface::CCID | UsbInterface::OTP | UsbInterface::FIDO;
let devices = list_devices(all).expect("enumeration failed");
let dev = devices.first().expect("no YubiKey found");
// 2. Open a SmartCard (CCID) connection
let conn = dev.open_smartcard().expect("connection failed");
// 3. Create an OATH session and list accounts
let mut session = OathSession::new(conn).expect("OATH init failed");
let creds = session.list_credentials().expect("list failed");
for cred in &creds {
println!("{cred:?}");
}§Transports and connections
YubiKeys expose different USB interfaces, each requiring its own connection type:
| Interface | Connection | Used by |
|---|---|---|
| CCID (SmartCard) | smartcard::SmartCardConnection | OATH, PIV, OpenPGP, Management, FIDO2, HSM Auth, Security Domain |
| FIDO HID | fido::FidoConnection | FIDO2/CTAP2, WebAuthn, Management |
| OTP HID | otp::OtpConnection | YubiOTP, Management |
All connection types implement core::Connection. Session types are
generic over their connection type, so the same ctap2::Ctap2Session
works over both SmartCard and FIDO HID.
§Module overview
§Device discovery and management
device— Enumerate connected YubiKeys, open connectionsmanagement— Read/write device configuration, capabilities, and mode
§YubiKey applications
oath— OATH TOTP/HOTP credential management and code calculationpiv— PIV (FIPS 201) smart card operations (keys, certificates, PIN)piv_util— CHUID generation and pivman management-key metadata helpersopenpgp— OpenPGP card operations (keys, certificates, PIN)hsmauth— YubiHSM Auth credential managementyubiotp— YubiOTP slot configuration (challenge-response, static passwords, HOTP)securitydomain— GlobalPlatform Security Domain (SCP03 key management)
§FIDO2 and WebAuthn
ctap— Low-level CTAP transport session (CTAP1/CTAP2 dispatch)ctap2— CTAP2 commands: credentials, assertions, PIN/UV, bio enrollment, large blobswebauthn— High-level WebAuthn client with extension support (PRF, credProtect, largeBlob, etc.)
§Transport and protocol infrastructure
platform— USB HID (FIDO and OTP) and PC/SC transport implementations (requirespcscorhid)smartcard— ISO 7816 SmartCard / CCID connection, APDU handling, and SCP03 secure channelotp— OTP HID framing protocolcore— Shared types:core::Version,core::Connectiontraitcbor— CBOR encoding/decoding helpers for CTAP2
Modules§
- cbor
- CBOR encoding and decoding utilities. Minimal CBOR implementation supporting the subset of types required for FIDO2 CTAP.
- core
- Core types shared across all YubiKey applications. Fundamental types shared across the crate.
- ctap
- CTAP session management and device communication. CTAP session for FIDO2 authenticator communication.
- ctap2
- CTAP2 protocol implementation for FIDO2 authenticator operations. CTAP2 protocol session and PIN/UV management.
- device
- High-level device enumeration and connection management. High-level device enumeration for YubiKeys.
- fido
- FIDO connection trait and transport abstraction. FIDO connection trait and error types.
- hsmauth
- YubiHSM Auth application for symmetric key storage and derivation. YubiHSM Auth application for symmetric key storage and derivation.
- keys
- Cryptographic key types, parsing utilities, and OID encoding. Cryptographic key types and parsing utilities.
- logging
- Logging utilities for diagnostic output. Logging utilities for yubikit.
- management
- Device management — reading info, configuring interfaces, and settings. YubiKey device management.
- oath
- OATH (TOTP/HOTP) credential management. OATH (TOTP/HOTP) credential management for YubiKeys.
- openpgp
- OpenPGP smart card application. OpenPGP smart card application for YubiKeys.
- otp
- OTP (One-Time Password) frame protocol and modhex codec. Low-level OTP HID frame protocol, codec, and related helpers.
- piv
- PIV (Personal Identity Verification) smart card application. PIV (Personal Identity Verification) smart card application.
- piv_
util - PIV utilities for CHUID generation and pivman management-key metadata. PIV helpers for generating CHUIDs and maintaining pivman management-key metadata.
- platform
- Platform-specific transport implementations (HID, PC/SC).
- securitydomain
- Security Domain operations for managing SCP keys and certificates. YubiKey Security Domain operations.
- smartcard
- Smart card communication primitives — APDUs, status words, ISO 7816-4, and SCP. Smart card communication primitives — APDU encoding, status words, and ISO 7816-4 command/response handling.
- webauthn
- WebAuthn client — high-level API for credentials and assertions. WebAuthn client implementation.
- yubiotp
- YubiOTP application — configuring OTP slots and challenge-response. YubiOTP application protocol.
Macros§
- log_
traffic - Log a TRAFFIC-level message (raw data sent/received).