Key Management

The GNU Privacy Handbook
Prev |  | Next

# Chapter 3. Key Management

Key tampering is a major security weakness with public-key cryptography. An eavesdropper may tamper with a user's keyrings or forge a user's public key and post it for others to download and use. For example, suppose Chloe wants to monitor the messages that Alice sends to Blake. She could mount what is called a man in the middle attack. In this attack, Chloe creates a new public/private keypair. She replaces Alice's copy of Blake's public key with the new public key. She then intercepts the messages that Alice sends to Blake. For each intercept, she decrypts it using the new private key, reencrypts it using Blake's true public key, and forwards the reencrypted message to Blake. All messages sent from Alice to Blake can now be read by Chloe.

Good key management is crucial in order to ensure not just the integrity of your keyrings but the integrity of other users' keyrings as well. The core of key management in GnuPG is the notion of signing keys. Key signing has two main purposes: it permits you to detect tampering on your keyring, and it allows you to certify that a key truly belongs to the person named by a user ID on the key. Key signatures are also used in a scheme known as the web of trust to extend certification to keys not directly signed by you but signed by others you trust. Responsible users who practice good key management can defeat key tampering as a practical attack on secure communication with GnuPG.

# Managing your own keypair

A keypair has a public key and a private key. A public key consists of the public portion of the master signing key, the public portions of the subordinate signing and encryption subkeys, and a set of user IDs used to associate the public key with a real person. Each piece has data about itself. For a key, this data includes its ID, when it was created, when it will expire, etc. For a user ID, this data includes the name of the real person it identifies, an optional comment, and an email address. The structure of the private key is similar, except that it contains only the private portions of the keys, and there is no user ID information.

The command-line option `--edit-key` may be used to view a keypair. For example,

    chloe% gpg --edit-key chloe@cyb.org
    Secret key is available.

    pub  1024D/26B6AAE1  created: 1999-06-15 expires: never      trust: -/u
    sub  2048g/0CF8CB7A  created: 1999-06-15 expires: never
    sub  1792G/08224617  created: 1999-06-15 expires: 2002-06-14
    sub   960D/B1F423E7  created: 1999-06-15 expires: 2002-06-14
    (1)  Chloe (Jester) <chloe@cyb.org>
    (2)  Chloe (Plebian) <chloe@tel.net>
    Command>

The public key is displayed along with an indication of whether or not the private key is available. Information about each component of the public key is then listed. The first column indicates the type of the key. The keyword `pub` identifies the public master signing key, and the keyword `sub` identifies a public subordinate key. The second column indicates the key's bit length, type, and ID. The type is `D` for a DSA key, `g` for an encryption-only ElGamal key, and `G` for an ElGamal key that may be used for both encryption and signing. The creation date and expiration date are given in columns three and four. The user IDs are listed following the keys.

More information about the key can be obtained with interactive commands. The command toggle switches between the public and private components of a keypair if indeed both components are available.

    Command> toggle

    sec  1024D/26B6AAE1  created: 1999-06-15 expires: never
    sbb  2048g/0CF8CB7A  created: 1999-06-15 expires: never
    sbb  1792G/08224617  created: 1999-06-15 expires: 2002-06-14
    sbb   960D/B1F423E7  created: 1999-06-15 expires: 2002-06-14
    (1)  Chloe (Jester) <chloe@cyb.org>
    (2)  Chloe (Plebian) <chloe@tel.net>

The information provided is similar to the listing for the public-key component. The keyword `sec` identifies the private master signing key, and the keyword `sbb` identifies the private subordinates keys. The user IDs from the public key are also listed for convenience.

## Key integrity

When you distribute your public key, you are distributing the public components of your master and subordinate keys as well as the user IDs. Distributing this material alone, however, is a security risk since it is possible for an attacker to tamper with the key. The public key can be modified by adding or substituting keys, or by adding or changing user IDs. By tampering with a user ID, the attacker could change the user ID's email address to have email redirected to himself. By changing one of the encryption keys, the attacker would also be able to decrypt the messages redirected to him.

