Email security
Email was designed without security. A message crosses several servers in the clear, and the From: line is just text. Three separate layers of protection exist today, and they answer different questions. Mixing them up is the usual reason people think a message is “secure” when it is not.
| Layer | Protects | Mechanism |
|---|---|---|
| Transport | A message on one hop between servers, or between client and server | TLS on SMTP, IMAP, and POP |
| Domain authentication | The claim that a domain sent the message | SPF, DKIM, DMARC |
| End-to-end | The message content, from the sender to the recipient’s mailbox | PGP or S/MIME |
Only end-to-end protection hides the content from the mail servers in the middle. How email works is covered with SMTP and DNS.
What secure email needs
Section titled “What secure email needs”| Requirement | Meaning |
|---|---|
| Confidentiality | Only the recipient can read the message, not the servers carrying it |
| Sender authentication | The recipient can be sure who wrote it |
| Message integrity | The recipient can tell if it was changed |
| Non-repudiation | The sender cannot credibly deny sending it (a signature supports this) |
The building blocks are those in cryptography fundamentals: a hash for a compact fingerprint, a private-key signature for authentication and integrity, symmetric encryption with a one-time key for the bulk of the message, and public-key encryption to deliver that key.
Building it, step by step
Section titled “Building it, step by step”Confidentiality. Public-key encryption of a long message is slow, so the sender uses the hybrid approach:
- Generate a random one-time session key
Ks. - Encrypt the message with
Ksusing a symmetric cipher. - Encrypt
Kswith the recipient’s public key. - Send both. Only the recipient’s private key recovers
Ks, and then the message.
Integrity and authentication. Signing the whole message with a private key works but is slow and large. Instead:
- Hash the message (for example SHA-256).
- Sign the hash with the sender’s private key.
- Send the message plus the signature. The recipient hashes the message, verifies the signature with the sender’s public key, and compares.
Both. Sign first, then encrypt the message and signature with a session key, and send the wrapped session key. The result is one package:
signature = Sign( private key of sender, Hash(message) )package = SessionKeyEncrypt( Ks, message + signature ) + PublicKeyEncrypt( recipient key, Ks )The recipient reverses it: unwrap Ks, decrypt, then verify the signature.
Trust in the keys is the hard part. A signature is only as good as your knowledge that the public key belongs to the sender. S/MIME gets that from X.509 certificates issued by certificate authorities, as in PKI and certificates. PGP uses a web of trust, in which people sign each other’s keys. Both are covered in GPG and file encryption.
PGP and S/MIME in practice
Section titled “PGP and S/MIME in practice”Both give the same four properties and use the same shape: hash, sign, session key, wrapped key. The differences are in key trust and tooling.
| PGP / OpenPGP | S/MIME | |
|---|---|---|
| Key trust | Web of trust, key servers, direct fingerprint checks | Certificate authority hierarchy |
| Typical users | Developers, activists, open-source projects | Enterprises, government |
| Client support | Plugins and some mail clients | Built into most mail clients |
| Key lifecycle | User-managed | Issued and revoked centrally |
Neither is widely used by general users. The usual reasons are key management, lost keys that cannot be recovered, and that search, spam filtering, and webmail all need to read content. Many organizations rely on transport security and domain authentication, and add end-to-end encryption only for specific high-risk exchanges, or use secure portals instead.
Signing git commits and release artifacts uses the same primitives, and is where most engineers meet them today.
# Check that a signed email's signature verifies (message saved to msg.eml)gpg --verify msg.sig msg.txt
# S/MIME: verify with OpenSSLopenssl smime -verify -in msg.eml -CAfile ca-bundle.crtTransport encryption between servers
Section titled “Transport encryption between servers”SMTP began as plain text. Servers upgrade it with STARTTLS: the connection starts in the clear, the client asks to switch to TLS, and both proceed encrypted. The weakness is that the upgrade is opportunistic. An attacker who strips the STARTTLS offer forces cleartext, and many servers will accept that.
# See whether a mail server offers STARTTLS and what certificate it presentsopenssl s_client -starttls smtp -connect mail.example.com:25 -servername mail.example.comStronger policies tell sending servers that TLS is required. MTA-STS publishes the policy over HTTPS and DNS, and DANE publishes certificate information in DNSSEC-signed DNS records. Clients submitting mail use the dedicated submission port (587 with STARTTLS, or 465 with implicit TLS) with authentication.
Even with perfect transport encryption, each receiving server reads the message and stores it. Transport security protects the wire, not the mailbox.
Domain authentication
Section titled “Domain authentication”SPF, DKIM, and DMARC answer “did this domain really send it?”, not “who wrote it?” and not “was it kept private?”. SPF lists the servers allowed to send for a domain. DKIM has the sending server sign selected headers and the body with a key published in DNS. DMARC sets what a receiver does when those checks do not align with the visible From: domain. They are covered in Social engineering attacks, where they matter most, and they should be on every domain that sends mail.
dig +short TXT example.com | grep spfdig +short TXT _dmarc.example.comdig +short TXT selector1._domainkey.example.com