TL;DR: Using Yubikey as SSH key, or decrypting PGP text, with GnuPG fails after Yubikey has been used by another PKCS11 program through pcscd.
I'm using a Yubikey 5C with on my Devuan machine running latest daedalus (testing).
The machine uses Yubikey as PKCS11 token with PCSCd, pam_pkcs11, Firefox etc, but also uses it as a "smart card" for GnuPG with scdaemon.
All pkcs11 operations works as normal (as long as no program locks the key on usage)
gpg-agent can use the key for GPG+SSH after it has been plugged in, but if some other program uses the key through pcscd, the key cannot be used with gpg-agent or scdaemon
until the key has been unplugged and plugged in again.
gpg-agent.conf
default-cache-ttl 300 enable-ssh-support no-grab max-cache-ttl 999999 allow-emacs-pinentry
scdaemon.conf
verbose debug-level expert log-file /home/mkj/.gnupg/scdaemon.log pcsc-shared
gpg-agent log exhibit after error:
2022-09-25 18:13:38 gpg-agent[3152] new connection to SCdaemon established (reusing) 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_11 -> SERIALNO --demand=.... 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_11 <- S SERIALNO .... 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_11 <- OK 2022-09-25 18:13:38 gpg-agent[3152] detected card with S/N .... 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_11 -> SETDATA .... 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_11 <- OK 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_11 -> PKDECRYPT .... 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_11 <- ERR 100663404 Card error <SCD> 2022-09-25 18:13:38 gpg-agent[3152] smartcard decryption failed: Card error 2022-09-25 18:13:38 gpg-agent[3152] command 'PKDECRYPT' failed: Card error <SCD> 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_10 -> ERR 100663404 Card error <SCD> 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_10 <- [eof] 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_11 -> RESTART 2022-09-25 18:13:38 gpg-agent[3152] DBG: chan_11 <- OK
scdamon log exhibit after error:
2022-09-25 18:13:38 scdaemon[5793] DBG: chan_7 <- SERIALNO --demand=.... 2022-09-25 18:13:38 scdaemon[5793] ccid open error: skip 2022-09-25 18:13:38 scdaemon[5793] DBG: chan_7 -> S SERIALNO ..... 2022-09-25 18:13:38 scdaemon[5793] DBG: chan_7 -> OK 2022-09-25 18:13:38 scdaemon[5793] DBG: chan_7 <- SETDATA .... 2022-09-25 18:13:38 scdaemon[5793] DBG: chan_7 -> OK 2022-09-25 18:13:38 scdaemon[5793] DBG: chan_7 <- PKDECRYPT .... 2022-09-25 18:13:38 scdaemon[5793] DBG: send apdu: c=00 i=2A p1=80 p2=86 lc=39 le=256 em=0 2022-09-25 18:13:38 scdaemon[5793] DBG: PCSC_data: .... 2022-09-25 18:13:38 scdaemon[5793] DBG: response: sw=6D00 datalen=0 2022-09-25 18:13:38 scdaemon[5793] operation decipher result: Card error 2022-09-25 18:13:38 scdaemon[5793] app_decipher failed: Card error 2022-09-25 18:13:38 scdaemon[5793] DBG: chan_7 -> ERR 100663404 Card error <SCD> 2022-09-25 18:13:38 scdaemon[5793] DBG: chan_7 <- RESTART 2022-09-25 18:13:38 scdaemon[5793] DBG: chan_7 -> OK
I have deliberately replaced some data with dots. Not sure if its relevant...