2015-06-10 13:24
Signing mail
If you’ve been on the Internet long enough, you might have been unlucky enough to be exposed to this UI decision from the 90s, the notorious PGP chunk:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Howdy,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13
iQIcBAEBAgAGBQJVZdlnAAoJEJyPPH5ga5Kwsi8P/R/dsUWld8oe6yc+Cnfdkufc
y0fIlLhyWLqaZVEv3zye4O7gw3s3LO91PWSbNqIax7aUZee+NmamZEKFSk7dKO+g
Lu6B4u3SxzNgeCfBPcexKS8S9ARBUuRr34Ow7U+l4rI6vNv85YBk8nVHgVcZL6vS
k4I0cc/nKRXV3m8HPlGWxUiaOdyMaMPYtQaxw7WcyiC3H/uuL58H1j2o2xoEtDBI
KghkjdI/N0fuYEpVTVQnd8+jDGVH+FwAjWJtGt/3RVzlH5APqkdHzlOwzerH0ORL
XUiEMFOsd6eez0zv4F+bfTBDBHsl4ih5Y7bwUH+A1fNLwP+SEbf0O+QO+mTHyTSf
e7H4MwsRyJfna4yCcnTH0s3yQ3DotFtRGgc32MrBBTIC0t2sJHtdL0yzAWCYZ3FU
6F3Yi6uAT/8V32FGiRB+NeFyaXPiZByg03Tv2yMkEUGanOXmDOKI9fTSn5MGhBPE
kLbYQmfSKxLT/iN/WGHtPAFNuQRFQ3hTkQ9NttSP+LMkuNOHx5ppEKho/bNTmMN3
ltd2c1XZN2VLoxtXAHSiUQ7yWxrh5aFHEaoSohufaAuilAo5rKs6/gQa9dmhbfUt
Kqr1zKqK2gMwjDE5JkV045tfTnfP48YwXTRxkFjPX+PqjwAQ15XytQVIigO5uQgw
Ak2Wt6X8KxBcNYA5JC1t
=ZKyE
-----END PGP SIGNATURE-----
Which is a good candidate for the worst UI decision of all time, and it’s utility is best summarized (as often is the case), by xkcd. Granted, PGP is one of few viable options for end-to-end encryption without inventing any new infrastructure, but you need to be aware that PGP offers no protection of metadata like sender, receiver, time sent, and subject of the mail.
So let’s consider, why do people sign their mail in this way, typically the privacy-minded and tech-savvy?
Disclaimer: This post does not concern using PGP for end-to-end encryption, using PGP to sign messages in other channels than mail, or any other use of PGP. This is only about PGP and signed mail. Also note that when I say PGP, I’m talking about all OpenPGP-compatible software, including GPG.
Tamper-proof mail
Mail that has been cryptographically signed will resist modification, as any single byte that has been modified will cause the signature to be invalid. This does however come with two heavy assumptions:
- The receiver will actually verify the integrity of the message
- A Man-in-the-middle capable of modifying the message during transmission will not simply remove the entire signature, rendering it as normal mail.
The first point includes having to first (securely!) exchange keys with the person you’re receiving the mail from. There’s the appalling option of just publishing your public key to a keyserver, but the fact is that even though most services have realized that you need to verify email addresses before using them for anything valuable, key servers – a service developed for exclusively for security-minded users – does not do this. Anyone can create a key claiming to be me, on any of the fifteen or so different email addresses I’ll reply on. If you trust Twitter or Facebook or any such site (odds are that if you’re this paranoid about integrity of your mail, you don’t), you could publish your fingerprint there, which could confirm that the key gotten from the keyservers is actually yours. Alternatively, if you have a web page (most people don’t), you could publish it there, granted that you serve your site over HTTPS, use DNSSEC to protect your domain, and trust that your registrar properly secures their DNS signing keys (or you do so yourself if you self-host DNS), you properly secure the private key associated to your certificate, you have complete trust in every single CA in the trust store, and that there’s no malware on sender or receiver’s computer who could snoop private keys or modify public keys.
A better option, key parties! Gather all your friends, drink beer and exchange public keys face to face, with no intermediaries or unreliable channels in between. Have you been to many of those? Me neither. I’ve studied information security for five years now, and I don’t know of anyone else in my class that even has a GPG key. I’m only using mine to sign uploads to PyPI.
As for the MitM threat, if I send you a message like the one above, it’s depressingly easy for an attacker to simply strip anything related to the signature, and the receiver would have no way of knowing that the message was originally signed unless she already knows that all messages from the sender is supposed to signed. For new parties communicating, that’s not feasible in the PGP system.
Authenticity of sender
Another worthwhile goal of signing mail, is to ensure that the sender is actually the person she claims to be. If you have the public key of the person, no one else can send correctly signed mail as that person. Many of the same concerns as for preventing tampering still applies, but this is a bit harder to subvert, since if someone is actually trying to confirm someone’s identity, you’d simply ask them to prove it. This could be the case if for example you start using a new email address, you could sign the first mail from the new address to let people know it’s actually you, which means that signatures will hopefully be checked and the system actually works like it should, assuming the parties have already exchanged keys.
A better way
New services are trying to improve on the key-exchange related troubles, which I applaud, but if we consider the mail case, the problem is for most practical purposes, solved. There are standardized, widely adopted and supported solutions, which solves the issues mentioned above (with some considerations). Thing is, we have a common name for incoming mail coming from forged addresses, it’s called spam. And spam has been around for long enough for us to establish a very solid grasp of how to prevent it.
SMTP, the protocol that actually exchanges mail between your mail server and mine, doesn’t have any way to authenticate that the claimed From: address is valid. Anything goes, as far as SMTP cares – anyone can claim to be anyone. Which is why spam started happening, and which is why we have other solid ways to verify this outside SMTP.
SPF
SPF (Sender Policy Framework) is a rather obvious way to prevent forged mail addresses – simply ask the sending domain whether the IP is allowed to send on its behalf. SPF is deployed by pretty much anyone who sends mail, as without it you’re destined for the spam folder, or to be rejected outright. If someone that checks SPF receives a mail claiming to be from someone@example.com, the receiver will issue a DNS TXT query to example.com and see if the IP of the sender is listed as an allowed sender for that domain in the SPF record. Not the case? No mail for you. This ensures that no-one can claim to be a sender on that domain, without having access to a mail service on that domain.
How about authenticity? Enter DKIM.
DKIM
DKIM (DomainKeys Identified Mail) works somewhat similar to SPF, in that it uses an already trusted channel (DNS), to exchange out-of-band information about mail. With DKIM, a domain publishes it’s public keys through DNS, so that any receiver can verify that the mail has not been tampered with since it left the senders mail server. And, in a startling contrast to PGP, DKIM includes the signature in the mail headers and not in the body, keeping it completely transparent to users, but being present if they want to check it manually.
But how about the risk we talked about earlier, where an attacker could simply strip the signature and the receiver would be none the wiser? We can handle that as well.
DMARC
DMARC is a policy and reporting tool, which you use to say stuff like “all mail from my domain should carry a valid signature, or be considered spam”. There’s three different policies you can apply to your domain:
- Ignore: No special action will be taken if unsigned mail is received
- Spam: Unsigned mail from me is spam
- Reject: Unsigned mail should be dropped, bypassing the spam folder entirely
This policy is distributed through – you might see a pattern here – DNS.
DMARC is also about reporting, as the record allows you to specify an email address where you’ll get daily reports from receivers of your mail about how they were treated. Thus, if anyone tries to spoof a mail from your domain with a bad signature or lacking a signature, you’d be notified and would not be kept in the dark about how people try to impersonate you.
As all of these technologies rely on DNS, it’s quite essential for their secure operation that your DNS records are protected by DNSSEC. I’m not going to go into detail about how to configure DNSSEC, but most modern registrars will either provide it for you automatically or have some way for you to enable DNSSEC. Make sure you do.
Confidentiality
Contrary to popular belief, most mail sent between people today are encrypted in transit, at least if you’re using GMail or any of the other large providers. On my own server, which I haven’t migrated all personal mail to yet, but is used for most of my accounts, 72% of my mail was received over TLS/SSL. If you’re paranoid and running your own mail server you can configure it to reject non-TLS transmissions, but that will probably prevent you from receiving quite much mail. You’d also not be RFC-compliant, if that’s important to you.
If you have transit encryption, that encryption will also cover metadata of the message, keeping everything except the sending and receiving domain confidential from anyone listening in.
Mail configured with SPF and DKIM will look like this, where you can see that postfix has verified that the sender was valid according to SPF and opendkim have verified that the DKIM signature matches:
<...>
Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.215.54;
helo=mail-la0-f54.google.com; envelope-from=<snip>@gmail.com; receiver=<snip>
Authentication-Results: thusoy.com; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=niwa/5j1;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by thusoy.com (Postfix) with ESMTPS id C3EF9A0745
for <snip>; Wed, 27 May 2015 18:32:01 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:sender:date:message-id:subject:from:to:content-type;
bh=JF1P0cVaOod0HI+SRSwmWbbutO+SFZzQejSnBlTt9UE=;
b=niwa/5j1vbY1rp5D/w8EezUZCKAPlT0bJLZFCfEFwwBkP+8A8Pw/urwZQTG64w2ZUj
KQH3fD/seNhTf3fPDuTS0O0nB24TTZkjJplaPE6g2wPP7k8pXe1O1c5fNFWRkuywTKcJ
nBXjj97i7n79QaSwLH4vLI0ySlOyr5pRAhJeo9+6vuTOJJNLMpCVPqP10BVJ69r+39KA
p2Au0Up+y2ZngArI0dFYtYqQFSgEHI2Yqjjm61jRBEbjEgWJkagLkfZY6R3yQsfFloff
Zk3rDreMVr5ronX7qPxIvpAaZTMhSg41hf+2NU38tpvoaBRBBOIyBz05JcI1jdPIEktp
oujg==
<...>
The Received: header tells us that the message was encrypted in transit (look for with ESMTPS), and I’ve configured postfix to also record the ciphers used, out of curiosity.
Issues with SPF, DKIM, DMARC and opportunistic encryption
Nothing is perfect. None of the technologies mentioned above help in verifying that someone on a given domain is not being impersonated by someone else on that domain, like if I claim to be sergey.brin@gmail.com or similar. To prevent this, you need to trust that the provider ensures proper access control and validation of its senders. But this is not unreasonable, trusting your mail provider is a natural thing to do, if you don’t, why would you use that mail provider? Granted, PRISM changed the rules of the game, as you’d also have to trust that your provider has sufficient opsec and legal power to keep governments out of their servers, which it seems has not been the case for any of the large US-based service providers. There are alternatives.
TLS certificates today costs money, which does not help foster adoption for encryption around the web. Granted, if you’re brave you can try to navigate the UI of StartCom’s StartSSL service, which will provide you domain-validated TLS certificates for free, but better things are coming. The EFF is working on Let’s Encrypt together with Mozilla to automate this process and provide free certificates for anyone, which is sorely needed. Alternatively, Postfix supports using DANE for key exchange, which removes the need for a cumbersome and vulnerable CA-structure, and moves the trust over to DNS providers. If you’re enough of a indie hipster you’ll claim that domain names are only for the weak, real enthusiasts manually keep their host files updated for their friends’ IPs and don’t need domain names, but for anyone else this is not practical. Thus letting your DNS provider publish your keys prevents any CA to sign certificates for your domain, without incurring any cost to stay secure.
UI for security service is essential, and in that regard many of these solutions have “failed”. The only way these technologies are presented to the user is whether mail ends up in your spam folder or your inbox. Greater transparency into why some mail is trusted and other is not is needed to establish trust in the system. If the UI presented that mail is verified with DKIM and SPF and was protected in transit that would probably yield much more trust in the mail system. Or preferably, assume that all these are mandatory, and notify the user if any of them fails. If this was actually visible, we’d reduce the number of self-signed certificates and invalid certificates seen in SMTP today. It would also push providers to support opportunistic encryption, as ordinary users would be notified if their mail was sent in plaintext.
It should be noted that these solutions are not mutually exclusive with using PGP, the best is having both, which means that DKIM, SPF and opportunistic encryption validates your service provider, while your PGP key validates you. In some cases, like if you self-host email, the service provider and the sender is the same person and this might not be necessary, but self-hosting email is not a solution for everyone. In any case, if you want to use PGP we’d still need better user interfaces, as I’d stop using any service that actually exposed me to mail that looks anything like the one in the beginning of this post. I’d recommend sending detached signatures as attachments instead of clearsigned mail, which means that if a recipient receives PGP-signed mail they would see an attachment they don’t recognize, instead of the PGP-blob. Attaching your own public key as well means that you could run a trust-on-first-use scheme, where no one could impersonate the other in a conversation after they have been communicating for some time.
SMTP is not the best tool for secure communication, but it’s one of the few usable, distributed systems we have that can achieve pretty good security and also has near-universal adoption. There’s plenty of secure communication tools which I hope will become only more and more widespread, but until then, or in addition to them, mail can actually work pretty well.