An Advanced Introduction To GnuPG
An Advanced Introduction To GnuPG
Neal H. Walfield
I Main Matter 7
1 Introduction 9
1.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2 OpenPGP Criticism . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.1 Usability . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.2 Deniability . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.3 Forward Sececy . . . . . . . . . . . . . . . . . . . . . . 12
1.3 Modern Chat Protocols . . . . . . . . . . . . . . . . . . . . . . 12
1.4 Privacy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.5 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2 A GnuPG Primer 15
3 Cryptography 17
4 OpenPGP 19
4.1 Data at Rest . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.2 Unbuffered Message Processing . . . . . . . . . . . . . . . . . 22
4.3 OpenPGP Messages . . . . . . . . . . . . . . . . . . . . . . . . 22
4.4 Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.4.1 Hybrid Encryption . . . . . . . . . . . . . . . . . . . . 24
4.4.2 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.4.3 An Encrypted Message . . . . . . . . . . . . . . . . . 25
4.5 Signing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.5.1 Multiple Signers . . . . . . . . . . . . . . . . . . . . . 30
4.5.2 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.5.3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.6 Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3
4 CONTENTS
5 Passwords 51
5.1 Diceware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
6 Key Creation 53
6.1 Keys Aren’t Forever, Revocation Certificates Are . . . . . . . 54
6.1.1 Backing Up a Revocation Certificate . . . . . . . . . . 56
6.1.2 Publishing a Revocation Certificate . . . . . . . . . . 57
6.1.3 Recruiting Your Friends . . . . . . . . . . . . . . . . . 58
6.2 Tweaking, Twiddling, and Frobbing . . . . . . . . . . . . . . 59
6.3 Security Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . 60
6.3.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . 61
6.3.2 Creating a Key . . . . . . . . . . . . . . . . . . . . . . 63
6.3.3 Tails . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6.3.4 Initializing the Security Token . . . . . . . . . . . . . 67
6.3.5 Formatting the Removable Storage Devices . . . . . . 70
6.3.6 Generating the Keys . . . . . . . . . . . . . . . . . . . 71
6.3.7 Saving Your Progress . . . . . . . . . . . . . . . . . . . 73
6.3.8 Creating a Backup . . . . . . . . . . . . . . . . . . . . 74
6.3.9 Copying the Keys to the Security Token . . . . . . . . 75
6.3.10 Using the Keys . . . . . . . . . . . . . . . . . . . . . . 79
6.3.11 Saving the Revocation Certificate . . . . . . . . . . . . 81
6.3.12 Signing Keys with an Offline Master . . . . . . . . . . 81
6.4 Key Expiration . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
6.5 Subkey Rotation . . . . . . . . . . . . . . . . . . . . . . . . . 86
CONTENTS 5
7 Validating Keys 89
7.1 Key Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
8 GnuPG’s Architecture 91
8.1 gpg-connect-agent . . . . . . . . . . . . . . . . . . . . . . . . 92
8.2 signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.3 Assuan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.4 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.5 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
10 MUA Integration 99
10.1 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
10.2 Key Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
10.2.1 Revocation Certificate . . . . . . . . . . . . . . . . . . 104
10.3 Expiration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
10.4 Sending Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
10.4.1 Encryption Keys . . . . . . . . . . . . . . . . . . . . . 107
10.4.2 BCC Recipients . . . . . . . . . . . . . . . . . . . . . . 108
10.4.3 Saving Drafts . . . . . . . . . . . . . . . . . . . . . . . 109
10.4.4 Sent Mails . . . . . . . . . . . . . . . . . . . . . . . . . 109
10.4.5 Attaching Keys . . . . . . . . . . . . . . . . . . . . . . 109
10.5 Reading Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
10.5.1 Verifying Messages . . . . . . . . . . . . . . . . . . . . 110
10.5.2 Multi-part Emails . . . . . . . . . . . . . . . . . . . . . 113
10.5.3 Unencrypted Cache . . . . . . . . . . . . . . . . . . . 114
10.6 Key Management . . . . . . . . . . . . . . . . . . . . . . . . . 114
10.6.1 Key Discovery . . . . . . . . . . . . . . . . . . . . . . . 115
10.6.2 Key Verification . . . . . . . . . . . . . . . . . . . . . . 119
10.6.3 TOFU Conflict Resolution . . . . . . . . . . . . . . . . 121
10.6.4 Address Book Integration . . . . . . . . . . . . . . . . 122
12 Misc. 125
Part I
Main Matter
7
Chapter 1
Introduction
9
10 CHAPTER 1. INTRODUCTION
And, GnuPG is used for much more. People use it to protect data
archives, such as, backups. Software distributors sign their software with it
so that users can verify the integrity of a copy. Software developers use it to
sign their commits [5]. Organizations like Debian use it to secure internal
processes, such as making sure that a package upload is authorized, that
a vote is legitimate, and that a resignation is authentic. GnuPG is used to
secure Bitcoin wallets. And, GnuPG is used to sign documents.
1.1 History
Werner Koch started GnuPG in 1997 [6]. But GnuPG’s roots lies in PGP,
an encryption program originally written by Phil Zimmermann in 1991 [7].
Zimmermann was a long-time political activist, and wrote PGP to allow
activists to securely store messages on BBSs. Although the source code for
PGP was available, it wasn’t free software. Further, due to its use of RSA
for public-key cryptography, and IDEA for symmetric encryption, PGP was
patent encumbered.
Around 1996, Richard Stallman, the founder of the Free Software Foun-
dation, started appealing to people to create a free replacement for PGP.
Koch was inspired by this speech, and began working on g10, as he ini-
tially called it, which was a reference to the tenth Grundgesetz (the tenth
article of German the constitution), which enshrines the right to private
communication in Germany. Since the reference was considered to be too
obscure even for most Germans, the name GNU Privacy Guard or GnuPG,
for short, was adopted soon after the initial release.
As of 2017, Koch has continued to work on GnuPG as the lead devel-
oper. Since its start, the project has remained relatively small in terms of
the number of contributors. But, it was only in 2012 that Koch found him-
self working alone on GnuPG. Prior to that, the project received enough
funding to employ a couple of developers. In 2012, however, GnuPG had a
funding crisis, and Koch was forced to lay off his last employee. The fund-
ing situation continued to deteriorate, and in 2014 Koch had to take side
jobs unrelated to GnuPG to supplement his income. The situation was un-
sustainable, and Koch nearly gave up. But, friends convinced him to give
a donation campaign one last shot. The response was amazing. Not only
did he receive enough money to fund himself, but he pulled in 250,000 eu-
ros in small donations, and Stripe, Facebook, and the Linux Foundation
1.2. OPENPGP CRITICISM 11
each committed to donating about 50,000 euros per year. Along with some
partially unexpected contracts from the German BSI (the Federal Office for
Information Security), Koch was able to hire five additional developers.
Since then, development of GnuPG has accelerated, and new features
are being added on a regular basis. For instance, Koch developed a new
key discovery protocol called the Web Key Directory (WKD) [8], there is
a new trust model based on TOFU [9], there is official support for a set of
Python bindings, and the GnuPG developers are actively contributing to
Enigmail.
1.2.1 Usability
GnuPG is infamous for being hard to use. There is a fair amount of truth to
this. Nevertheless, the argument can be made that some of the difficulties
are required to achieve the support that it wants to achieve. For instance, it
is unavoidable that people who are worried about active attackers need to
think about authentication.
1.2.2 Deniability
Deniability (or deniable authentication) is the property that participants
in a conversation are able to authenticate each other’s messages, but they
cannot later prove this to a third party. In OTR, this works by having the
participants use a shared key for authenticating messages. Thus, if Alice
knows that she didn’t send a given authenticated message, then it must
have come from Bob. This style of authentication is fundamentally different
12 CHAPTER 1. INTRODUCTION
Over the past few years, the amount of activity in the encryption space
has increased dramatically. One of the catalysts was almost certainly the
Snowden leaks in June 2013, which not only motivated activists to do some
work, but also sensitized the public to the work’s importance. The area
that has probably received the most attention has been in the end-to-end
instant messaging space [10]. In particular, Signal, whose protocol has been
adopted by WhatsApp and Google Allo, has received very strong endorse-
ments from many prominent members of the InfoSec community. In fact,
the creators of the Signal protocol, Moxie Marlinspike and Trevor Perrin,
received the 2017 Levchin Prize at the Real World Crypto Symposium for
their work on the protocol.
The first major difference between OpenPGP and Signal is with respect
to their scope: signal focuses exclusively on real-time communication. This
narrow focus has a number of advantages in terms of security. In particular,
because communication is near real time, clients can negotiate parameters,
and it is possible to implement forward secrecy.
The other major difference is that OpenPGP focuses on a decentralized
model whereas these solutions tend to be walled gardens.
Signal uses the telephone number as a stable identifier, which is a strong
identifier.
https://jilliancyork.com/2017/08/03/i-dont-want-to-give-out-my-phone
Unlike GnuPG, these tools focus on real-time communication.
1.4. PRIVACY 13
1.4 Privacy
Address nothing to hide argument (that misses the point—everyone needs
privacy).
1.5 Scope
As its title suggests, this book is intended to be an advanced introduction
to GnuPG. It is explicitly not a reference manual. That is, the focus is not
on providing a highly technical, exhaustive guide covering exactly what
GnuPG does, but on gradually building up reader’s understanding. This
isn’t a value judgment; I believe that the two are complementary. And, my
hope is that after reading this book, you’ll have a solid understanding of
GnuPG’s internals, and can quickly use GnuPG’s reference manual to fill
in any required details.
14 CHAPTER 1. INTRODUCTION
Chapter 2
A GnuPG Primer
Examples of how to use gpg from the command line. Cover all of the im-
portant stuff and little to none of the esoteric options. E.g., generating an
online key, encryption, decryption, signing (inline or detached, clearsign),
verifying sigs, using the --edit-key interface. Adding a new user id.
Retiring a user id. Revoking a key. Signing someone’s key. Setting owner
trust. To armor or not to armor. Talk about importing and exporting keys
(including import and export filters). Some useful options.
Listing keys. Talk about the different search methods, e.g., prefixing @
to only search on the email.
Note that the right way to interact with GPG is not by screen scraping,
but by using gpg ’s --status-fd family of options or using the GPGME
library (or one of the many bindings), which remove the need to parse
--status-fd ’s output.
GPG is not a library. Talk about how this arose historically. The ten-
sion between providing a user interface and a programming API (former
wants convenience and implication, the latter not.) If you want to program
GnuPG then it is recommended that you use GPGME (or a binding built on
top of GPGME). A lower level interface is --status-fd. Has been around
since GnuPG 1.2. Example of why it is important to use this interface.
Groups/aliases
15
16 CHAPTER 2. A GNUPG PRIMER
Chapter 3
Cryptography
2. Example: most people have probably secured a zip file with a pass-
word.
3. How does that work? A simple approach is to imagine that each let-
ter is a number—A is 0, B is 1, C is 2, etc.—and then add (without
carrying—that is B (2) + Z (25) is 27, 27 is larger than 25, so do: 27 -
26 = 1 and take 1, i.e., do modular 26 arithmetic) the plain text to the
password. For instance consider the text "Meet me in Mantua" and
the password "tank boil throw letter".
MEETMEINMANTUA
• TANKBOILTHROWLETTER
....
If you know the password, you can easily reverse the process. But if
you don’t know the password, it is effectively impossible to recover
the plaintext given the ciphertext.
17
18 CHAPTER 3. CRYPTOGRAPHY
Note: if the password is at least as long the text and password is never
reused, this is referred to as a one-time pad and is the strong known
cryptography.
Explain signing.
Give other examples of how to explain public key cryptography.
Talk about threat modeling. What are you trying to protect? From
whom? What resources does the adversary have?
Chapter 4
OpenPGP
19
20 CHAPTER 4. OPENPGP
cent version was published in 2007 as RFC 4880. In 2015, the OpenPGP
community again reformed the OpenPGP working group to update the
specification [11].
The major goals for the next version are: the deprecation of some old
cryptographic algorithms like SHA-1, the introduction of some new cryp-
tographic algorithms based on elliptic curves, the addition of modern mes-
sage integrity protection in the form of something like Authenticated En-
cryption with Associated Data (AEAD), and an updated fingerprint format.
From an application programmer or user’s perspective, the working
group is not considering any major changes to the existing functionality;
they are primarily tightening the standard’s security and cleaning up a few
issues. This is true even of OpenPGP’s use of SHA-1, which, although
SHA-1 has many flaws, is still considered safe in the way that OpenPGP
uses it. That is, the changes are mostly to proactively—not reactively—
address weaknesses. In the words of the cryptographer Peter Gutmann,
"OpenPGP is still too good enough, there’s lots of things there that you can
nitpick but nothing really fatal, or even close to fatal" [12].
Another result of this decision to protect data at rest is that enabling for-
ward secrecy is not possible. Forward secrecy is an oft-lauded encryption
property, which prevents old encrypted messages from being decrypted if
the private key material is somehow compromised. Forward secrecy works
by mutating the key material in time. This scheme is fine if you never need
to decrypt old messages (as is typically the case for data transferred via
HTTPS, say), but doesn’t work at all for data at rest: if you want to decrypt
some data a week later, nevermind 10 years later, then you won’t be able to
if you’ve destroyed the private key material needed to decrypt it!
Perfect secrecy becomes even more complicated when a user has mul-
tiple devices, and all devices should be able to decrypt all messages.
OpenPGP doesn’t require that those devices somehow synchronize their
state after the private key is copied. But, some type of synchronization is
necessary for forward secrecy.
This raises the question: why have a single algorithm for both data in
motion and data at rest? The reason is that OpenPGP messages are often
not stored on a trusted host or even processed on a trusted host before being
stored. Consider email. Email is normally stored on a mail server. Even
after the mail is read, it remains on the mail server so that it can be read
later—potentially years later—on a different device. Thus, even assuming
that we could harden the security of the transport layer, it is not clear that
when the data is on a mail server, it is any less vulnerable than when it
is on the wire. In fact, data breaches at huge companies entrusted with
highly personal information from millions or even billions of users, such as
Yahoo! and Adult Friend Finder, are evidence that this is not the case.
22 CHAPTER 4. OPENPGP
4.4 Encryption
Most lay people and even many technical people assume that encryption
includes both an integrity check and authentication. In reality, encryption
by itself provides neither. This assumption perhaps arises due to condition-
ing from web browsers that not only conflate the two concepts, but treat a
connection secured with a self-signed certificate (which provides encryp-
tion, but not authentication), worse than those that use neither encryption
nor authentication. Additionally, in recent years, the term end-to-end en-
cryption has entered the mainstream. Although authentication is as impor-
tant as encryption in such systems, only encryption is mentioned. Be that
as it may, in OpenPGP, encryption and signing are separate, independent
operations.
24 CHAPTER 4. OPENPGP
4.4.2 Algorithm
Encryption in OpenPGP is a more or less standard hybrid encryption
scheme:
Packet Metadata
After listing the recipients, gpg outputs each packet. Each packet starts
with a line preceded by a #. This line shows some meta-data and the
packet’s header. Specifically, off indicates the offset of the packet within
the stream (this may not be accurate if there are compressed packets); ctb
(Content Tag Byte) includes the type of the packet, and some information
about the length of the packet (if this is a new format packet, then new-ctb
will appear towards the end of the line); tag is the type of the packet as ex-
4.4. ENCRYPTION 27
tracted from the ctb; and, hlen and plen are the header and body lengths,
respectively.
Sometimes the length of a packet is not known apriori. In this case,
plen will be 0 and indeterminate or partial will appear towards the
end of the line. This can occur when the data is streamed. indeterminate
means that all data until the end of the message belongs to this packet;
partial means the packet uses a chunked encoding method to encode
the data. The mechanism is similar to HTTP’s chunked transfer encoding
method. These encoding schemes are essential for supporting unbuffered
operations. See Section 4.2.2.4 of RFC 4880 for more details.
The first two packets in the message are PK-ESK packets. Each of these
holds the session key encrypted to a recipient. A PK-ESK packet also in-
cludes the 64-bit key ID of key that the session key was encrypt to.
If the key ID wasn’t included, then a recipient wouldn’t know whether
a given PK-ESK packet is encrypted with her or someone else’s key and
she would just have to try to decrypt them one by one. The obvious conse-
quence is that CPU cycles could be wasted. But, the more important reason
for avoiding a decryption attempt is that the user might have to unlock
multiple private keys. This can seriously impact an application’s usability.
Avoiding this UX annoyance by including the key ID in the PK-ESK has
a cost: it leaks meta-data. In practice, however, this information is exposed
in other places, e.g., at the SMTP level. Nevertheless, OpenPGP provides a
mechanism to hide this meta-data by setting the key ID to 0, which means
the key ID is speculative. Such key IDs are also referred to as wild card key
IDs.
A speculative key ID can be set in GnuPG by either specifying --throw-keyids
to clear the key ID field for all recipients, or --hidden-recipient in
place of --recipient to clear the key ID field for a particular recipient.
which contains 0 or more OpenPGP packets. This is not obvious from the
output of the --list-packets command, because it doesn’t show the
message’s tree structure. In this case, as is usually the case, the encrypted
data packet contains a single packet.
In OpenPGP, there are actually two types of encrypted data pack-
ets: Symmetrically Encrypted Data (SED) packets and Symmetrically En-
crypted Integrity Protected data (SEIP) packets. Although the former are
technically allowed by the standard, they are deprecated in practice due
to security concerns. For instance, it is possible to conduct an oracle at-
tack [13], and message extension and deletion attacks are also possible.
Consequently, when GnuPG encounters such a packet, it emits a warning.
GnuPG itself will not emit an encrypted packet without integrity protec-
tion.
We can see that the encrypted data packet includes integrity protec-
tion based on the packet’s tag (18 instead of 9), and the presence of the
mdc_method field in the above output.
+------+-----------------------------------+-------------+
| SEIP | Data (e.g. a literal data packet) | MDC hash |
+------+-----------------------------------+-------------+
\ / ^
‘--------------------------------------’ |
SHA-1 -----------------------------’
Compressed Packet
The compressed packet is nested within the encrypted packet. RFC 4880
specifies three different compression algorithms—ZIP, ZLIB, and BZip2—but
notes that they are optional. But even though compression is not required,
the RFC recommends it as an operationally useful (even if not rigorous)
form of integrity protection. Unfortunately, it has been shown that com-
pressing data prior to encryption can enable a chosen plaintext attack as
demonstrated by the CRIME on TLS, and BREACH on HTTP attacks.
Literal Data
Nested within the compression packet is a literal data packet. A literal data
packet contains not only the cleartext, but also a bit of metadata. In partic-
ular, a literal packet includes a formatting field, which indicates whether
30 CHAPTER 4. OPENPGP
the contents are binary data or text, and, in the latter case, whether the text
is believed to be UTF-8 formatted. The packet also contains a filename,
which is helpful when transferring a file, but is mostly ignored by GnuPG
in practice. And, it contains a timestamp. GnuPG sets the timestamp to the
current time when the packet is created (not the file’s mtime).
It is worth pointing out that when GnuPG is told to decrypt data
(gpg --decrypt), it doesn’t look for an encrypted message to decrypt,
but processes the message and tries to decrypt any encypted data that it
encounters. This subtle difference in behavior can be important, because if
GnuPG is told to decrypt a message with just a literal packet, it will simply
output the contents of the literal packet without warning the user that the
data was not actually encrypted. If a program uses the ability to decrypt a
message as an authentication check (e.g., in AutoCrypt’s Setup Message),
this behavior could lead to subtle attacks [15].
4.5 Signing
A signature provides cryptographic proof of both the signed data’s in-
tegrity and its authenticity—assuming the key used to sign the data is
trusted. That is, like a checksum, a signature can be used to make sure
that the data was not modified in transit. But unlike a checksum, a signa-
ture can also provide proof of the data’s origin (or at least, who signed off
on the message).
Note: the exact semantics of a signature are not defined by the standard.
This is done on purpose, and is viewed by the RFC editors as a feature, be-
cause, in the end, a signature’s meaning is determined by the actual human
users of the system—some will be more casual, and some will be more rig-
orous no matter what some standard says.
4.5.2 Algorithm
As in the encryption case, signing is a two-step process. First, the data to
be signed is hashed, and then the resulting hash is signed using public-
key cryptography. This two-step process is primarily motivated by perfor-
mance considerations.
32 CHAPTER 4. OPENPGP
3. Emit a signature packet, which includes the computed hash and the
signature.
As its name and the implementation suggest, the OPS packet makes
it possible to both create a signature, and verify it without buffering any
data. Since detached signatures are separate from the main OpenPGP mes-
sage, and OPS packets are effectively redundant, to generate a detached
signature, we just skip the first step. A limitation of detached signatures is
that they are over the entire OpenPGP message. Thus, nesting them is not
possible.
4.5.3 Example
Using our above example with inline signatures, the resulting message has
the following packets:
Compressed Packet
Again, we see that the message starts with a compression container. Since
the length of the data is not known apriori, the length is marked as
indeterminate, which means that the packet includes all of the data un-
til the end of the message.
________________________________________________
,-----> / \
+-----------+-----------+-----------+------+---------+---------+-------
| A, last=1 | B, last=0 | C, last=1 | Data | C’s sig | B’s sig | A’s si
+-----------+-----------+-----------+------+---------+---------+-------
| ‘----> \____/
‘------------------^
Working our way in, we see that last is set for A’s signature. Thus,
A’s signature is over everything immediately following the OPS packet up
4.5. SIGNING 35
to the matching signature packet. That is, it is over not only the data, but
also over B and C’s signatures. In contrast, in B’s OPS packet, last is
clear. Thus, B’s signature is over everything following the next OPS packet
with last set to 1, i.e., everything follow C’s OPS packet, up to, but not
including, the signature packet matching C’s OPS packet. That is, like C’s
signature, B’s signature is only over the literal data packet, not the data
packet and C’s signature.
Literal Data
The literal data packet contains the document to be signed. Of course, if the
signatures are nested, then the signature may include other data as well.
Signature Packet
The last two packets are the signature packets that match the OPS packets
at the start of the message. Like braces in a programming language, the first
OPS packet matches the last signature packet, and the second OPS packet
matches the second to last signature packet.
Except for the nesting information, the signature packet includes every-
thing present in the OPS packet as well as some additional meta-data, and
the actual signature.
The additional meta-data usually includes a timestamp (the OpenPGP
Signature Creation Time subpacket), and the user ID that was used to make
the signature (the OpenPGP Issuer subpacket). There are several other
pieces of metadata that can be added, but they are not usually set in this
context.
The issuer is usually used by a mail user agent to make sure the alleged
sender matches the signer. For instance, Romeo might have verified his
father’s key, but his father might try to trick him by sending him an email
that appears to be from Juliet. Because he knows that Romeo always checks
a signature’s validity, he could just sign the message with his own key. If
the mail user agent only shows whether a signature is valid, then Romeo
might be tricked. Making sure the from header matches the issuer catches
this attack.
36 CHAPTER 4. OPENPGP
4.6 Keys
As mentioned above, OpenPGP messages are not only used to transport
documents, but are also used to transport keys and key signatures.
In OpenPGP, a so-call key is a lot more than just a public and private
key pair. Modern OpenPGP keys normally include at least two key pairs
as well as a fair amount of meta-data.
1. Encryption
2. Signing
3. Certification
4. Authorization
4.6. KEYS 37
the user has one signing-capable key per device and revokes just the single
signing-capable subkey that was compromised, then the attacker will be
thwarted and only signatures created using that key will fail to verify after
it has been revoked.
4.6.3 Example
The following example shows Romeo’s key. This key was created by
GnuPG using the default parameters. Thus, it has a primary key, which
is signing- and certification-capable, and a single subkey, which is encryp-
tion capable.
The public key packet normally comes first. It just contains a minimum
amount of information: the public key algorithm (algo), the public key
parameters (pkey), the creation time (created), and the expiry time
(expires). Although the --list-packets output shows the key ID,
this is not included in the packet; it is shown as a matter of convenience.
Including it in the packet would be redundant, because it is derived from
the creation time and the public key parameters.
In the above listing, there is no self-signature for the public-key packet.
The parameters are, however, protected by the self-signature over each user
ID packet, which is over not only the user ID packet, but also the primary
key. It is possible to make signatures just over the primary key. But, this is
typically only used in the case of key revocation.
Not using a self-signature for the key means that meta-data like user
preferences needs to be stored someplace else. By convention, they are
stored in a user ID’s self-signature. Consequently, if you have multiple
user IDs, you could have multiple sets of conflicting preferences. This is
actually by design: the relevant preferences are determined by how the
key is addressed, which allows different sets of preferences for different
environments. So, if you have two user IDs, one for work, and one for
home, when someone uses your key to encrypt to your work email address,
the preferences are taken from the work user ID. If the caller just specifies
the key ID, then the preferences are taken from the so-called primary user
ID. (The primary user ID is the user ID with the primary user ID flag set in
its self-signature. If there are no user IDs that have this flag set or multiple
user IDs, then RFC 4880 recommends using the user ID with the newest
self-signature.) Thus, because it is reasonable to have different preferences
for different user IDs, if the intended user ID is known, it—and not the key
ID—should be used to address the key.
By convention, self-signatures immediately follow the packet that they
certify. As such, any direct key signatures would immediately follow the
public key prior to any user ID or subkey packets. In practice, this is not
always the case due to implementation bugs or malicious intent. Thus,
on import, GnuPG will attempt to fix any out-of-order packets. This can
involve some overhead, but this additional overhead is only incurred if the
packets are actually out of order.
When some meta-data is changed, a new self-signature is created. Since
4.6. KEYS 41
data that is publish can’t easily be deleted, OpenPGP treats the key as an
append-only log. The result is that a user ID packet, for instance, might
have multiple self signatures.
In general, if there are multiple self-signed packets for a given packet,
only the newest one is used. One important exception is for revocation cer-
tificates and any designated revoker settings: it is necessary to respect these
even if a later self signature would somehow override them, because this
capability could be used by an attacker to invalidate a revocation, which
would effectively make revocations of compromised keys impossible.
User ID Packet
User IDs are stored between the public key and any subkeys. In this exam-
ple, the key only contains a single user ID.
A user ID packet just contains a single value: a free-form string. By con-
vention (per the RFC), this string is an RFC 2822-style mailbox, i.e., a UTF-8
encoded string of the form Name <[email protected]> (Comment).
Normally, a user ID doesn’t require a comment, and, like Romeo’s
key, most keys don’t have one. Nevertheless, even though comments can
(rarely!) be useful for advanced users, it is recommended that most tools
not offer users the option to set it, because most people don’t understand
what they are for.
There are two main uses for comments: to distinguish security levels
and roles. Thus, if a user wants to have two OpenPGP keys associated
with a given email address, one for low-security communication, which
is stored directly on the device thereby allowing immediate decryption,
and one for high security communication, which is, say, stored on an air-
gapped computer and therefore may introduce a long delay if the user is
not near the air-gapped computer, comments along the lines of "day-to-day
key" and "high security key," respectively, might be appropriate. Similarly,
if a developer has a key that is only used for signing commits and releases,
a reasonable comment on that key could be "dist sig". Daniel Kahn Gill-
mor takes an even more conservative stance, and argues that even these
comments are probably unnecessary [18].
It is also possible to use an image as a user ID. In such cases, the image
is stored in a so-called user attribute packet. One problem with images
is that they can be fairly large. Since images like old signatures can’t be
deleted once they are published, and they are downloaded whenever a key
42 CHAPTER 4. OPENPGP
is only one flag defined, which indicates that the OpenPGP implementa-
tion supports the MDC system. And, keyserver preferences is a set
of flags indicating how the key server should handle the key.
With the exception of the issuer key ID, all of the subpackets are
prefixed with hashed. This indicates that this data is part of the signed
data. Subpackets that are not hashed are considered advisory, because an
attacker may modify them without detection in transit.
There is also a Preferred Key Server subpacket. But, to avoid leaking
metadata, GnuPG ignores this option by default.
The public subkey packets follow the user ID packets. Other than their
type, these packets are effectively identical to the public key packet.
4.7.2 Confidence
When someone verifies a key, she doesn’t always have the same degree of
confidence that the verification is correct. For instance, when Romeo signs
Juliet’s key, he is almost certainly convinced that Juliet really controls the
4.7. KEY SIGNING 45
stated key. On the other hand, if Romeo is at the pub and meets Iago, and
he asks him to sign his key, Romeo is almost certainly less confident that
Iago controls the stated key. This is the case even if Iago shows him his
government issued identification papers. And, it is also the case if he sends
an encrypted email to the email address in Iago’s user ID, and receives a
signed reply with a shared secret code.
OpenPGP provides a mechanism for expressing different degrees of
confidence in the form of three confidence levels ranging from "the person
said she controls the key" to "I’m confident she controls the stated key" as
well as a generic, "no comment," level. Other than completely ignoring the
weakest certification level, this information is not included in web of trust
calculations by GnuPG. Thus, for all intents and purposes, it is just gratu-
itous meta-data. As such, it is better to always use a generic certification
level [19]. This is what GnuPG does by default.
4.7.5 Example
The following example shows Juliet’s key including Romeo’s signature of
her key.
The listing follows the usual format described above. The first packet
is the public key packet, which is followed by a user ID packet and its self
signature. And, at the end comes the subkey key and its self signature.
There is one small difference, however. In this listing, Juliet’s user
ID is followed by not one, but two signatures. And, the second one is
not a self-signature, but Romeo’s certification signature: we can see from
the issuer fpr subpacket that Romeo, not Juliet, created this signature.
There are two important things to observe here.
First, Romeo’s signature is associated with Juliet’s key, not his key. Once
it is clear that the signature says something about Juliet’s key and not
Romeo’s, this makes sense. Nevertheless, many beginners don’t under-
stand this and think that they somehow own the signature. Unfortunately,
this arrangement can lead to denial of service attacks. For instance, vandals
could create many signatures on a particular key so that it becomes so large
that it can’t be imported.
Second, certification signatures are associated with user IDs and not
with keys. This avoids bait-and-switch type attacks. Consider Paris who
convinces Romeo to sign his key. If Romeo signed the key, and not the
user ID, then Paris could simply revoke the user ID and replace it with
another, say, Juliet’s. Since Romeo would still consider the key to be valid,
Paris could possibly trick him into believing a message from the key is from
Juliet.
4.8 Revocations
If a key has been compromised or simply retired, it is essential to revoke it
so that other people don’t accidentally use it. It is also important to revoke
a user ID if the identity is no longer valid, e.g., when leaving an organiza-
tion, but keeping the same key. Occasionally, it can be useful to revoke a
user ID certification. For instance, you should revoke a certification if: you
find out that you signed the wrong key; the person who controlled the key
somehow lost control of it (e.g., he forgot the password, and doesn’t have a
revocation certificate); or, you find out that you signed an impostor’s key.
The following example shows what Juliet’s key looks like when she re-
vokes her own key (the output has been truncated):
4.9. NOTATIONS 49
4.9 Notations
RFC 4880 allows signatures to contain arbitrary data. This mechanism can
be extremely useful for extending the OpenPGP system. But, despite its
availability, they aren’t generally used. One example of how they could
be used was considered by the Debian project, which thought about using
50 CHAPTER 4. OPENPGP
4.10 Summary
This chapter has presented the important details of the OpenPGP standard.
This introduction wasn’t intended for someone who is planning to write an
OpenPGP parser, but to provide a rough overview of the system. Many de-
tails have been omitted, as well as several minor features (yes, for better or
worse, OpenPGP is that feature rich). For those looking for more informa-
tion, the RFC is probably the best place to start: it is highly readable, and
this introduction should hopefully make it easy to navigate.
Chapter 5
Passwords
What are passwords used for (symmetric encryption and protecting private
key). Passwords are not used to protect asymmetric encryption. The reason
for having a password is to protect the key if the device is compromised
(e.g., malware or stolen). Thus, a weak password does not mean weak
transport security; the security of the transport is the e.g. RSA encryption.
If threat model is typical of a private individual, then using a password
manager and a relative weak password is acceptable.
How to generate a strong password: need to be able to measure entropy.
Long passphrase doesn’t mean anything: if it is a line from a song, it is
probably weak. NSA probably tries all of Wikipedia in various forms in
the first few hours of trying to crack your password. The only secure way
is to use diceware.
Snowden: "Assume your adversary is capable of one trillion guesses
per second." To withstand one year, need 65 bits of entropy! How to mea-
sure a password’s entropy? Need a random password. But that’s impossi-
ble to memorize. Unless we encode it smartly!
5.1 Diceware
Encode using a simple word list
51
52 CHAPTER 5. PASSWORDS
Examples:
1. able
2. about
3. above
Word lists: Diceware (8k). PGP Biometric word list (512). Voice of
America’s simple English word list (1.5k)
Chapter 6
Key Creation
Today, creating an OpenPGP key could hardly be easier or less error prone.
It’s as simple as thinking of a password and using gpg ’s --quick-gen-key
command:
Continue? (Y/n) y
...
gpg: revocation certificate stored as
’/home/jc/.gnupg/openpgp-revocs.d/98DB84C56F56DB5CF4733CCDEACAE136B8AF8CC2.rev
public and secret key created and signed.
53
54 CHAPTER 6. KEY CREATION
If you have multiple email addresses, then it is useful to also add them
to your key if they are in the same trust domain. (For instance, work and
private email should often be kept separate.) This can be done just as
painlessly using the --quick-add-uid option:
For most users, the only important thing left to do is to backup the
revocation certificate (this is explained in the next section), and publish the
key, so that others can find it:
For users with stronger security requirements—those users who are not
just worried about protecting their privacy—we recommend that they use a
security token instead of an online key so that if the device is compromised,
an attacker cannot get access to the secret key material. This is actually very
easy: any program can normally access any file. Thus, using an online key,
it is necessary to trust all programs that run on your system. Although
setting up a security token—the focus of Section 6.3—is more work, the
day-to-day use of a security token is no more complicated than an online
key.
If you are replacing an existing key, then it is strongly recommended
that you have the old key sign the new one, and the new key sign the old
one so that there is strong, machine readable evidence that the two keys are
controlled by the same party. This information is used by gpg in the TOFU
trust model, for instance, to avoid spurious conflicts.
Even if the user doesn’t have a QR code scanner installed on her camera,
it is possible to decode it later. This can be done, for instance, using ZBar,
which is available on Debian as part of the zbar-tools package. Because
the user probably won’t know what the QR code is for after a few weeks,
6.1. KEYS AREN’T FOREVER, REVOCATION CERTIFICATES ARE 57
it is essential to add text next to the QR code to explain that the QR code
contains a revocation certificate. The main security problem here is that
many phones automatically backup data to the cloud, and, as above, the
provider needs to be trusted to not publish it.
It is also reasonable to print the revocation certificate. Paper, for in-
stance, has much better archival properties than many digital storage medi-
ums, such as CD-ROMs. This can either be in text form (but this form is a
pain to reenter) or as a QR code. Unfortunately, printers are no longer as
secure as they once were: to simplify printing, some local printers are ac-
cessed via the cloud! But, even if this is not the case, in the very least, most
are connected to the internet, and don’t receive software updates. But, as
before, the damage that an attacker who has a revocation certificate can
cause is limited.
...
To avoid an accidental use of this file, a colon has been inserted
before the 5 dashes below. Remove this colon with a text editor
58 CHAPTER 6. KEY CREATION
iQE2BCABCAAgFiEEmNuExW9W21z0czzN6srhNrivjMIFAlmNo+4CHQAACgkQ6srh
...
sec rsa2048/B003B1463C7B41BE
created: 2017-08-11 expires: 2019-08-11 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/50A1A6C84DBDEA6F
created: 2017-08-11 expires: never usage: E
[ultimate] (1). Romeo Montague <[email protected]>
gpg> addrevoker
Are you sure you want to appoint this key as a designated revoker? (y/N) y
This key may be revoked by RSA key EACAE136B8AF8CC2 Juliet Capulet <juliet@rise
sec rsa2048/B003B1463C7B41BE
created: 2017-08-11 expires: 2019-08-11 usage: SC
trust: full validity: full
ssb rsa2048/50A1A6C84DBDEA6F
created: 2017-08-11 expires: never usage: E
[ full ] (1). Romeo Montague <[email protected]>
gpg> quit
Save changes? (y/N) y
Now, Juliet can generate a revocation certificate for Romeo’s key using
gpg ’s --generate-designated-revocation command. The result-
ing revocation certificate is just like a normal revocation certificate. So, as
above, Juliet would import this certificate, and then publish Romeo’s key
to cause it to be revoked.
tography. But, larger key sizes have a cost. In particular, verifying a sig-
nature generated by a 4096-bit RSA key doesn’t take twice as long as a
2048-bit RSA key, but orders of magnitude longer. So, the question is: does
the stronger cryptography actually increase the system’s security? Bruce
Schneier argues that the Snowden leaks provide strong evidence that the
NSA has not broken strong cryptography: when the NSA wants to access
someone’s data, they compromise the infrastructure and the endpoints,
which is more costly, and more likely to be noticed [21]. Assuming Schneier
is correct, since the strongest potential adversary in the world isn’t break-
ing strong cryptography, further increasing the strength of the cryptogra-
phy will not increase the system’s security. Instead, to increase the system’s
security, it is better to protect the endpoint, and improve the user’s opera-
tional security.
There are several things that can be done to better protect an endpoint.
These include encrypting the storage device, using a good password for
logging in, enabling a screen locker, promptly installing system updates,
and avoiding malware. The next step is to better protect the cryptographic
keys. This can be done by using a security token, which is a small piece of
hardware that stores the cryptographic keys, and performs the basic cryp-
tographic operations. In this way, if the end point is compromised, the keys
are still safe. Although any data that was decrypted while the adversary
controlled the computer could have been recovered.
For those few cases where it is necessary to override some defaults, it is
still possible to use the --key-gen command or --full-key-gen com-
mand. And, it is also possible to modify a key using gpg ’s --edit-key
interface.
gpg also provides an interface for batch operations. See the "Unat-
tended key generation" chapter of the GnuPG manual for details.
6.3.1 Hardware
There are a variety of security tokens that support OpenPGP. These have
different advantages and disadvantages in terms of the degree to which
they respect the user’s freedom, their security properties, their feature
sets, and their commercial availability. Below, we introduce a few that are
known to work well with GnuPG.
62 CHAPTER 6. KEY CREATION
OpenPGP Smartcard
The OpenPGP smartcard has been around since 2003. Although the soft-
ware is proprietary, the specification is freely available and usable without
constraints [22], and it has become the de facto interface for interacting with
OpenPGP security tokens.
The main distributor is Kernel Concepts. They sell them to end
users in their online shop, and they ship worldwide (https://www.
floss-shop.de/en). These smartcards are relatively inexpensive. At
the time of this writing, the FLOSS Shop sells them for 16.40 euros. But,
because most systems don’t include a smartcard reader, this hardware also
needs to be purchased. Depending on the required features, in particular,
whether an external PIN entry pad is desired, a smartcard reader currently
costs between 20 euros and 50 euros.
Gnuk
Nitrokey
YubiKey
If you are going to take the trouble to use a smartcard to separate your
secret keys and your main system, then you can’t use your main system to
manage your keys.
There are two ways around this: you can either use a dedicated offline
computer, or a live CD. The former is more secure, particularly, if you are
willing to completely cut off its network access (i.e., air gap it by removing
all network cards, bluetooth module, etc.). Given that used IBM Thinkpads
are readily available for under 50 euros, this is the preferred solution. That
said, for the majority of people who have modest security requirements,
managing keys from a live CD that is booted from their main computer is
reasonable.
Unfortunately, most live CDs are not appropriate for working with of-
fline keys. Tails, however, is a GNU/Linux distribution that takes the nec-
essary precautions. First, Tails starts as few services as possible to reduce
the attack surface, and, with one clearly marked exception, it doesn’t allow
outbound network access except over Tor. And, when Tails shuts down, it
wipes the system’s memory. This is essential to make sure the keys are not
accidentally exposed to an attacker. This protection is not just necessary to
prevent cold boot attacks [25], which only those who require the highest
levels of security have to worry about, but also to prevent the system af-
ter it restarts from accessing, and perhaps accidentally leaking the keys in
uninitialized memory.
Whether you use a dedicated computer or reboot your normal com-
puter into Tails, you need:
• A security token,
It doesn’t matter whether the storage devices are USB keys, SD cards,
hard drives, or something else. The important bit is that your computer can
6.3. SECURITY TOKENS 65
boot from the one for Tails, and the security token, and the storage devices
can all be attached to the computer at the same time.
6.3.3 Tails
Tails is available from https://tails.boum.org/. The key used to sign
the distribution is:
A490 D0F4 D311 A415 3E2B B7CA DBB8 02B2 58AC D84F
First, download the ISO image, and the corresponding signature file.
The latest version is linked to from https://tails.boum.org/install/
download/openpgp/, and the files are named like tails-amd64-VERSION.iso
and tails-amd64-VERSION.iso.sig.
Next, verify the signature. To do this, you need to first fetch the afore-
mentioned key:
$ gpg -k 79192EE220449071F589AC00AF292B44A0EDAA41
pub rsa4096/0xDBB802B258ACD84F 2015-01-18 [C] [expires: 2018-01-11]
Key fingerprint = A490 D0F4 D311 A415 3E2B B7CA DBB8 02B2 58AC D
-----------------------------------------------
uid [ undef ] Tails developers (offline long-term id
uid [ undef ] Tails developers <[email protected]>
sub rsa4096/0x98FEC6BC752A3DB6 2015-01-18 [S] [expires: 2018-01-11]
sub rsa4096/0x3C83DCB52F699C56 2015-01-18 [S] [expires: 2018-01-11]
sub rsa4096/0xAF292B44A0EDAA41 2016-08-30 [S] [expires: 2018-01-11]
Note: when you try this, you might see a different signing key. This
is okay. What is important is that the main key is correct in the sense that
the fingerprint matches: the user ID is not enough to prove the download’s
authenticity; creating a key with an arbitrary user ID, and uploading it to
a key server is easy. By rotating keys, the Tails developers can reduce the
amount of time that an undetected compromise of the signing key is useful
to an attacker.
If gpg --verify indicates that the signature is bad, or gpg -k indi-
cates that the signing key is not associated with A490D0F4D311A4153E2BB7CADBB802B258AC
then there is a problem with the download. You should first try again from
a different network. If the problem persists, seek help from an expert. Since
Tails is used by people who are trying to protect sensitive information,
there are bound to be copies that have been modified to include malware;
do not use the ISO image if you (or someone you trust) can’t verify it.
Assuming the data is okay, it is now possible to copy the Tails ISO to a
USB key. This can be done using dd:
like system with gpg already installed, which these instructions take for
granted.
$ gpg --card-status
Reader ...........: 04E6:E003:21251019201732:0
Application ID ...: D276000124010201000500002D9D0000
Version ..........: 2.1
Manufacturer .....: ZeitControl
Serial number ....: 00002D9D
Name of cardholder: [not set]
Language prefs ...: de
Sex ..............: unspecified
URL of public key : [not set]
Login data .......: [not set]
Signature PIN ....: forced
Key attributes ...: rsa2048 rsa2048 rsa2048
Max. PIN lengths .: 32 32 32
PIN retry counter : 3 0 3
Signature counter : 0
Signature key ....: [none]
Encryption key....: [none]
Authentication key: [none]
General key info..: [none]
$ gpg --card-edit
...
gpg/card> admin
Admin commands are allowed
gpg/card> factory-reset
gpg: OpenPGP card no. D276000124010200FFFE50FF6C060000 detected
gpg: This command is not supported by this card
$ gpg-connect-agent
/hex
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 e6 00 00
scd apdu 00 44 00 00
The first four lines after the /hex directive enter a bad user PIN.
The next four enter a bad admin PIN. Then, the last two lines terminate,
and reactivate the card, respectively. After removing the security token
and reconnecting it, it should be reset. You can verify this by running
gpg --card-edit, checking that the card contains no keys, and then us-
ing the verify subcommand to make sure the user PIN has been reset to
the default (normally 123456).
6.3. SECURITY TOKENS 69
Next, we need to change the default PINs. The OpenPGP card has two
PINs: a user PIN and an admin PIN. The user PIN is used on a day-to-day
basis to authorize decryption and signing; the admin PIN allows adding
new keys, among other things. The admin PIN should not be used on the
main computer, and it should be different from the user PIN. The default
PINs are usually 123456 and 12345678, respectively.
To change the PINs, we need to first enable admin mode. Then, we can
use the passwd command to change each PIN. GnuPG will prompt you to
enter the old PIN and the new PIN. If you are using a PIN pad, this can be
confusing: you need to enter the new PIN twice.
$ gpg --card-edit
...
gpg/card> admin
Admin commands are allowed
gpg/card> passwd
gpg: OpenPGP card no. D276000124010201000500002D9D0000 detected
1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit
Your selection? 1
PIN changed.
1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit
Your selection? 3
PIN changed.
1 - change PIN
70 CHAPTER 6. KEY CREATION
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit
Your selection? q
You’ll almost certainly want to write the admin PIN down someplace.
Given how often it is normally used, most people forget it. A good place
to hide it is at a physically different location from where you hide the USB
key with your secret keys on it.
Unfortunately, most security tokens don’t store the public key or have any
storage space on them. Thus, to transfer the public key to the main com-
puter, we need a third storage device.
This time, when partitioning the file system, name the file system
sneaker-net, and use an unencrypted ext4 file system. After it has been
formatted, mount the partition. The file system will be mounted under
/media/amnesia/sneaker-net.
signing subkey, it is only necessary to revoke the signing subkey, and create
a new one.
The following transcript shows how to create a certification-capable
master key, and three subkeys. Note that we first change gpg ’s home di-
rectory to be on the encrypted file system.
$ mkdir -p /media/amnesia/secret-keys/gnupg
$ export GNUPGHOME=/media/amnesia/secret-keys/gnupg
$ gpg --quick-gen-key ’Juliet Capulet <[email protected]>’ rsa cert 2y
gpg: WARNING: unsafe permissions on homedir ’/media/amnesia/secret-keys
gpg: keybox ’/media/amnesia/secret-keys/gnupg/pubring.kbx’ created
gpg: /media/amnesia/secret-keys/gnupg/trustdb.gpg: trustdb created
gpg: key E9794A89BDB70380 marked as ultimately trusted
gpg: directory ’/media/amnesia/secret-keys/gnupg/openpgp-revocs.d’ crea
gpg: revocation certificate stored as ’/media/amnesia/secret-keys/gnupg
public and secret key created and signed.
Note that this key cannot be used for encryption. You may want to use
the command "--edit-key" to generate a subkey for this purpose.
pub rsa2048 2017-08-14 [C] [expires: 2019-08-14]
635D6A0EA043F835A1FFD9A7E9794A89BDB70380
uid Juliet Capulet <[email protected]>
Listing the key, we can see that we got the desired structure:
$ gpg -K
gpg: WARNING: unsafe permissions on homedir ’/media/amnesia/secret-keys
gpg: checking the trustdb
gpg: marginals needed: 3 completes needed: 1 trust model: pgp
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: next trustdb check due at 2019-08-14
/media/amnesia/secret-keys/gnupg/pubring.kbx
--------------------------------------------
sec rsa2048 2017-08-14 [C] [expires: 2019-08-14]
635D6A0EA043F835A1FFD9A7E9794A89BDB70380
6.3. SECURITY TOKENS 73
Because the OpenPGP card doesn’t include the public key, it is neces-
sary to use the sneaker net storage device to transfer the public key from
the offline machine to the online machine:
If your Tails machine is connected to the Internet, you could transfer the
public key by uploading it to a key server or a website, and then retrieving
it with the online machine.
$ rm -rf /media/amnesia/secret-keys/gnupg
$ mkdir /media/amnesia/secret-keys/gnupg
$ gpg --import secret-keys.gpg
gpg: WARNING: unsafe permissions on homedir ’/media/amnesia/secret-keys/gnupg’
gpg: keybox ’/media/amnesia/secret-keys/gnupg/pubring.kbx’ created
gpg: /media/amnesia/secret-keys/gnupg/trustdb.gpg: trustdb created
gpg: key E9794A89BDB70380: public key "Juliet Capulet <[email protected]>" impor
gpg: key E9794A89BDB70380: secret key imported
gpg: Total number processed: 1
gpg: imported: 1
gpg: secret keys read: 1
gpg: secret keys imported: 1
$ gpg --edit-key [email protected]
...
74 CHAPTER 6. KEY CREATION
Please decide how far you trust this user to correctly verify other use
(by looking at passports, checking fingerprints from different sources,
Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y
$ cp /media/amnesia/secret-keys/gnupg/openpgp-revocs.d/635D6A0EA043F835
> /media/amnesia/sneaker-net
Backing up the secret key is more difficult, because its security require-
ments are much higher given the consequences of a compromise. Paperkey
is a relatively convenient way to back up secret key material on paper. To
do this, you have to to attach and configure a printer. Make sure the printer
is not connected to the network, and reset the printer afterwards.
# a) 1 octet:
Version of the paperkey format (currently 0).
# b) 1 octet:
OpenPGP key or subkey version (currently 4)
# c) n octets:
Key fingerprint (20 octets for a version 4 key or subkey)
# d) 2 octets:
16-bit big endian length of the following secret data
# e) n octets:
Secret data: a partial OpenPGP secret key or subkey packet as
# specified in RFC 4880, starting with the string-to-key usage
# octet and continuing until the end of the packet.
# Repeat fields b through e as needed to cover all subkeys.
#
# To recover a secret key without using the paperkey program, use the
# key fingerprint to match an existing public key packet with the
# corresponding secret data from the paper key. Next, append this secret
# data to the public key packet. Finally, switch the public key packet tag
# from 6 to 5 (14 to 7 for subkeys). This will recreate the original secret
# key or secret subkey packet. Repeat as needed for all public key or subkey
# packets in the public key. All other packets (user IDs, signatures, etc.)
# may simply be copied from the public key.
#
# Each base16 line ends with a CRC-24 of that line.
# The entire block of data ends with a CRC-24 of the entire block of data.
1: 00 04 63 5D 6A 0E A0 43 F8 35 A1 FF D9 A7 E9 79 4A 89 BD B7 03 80 1D7942
2: 02 B9 FE 07 03 02 E7 84 42 CB 86 E4 73 CA DB 47 A2 C0 4F 0A BB 57 2C46C8
3: 04 63 BF E6 11 52 C4 F3 7A BB 12 34 66 DB 79 5A 89 E1 C2 8D 2E 10 603062
4: 0B 3D 57 0A FD ED 8A 97 71 0B 51 EB 31 C4 02 28 C1 6E 64 18 B9 2C 8470F7
...
132: C5CD3A
Note: when you restore the key, you’ll still need the key’s passphrase.
Another way to backup the secret key is to copy it to another encrypted
storage device.
sec rsa2048/E9794A89BDB70380
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: ultimate validity: ultimate
ssb rsa2048/F8D8ED7BB1A2A8F6
created: 2017-08-14 expires: 2018-08-14 usage: E
ssb rsa2048/305A846803A91753
created: 2017-08-14 expires: 2018-08-14 usage: S
ssb rsa2048/300BA8EE1B5EDEED
created: 2017-08-14 expires: 2018-08-14 usage: A
[ultimate] (1). Juliet Capulet <[email protected]>
sec rsa2048/E9794A89BDB70380
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: ultimate validity: ultimate
ssb* rsa2048/F8D8ED7BB1A2A8F6
created: 2017-08-14 expires: 2018-08-14 usage: E
ssb rsa2048/305A846803A91753
created: 2017-08-14 expires: 2018-08-14 usage: S
ssb rsa2048/300BA8EE1B5EDEED
created: 2017-08-14 expires: 2018-08-14 usage: A
[ultimate] (1). Juliet Capulet <[email protected]>
gpg> keytocard
Please select where to store the key:
(2) Encryption key
Your selection? 2
...
gpg> key 2 # Select the second subkey.
6.3. SECURITY TOKENS 77
sec rsa2048/E9794A89BDB70380
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: ultimate validity: ultimate
ssb* rsa2048/F8D8ED7BB1A2A8F6
created: 2017-08-14 expires: 2018-08-14 usage: E
ssb* rsa2048/305A846803A91753
created: 2017-08-14 expires: 2018-08-14 usage: S
ssb rsa2048/300BA8EE1B5EDEED
created: 2017-08-14 expires: 2018-08-14 usage: A
[ultimate] (1). Juliet Capulet <[email protected]>
sec rsa2048/E9794A89BDB70380
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: ultimate validity: ultimate
ssb rsa2048/F8D8ED7BB1A2A8F6
created: 2017-08-14 expires: 2018-08-14 usage: E
ssb* rsa2048/305A846803A91753
created: 2017-08-14 expires: 2018-08-14 usage: S
ssb rsa2048/300BA8EE1B5EDEED
created: 2017-08-14 expires: 2018-08-14 usage: A
[ultimate] (1). Juliet Capulet <[email protected]>
gpg> keytocard
Please select where to store the key:
(1) Signature key
(3) Authentication key
Your selection? 1
...
gpg> key 3 # Select the third subkey.
...
gpg> key 2 # Deselect the second subkey.
...
gpg> keytocard
Please select where to store the key:
(3) Authentication key
Your selection? 3
78 CHAPTER 6. KEY CREATION
...
gpg> quit
Save changes? (y/N) n
Quit without saving? (y/N) y
At the end of the transcript, we explicitly do not save the changes. Sav-
ing the changes would cause the secret key material for the corresponding
subkey to be deleted. The reason for this is that the keytocard command
doesn’t copy, but moves the secret key material to the card. Saving with-
out quitting inhibits this side effect. In practice, this isn’t a problem if you
backed up the secret key material, as recommended above.
Using --card-status, we can see that the keys were successfully
loaded on to the security token:
$ gpg --card-status
Reader ...........: SCM Microsystems Inc. SPR 532 [Vendor Interface] (2
Application ID ...: D276000124010201000500002D9D0000
Version ..........: 2.1
Manufacturer .....: ZeitControl
Serial number ....: 00002D9D
Name of cardholder: [not set]
Language prefs ...: de
Sex ..............: unspecified
URL of public key : [not set]
Login data .......: [not set]
Signature PIN ....: forced
Key attributes ...: rsa2048 rsa2048 rsa2048
Max. PIN lengths .: 32 32 32
PIN retry counter : 3 0 3
Signature counter : 0
Signature key ....: A17A D462 C473 51AD D0E8 988B 305A 8468 03A9 1753
created ....: 2017-08-14 13:07:49
Encryption key....: C9CD 8F3D ECDE BB7E 720A 7CD9 F8D8 ED7B B1A2 A8F6
created ....: 2017-08-14 13:07:32
Authentication key: 9308 3590 BCD9 3CC5 044C BEAD 300B A8EE 1B5E DEED
created ....: 2017-08-14 13:08:04
General key info..: sub rsa2048/305A846803A91753 2017-08-14 Juliet Cap
sec rsa2048/E9794A89BDB70380 created: 2017-08-14 expires: 2019-08-1
6.3. SECURITY TOKENS 79
$ gpg -K 635D6A0EA043F835A1FFD9A7E9794A89BDB70380
sec# rsa2048/0xE9794A89BDB70380 2017-08-14 [C] [expires: 2019-08-14]
Key fingerprint = 635D 6A0E A043 F835 A1FF D9A7 E979 4A89 BDB7 0
uid [unknown] Juliet Capulet <[email protected]>
ssb> rsa2048/0xF8D8ED7BB1A2A8F6 2017-08-14 [E] [expires: 2018-08-14]
ssb> rsa2048/0x305A846803A91753 2017-08-14 [S] [expires: 2018-08-14]
ssb> rsa2048/0x300BA8EE1B5EDEED 2017-08-14 [A] [expires: 2018-08-14]
The # after the sec header for the master key means that the master
key is not available; the > next to the ssb keys means that the keys are on
a security token.
Looking at the above output, we also see that the key is not marked
as trusted. In order for certifications by this key to be respected, it is nec-
essary to mark the key as ultimately trusted. This can be done using the
--edit-key interface.
Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y
...
6.3. SECURITY TOKENS 81
Finally, you’ll also want to publish your key so that others can more
easily find it.
Note that this key cannot be used for encryption. You may want to use
the command "--edit-key" to generate a subkey for this purpose.
pub rsa2048/0xCD6AF594BAA8EF38 2017-08-14 [C] [expires: 2019-08-14]
Key fingerprint = 149D 0735 A25E 63B1 EC9F EEBD CD6A F594 BAA8 E
uid Juliet Capulet (certification key)
There are two things to note about this key. First, the user ID doesn’t in-
clude an email address. This is useful to prevent people who search the key
servers by email address from finding the wrong key. Although searching
a key server by email address is strongly discouraged, there is no need to
make such users’ lives worse than necessary. Second, the key only includes
a certification-capable key; there are no signing or encryption subkeys. This
prevents people from accidentally encrypting data to your secondary key,
or a misconfigured GnuPG from accidentally using it to generate a signa-
ture.
After creating the key, we need to sign it using the main key. This re-
quires transferring the public key to the offline computer.
$ export GNUPGHOME=/media/amnesia/secret-keys/gnupg
$ gpg --import /media/amnesia/sneaker-net/149D0735A25E63B1EC9FEEBDCD6AF
gpg: key CD6AF594BAA8EF38: public key "Juliet Capulet (certification ke
gpg: Total number processed: 1
gpg: imported: 1
$ gpg --edit-key 149D0735A25E63B1EC9FEEBDCD6AF594BAA8EF38
pub rsa2048/CD6AF594BAA8EF38
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: unknown validity: unknown
[ unknown] (1). Juliet Capulet (certification key)
6.3. SECURITY TOKENS 83
gpg> tsign
pub rsa2048/CD6AF594BAA8EF38
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: unknown validity: unknown
Primary key fingerprint: 149D 0735 A25E 63B1 EC9F EEBD CD6A F594 BAA8 EF38
1 = I trust marginally
2 = I trust fully
Your selection? 2
Your selection? 2
Your selection?
Are you sure that you want to sign this key with your
key "Juliet Capulet <[email protected]>" (E9794A89BDB70380)
It is also a good idea to have the certification key cross sign the main
key. (The -u option indicates what key to use for the signature. This is
useful if you have multiple keys.)
$ gpg -u 149D0735A25E63B1EC9FEEBDCD6AF594BAA8EF38 \
> --edit-key 635D6A0EA043F835A1FFD9A7E9794A89BDB70380
Secret key is available.
pub rsa2048/0xE9794A89BDB70380
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: ultimate validity: ultimate
ssb rsa2048/0xF8D8ED7BB1A2A8F6
created: 2017-08-14 expires: 2018-08-14 usage: E
card-no: 0005 00002D9D
ssb rsa2048/0x305A846803A91753
created: 2017-08-14 expires: 2018-08-14 usage: S
card-no: 0005 00002D9D
ssb rsa2048/0x300BA8EE1B5EDEED
6.4. KEY EXPIRATION 85
gpg> sign
pub rsa2048/0xE9794A89BDB70380
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: ultimate validity: ultimate
Primary key fingerprint: 635D 6A0E A043 F835 A1FF D9A7 E979 4A89 BDB7 0380
was issued:
Rotating keys is as simple as revoking the old keys, and generating new
subkeys. To revoke a subkey, it is necessary to use the --edit-key inter-
face, select the subkeys to revoke using the key subcommand, and use the
revkey subcommand to revoke the selected subkeys. This is illustrated
below:
sec rsa2048/E9794A89BDB70380
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: ultimate validity: ultimate
ssb rsa2048/F8D8ED7BB1A2A8F6
created: 2017-08-14 expires: 2018-08-14 usage: E
ssb rsa2048/305A846803A91753
created: 2017-08-14 expires: 2018-08-14 usage: S
ssb rsa2048/300BA8EE1B5EDEED
created: 2017-08-14 expires: 2018-08-14 usage: A
[ultimate] (1). Juliet Capulet <[email protected]>
gpg> key * # Select all keys. You can also use key N
# to select the Nth subkey.
sec rsa2048/E9794A89BDB70380
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: ultimate validity: ultimate
ssb* rsa2048/F8D8ED7BB1A2A8F6
created: 2017-08-14 expires: 2018-08-14 usage: E
ssb* rsa2048/305A846803A91753
created: 2017-08-14 expires: 2018-08-14 usage: S
ssb* rsa2048/300BA8EE1B5EDEED
created: 2017-08-14 expires: 2018-08-14 usage: A
[ultimate] (1). Juliet Capulet <[email protected]>
gpg> revkey
Do you really want to revoke the selected subkeys? (y/N) y
Please select the reason for the revocation:
0 = No reason specified
88 CHAPTER 6. KEY CREATION
sec rsa2048/E9794A89BDB70380
created: 2017-08-14 expires: 2019-08-14 usage: C
trust: ultimate validity: ultimate
The following key was revoked on 2017-08-15 by RSA key E9794A89BDB70380
ssb rsa2048/F8D8ED7BB1A2A8F6
created: 2017-08-14 revoked: 2017-08-15 usage: E
The following key was revoked on 2017-08-15 by RSA key E9794A89BDB70380
ssb rsa2048/305A846803A91753
created: 2017-08-14 revoked: 2017-08-15 usage: S
The following key was revoked on 2017-08-15 by RSA key E9794A89BDB70380
ssb rsa2048/300BA8EE1B5EDEED
created: 2017-08-14 revoked: 2017-08-15 usage: A
[ultimate] (1). Juliet Capulet <[email protected]>
Chapter 7
Validating Keys
89
90 CHAPTER 7. VALIDATING KEYS
GnuPG’s Architecture
91
92 CHAPTER 8. GNUPG’S ARCHITECTURE
use-tor, etc.
Give some details about the different sockets.
8.1 gpg-connect-agent
What it does (communicate with the different components). How to use it.
Fact that it exposes a command line interface. Use help to figure out what
to do.
Show how to script with gpg-connect-agent, e.g., shutting down a
server.
8.2 signals
Talk about how e.g. SIGUSR1 can be used to cause gpg-agent to dump
debugging information.
8.3 Assuan
Talk about Assuan. IPC protocol Pipe / socket based. Very simple, text-
based interface. No interface definition language (IDL). Show example of a
pinentry session calling getpin.
Can use gpg-connect-agent to connect to the running GPG Agent.
Assuan is a separate package from gpg. Anyone can use it.
8.4 Debugging
Due to the distributed nature of the architecture, it can be hard to figure out
what went wrong (error messages become more generic as they are passed
further along the stack).
watchgnupg helps. Tool for gathering log entries.
In gpg-agent.conf, add:
• log-file socket:///home/USER/.gnupg/S.log
8.5 configuration
Talk about gpg.conf, gpg-agent.conf, etc.
Talk about gpgconf.
94 CHAPTER 8. GNUPG’S ARCHITECTURE
Chapter 9
9.3 Backups
Don’t backup the RNG’s seed! Exclude .gnupg/random_seed from
backups!
9.4 ssh
Keys Instead of Passwords. Using keys means password is not sent to
server. Ever enter password for a different server? You’ve just disclosed
95
96 CHAPTER 9. GOOD PRACTICES AND TIPS
your password!
OpenSSH stores private keys on hard drive. Keys are protected by a
passphrase. Passphrase is cached by ssh agent.
GnuPG implements the ssh agent protocol. GnuPG can use keys stored
on a smart card.
GnuPG’s ssh agent: configuration:
Set SSH_AUTH_SOCK in .bashrc:
export SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh
$ ssh-add -L
ssh-rsa AAAAB3NzaC1...zyt cardno:000603016636
extra-socket /home/gpg/.gnupg/S.gpg-agent-remote
MUA Integration
99
100 CHAPTER 10. MUA INTEGRATION
• Very Strong Security: Some users turn to GnuPG, because they fear
targeted attacks from a nation state adversary including rubber-hose
cryptoanalysis (i.e., the use of torture to recover passwords). These
users should almost certainly use a security token, which the MUA
should help them configure, HTML should be disabled, and all op-
erations that could leak sensitive information should require explicit
confirmation. The MUA should also help these users implement for-
ward secrecy (by regularly rotating subkeys), provide a mechanism
to automatically purge old emails, and disable indexing encrypted
emails.
about their privacy, and mass surveillance. Other reasons include the
need to occasionally send a password by email, and a desire for pro-
tection from drive-by phishing expeditions (although since few or-
ganizations currently sign their email, this is more wishful thinking
than practical protection).
With few exceptions, the MUA should avoid interrupting these users
with security questions. One exception is when the user follows up
to an encrypted email, but the reply won’t be sent in an encrypted
manner. Since the sender encrypted the email, it might be for a good
reason and, consistent with the do no harm principle, the user should
not accidentally endanger her communication partner, or the subject
of the mail.
This doesn’t mean that the encryption should entirely disappear into
the background. The MUA should still help the user understand
what is going on, and allow the user to provide input, if desired.
For instance, like a web browser, the MUA should indicate whether a
message is secure. And, if the user clicks on the icon, she should get
more information, and have the option to verify her communication
partner’s identity. In other words, security should largely be opt-in.
The trade off that these profiles make is straightforward: someone who
requires more security is more sensitive to a mistake, and is more willing
to interact with the system to ensure this security. For people who have
lower security requirements, not only are these interactions annoying, they
can actually hurt security elsewhere: showing dialog boxes that are simply
clicked away results in habituation [29, 28].
Communication, of course, necessarily involves multiple parties. Thus,
if a user with high security requirements communicates with a user with
low security requirements, the casual user could accidentally compromise
the careful user by forgetting to encrypt an email. Thus, consistent with
the do-no-harm principle, it is important that even an implementation de-
signed for users with low security requirements not be too lax.
10.1 Integration
There are two basic ways to add GnuPG support to a MUA: it can be added
natively, or it can be added via a plug-in. KMail, and Claws are examples
102 CHAPTER 10. MUA INTEGRATION
of MUAs that have native GnuPG support; Enigmail, GPGTools, and gpgol
are examples of plug-ins.
One approach isn’t necessarily better than the other. But, the develop-
ment of plug-ins tends to be highly divorced from the actual development
of the MUA with the practical result that the needs of the plug-in are often
not sufficiently taken into account by the MUA developers. This has been
a problem for the Enigmail developers, for instance.
One common problem is controlling how messages are rendered: the
GnuPG support code needs a lot of control over this. This control is nec-
essary to prevent mimicry attacks. For instance, it is necessary to not only
show when a message is verified, but also prevent an attacker from craft-
ing a message that appears to be verified. One way to accomplish this is to
style not only the message, but also the chrome around the message.
The things that need to be added to a MUA for reasonable GnuPG sup-
port is not long: there needs to be a way to create a key, encrypt messages,
verify messages, and do some basic key management. But, all of these
things have numerous gotchas that can negatively impact both the user ex-
perience, and the security of the system. The point of this chapter is to
point out these issues to avoid making developers—or worse, their users—
rediscover these problems the hard way.
the sending email address, then the MUA should show the key creation
wizard. This significantly improves discoverability.
The key generation wizard should not only allow the user to generate
a new key, but also provide an option to import an existing one. When the
user enters or selects a user ID, the wizard should look for an existing key
with that email address both in the appropriate WKD, and on any config-
ured key servers. If there is a matching key, the wizard should ask the user
if she wants to import the key or really create a new one. Importing the key
might not be possible if the key is a fake, or if the user lost access to the key,
e.g., by formatting the computer, or forgetting the key’s passphrase. Both
are unfortunately rather common for novice users.
When the key generation wizard starts, the user ID should default
to the current identity. For instance, if the user has the email addresses
[email protected] and [email protected], and clicks on encrypt while
composing an email from [email protected], the wizard should default
to creating a key for [email protected]. If Alice selects a different iden-
tity, then the wizard should explain why the key won’t be usable for the
email she is currently composing.
If the user already has a key, but not one for the current identity, it is
reasonable for the key creation wizard to offer to add the identity to the
existing key. However, current thinking in the GnuPG project is that users
require less training when there is a one-to-one mapping of keys and email
addresses than when multiple user IDs are associated with a single key.
For instance, if the MUA offers to add the user ID to an existing key, it
becomes necessary to explain why this might be undesirable, e.g., most
people probably want separate keys for their private, and their work email.
And later, if the user retires her email address, it will become necessary to
explain the difference between revoking the key and revoking a user ID. Of
course, since many users do use keys with multiple user IDs, it is necessary
for the MUA to support such keys, and explain their meaning when signing
keys, for instance.
The key generation wizard should make key creation as easy as possi-
ble by prompting the user for as little information as reasonable. In par-
ticular, the user should not have the option to enter a comment; adding
a comment is almost always inappropriate [18]. Likewise, key generation
parameters should not be configurable. But, the user should be allowed
to choose whether the key is published on the Internet. This requires an
explanation, which can be made by simile: publishing a key on the Inter-
104 CHAPTER 10. MUA INTEGRATION
10.3 Expiration
When GnuPG 2.1 creates a new key, the default is to set the key to expire in
two years. Just because a key expires does not mean that the user needs a
new key: the expiration is just an emergency brake if the user loses access to
her key, and can’t publish a revocation certificate. Consequently, the MUA
should support extending a key’s expiration date. This can be done when
the MUA starts. But, since many users rarely restart their MUA, it may be
better to check whenever the key is used.
If the key is about to expire (within, say, three months), the MUA should
extend the expiration. Once the expiration is extended, the key needs to be
uploaded to the key servers or otherwise distributed to the user’s com-
munication partners so that their OpenPGP implementation can take the
change into account.
Since extending a key’s expiry requires making a self-signature, the user
will need to unlock the secret key. This interaction can be hidden by piggy
backing the operation onto some other operation that requires the user to
unlock the key.
For security sensitive users, it may make sense to ask the user if this is
desired. For very high risk users, there should also be an option to rotate
the keys.
help the user find the keys, and, in this case, finding appropriate keys is
actually straightforward: due to the way that OpenPGP encrypts data, the
long key ID of the sender and any recipients will normally be embedded
in the message (specifically, in the PK-ESK packets). Unfortunately, the
key IDs are subject to tampering, but since this requires a more determined
adversary, they are almost certainly much more reliable than simply search-
ing a key server for keys with a particular email address. It is also possible
to try and find the key using WKD, which provides a basic verification
check. Another reason to avoid key servers is that using a key found on a
key server may cause more problems than it solves: the message may be
encrypted, but because it is the wrong key, the intended recipient can’t de-
crypt it. Making decryption unreliable is a sure way to discourage the use
of encryption. Key discovery is covered in more detail in Section 10.6.1.
Sometimes mails include keys as attachments, or references to them. In
such cases, the MUA should either import them automatically or provide
a button to allow the user to import them. But, the keys should always
be imported if they are already available locally: the keys might contain
updates, such as new subkeys, an extended expiration, or a revocation cer-
tificate. This topic is discussed further in Section 10.6.1.
tant for security conscious users, and, as a rule of thumb, marginally veri-
fied keys should not be shown as having the same level of security as fully
verified keys. Instead, fully verified keys should be shown in, say, green,
and partially verified keys should be shown in, say, yellow. If it is somehow
desirable that marginally verified keys have the same security level as fully
verified keys, then the user should explicitly set the marginals-needed
option in her gpg.conf file to 1. In the very least, the UI should distin-
guish between fully verified keys, and not fully verified keys, i.e., if the UI
only shows two states, it should show marginally verified keys the same
way it shows completely unverified keys.
If the TOFU trust model is enabled, the number of days on which a
message has been encrypted to the key plus the number of days on which
a message signed by the key has been verified should be shown next to the
icon. This can be shown in a small bubble subscripting the icon, which is
similar to what Twitter does for showing counts. For large numbers, it is
reasonable to show approximate numbers (e.g., rounding 1132 to 1.1k).
Showing these statistics is important to help users to detect mimicry
attacks, which are often employed by phishers. For instance, if a bank nor-
mally signs their emails, then users hopefully become used to seeing the
count slowly increase. Then, if they get an email that appears to be from
their bank, but the count is 0, they will hopefully become suspicious.
If the user hovers the mouse over the padlock icon or clicks on it, the
MUA should show a short, tweet-length message explaining why the key is
considered verified (or not). If the key is not fully verified, an option to start
a key verification wizard should be provided. If there is a TOFU conflict,
there should be an option to start a TOFU conflict resolution wizard. And, if
there is no key associated with the email address, there should be an option
to start a key discovery wizard. (The wizards are described in Section 10.6.)
Figure 10.1: Padlock icons shown by Firefox and Chromium when a web-
site is transferred securely.
"more information" icon if TLS was not used at all [32]. There are two im-
portant issues with this scheme.
The first issue is that this scheme conflates encryption and authentica-
tion. Although it might be reasonable to demand that websites that use au-
thentication also use encryption to be considered secure—it simplifies user
training, and doesn’t impose a significant deployment cost—this argument
doesn’t apply in an email setting. Consider, for instance, a company that
wants to sign all of its outgoing emails to help mitigate phishing. In this
scenario, encryption is more of a hindrance than a help: requiring encryp-
tion would mean that the company would have to somehow find the right
encryption key for each of its correspondents. When only providing an
authentication mechanism, not only are the customers’ keys not required,
the customers don’t even need to have a key: they just need the ability to
validate the signature.
The second problem is that a TLS connection that can’t be authenticated
is shown to be worse than a connection that is completely insecure. For in-
stance, until the recent introduction of Let’s Encrypt, website operators who
wanted to offer an encrypted connection to their website, but didn’t want
to pay for a certificate could use a self-signed certificate. Although data
protected by such certificates is not secure in the sense that the end point
can’t be authenticated without user intervention, such certificates enable
encryption, which does protect users from passive surveillance. In other
words, self-signed certificates provide more protection than nothing at all,
but websites that use self-signed certificates are shown as being less secure
than sites that use no protection at all! (Although encrypting is better than
not encrypting, we nevertheless recommend that MUAs show encrypted
and unsigned mails in the same way that they show unencrypted and un-
signed mails to avoid confusing users.)
Happily, at least the Chrome browser does not make this distinction.
And, like Chrome, we strongly recommend that whatever mechanism is
used to show that a mail can’t be authenticated be used for both unsigned
mails, and mails with a signature that can’t be verified. Specifically, we rec-
ommend considering an unencrypted and unsigned email to be the base-
line, and that an email is never displayed in such a way that the user would
consider it to be less secure than the baseline, unless there is strong evi-
dence of an attack.
It is reasonable to show unverified messages, and unsigned messages
in a neutral manner, and to show verified messages in a positive man-
112 CHAPTER 10. MUA INTEGRATION
The OpenPGP email workflow assumes that messages are stored on an un-
trusted server, and thus continue to need protection even after the mail has
been delivered. Supporting this type of workflow is one of the primary rea-
sons that OpenPGP doesn’t provide forward secrecy. There are two major
consequences of this workflow.
First, every time a message is accessed, it needs to be decrypted. This
can lead to many passphrase prompts. These can be largely mitigated by
increasing the amount of time gpg-agent caches passphrases, or by using
a password manager. But, it is also annoying for smartcard users who need
to basically always leave their smartcard inserted, which effectively nulli-
fies a nice security property of smartcards: the user can observe operations,
because they can only be done when the card is inserted.
Second, it is not possible to search encrypted mails. This is a major
usability problem, particularly when the subject line is also obscured as it
should be to avoid accidentally leaking the message’s contents.
Both of these issues can be largely mitigated by caching the unen-
crypted version of each message locally. This assumes, of course, that the
local device is secure. At a minimum, the user should have the mail stored
on an encrypted partition.
There are three main aspects to key management: key discovery, key veri-
fication, and key organization.
10.6. KEY MANAGEMENT 115
The most secure way to find a person’s key is to get it from that person di-
rectly. If a physical meeting is possible, this can be done by exchanging fin-
gerprints in person. At least in the business world, the cost of this exchange
can be driven to zero: because exchanging business cards is a common
practice in this world, adding your fingerprint to your business card makes
securely exchange fingerprints a free byproduct of a well-established ritual.
Having a fingerprint on a business card is not quite enough to use it:
it still needs to be entered into the system. The key discovery wizard can
make this process easier by suggesting possible matches based on what the
user has entered so far. (Possible matches can be found by querying a key
server.)
We recommend having the user enter at least 64-bits worth of the fin-
gerprint before enabling auto completion to ensure that the user checked a
minimal amount of the fingerprint. For instance, it is possible to create a
key with a specific 32-bit key ID in just a few seconds on modern desktop
computers [34].
If the email address is known (and it is probably reasonable to first ask
the user to specify a contact if this is not clear from the context), and there
is at least one matching key, an alternative approach is to show a series
of buttons with fragments of the matching fingerprints, and have the user
select the matching fragments. This idea is illustrated below:
The "none of the above" option is useful if the right key is not on the
key servers, for whatever reason.
A more user-friendly technique could use a webcam and OCR to read
in the fingerprint. From an implementation perspective, this is more de-
manding than scanning a QR code, for instance, but there are many fewer
people who add a QR code containing their fingerprint to their business
card than those who add their fingerprint. But, providing an option to dis-
play a public key using a QR code on screen can be helpful: someone could
scan it.
Exchanging keys in person requires that people actually meet face to face.
This is often not practical. The next best alternative is to pick up the phone.
This approach is appropriate for all but those people who have the high-
est security concerns—those whose threat model includes a real-time voice
imitator. Although this has been technically feasible for years. It requires
precise timing that only a nation-state adversary could afford.
Again, assuming the email address is known, the button grid can be
used to facilitate transcription of the fingerprint.
Searching a Website
There are two main places where context can be used to discover poten-
tially useful keys: a signed message indicates what key was used to sign
118 CHAPTER 10. MUA INTEGRATION
it, and an encrypted message usually includes the key IDs of the sender
and other recipients in the PK-ESK packets. Emails also sometimes include
hints about the right keys to use. For instance, some people attach either
their key to the emails that they send (pEp does this by default), or the keys
of all recipients in order to make it easier for people to reply in a multi-party
discuss. Another hint can sometimes be found among a mail’s headers: the
OpenPGP header allows the sender to advertise a key [31].
In theory, there is no reason to not import these keys. Simply importing
a key will not cause it to be considered verified: whether a key is considered
to be verified, is determined exclusively by the trust model, not whether
it happens to be available locally. But, having what is probably the right
key available locally is useful for opportunistic encryption. And, used in
conjunction with the TOFU trust model, it is even possible to bootstrap
some trust over time.
Unfortunately, in practice there are two important issues with harvest-
ing keys.
The first issue is that automatically fetching keys via the network can
be used as a back channel. A sophisticated attacker could create a new key
for each message. When a user fetches the key, the attacker can potentially
learn not only that the user opened the message, but also the user’s IP ad-
dress. This attack can be mitigated by routing this type of traffic via Tor (to
do this, Tor must be installed and GnuPG configured to use it by adding
use-tor to dirmngr.conf). Using Tor not only hides the user’s IP ad-
dress, but also requires the attacker to actually control the user’s preferred
key servers to observe the fetch. This is only feasible by an adversary with
a lot of resources.
Even if automatically fetching keys is disabled, the MUA can still har-
vest this information, and save it in a local database. Then when the user
explicitly searches for the key associated with an email address, say, the
hints can be exploited.
The second issue is that GnuPG doesn’t handle very large key rings
(those with thousands of keys) very well. This manifests itself in two
ways. It shows up as longer random access times: gpg does a linear scan
of the key ring the first time it is accessed. Also, GnuPG’s trust calcula-
tions are done on demand when gpg starts. These calculations can take
minutes on large key rings. And, they are done whenever a new key
or signature is imported, or a key expires or is revoked. When harvest-
ing keys, this can happen very often. Happily, the trust calculations can
10.6. KEY MANAGEMENT 119
8F17 7771 18A3 3DDA 9BA4 8E62 AACB 3243 6300 52D9
[ Ok ] [ Cancel ]
Instead, the key verification wizard should ask the user how she wants
to confirm the key: using a business card or other printout, or via phone.
This approach educates the user without being patronizing: the user learns
how to verify a fingerprint, and that it is not okay to just click verify without
actually verifying the key.
To prevent the user from simply clicking okay without checking the
fingerprint, we recommend requiring that the user enter at least part of
the fingerprint. This can be done by using the buttons with the fingerprint
fragments, as described above.
Ownertrust
Publishing Signatures
The key verification wizard should provide an option to publish the sig-
nature. This should be accompanied by an explanation of what this means
and why this is useful (people who trust you won’t need to manually verify
this fingerprint).
It is also reasonable to provide an option to make a trusted signature
instead of a simple certification. Again, this requires an explanation. This
option should probably only be hidden unless expert mode is enabled.
the most recent message. Likewise, the new key is not necessarily the right
one: the man in the middle might just have started the attack.
123
124 CHAPTER 11. PROGRAMMING WITH GNUPG
Chapter 12
Misc.
• gpgv
• /etc/skel/.gnupg
• What’s a keygrip.
125
126 CHAPTER 12. MISC.
Bibliography
127
128 BIBLIOGRAPHY
[9] Neal H. Walfield and Werner Koch. TOFU for OpenPGP. In Proceed-
ings of the 9th European Workshop on System Security, EuroSec ’16, pages
2:1–2:6, New York, NY, USA, 2016. ACM.
[13] Serge Mister and Robert Zuccherato. An attack on CFB mode encryp-
tion as used by OpenPGP. 3897:82–94, 2005.
[15] Holger P. Krekel, Danial Kahn Gillmor, et al. Autocrypt level 1: En-
abling encryption, avoiding annoyances - bad import. https://
autocrypt.readthedocs.io/en/latest/bad-import.html.
[17] Ian Brown, Adam Back, and Ben Laurie. Forward Secrecy Ex-
tensions for OpenPGP. Internet-Draft draft-brown-pgp-pfs-03, IETF
Secretariat, October 2001. https://tools.ietf.org/html/
draft-brown-pgp-pfs-03.
BIBLIOGRAPHY 129
[28] Rainer Böhme and Stefan Köpsell. Trained to accept?: A field exper-
iment on consent dialogs. In Proceedings of the SIGCHI Conference on
130 BIBLIOGRAPHY
[29] Rainer Böhme and Jens Grossklags. The security cost of cheap user in-
teraction. In Proceedings of the 2011 Workshop on New Security Paradigms
Workshop, NSPW ’11, pages 67–82, New York, NY, USA, 2011. ACM.
[34] Richard Klafter and Eric Swanson. Evil 32: Check your gpg
fingerprints. https://evil32.com/, https://www.defcon.
org/html/defcon-22/dc-22-speakers.html#Klafter, Au-
gust 2014. Last accessed: July 28, 2017.