Yubico / python-yubico

Python code to talk to YubiKeys
https://developers.yubico.com/python-yubico/
BSD 2-Clause "Simplified" License
229 stars 33 forks source link

find_yubikey() fails with ValueError: No backend available #32

Closed bhechinger closed 5 years ago

bhechinger commented 8 years ago

I was trying to work with FreeIPA and YubiKey on CentOS 7, but the ipa otptoken-add-yubikey command was exploding. I tracked it down to being this module that has the actual issues.

Using python-yubico 1.3.1:

[root@ipa-yubikey-test ~]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import yubico
>>> yubikey = yubico.find_yubikey(debug=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/yubico/yubikey.py", line 53, in find_key
    hid_device = YubiKeyHIDDevice(debug, skip)
  File "/usr/lib/python2.7/site-packages/yubico/yubikey_usb_hid.py", line 123, in __init__
    if not self._open(skip):
  File "/usr/lib/python2.7/site-packages/yubico/yubikey_usb_hid.py", line 317, in _open
    usb_device = self._get_usb_device(skip)
  File "/usr/lib/python2.7/site-packages/yubico/yubikey_usb_hid.py", line 367, in _get_usb_device
    find_all=True, idVendor=YUBICO_VID)]
  File "/usr/lib/python2.7/site-packages/usb/core.py", line 864, in find
    raise ValueError('No backend available')
ValueError: No backend available
>>>

The YubiKey (Standard) is definitely there:

[ 1955.426313] usb 2-2.2: USB disconnect, device number 7
[ 2489.666237] usb 2-2.2: new low-speed USB device number 8 using uhci_hcd
[ 2489.758404] usb 2-2.2: New USB device found, idVendor=1050, idProduct=0010
[ 2489.758407] usb 2-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2489.758408] usb 2-2.2: Product: Yubico Yubikey II
[ 2489.758409] usb 2-2.2: Manufacturer: Yubico
[ 2489.766705] input: Yubico Yubico Yubikey II as /devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-2/2-2.2/2-2.2:1.0/input/input8
[ 2489.818727] hid-generic 0003:1050:0010.0005: input,hidraw1: USB HID v1.11 Keyboard [Yubico Yubico Yubikey II] on usb-0000:02:00.0-2.2/input0

Also:

[root@ipa-yubikey-test ~]# lsusb | grep Yubikey
Bus 002 Device 008: ID 1050:0010 Yubico.com Yubikey

This is extremely frustrating!

bhechinger commented 8 years ago

Some additional information. If I run this without the key attached it does recognize that it isn't there:

>>> yubikey = yubico.find_yubikey(debug=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/yubico/yubikey.py", line 65, in find_key
    raise YubiKeyError('No YubiKey found')
yubico.yubikey_base.YubiKeyError: <YubiKeyError instance at 0x7f0263fa0550: No YubiKey found>

Here's the output (with they key connected) with debug=True:

.................

Ok then. I do not understand this at all. I've been at this for hours and not once has this ever worked.

Just now it did.

>>> yubikey = yubico.find_yubikey(debug=False)
>>> print(yubikey.version())
2.4.2
>>>

This is extremely odd. :(

afitzgerald commented 7 years ago

I have the same error, but it never works.

AnnaAnge commented 7 years ago

same error here and it never works. What's the backend that it refers to actually? Thanks in advance guys!

Ratler commented 7 years ago

It sounds like libusb is missing on your system, which is the 'backend' it is looking for. If you are using CentOS try yum install libusb and then try again.

AnnaAnge commented 7 years ago

Hi again, We've installed the package that you suggested and we've followed the instructions here: https://github.com/Yubico/python-yubico but we still have an error: usb.core.USBError: [Errno 13] Access denied (insufficient permissions) Could it be due to the fact that we use a macOS ? Do you have a workaround ?

Thanks in advance :)

Ratler commented 7 years ago

@AnnaAnge I'm afraid that you've run into a known issue on OS X/macOS, see https://github.com/Yubico/python-yubico/issues/7. The issue is with libusb on OS X/macOS and as far as I know there is no known workaround.

mdxs commented 5 years ago

I think this issue can be closed; the original question was about CentOS and was reported to start working at one point in time (by @bhechinger as the original poster). While @Ratler added a note on 4 Jan 2017 that for this CentOS a particular step might be important (for anyone else hitting this on CentOS).

The remaining comments about permissions is to be addressed at https://github.com/Yubico/python-yubico/issues/7 (as noted before by @Ratler).

Thus, this issue can be closed in my opinion.

dainnilsson commented 5 years ago

Agreed, closing.