49

Short OpenPGP key IDs (with 32 bits / 8 hex characters) are subject to collision attacks. It is strongly recommended to stop using 32 bit IDs:

Stop using 32bit key ids

It takes 4 seconds to generate a colliding 32bit key id on a GPU (using scallion). Key servers do little verification of uploaded keys and allow keys with colliding 32bit ids. Further, GPG uses 32bit key ids throughout its interface and does not warn you when an operation might apply to multiple keys.

But how do I tell GnuPG to use long IDs (with 64 bits, or 16 hex characters)?

Jens Erat
  • 23,446
  • 12
  • 72
  • 96

1 Answers1

65

How the Fingerprint and Long and Short Key IDs are Related

Each OpenPGP key has a fingerprint attached, calculated mainly from its public key packet which also contains the creation time. The calculation is defined in RFC 4880, OpenPGP, 12.2. Key IDs and Fingerprints.

There are short and long key IDs, which resemble the lower 32 respective 64 bits of the fingerprint. For example, looking at the IDs of my OpenPGP key:

fingerprint: 0D69 E11F 12BD BA07 7B37  26AB 4E1F 799A A4FF 2279
long id:                                    4E1F 799A A4FF 2279
short id:                                             A4FF 2279

Fingerprints and key IDs are used, as sharing and comparing a whole key with usually 1024 to 8096 bits (adding some more for headers like the creation date) is very impractical.

Using Long Key IDs

Whenever specifying OpenPGP keys, you can not only pass short key IDs, but also long key IDs and even whole fingerprints. Instead of passing the short key ID

gpg --recv-keys A4FF2279

you can always write the long key ID

gpg --recv-keys 4E1F799AA4FF2279

or even the full fingerprint (recommended for scripting and similar purpose)

gpg --recv-keys 0D69E11F12BDBA077B3726AB4E1F799AA4FF2279

Printing Long Key IDs

But where to take the long key ID from? If anybody passed his short ID, you cannot do anything but trying to fetch all keys for that ID, and see if there is a collision (and hope nobody is hiding the real key from you, and only passing the faked one).

So whenever handing over your OpenPGP key ID, announce the long ID! You can easily make GnuPG printing this one by adding the --keyid-format long option:

gpg --keyid-format long --list-keys email@jenserat.de

This option takes values short or 0xshort for short key IDs (without or with 0x prefixed to indicate that it is a hex number) and long or 0xlong for long key IDs.

Configurating Long Key IDs as Default

To make sure GnuPG is always printing the long key ID, add the option to your ~/.gnupg/gpg.conf file stripping the --. For example, I have configured GnuPG to always print the 0x-prefixed long key ID by adding a line

keyid-format 0xlong

Printing the Fingerprint

Sadly, you cannot set GnuPG to print the whole fingerprint this way, probably because it would break GnuPG's output format for pretty much every screen size. Instead, request it by running

gpg --fingerprint 4E1F799AA4FF2279

which will dump something like

pub   8192R/0x4E1F799AA4FF2279 2012-12-25
      Key fingerprint = 0D69 E11F 12BD BA07 7B37  26AB 4E1F 799A A4FF 2279

As this has the disadvantage of containing spaces (bad thing for using it in scripting), you could use the colon-delimited machine-readable output instead:

gpg --with-colons --fingerprint 4E1F799AA4FF2279

To filter everything but the fingerprint, additionally use grep and cut:

gpg --with-colons --fingerprint 4E1F799AA4FF2279 | grep fpr | cut -d ':' -f 10
Jens Erat
  • 23,446
  • 12
  • 72
  • 96
  • 7
    Actually, you can (at least as of GnuPG 2.1) add `with-subkey-fingerprint` to your `gpg.conf`. And probably also `keyid-format none` since long key ids are insecure as well. – kirelagin May 31 '17 at 07:44
  • 2
    You can also put a line of `with-fingerprint` to the `gpg.conf` file to display fingerprints. – Константин Ван Jun 15 '19 at 16:13
  • I also added `| grep 4E1F799AA4FF2279` as final pipe, there is two fingerprints (`fpr`) listed under a single ID (I don't know why). Please see the example of generated multiple `fpr` on https://gist.github.com/avatar-lavventura/c07af91b958db0d889d0d09b107f28be @Jens Erat – alper Jun 02 '20 at 18:42