Using digital signatures is a solution to this problem. When data is signed by a private key, the corresponding public key is bound to the signed data. In other words, only the corresponding public key can be used to verify the signature and ensure that the data has not been modified. A public key can be protected from tampering by using its corresponding private master key to sign the public key components and user IDs, thus binding the components to the public master key. Signing public key components with the corresponding private master signing key is called self-signing, and a public key that has self-signed user IDs bound to it is called a certificate.

As an example, Chloe has two user IDs and three subkeys. The signatures on the user IDs can be checked with the command check from the key edit menu.

    chloe% gpg --edit-key chloe
    Secret key is available.

    pub  1024D/26B6AAE1  created: 1999-06-15 expires: never      trust: -/u
    sub  2048g/0CF8CB7A  created: 1999-06-15 expires: never
    sub  1792G/08224617  created: 1999-06-15 expires: 2002-06-14
    sub   960D/B1F423E7  created: 1999-06-15 expires: 2002-06-14
    (1)  Chloe (Jester) <chloe@cyb.org>
    (2)  Chloe (Plebian) <chloe@tel.net>

    Command> check
    uid  Chloe (Jester) <chloe@cyb.org>
    sig!	   26B6AAE1 1999-06-15	 [self-signature]
    uid  Chloe (Plebian) <chloe@tel.net>
    sig!	   26B6AAE1 1999-06-15	 [self-signature]

As expected, the signing key for each signature is the master signing key with key ID `0x26B6AAE1`. The self-signatures on the subkeys are present in the public key, but they are not shown by the GnuPG interface.

## Adding and deleting key components

Both new subkeys and new user IDs may be added to your keypair after it has been created. A user ID is added using the command adduid. You are prompted for a real name, email address, and comment just as when you create an initial keypair. A subkey is added using the command addkey. The interface is similar to the interface used when creating an initial keypair. The subkey may be a DSA signing key, and encrypt-only ElGamal key, or a sign-and-encrypt ElGamal key. When a subkey or user ID is generated it is self-signed using your master signing key, which is why you must supply your passphrase when the key is generated.

Additional user IDs are useful when you need multiple identities. For example, you may have an identity for your job and an identity for your work as a political activist. Coworkers will know you by your work user ID. Coactivists will know you by your activist user ID. Since those groups of people may not overlap, though, each group may not trust the other user ID. Both user IDs are therefore necessary.

Additional subkeys are also useful. The user IDs associated with your public master key are validated by the people with whom you communicate, and changing the master key therefore requires recertification. This may be difficult and time consuming if you communicate with many people. On the other hand, it is good to periodically change encryption subkeys. If a key is broken, all the data encrypted with that key will be vulnerable. By changing keys, however, only the data encrypted with the one broken key will be revealed.

Subkeys and user IDs may also be deleted. To delete a subkey or user ID you must first select it using the key or uid commands respectively. These commands are toggles. For example, the command key `2` selects the second subkey, and invoking key `2` again deselects it. If no extra argument is given, all subkeys or user IDs are deselected. Once the user IDs to be deleted are selected, the command deluid actually deletes the user IDs from your key. Similarly, the command delkey deletes all selected subkeys from both your public and private keys.

For local keyring management, deleting key components is a good way to trim other people's public keys of unnecessary material. Deleting user IDs and subkeys on your own key, however, is not always wise since it complicates key distribution. By default, when a user imports your updated public key it will be merged with the old copy of your public key on his ring if it exists. The components from both keys are combined in the merge, and this effectively restores any components you deleted. To properly update the key, the user must first delete the old version of your key and then import the new version. This puts an extra burden on the people with whom you communicate. Furthermore, if you send your key to a keyserver, the merge will happen regardless, and anybody who downloads your key from a keyserver will never see your key with components deleted. Consequently, for updating your own key it is better to revoke key components instead of deleting them.

## Revoking key components

