Bug 2005714

Summary: [Regression] Yubikey smart card support broken in GnuPG 2.3
Product: [Fedora] Fedora Reporter: James <james>
Component: gnupg2Assignee: Red Hat Crypto Team <crypto-team>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: medium    
Version: 35CC: bcl, crypto-team, jjelen, joe, tm
Target Milestone: ---Keywords: Triaged
Target Release: ---Flags: fedora-admin-xmlrpc: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: gnupg2-2.3.2-2.fc35 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-09-29 00:17:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
debug output of gpg 2.3.1 none

Description James 2021-09-19 19:02:54 UTC
Description of problem:
Smart card support does not work in Fedora 35 with GnuPG 2.3.2. Using both a pre-upgrade and fresh configuration:

$ gpg2 --card-status
gpg: selecting card failed: No such device
gpg: OpenPGP card not available: No such device

The device in question is a Yubikey 5 NFC.

[17102.387503] usb 1-1: new full-speed USB device number 5 using xhci_hcd
[17102.516051] usb 1-1: New USB device found, idVendor=1050, idProduct=0407, bcdDevice= 5.24
[17102.516059] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[17102.516062] usb 1-1: Product: YubiKey OTP+FIDO+CCID
[17102.516064] usb 1-1: Manufacturer: Yubico
[17102.519531] input: Yubico YubiKey OTP+FIDO+CCID as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/0003:1050:0407.0006/input/input31

No problems at all with the 'LTS' version gnupg2-2.2.27-4.fc34.x86_64 on F34.

Version-Release number of selected component (if applicable):
gnupg2-2.3.2-1.fc35.x86_64

How reproducible:
Always

Additional information:
Can be worked around by adding disable-ccid to ~/.gnupg/scdaemon.conf, but this shouldn't be necessary.

See also:
https://dev.gnupg.org/T5415

Comment 1 Jakub Jelen 2021-09-20 07:45:09 UTC
I think we should build gnupg with `--disable-ccid-driver` as described in the bug. When we have two competing ccid daemons in the system, it can not end well.

Do you have Fedora 35 at hand to verify that this solves your issue?

https://koji.fedoraproject.org/koji/taskinfo?taskID=75988245

I tested with this build on Fedora 34 and the basic operations seems to work fine.

Comment 2 Jakub Jelen 2021-09-20 07:46:57 UTC
Here is a PR with changes I used to build the above scratch build:

https://src.fedoraproject.org/rpms/gnupg2/pull-request/11

