With other words, gpg-agent silently deletes the locally stored private key without asking for confirmation. Let's hope the user has a backup because otherwise they have lost access to the private key material. I consider this a serious regression.
This bug is only present in GnuPG 2.2.
Reproduce:
- Ensure you use gpg 2.2.37 or later (but not 2.3 or later)
$ gpg --version gpg (GnuPG) 2.2.42-beta145 libgcrypt 1.8.11-beta2
- Have a secret key available.
$ gpg -K sec rsa3072 2023-02-24 [SC] [expires: 2025-02-24] 4A24FA992B0A1181179F817EE0CF08F792BD5422 uid [ultimate] Ada Lovelace <ada@example.net> ssb rsa3072 2023-02-24 [E] [expires: 2025-02-24]
- Use --edit-key to move the primary key to the card and quit without saving.
$ gpg --edit-key 4A24FA992B0A1181179F817EE0CF08F792BD5422 gpg (GnuPG) 2.2.42-beta145; Copyright (C) 2023 g10 Code GmbH This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Secret key is available. sec rsa3072/E0CF08F792BD5422 created: 2023-02-24 expires: 2025-02-24 usage: SC trust: ultimate validity: ultimate ssb rsa3072/FF2AE96F2FD6024F created: 2023-02-24 expires: 2025-02-24 usage: E [ultimate] (1). Ada Lovelace <ada@example.net> gpg> keytocard Really move the primary key? (y/N) y Please select where to store the key: (1) Signature key (3) Authentication key Your selection? 1 sec rsa3072/E0CF08F792BD5422 created: 2023-02-24 expires: 2025-02-24 usage: SC trust: ultimate validity: ultimate ssb rsa3072/FF2AE96F2FD6024F created: 2023-02-24 expires: 2025-02-24 usage: E [ultimate] (1). Ada Lovelace <ada@example.net> gpg> quit Save changes? (y/N) N Quit without saving? (y/N) y
- Verify that the secret key of the primary key is still available.
$ gpg -K sec rsa3072 2023-02-24 [SC] [expires: 2025-02-24] 4A24FA992B0A1181179F817EE0CF08F792BD5422 uid [ultimate] Ada Lovelace <ada@example.net> ssb rsa3072 2023-02-24 [E] [expires: 2025-02-24]
- Run the command "READKEY --card --no-data -- OPENPGP.1"
$ gpg-connect-agent "READKEY --card --no-data -- OPENPGP.1" /bye OK
- Observe that the secret key of the primary has been replaced with a stub effectively deleting the secret key without confirmation.
$ gpg -K sec> rsa3072 2023-02-24 [SC] [expires: 2025-02-24] 4A24FA992B0A1181179F817EE0CF08F792BD5422 Card serial no. = 0006 09074582 uid [ultimate] Ada Lovelace <ada@example.net> ssb rsa3072 2023-02-24 [E] [expires: 2025-02-24]
This regression was introduced by rG755920d43357: agent: Let READKEY update the display-s/n of the Token entry. which unconditionally overwrites the private key file "to update the shadow key" without checking whether the private key file actually contains a shadow key.