To revoke a subkey it must be selected. Once selected it may be revoked with the revkey command. The key is revoked by adding a revocation self-signature to the key. Unlike the command-line option `--gen-revoke`, the effect of revoking a subkey is immediate.

    Command> revkey
    Do you really want to revoke this key? y

    You need a passphrase to unlock the secret key for
    user: "Chloe (Jester) <chloe@cyb.org>"
    1024-bit DSA key, ID B87DBA93, created 1999-06-28

    pub  1024D/B87DBA93  created: 1999-06-28 expires: never      trust: -/u
    sub  2048g/B7934539  created: 1999-06-28 expires: never
    sub  1792G/4E3160AD  created: 1999-06-29 expires: 2000-06-28
    rev! subkey has been revoked: 1999-06-29
    sub   960D/E1F56448  created: 1999-06-29 expires: 2000-06-28
    (1)  Chloe (Jester) <chloe@cyb.org>
    (2)  Chloe (Plebian) <chloe@tel.net>

A user ID is revoked differently. Normally, a user ID collects signatures that attest that the user ID describes the person who actually owns the associated key. In theory, a user ID describes a person forever, since that person will never change. In practice, though, elements of the user ID such as the email address and comment may change over time, thus invalidating the user ID.

The OpenPGP specification does not support user ID revocation, but a user ID can effectively be revoked by revoking the self-signature on the user ID. For the security reasons described previously, correspondents will not trust a user ID with no valid self-signature.

A signature is revoked by using the command revsig. Since you may have signed any number of user IDs, the user interface prompts you to decide for each signature whether or not to revoke it.

    Command> revsig
    You have signed these user IDs:
         Chloe (Jester) <chloe@cyb.org>
       signed by B87DBA93 at 1999-06-28
         Chloe (Plebian) <chloe@tel.net>
       signed by B87DBA93 at 1999-06-28
    user ID: "Chloe (Jester) <chloe@cyb.org>"
    signed with your key B87DBA93 at 1999-06-28
    Create a revocation certificate for this signature? (y/N)n
    user ID: "Chloe (Plebian) <chloe@tel.net>"
    signed with your key B87DBA93 at 1999-06-28
    Create a revocation certificate for this signature? (y/N)y
    You are about to revoke these signatures:
         Chloe (Plebian) <chloe@tel.net>
       signed by B87DBA93 at 1999-06-28
    Really create the revocation certificates? (y/N)y

    You need a passphrase to unlock the secret key for
    user: "Chloe (Jester) <chloe@cyb.org>"
    1024-bit DSA key, ID B87DBA93, created 1999-06-28

    pub  1024D/B87DBA93  created: 1999-06-28 expires: never      trust: -/u
    sub  2048g/B7934539  created: 1999-06-28 expires: never
    sub  1792G/4E3160AD  created: 1999-06-29 expires: 2000-06-28
    rev! subkey has been revoked: 1999-06-29
    sub   960D/E1F56448  created: 1999-06-29 expires: 2000-06-28
    (1)  Chloe (Jester) <chloe@cyb.org>
    (2)  Chloe (Plebian) <chloe@tel.net>

A revoked user ID is indicated by the revocation signature on the ID when the signatures on the key's user IDs are listed.

    Command> check
    uid  Chloe (Jester) <chloe@cyb.org>
    sig!	   B87DBA93 1999-06-28	 [self-signature]
    uid  Chloe (Plebian) <chloe@tel.net>
    rev!	   B87DBA93 1999-06-29	 [revocation]
    sig!	   B87DBA93 1999-06-28	 [self-signature]

Revoking both subkeys and self-signatures on user IDs adds revocation self-signatures to the key. Since signatures are being added and no material is deleted, a revocation will always be visible to others when your updated public key is distributed and merged with older copies of it. Revocation therefore guarantees that everybody has a consistent copy of your public key.

## Updating a key's expiration time

The expiration time of a key may be updated with the command expire from the key edit menu. If no key is selected the expiration time of the primary key is updated. Otherwise the expiration time of the selected subordinate key is updated.

A key's expiration time is associated with the key's self-signature. The expiration time is updated by deleting the old self-signature and adding a new self-signature. Since correspondents will not have deleted the old self-signature, they will see an additional self-signature on the key when they update their copy of your key. The latest self-signature takes precedence, however, so all correspondents will unambiguously know the expiration times of your keys.

Prev | Home | Next
Digital signatures |  | Validating other keys on your public keyring