Native YubiKey transport
Procedure
Transport.available?(application: :piv) probes host shared libraries only.
Optional backend: :hid or :pcsc narrows the probe. Requiring the module and
checking availability never initialize HIDAPI, enumerate devices, establish a
PC/SC context, or open hardware. Availability does not prove permission,
service health, card presence, or application support.
Transport.devices(timeout: 5) explicitly enumerates HID interfaces and
PC/SC readers. Reader descriptors do not prove that a card is inserted.
backend:, exact serial:, reader: and device_path: filter inventory.
This inventory call does not connect to cards to obtain their serials.
Transport.open(application: :otp, serial: '0007', timeout: 30) selects one
endpoint or raises on absent/ambiguous selection. Preserve the operator's
exact serial String; never normalize, trim or parse it as an Integer.
Use device_path: or reader: for serial-less Security Key models. A reader
explicitly selects PC/SC, including OTP/management smartcard variants. Generic
NFC readers require explicit selection. Default OTP/FIDO prefers matching HID;
other applications prefer PC/SC. PC/SC ownership is exclusive, with no shared
fallback, process killing, automatic authentication or command replay.
- Call
connection.exchange(opts) and always close in ensure. The descriptor's
:protocol is authoritative:
:otp: command: byte, binary data: up to 64 bytes, optional
response_length:. CRC is checked and removed; status writes require a
programming-sequence acknowledgment. Command 0 with empty data reads six
status bytes without writing a command. Supply expected data lengths whenever
known; variable-length replies require an unambiguous CRC/padding boundary.
:ctap: command: in 1..127, excluding internal INIT/CANCEL/KEEPALIVE/ERROR,
binary data: up to 7609 bytes. open performs nonce-checked CTAPHID INIT and
exposes :version and :capabilities. Responses retain the CTAP status byte.
:apdu: binary data: containing the complete C-APDU. The result is the
complete R-APDU including SW1/SW2; shared Protocol.apdu owns chaining,
GET RESPONSE and application-status validation.
timeout: is a finite positive monotonic budget. Optional cancelled: is a
callable returning truthy to stop; on_keepalive: receives 1 (processing) or
2 (touch/user presence). Callbacks must be bounded and thread-safe. They run
on the connection's owner worker. Never log packet bodies or secret replies.
Lifecycle and limits
- A transport error, interrupted exchange or deadline retires the connection.
CTAPHID CANCEL / OTP reset is sent serially after the current native call.
Application-error status bytes are returned unchanged and do not retire it.
Do not expect subsequent application cleanup on a retired connection to work.
close is idempotent. :closed means native cleanup completed; :closing
means it is deferred. Timed-out C calls retain their owned thread, buffers and
handle until the native call returns. Never kill that Ruby thread or close its
in-flight handle: this would risk a use-after-free and is not native cancellation.
- HID interrupt reads use
hid_read_timeout. HID feature/write calls and PC/SC
SCardTransmit have no portable hard deadline. SCardCancel does not universally
cancel transmit. A permanently stuck driver may retain a thread and native
resources indefinitely; a bounded Ruby waiter is not driver-independent abort.
- Explicit serial selection may perform read-only OTP identity APDUs, with a
management-information fallback using shared Protocol codecs when OTP is
disabled. Unobservable identities fail closed; no serial is invented.
- PC/SC
:transport derives from the Yubico ATR USB/NFC distinction; it is not
cryptographic device/vendor attestation. HID transport is USB. NEO's historic
cached-programming-sequence workaround is not issued automatically; uncertain
acknowledgments fail rather than trigger an implicit write or retry.
Offline verification
Run bundle exec rspec spec/lib/pwn/plugins/yubikey/transport_spec.rb and focused
RuboCop on the paired source/spec. Default tests use fake native C-library/IO
boundaries with independent fixed CTAPHID and OTP CRC/framing fixtures. They
exercise ordering, bounds, exact selectors, platform ABI widths/wide strings,
blocked-call ownership, cancellation, and native cleanup without real hardware.
Linux library-symbol load checks are separate from physical interoperability;
Windows/macOS ABI simulations are not tests executed on those operating systems.
Protocol provenance
This is a native Ruby implementation, not a launcher or a vendored SDK runtime.
Protocol references:
1---2name: pwn-plugins-yubikey-transport3description: Use native HIDAPI and PC/SC YubiKey transports.4license: MIT5allowed-tools: [pwn, pwn_eval]6metadata:7 bundled: true8 preserve: true9 module: PWN::Plugins::YubiKey::Transport10 source: https://skillmd.com/skills/0dayinc/pwn-plugins-yubikey-transport11 upstream: pwn/plugins/yubikey/transport.rb12---1314# Native YubiKey transport1516## Procedure17181. `Transport.available?(application: :piv)` probes **host shared libraries only**.19 Optional `backend: :hid` or `:pcsc` narrows the probe. Requiring the module and20 checking availability never initialize HIDAPI, enumerate devices, establish a21 PC/SC context, or open hardware. Availability does not prove permission,22 service health, card presence, or application support.232. `Transport.devices(timeout: 5)` explicitly enumerates HID interfaces and24 PC/SC readers. Reader descriptors do not prove that a card is inserted.25 `backend:`, exact `serial:`, `reader:` and `device_path:` filter inventory.26 This inventory call does not connect to cards to obtain their serials.273. `Transport.open(application: :otp, serial: '0007', timeout: 30)` selects one28 endpoint or raises on absent/ambiguous selection. Preserve the operator's29 exact serial String; never normalize, trim or parse it as an Integer.30 Use `device_path:` or `reader:` for serial-less Security Key models. A reader31 explicitly selects PC/SC, including OTP/management smartcard variants. Generic32 NFC readers require explicit selection. Default OTP/FIDO prefers matching HID;33 other applications prefer PC/SC. PC/SC ownership is exclusive, with no shared34 fallback, process killing, automatic authentication or command replay.354. Call `connection.exchange(opts)` and always close in `ensure`. The descriptor's36 `:protocol` is authoritative:37 - `:otp`: `command:` byte, binary `data:` up to 64 bytes, optional38 `response_length:`. CRC is checked and removed; status writes require a39 programming-sequence acknowledgment. Command `0` with empty data reads six40 status bytes without writing a command. Supply expected data lengths whenever41 known; variable-length replies require an unambiguous CRC/padding boundary.42 - `:ctap`: `command:` in 1..127, excluding internal INIT/CANCEL/KEEPALIVE/ERROR,43 binary `data:` up to 7609 bytes. `open` performs nonce-checked CTAPHID INIT and44 exposes `:version` and `:capabilities`. Responses retain the CTAP status byte.45 - `:apdu`: binary `data:` containing the complete C-APDU. The result is the46 complete R-APDU **including SW1/SW2**; shared `Protocol.apdu` owns chaining,47 GET RESPONSE and application-status validation.485. `timeout:` is a finite positive monotonic budget. Optional `cancelled:` is a49 callable returning truthy to stop; `on_keepalive:` receives 1 (processing) or50 2 (touch/user presence). Callbacks must be bounded and thread-safe. They run51 on the connection's owner worker. Never log packet bodies or secret replies.5253## Lifecycle and limits5455- A transport error, interrupted exchange or deadline retires the connection.56 CTAPHID CANCEL / OTP reset is sent serially after the current native call.57 Application-error status bytes are returned unchanged and do not retire it.58 Do not expect subsequent application cleanup on a retired connection to work.59- `close` is idempotent. `:closed` means native cleanup completed; `:closing`60 means it is deferred. Timed-out C calls retain their owned thread, buffers and61 handle until the native call returns. Never kill that Ruby thread or close its62 in-flight handle: this would risk a use-after-free and is not native cancellation.63- HID interrupt reads use `hid_read_timeout`. HID feature/write calls and PC/SC64 `SCardTransmit` have no portable hard deadline. `SCardCancel` does not universally65 cancel transmit. A permanently stuck driver may retain a thread and native66 resources indefinitely; a bounded Ruby waiter is not driver-independent abort.67- Explicit serial selection may perform read-only OTP identity APDUs, with a68 management-information fallback using shared Protocol codecs when OTP is69 disabled. Unobservable identities fail closed; no serial is invented.70- PC/SC `:transport` derives from the Yubico ATR USB/NFC distinction; it is not71 cryptographic device/vendor attestation. HID transport is USB. NEO's historic72 cached-programming-sequence workaround is not issued automatically; uncertain73 acknowledgments fail rather than trigger an implicit write or retry.7475## Offline verification7677Run `bundle exec rspec spec/lib/pwn/plugins/yubikey/transport_spec.rb` and focused78RuboCop on the paired source/spec. Default tests use fake native C-library/IO79boundaries with independent fixed CTAPHID and OTP CRC/framing fixtures. They80exercise ordering, bounds, exact selectors, platform ABI widths/wide strings,81blocked-call ownership, cancellation, and native cleanup without real hardware.82Linux library-symbol load checks are separate from physical interoperability;83Windows/macOS ABI simulations are not tests executed on those operating systems.8485## Protocol provenance8687This is a native Ruby implementation, not a launcher or a vendored SDK runtime.88Protocol references:8990- YubiKey Manager 5.9.1 `yubikit/core/otp.py`, `yubikit/yubiotp.py`, and91 `ykman/pcsc/__init__.py` (read-only reference).92- python-fido2 2.2.1 `fido2/hid/__init__.py` (read-only reference), and the93 [FIDO HID protocol](https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#usb-hid).94- [HIDAPI 0.14.0 C header](https://github.com/libusb/hidapi/blob/hidapi-0.14.0/hidapi/hidapi.h).95- [PC/SC ABI definitions](https://github.com/LudovicRousseau/PCSC/blob/master/src/PCSC/wintypes.h):96 Unix `DWORD=unsigned long`, Darwin `DWORD=uint32`, Windows handles pointer-sized;97 exported PCI symbols avoid guessed structure packing.98- [Microsoft SCardCancel](https://learn.microsoft.com/en-us/windows/win32/api/winscard/nf-winscard-scardcancel)99 and [SCardTransmit](https://learn.microsoft.com/en-us/windows/win32/api/winscard/nf-winscard-scardtransmit).