Comment 3 James 2021-09-20 20:25:34 UTC
(In reply to Jakub Jelen from comment #1)
> I think we should build gnupg with `--disable-ccid-driver` as described in
> the bug. When we have two competing ccid daemons in the system, it can not
> end well.
> 
> Do you have Fedora 35 at hand to verify that this solves your issue?
> 
> https://koji.fedoraproject.org/koji/taskinfo?taskID=75988245
> 
> I tested with this build on Fedora 34 and the basic operations seems to work
> fine.

Tested the build found following the link, and it works on F35 with an empty scdaemon.conf.

Comment 4 Joe Doss 2021-09-20 22:33:28 UTC
GnuPG 2.3.x is still broken when using a Yubikey 5 to sign git commits with GPG. It keeps complaining about not being able to find the secret key. My Yubikey 5 NFC was setup with my keys following this guide: https://github.com/drduh/YubiKey-Guide

Steps to reproduce:

$ rpm -qa |grep gnupg
gnupg2-smime-2.3.2-2.fc36.x86_64
gnupg2-2.3.2-2.fc36.x86_64

$ mkdir testing
$ cd testing
$ git init .
$ touch README.md
$ git add .

$ GIT_TRACE=1 git commit -m "GPG Signing on Fedora 35 and a Yubikey is broken with 2.3.2-2.fc35"
16:52:42.625390 git.c:455               trace: built-in: git commit -m ''
16:52:42.625904 run-command.c:667       trace: run_command: /usr/bin/gpg --status-fd=2 -bsau 0x00000000000000
error: gpg failed to sign the data
fatal: failed to write commit object

$ /usr/bin/gpg --status-fd=2 -bsau 0x00000000000000
[GNUPG:] KEY_CONSIDERED snip 0
[GNUPG:] BEGIN_SIGNING H10
Testing
gpg: signing failed: No secret key
[GNUPG:] FAILURE sign 67108881
gpg: signing failed: No secret key

Downgrading to 2.2.27-4.fc35 fixes the issue.

$ sudo dnf install https://kojipkgs.fedoraproject.org//packages/gnupg2/2.2.27/4.fc35/x86_64/gnupg2-2.2.27-4.fc35.x86_64.rpm https://kojipkgs.fedoraproject.org//packages/gnupg2/2.2.27/4.fc35/x86_64/gnupg2-smime-2.2.27-4.fc35.x86_64.rpm

$ rpm -qa |grep gnupg
gnupg2-2.2.27-4.fc35.x86_64
gnupg2-smime-2.2.27-4.fc35.x86_64

$ GIT_TRACE=1 git commit -m "GPG Signing on Fedora 35 and a Yubikey is broken with 2.3.2-2.fc35"
17:01:16.864536 git.c:447               trace: built-in: git commit -m 'GPG Signing on Fedora 35 and a Yubikey is broken with 2.3.2-2.fc35'
17:01:16.865087 run-command.c:667       trace: run_command: /usr/bin/gpg --status-fd=2 -bsau 0x00000000000000
17:01:48.385805 run-command.c:667       trace: run_command: git maintenance run --auto --no-quiet
17:01:48.387070 git.c:447               trace: built-in: git maintenance run --auto --no-quiet
[main (root-commit) 7eae7e9] GPG Signing on Fedora 35 and a Yubikey is broken with 2.3.2-2.fc35
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md

$ /usr/bin/gpg --status-fd=2 -bsau 0x00000000000000
[GNUPG:] KEY_CONSIDERED snip 0
[GNUPG:] BEGIN_SIGNING H10
Testing
[GNUPG:] SIG_CREATED D 1 10 00 1632175995 snip
-----BEGIN PGP SIGNATURE-----
snip
-----END PGP SIGNATURE-----

Comment 5 Jakub Jelen 2021-09-21 07:42:10 UTC
Hi Joe, did you try to restart the scdeamon and gpg-agents running in the background after the update?

The `u 0x00000000000000` looks suspicious. I think it should be configured as user.signingkey in your ~/.gitconfig

Comment 6 Joe Doss 2021-09-21 13:30:16 UTC
Hey Jakub,

Yeah, I restarted them a lot with no change in behavior. Also, sorry, I just redacted my key in my example with `0x00000000000000` I have my real key configured in ~/.gitconfig.

Comment 7 James 2021-09-21 14:24:48 UTC
Hmm... no problem here doing a detached sign with 2.3.2-2:

$ gpg2 -bsa somedata.svg 
gpg: using "..." as default secret key for signing

$ gpg2 --verify somedata.svg.asc 
gpg: assuming signed data in 'somedata.svg'
gpg: Signature made Tue 21 Sep 2021 15:20:18 BST
gpg:                using RSA key ...
gpg: Good signature from "James

etc. Tried exporting keys, reloading into a fresh ~/.gnupg and doing a gpg2 --card-status?

Comment 8 Joe Doss 2021-09-21 14:34:34 UTC
Try doing this:

/usr/bin/gpg --status-fd=2 -bsau <your key>

type `testing` and then ctrl+d to sign it with 2.3.2-2

I copied my `~/.gnupg` to this Fedora 35 from my Fedora 34 laptop that is running gnupg2-2.2.27 where it works perfectly fine.

Comment 9 James 2021-09-21 16:21:55 UTC
(In reply to Joe Doss from comment #8)
> /usr/bin/gpg --status-fd=2 -bsau <your key>
> 
> type `testing` and then ctrl+d to sign it with 2.3.2-2

From what I can tell, that worked OK for me: I pressed Ctrl+D, answered the PIN prompt, and it printed out an ascii-armoured signature.

Comment 10 Jakub Jelen 2021-09-22 08:35:14 UTC
Can you get more debug information from the gpg, gpg-agent or scdaemon?

Comment 11 Joe Doss 2021-09-22 13:52:07 UTC
Created attachment 1825338 [details]
debug output of gpg 2.3.1

See attached txt file for debug output from the following command:

/usr/bin/gpg  --debug-level guru --status-fd=2 -bsau <my key id>

Comment 12 Joe Doss 2021-09-22 13:56:17 UTC
It looks like it is prompting for the PIN here:

gpg: DBG: chan_4 -> SETKEYDESC Please+enter+the+passphrase+to+unlock+the+OpenPGP+secret+key:%0A%22Joe+Doss+<joe>%22%0A4096-bit+RSA+key,+ID+0xsnip,%0Acreated+2019-12-19.%0A

but it never prompts pinentry-gnome3 so I can enter in the pin. 2.2.27 prompts just fine.

Comment 13 Joe Doss 2021-09-22 13:59:30 UTC
Setting pinentry-program /usr/bin/pinentry-curses in gpg-agent.conf results in the same issue with 2.3.x

Comment 14 Jakub Jelen 2021-09-23 10:18:59 UTC
Thanks for the logs.

This does not look like a communication with the pinentry, but with the gpg-agent or scdaemon. Pinentry version is on 1.1.1

gpg: DBG: chan_4 -> GETINFO version
gpg: DBG: chan_4 <- D 2.3.1

This is also not the latest one. Can you check with the gnupg2-2.3.2-2 posted before? It should be now in updates-testing.

Using `debug-pinentry` in gpg-agent.conf might also show more information how it is communicated with pinentry if this would be a problem.

If the issue should be in the scdaemon, you might also turn log level of the scdeamon in scdaemon.conf, but I am not sure where the logs would go.

Comment 15 Joe Doss 2021-09-24 02:32:48 UTC
Looks like gnupg2-2.3.2-2 fixes things! I thought I had tried that version from the previous posts but installing it from updates-testing seems to have sorted things out. I had to unmask and enable pcscd.socket and pcscd.service because having those enabled prevented my yubikey from being recognized without restarting pcscd over and over again. Which makes sense since this version disabled the ccid driver. 

Thanks Jakub!

Comment 16 Fedora Update System 2021-09-24 07:33:54 UTC
FEDORA-2021-c4e724a2ba has been submitted as an update to Fedora 35. https://bodhi.fedoraproject.org/updates/FEDORA-2021-c4e724a2ba

Comment 17 Jakub Jelen 2021-09-24 07:36:16 UTC
Thanks for checking. I added this bug to the update so it should be closed once the update will land in stable.

Comment 18 Fedora Update System 2021-09-29 00:17:08 UTC
FEDORA-2021-c4e724a2ba has been pushed to the Fedora 35 stable repository.
If problem still persists, please make note of it in this bug report.