scdaemon monitoring usb device removal

NIIBE Yutaka gniibe at
Mon Dec 19 10:37:19 CET 2016


In Debian, we have dirmngr-idling and gpg-agent-idling patches.
Inspired by those patches, I'm considering possible changes to scdaemon,
which also has "handle_tick" thing.

Basically, scdaemon's handle_tick checks the removal of card or the
removal of device periodically, by explicitly sending status request
to USB device.

I don't think we can remove handle_tick for all cases.  The reasons
     We support Windows.
     We support access through PC/SC.
     We support card readers with no interrupt transfer support.

Nevertheless, we don't need handle_tick, for following two cases.

(1) With internal CCID driver, when it's USB token (like Yubikey,
Nitrokey, and Gnuk Token), we can use select system call for detecting
removal of device.

(2) With internal CCID driver, when the card reader support interrupt
transfer support for card change, we can check the USB endpoint for
card removal.

I am now testing the change of (1) on GNU/Linux.  On GNU/Linux, the
file descriptor for USB device can be used for removal of device.  It
returns POLLHUP for poll(2).

In the libusb API 1.0, we have libusb_getpollfds function.
Unfortunately, there is no access directly to get the file descriptor
for specific device.  Still, we can distinguish the file descriptor,
by the returned pollfd structure with POLLOUT events (on GNU/Linux).
I don't know if there is similar way for FreeBSD / macOS.

And we use select(2) instead of poll(2) in scdaemon (through nPth
library).  Here we have an interface mismatch somehow.  I checked that
when select is called with read_fdset of the USB device descriptor, we
can detect the removal of device.

I'll post the change after the release of GnuPG 2.1.17.  Please
note that this is experimental change.

Obvious drawback would be that the LED blinking of FST-01 will be

More information about the Gnupg-devel mailing list