Documentation
¶
Overview ¶
Package fido reaches a FIDO security key on Linux, over hidraw, in pure Go with CGO_ENABLED=0.
It is a transport and nothing else. The protocol — CTAPHID, CTAP2, ClientPIN, credentials — lives in github.com/go-authn/fido, which knows nothing about any operating system. What is here is the part that cannot be portable: finding the device and moving 64-byte reports.
k, err := fido.Open(ctx) // finds the key, speaks the handshake defer k.Close() fmt.Println(k) // YubiKey FIDO (CTAPHID v2, firmware 5.7.4, ...)
No libudev ¶
The reference implementation enumerates with libudev, which is a C library and would cost cgo. It does not have to: libudev is used only to LIST the hidraw nodes, and /sys/class/hidraw already lists them. Everything else libfido2 reads, it reads out of the sysfs "uevent" file by hand — so this package does the same, and stays pure Go.
The permission is the obstacle, not the API ¶
/dev/hidraw* belongs to root on a stock system. libfido2 ships a udev rule (70-u2f.rules) that hands the console user access to known keys. Without it a plugged-in key is found and then refuses to open, so ErrPermission says exactly that rather than letting it look like an absent key.
Index ¶
Constants ¶
const ReportSize = 64
ReportSize is the CTAPHID report size, which every FIDO device uses.
const UsagePageFIDO = 0xF1D0
UsagePageFIDO is the HID usage page that marks a device as speaking CTAP. It is the same number on every operating system; it is how a security key is told apart from a keyboard on the same bus.
Variables ¶
var ( // ErrNoKey is returned when nothing on this machine speaks CTAP. ErrNoKey = errors.New("fido: no security key is attached") // ErrPermission is returned when a key was FOUND and could not be opened. // // It is deliberately distinct from ErrNoKey. On a stock system // /dev/hidraw* is root-only, and a caller that reported "no key" here // would send a person to check a cable when the answer is a udev rule. ErrPermission = errors.New("fido: a security key is attached but this user cannot open it; " + "install a udev rule for /dev/hidraw* (see libfido2's udev/70-u2f.rules)") )
Functions ¶
func OpenDevice ¶
OpenDevice opens one particular key, for a machine with more than one.
Types ¶
type Device ¶
type Device struct {
// Path is the node to open, e.g. "/dev/hidraw3".
Path string
// Node is the sysfs name, e.g. "hidraw3".
Node string
// Bus is the HID bus number from HID_ID (3 is USB, 5 is Bluetooth).
Bus uint16
// VendorID and ProductID identify the model.
VendorID, ProductID uint16
// Name is what the device calls itself, for a person to read.
Name string
// Phys is the physical port the key sits in (HID_PHYS, e.g.
// "usb-0000:00:14.0-3/input0"). Unlike Path, which is numbered in the order
// the kernel met the devices, it does not change when another key is
// plugged in first, so it is what to give back as a stable identifier.
Phys string
// Serial is the device's unique string (HID_UNIQ), empty when it has none.
Serial string
}
Device is one hidraw node that speaks CTAP.