Keys, subkeys and certificates
A key in the context of OpenPGP is actually a dataset containing User IDs, key material (both public and secret), metadata like the expiration date, preferences, certifications, lots of signatures and subkeys - to name a few. This dataset is not fixed, parts of it will (likely) be modified over time as new certifications might be added, User IDs might change and the expiration might be prolonged.
A key is needed for operations only the keyholder should be able to do, like decrypting or signing.
A certificate is the public representation of a key. It contains the same objects as the key with the exception of the secret key material. It is used for operations everyone should be able to do, like encryption or signature verification.
The objects within a key (and a certificate) can be signed using the secret key material of that key. This signifies that the keyholder either added the object herself or is content with it (like third party certifications). Keys and specifically certificates can also hold unsigned objects like additional User IDs or unapproved certifications.
Keys (and certificates) can and usually have subkeys. These are keys which are bound to another key (called primary key) by a subkey binding signature.
Subkeys introduce new key material to keys. With subkeys, a key can have different key material for different operations, thus avoids using the same material for (say) signing and encrypting. As certifications are always for the primary key, key rotation or revocation of subkeys doesn't effect them. That way updating your key material (or switching the cipher) doesn't impact the web of trust.
Subkeys do not have User IDs, these are associated with the primary key, but they (can) have an expiration date. They are also marked for an intended use case.
There is no limit to the number of subkeys a key can have. When generating a new key, sq
creates 3 subkeys with it. One for encryption, one for signing and one for authentication. The primary key is used to certify the authenticity of the subkeys. As subkeys have markings (flags) for their use case, an application (like sq
) can choose the right subkey for each operation. In some ways a key is a little PKI with the primary key acting as a certificate authority, certifying the subkeys.
You can have a peek into a key by:
$ sq key generate --own-key --userid alice --output - --rev-cert /dev/null --overwrite | sq packet dump
This example generates a key with a User ID of "alice", it specifies --output
, so that the generated key is not added to the key store. Using --output -
redirects the new key to STDOUT
, so that sq packet dump
can display it's contents. --rev-cert
and --overwrite
are needed as a side effect of --output
- in this example the result is discarded. --own-key
authorizes the new key to introduce certificates - you can try --shared-key
instead to see an unauthorized key.