Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

As I understand it, keypairs used with gpg generally have more than one associated key: one for signing and one for encryption. How are these multiple keys managed when using gpg (to push to a keyserver, retrieve someone else's key, encrypt, or sign)? Will it automatically use the correct key for the correct action, or is that something the user needs to specify? How is the purpose of each key within a keypair identified?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

What is often called a "GPG key" is more like a certificate. Just like in X.509, the certificate contains a lot more information than just the key(s): a 'primary' keypair and multiple 'subkey' keypairs, along with their usage flags and expiry dates, as well as multiple 'user IDs' and 'photo IDs' along with their signatures.

When you upload your "keypair" to a keyserver, you are submitting everything that's public – key, subkeys, user IDs, signatures – as one single certificate. The 'primary' key identifies the entire certificate; its public key hash is the "fingerprint" you see, and the key ID is based on it. Normally, the primary key has "Sign" and "Certify" usage flags, for signing data and other keys respectively.

By default, there is at least one "Encrypt" subkey created, for encrypting data. You can have multiple such subkeys – for example, with different expiry dates. I couldn't find any good source, but it seems that the newest valid (after starting date and not expired/revoked) subkey will be chosen for encryption. When decrypting data, all subkeys will be tried.

(You might have noticed that gpg -k lists key IDs for both keys and subkeys. When you need to force a specific key or subkey to be used, you can give keyid! – the (sub)key ID followed by an exclamation mark – to bypass all calculations on which subkey is best.)

Optionally you can add subkeys marked allowed to "Authenticate", which can then be used in protocols such as SSH (via gpg-agent, by extracting the raw RSA keypair) or SSL (implemented by GnuTLS as an alternative to X.509). Which subkeys are used depends on the specific implementation.

You can see the full structure of a PGP certificate by using:

  • gpg --export mykey | gpg -vvv
  • gpg --export mykey | pgpdump
  • gpg --export mykey | certtool --pgp-certificate-info
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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