FiloSottile / yubikey-agent

yubikey-agent is a seamless ssh-agent for YubiKeys.
https://filippo.io/yubikey-agent
BSD 3-Clause "New" or "Revised" License
2.6k stars 124 forks source link

Power-cycling a key while the system is asleep breaks the connection #142

Closed 9ary closed 1 year ago

9ary commented 1 year ago

I initially ran into this because I've disabled always-on USB on my laptop.

Using up to date Arch Linux, yubikey-agent 0.1.6, pcsclite 1.9.9.

Steps to reproduce:

At this point, yubikey-agent fails to reconnect to the key. I see log messages such as could not reach YubiKey: selecting piv applet: command failed: transmitting request: an attempt was made to end a non-existent transaction and could not reach YubiKey: connecting to smart card: the smart card cannot be accessed because of other connections outstanding.

I can fix it by unplugging the key and plugging it back in again, or restarting either yubikey-agent or pcscd.

Moving the key to a different USB port or waiting for the computer to be awake doesn't trigger the problem.

I'm not ruling out the possibility of this being a pcscd bug, but maybe yubikey-agent is not handling something that it should somewhere along the way? Something noteworthy though is that in the case that breaks, the monitor example from yubikey.rs does not see any events.

9ary commented 1 year ago

I just tested for fun, and it looks like replacing the yubikey with a different one while the system is asleep also causes the exact same behavior.

Also looks like the kernel only sees a device reset, rather than a new device. I see these messages in dmesg:

[  +0.233951] usb 1-2: reset full-speed USB device number 62 using xhci_hcd

and

[  +0.351115] usb 1-2: usbfs: process 252659 (pcscd) did not claim interface 1 before use

This is starting to look like a pcscd bug. I'll take this upstream.

9ary commented 1 year ago

With https://github.com/LudovicRousseau/CCID/commit/f3d3b868d8ebdd3bf75dc1805d8ee02263622eee, this should now be fixed.