I was playing around with GnuPG 2.1 and its new storage formats when I stumbled across a strange behaviour.
As I tried to import my old (GnuPG 1.4/2.0) secret keys with
$ gpg2 --import ~/.gnupg.old/secring.gpg
I ended up with unusable (private) keys. More precisely the private keys are lacking their subkeys:
$ gpg2 --list-keys /home/tux/.gnupg/pubring.kbx ---------------------------- pub rsa4096/0xABCDABCDABCDABCD 2016-01-01 [C] [expired: 2017-01-01] 12341234123412341234ABCDABCDABCDABCDABCD uid [ expired] Tux Penguin <tux@example.org> uid [ expired] Tux Penguin $ gpg2 --list-secret-keys /home/tux/.gnupg/pubring.kbx ---------------------------- sec# rsa4096/0xABCDABCDABCDABCD 2016-01-01 [C] [expired: 2017-01-01] 12341234123412341234ABCDABCDABCDABCDABCD uid [ expired] Tux Penguin <tux@example.org> uid [ expired] Tux Penguin
No subkeys listed at all. (The keys are marked as expired due to missing self-signatures which seem to be stored along with the subkeys.)
This only happens to keys where the primary secret subkey is missing (sec#).
Subkeys of keys which have a primary secret key are imported correctly by the above statement.
My question is:
Is this intended behaviour and is it documented anywhere?
If yes, then printing a warning when importing secring.gpg might be a good idea, e.g.
Warning you are importing from secring.gpg. This might not import all keys correctly. Consider using gpg --export-secret-keys > seckeys.gpg && gpg --import seckeys.gpg instead.
Thanks in advance.
Simple workaround for people how stumble upon this and want a quick solution:
Export the secret keys into a file and import them afterwards
$ gpg2 --homedir ~/.gnupg.old --export-secret-keys > ~/tmp/seckeys.gpg $ gpg2 --homedir ~/.gnupg --import ~/tmp/seckeys.gpg
The shorter
$ gpg2 --homedir ~/.gnupg.old --export-secret-keys | gpg2 --homedir ~/.gnupg --import
should also work but gave me an unusable terminal due to two instances of pinentry/gpg-agent fighting over one terminal.