Yubico / yubikey-manager

Python library and command line tool for configuring any YubiKey over all USB interfaces.
https://developers.yubico.com/yubikey-manager/
BSD 2-Clause "Simplified" License
871 stars 125 forks source link

Send SIGHUP to `yubikey-agent` if it's running and the connection fails #598

Closed Ma27 closed 6 months ago

Ma27 commented 7 months ago

yubikey-agent is an SSH agent written in Go that uses the PIV module of a YubiKey for SSH[1].

Since it takes a persistent transaction on the YubiKey, using e.g. ykman will fail when it's active. I think it's tedious to always send a SIGHUP to it whenever I want to use ykman, so I added this small patch that does that for me. Inspired by what age-plugin-yubikey is also doing[2].

Not sure about Windows support, but I left it out because yubikey-agent doesn't do any Windows AFAIK and SIGHUP isn't supported there.

[1] https://github.com/FiloSottile/yubikey-agent [2] https://github.com/str4d/age-plugin-yubikey/commit/1913838f8ed4b30c756c3c20ea5fdf1680ea97ca

dainnilsson commented 7 months ago

Thanks! We do already have something similar in place for scdaemon (part of gpg) and I would prefer if this addition was done in the same way and place, without introducing new project dependencies. See https://github.com/Yubico/yubikey-manager/blob/main/ykman/pcsc/__init__.py#L98 for details.

Ma27 commented 7 months ago

@dainnilsson fair point! Updated accordingly! :)

dainnilsson commented 6 months ago

Thanks! It's in the right location now, but I still think we should be able to do this without adding the psutil dependency.

Ma27 commented 6 months ago

Fair. Will look into it soonish and report back :)

Ma27 commented 6 months ago

Right, we depend on procps being installed here, so it's effectively just pkill -HUP. Updated the PR @dainnilsson .

dainnilsson commented 6 months ago

Thanks. The code looks fine, but you still have some unused imports that need to be removed.

Edit: I will fix up this myself so that we can get it merged, as we'll be doing a new release quite soon. Please leave it as is!