-
Notifications
You must be signed in to change notification settings - Fork 904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hid_open_path fails intermittently on Mac #266
Comments
An interesting observation: when I change the call to However, there still appears to be a discrepancy here, because my native example uses |
Another observation: according to TN2187, you need to call |
Unfortunately I don't have a U2F device to try out, but you've given lots of good info. Dumb question first: is there anything else on the system that's opening/using the device? The difference that sticks out to me between your native and hidapi samples is that the native sample creates a matching dictionary, so the HID Manager can filter and enumerate just the devices you want. Whereas hidapi just gets all devices from the HID Manager, and then filtering happens in the user's code. As for I'm out of ideas for now, I'll see if I can come up with anything else |
Dumb question in response to your (not so dumb) question: is there a way I can definitively tell if another process on my system is using the same device? (e.g. a diagnostic tool) As a rough test, I've tried rebooting my machine and running the test on a fresh boot before starting any other processes. The error still occurs. |
FWIW, I've also tried a Kensington USB keyboard and a Logitech mouse. Interestingly, I could reproduce the same behavior with the keyboard, but could not with the mouse (it always connects successfully). |
In the context of #266 (comment), why does |
Another interesting observation: if you run the program that uses HIDAPI with root privileges (e.g. |
Unfortunately, I don't know of a way to see whether other processes have a device open. As for why behavior changes when running as root, from Apple's docs:
As for hidapi using |
Ok, I found the source of the problem. Fundamentally, the issue is that
The Yubikey is in OTP+U2F+CCID mode, which presents two HID devices: a keyboard (0x01/0x06) for OTP mode and a U2F HID device (0xf1d0/0x01) for U2F mode. However, they have the same path: Here's what's causing the intermittent failure to connect in my test program (and would cause the same error in any program that uses HIDAPI on Mac):
The correct solution is to ensure that |
Chromium's HID implementation uses IORegistryEntryGetRegistryEntryID to uniquely identify HID devices. HIDAPI should probably do the same, instead of trying to cobble together a unique ID from various attributes of IOHIDDevice. |
Aha, very interesting. I actually have a several-year-old pull request which solves that exact problem (by using the IOKit path instead of fabricating one), I've wanted it to be merged for a while and this is a real problem that hopefully will be solved. Give it a try: #40 |
That's a good find, Chromium switched to using the entry ID about a year ago because IOKit paths were not unique for Bluetooth HID devices (at least on 10.10): Testing hidapi with Bluetooth devices is something I've always wanted to do but never got around to |
OS: Mac OS 10.10.5
HIDAPI commit: b5b2e17 (current master)
I'm trying to write some code to connect to a HID U2F authentication device on a Mac. I've been encountering intermittent but frequent failures to connect to the device with
hid_open_path
. There is no apparent pattern or cause as to whether the connection succeeds or fails.I did some debugging and found that it was failing in
mac/hid.c
becauseIOHIDDeviceOpen
was returningkIOReturnNotPrivileged
.I rewrote the same functionality (trying to connect to a specific device) using only the native APIs and it does not have the same problem: connecting to the same device succeeds every time. This implies that this is a problem in HIDAPI, although so far I have not been able to figure out why that might be the case.
To aid debugging, I've forked HIDAPI and created a branch that has some test programs that demonstrate this behavior. I included a README that explains the different programs and how to build them.
The text was updated successfully, but these errors were encountered: