Skip to content

Commit

Permalink
Add rules for accessing HID devices with libusb
Browse files Browse the repository at this point in the history
HID devices can be accessed with libusb or with hidraw.  So far, we have
mostly been using hidraw and our udev rules only apply to hidraw
devices.  This patch adds rules for access with libusb as recommended by
the hidapi developers:

https://github.com/libusb/hidapi/blob/ff67c77daddbd8e61ad3873ac16f8edc005f943f/udev/69-hid.rules
  • Loading branch information
robin-nitrokey committed Dec 16, 2024
1 parent 922e0f9 commit 5ffac5d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
6 changes: 6 additions & 0 deletions 41-nitrokey.rules
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ ACTION!="add|change", GOTO="u2f_end"

# Nitrokey U2F
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="2581", ATTRS{idProduct}=="f1d0", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2581", ATTRS{idProduct}=="f1d0", TAG+="uaccess"
# Nitrokey FIDO U2F
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="4287", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="4287", TAG+="uaccess"
# Nitrokey FIDO2
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42b1", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42b1", TAG+="uaccess"
# Nitrokey 3A Mini/3A NFC/3C NFC
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42b2", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42b2", TAG+="uaccess"
# Nitrokey 3A NFC Bootloader/3C NFC Bootloader
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42dd", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42dd", TAG+="uaccess"
# Nitrokey 3A Mini Bootloader
ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42e8", TAG+="uaccess"
# Nitrokey Passkey
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42f3", TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42f3", TAG+="uaccess"
# Nitrokey Passkey Bootloader
ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="42f4", TAG+="uaccess"

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Add rules for accessing HID devices with libusb.

## [v1.0.0][] (2024-01-29)

[v1.0.0]: https://github.com/Nitrokey/nitrokey-udev-rules/releases/tag/v1.0.0
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ check:
.PHONY: fix
fix:
$(RUFF) check --fix
$(PYRIGHT) format
$(RUFF) format

.PHONY: generate
generate:
Expand Down
12 changes: 6 additions & 6 deletions devices.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
name = "Nitrokey U2F"
vid = 0x2581
pid = 0xf1d0
hidraw = true
hid = true

[[u2f]]
name = "Nitrokey FIDO U2F"
vid = 0x20a0
pid = 0x4287
hidraw = true
hid = true

[[u2f]]
name = "Nitrokey FIDO2"
vid = 0x20a0
pid = 0x42b1
hidraw = true
hid = true

[[u2f]]
name = "Nitrokey 3A Mini/3A NFC/3C NFC"
vid = 0x20a0
pid = 0x42b2
hidraw = true
hid = true

[[u2f]]
name = "Nitrokey 3A NFC Bootloader/3C NFC Bootloader"
vid = 0x20a0
pid = 0x42dd
hidraw = true
hid = true

[[u2f]]
name = "Nitrokey 3A Mini Bootloader"
Expand All @@ -38,7 +38,7 @@ all = true
name = "Nitrokey Passkey"
vid = 0x20a0
pid = 0x42f3
hidraw = true
hid = true

[[u2f]]
name = "Nitrokey Passkey Bootloader"
Expand Down
5 changes: 3 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Device:
name: str
vid: int
pid: int
hidraw: bool = False
hid: bool = False
gnupg: bool = False
all: bool = False

Expand All @@ -25,12 +25,13 @@ def generate(self) -> str:
("ATTRS{idProduct}", "==", f"{self.pid:04x}"),
]
uaccess = [("TAG", "+=", "uaccess")]
if self.hidraw:
if self.hid:
s += generate_rule(
[("KERNEL", "==", "hidraw*"), ("SUBSYSTEM", "==", "hidraw")]
+ attrs_vid_pid
+ uaccess
)
s += generate_rule([("SUBSYSTEMS", "==", "usb")] + attrs_vid_pid + uaccess)
if self.gnupg:
s += generate_rule(
attr_vid_pid
Expand Down

0 comments on commit 5ffac5d

Please sign in to comment.