Cannot find Yubikey devices using python-yubico library on Windows 10

90 Views Asked by At

I'm looking to integrate 2FA into a Python app using the python-yubico library. To that end, I'm trying to run the following example they've given:

import sys
import yubico


try:
    yk = yubico.find_yubikey(debug=False)
    print(yk.version())
except yubico.yubico_exception.YubicoError as e:
    print(e.reason)
    sys.exit(1)

The above code results in usb.core.NoBackendError: No backend available - apparently this is a known issue with Windows caused by libusb being unavailable.

Some digging led me to download the libusb binaries from https://github.com/libusb/libusb/releases/tag/v1.0.26

Once I had libusb, I moved libusb-1.0.dll into C:\Windows\SysWOW64 and C:\Windows\system32 (just to cover my bases) and tried the following solution I found from the pyusb GitHub page to set the USB backend explicitly:

import sys
import usb.backend.libusb1
import yubico


# set the backend used by pyusb
LIBUSB_DLL = r'C:\Windows\SysWOW64\libusb-1.0.dll'
usb.backend.libusb1.get_backend(lambda _: LIBUSB_DLL)

try:
    yk = yubico.find_yubikey(debug=False)
    print(yk.version())
except yubico.yubico_exception.YubicoError as e:
    print(e.reason)
    sys.exit(1)

Setting the DLL path to use SysWOW64 as above results in No YubiKey found, even if my YubiKey is plugged in

And, FWIW, using system32 in the DLL path instead results in the same No Backend Available error.

Obviously there's something I'm missing here. I've at the very least gotten past the "backend" issue, but I still can't get python-yubico to find my connected device(s). Any help is appreciated!

0

There are 0 best solutions below