I have three keys; I'll refer to them as 'foo' [C], 'bar' [SE], and 'baz' [A]. Whenever I run gpg2 --export-private-subkeys baz!, it asks for a password, as it should. However, if I click 'Cancel', it proceeds to print out half of the private key anyway!

Output of wc when I don't enter a password: 29 36 1658.
Output of wc when I do enter a password: 60 67 3717.

By comparing the output from "no password" to the output from "yes password", I can see that the text is, indeed, identical to the first half of the 'baz' key.

Even stranger, when I run gpg2 --export-private-subkeys on 'foo' or 'bar', it still prints out half of 'baz' when I decline to enter a password!

Is there any way I can stop it from exposing half of 'baz' when there is no password entered? Why do you think it would be doing this?

  • It turns out that the first halves of 'bar' and 'baz' are identical. – Miles B Huff Dec 29 '17 at 15:21

When you use the --export-secret-subkeys command, it will export the public part of the key as well. You're seeing the output of that. You can test with the following:

gpg2 --export-secret-subkeys > /tmp/cancelled.gpg
gpg2 --export-secret-subkeys > /tmp/not-cancelled.gpg

Cancel the passphrase input on the first one, and then try this:

export GNUPGHOME=$(mktemp -d)
gpg2 --import /tmp/cancelled.gpg
# the output will mention importing the public key
# you will not be asked for the passphrase
gpg2 --list-secret-keys
# the output will be empty

Do the same with the non-cancelled one:

export GNUPGHOME=$(mktemp -d)
gpg2 --import /tmp/non-cancelled.gpg
# the output will mention importing the public and secret keys
# you will also need to put in the passphrase to import the key
gpg2 --list-secret-keys
# the output will show the secret key

So, when you click "Cancel" only the public key is written out.

  • Thanks! Alright, that makes sense. And the reason why it was showing the same "public" portion of the private key for 'bar' as 'baz', was because the two of them are actually identical where that part is concerned. – Miles B Huff Dec 24 '17 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.