Yubico / python-fido2

Provides library functionality for FIDO 2.0, including communication with a device over USB.
BSD 2-Clause "Simplified" License
432 stars 109 forks source link

Can't find Yubikey in version 0.9.2 (works in 0.9.1) #127

Closed Prillan closed 3 years ago

Prillan commented 3 years ago

Hi!

I just upgraded to 0.9.2 and it looks like it can't find my Yubikey. I've managed to find the offending commit (6bc40d1) with git bisect:

$ git checkout ce19ba5 && pipenv install --dev && pipenv run python -c 'from fido2.hid import CtapHidDevice; print(list(CtapHidDevice.list_devices()))'
HEAD is now at ce19ba5 Don't use enum.auto (Python 2).
Installing dependencies from Pipfile.lock (a56c25)...
  🐍   β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰ 1/1 β€” 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
[CtapHidDevice(/dev/hidraw3)]

$ git checkout 6bc40d1 && pipenv install --dev && pipenv run python -c 'from fido2.hid import CtapHidDevice; print(list(CtapHidDevice.list_devices()))'
HEAD is now at 6bc40d1 USB HID: add product name and serial to descriptor.
Installing dependencies from Pipfile.lock (a56c25)...
  🐍   β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰ 1/1 β€” 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
[]

Any thoughts?

EDIT: Fails here:

>>> fido2.hid.linux.get_descriptor("/dev/hidraw3")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/python-fido2/fido2/hid/linux.py", line 64, in get_descriptor
    length = fcntl.ioctl(f, HIDIOCGRAWUNIQ, buf, True)
OSError: [Errno 25] Inappropriate ioctl for device
dainnilsson commented 3 years ago

I'd like to get a better understanding for why this is failing before merging the PR. The code does several ioctl calls both before and after the one that is causing an error. Which Linux distribution and version are you running? With your patch in place, are all other calls succeeding? And the device is then usable?

Prillan commented 3 years ago

Of course!

I'm on Ubuntu 20.04.3 LTS. This is the device according to lsusb:

ID 1050:0407 Yubico.com Yubikey 4 OTP+U2F+CCID

The program/code/library works as expected after the patch has been applied.

dainnilsson commented 3 years ago

Some digging seems to indicate that HIDIOCGRAWUNIQ was added in Linux kernel 5.6 (late 2019), so anything older is expected to have this issue. I'll merge the PR and try to get a release out shortly. Thanks!

Prillan commented 3 years ago

Ah!

Thanks a lot for your quick help/review/merge!