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

FIDO functionality becomes unusable with "Invalid value size specified" error #90

Closed troyready closed 4 years ago

troyready commented 4 years ago

I'm running into an issue where my Yubikey 5 NFC becomes unusable after a some time (typically fine after a reboot, but then this issue comes back after a couple of days). Doesn't seem specific to older or newer library versions (had this same issue in the 0.7.x versions on a ubuntu 19.04 system, and I'm seeing it still with a fresh ykman install on a ubuntu 19.10 system)

The exact output looks like:

troyready@notebook:~$ .local/bin/ykman fido list
Traceback (most recent call last):
  File ".local/bin/ykman", line 8, in <module>
    sys.exit(main())
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/ykman/cli/__main__.py", line 273, in main
    cli(obj={})
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/ykman/cli/fido.py", line 112, in list_creds
    controller = ctx.obj['controller']
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/ykman/cli/util.py", line 127, in __getitem__
    self.resolve()
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/ykman/cli/util.py", line 124, in resolve
    self._objects[k] = f()
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/ykman/cli/__main__.py", line 194, in resolve_device
    dev = _run_cmd_for_single(ctx, subcmd.name, transports, reader)
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/ykman/cli/__main__.py", line 132, in _run_cmd_for_single
    return descriptor.open_device(transports)
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/ykman/descriptor.py", line 96, in open_device
    for drv in _list_drivers(transports):
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/ykman/descriptor.py", line 164, in _list_drivers
    for dev in open_fido():
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/ykman/driver_fido.py", line 97, in open_devices
    for dev in CtapHidDevice.list_devices(descriptor_filter):
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/fido2/hid.py", line 135, in list_devices
    for d in hidtransport.hid.Enumerate():
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/fido2/_pyu2f/linux.py", line 193, in Enumerate
    ParseReportDescriptor(rd_file.read(), desc)
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/fido2/_pyu2f/linux.py", line 149, in ParseReportDescriptor
    usage_page = ReadLsbBytes(rd, pos + 1, value_length)
  File "/home/troyready/.local/venvs/yubikey-manager/lib/python3.7/site-packages/fido2/_pyu2f/linux.py", line 86, in ReadLsbBytes
    raise OSError('Invalid value size specified')
OSError: Invalid value size specified

If I add a debug print line to that ReadLsbBytes function, it's a bunch of 1s, a few 2s, and then a 0 causes that ^ exception.

Not sure if there's some method of resetting or troubleshooting I can provide, but would love to help.

dainnilsson commented 4 years ago

Hmm, I haven't seen this one before. When you encounter the issue you say that a reboot typically of the computer fixes it? Have you tried other things, like removing and re-inserting the YubiKey? Have you seen this issue on more than one physical computer?

dainnilsson commented 4 years ago

Closing due to inactivity (feel free to reopen).

troyready commented 4 years ago

(sorry for the delay in responding -- needed to clear some time for proper troubleshooting)

I've spent more time poking at it today and it seems to be isolated to one system, a Lenovo Thinkpad T470s notebook. I don't have any other issues with the yubikeys with the system (using them on the cli for challenge-response & u2f, and in Chromium for Google account security keys), but on this notebook in particular (tested with my 2 Yubikey 5 NFCs) I consistently end up in this state:

troyready@stargazer:~$ .local/bin/ykman fido list
Traceback (most recent call last):
  File ".local/bin/ykman", line 8, in <module>
    sys.exit(main())
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/ykman/cli/__main__.py", line 273, in main
    cli(obj={})
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/ykman/cli/fido.py", line 112, in list_creds
    controller = ctx.obj['controller']
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/ykman/cli/util.py", line 127, in __getitem__
    self.resolve()
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/ykman/cli/util.py", line 124, in resolve
    self._objects[k] = f()
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/ykman/cli/__main__.py", line 194, in resolve_device
    dev = _run_cmd_for_single(ctx, subcmd.name, transports, reader)
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/ykman/cli/__main__.py", line 132, in _run_cmd_for_single
    return descriptor.open_device(transports)
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/ykman/descriptor.py", line 96, in open_device
    for drv in _list_drivers(transports):
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/ykman/descriptor.py", line 164, in _list_drivers
    for dev in open_fido():
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/ykman/driver_fido.py", line 97, in open_devices
    for dev in CtapHidDevice.list_devices(descriptor_filter):
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/fido2/hid.py", line 135, in list_devices
    for d in hidtransport.hid.Enumerate():
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/fido2/_pyu2f/linux.py", line 193, in Enumerate
    ParseReportDescriptor(rd_file.read(), desc)
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/fido2/_pyu2f/linux.py", line 149, in ParseReportDescriptor
    usage_page = ReadLsbBytes(rd, pos + 1, value_length)
  File "/home/troyready/.local/pipx/venvs/yubikey-manager/lib/python3.8/site-packages/fido2/_pyu2f/linux.py", line 86, in ReadLsbBytes
    raise OSError('Invalid value size specified')
OSError: Invalid value size specified

(this is after a fresh install of Ubuntu 20.04; same results with both keys)

I wasn't able to reproduce the issue on another desktop, which leads me to believe it's some oddity of this system specifically.

If troubleshooting it would be helpful for the project and others, I'd love to do it. ~If it affects literally no one else and there's no clear path forward, then I'll understand if we want to just close the issue again.~

If it could potentially affect others in the future, I'd love to help troubleshoot it, but understand if that's not feasible/practical.