Computer Networking › Section H · Security in computer networks › Topic H.5
Securing e-mail
E-mail is the first place this section puts its cryptographic tools to work in a real application. Because a message is written now and read later, its protection has to travel inside the message itself, and that shapes every design choice.
Security for a message, not a connection
As "Electronic mail" explained, mail is store-and-forward: Alice's message passes from her mail server to Bob's by SMTP and waits there until Bob collects it, perhaps hours later. Alice and Bob are rarely online together, so they cannot run a handshake, exchange nonces or agree a key in real time. Whatever protection Alice wants must be built into the message before she sends it, using only what she already knows, chiefly Bob's public key. Bob may want three things: confidentiality, proof that the message came from Alice, and proof that it was not altered. Each can be added separately.
Confidentiality: a session key in an envelope
Alice could encrypt with a symmetric key, but she and Bob would need to share one in advance. She could encrypt the whole message with Bob's public key, but that is slow for long messages and attachments. The standard design uses both. Alice picks a fresh random session key \(K_S\) and encrypts the message with it using a fast symmetric cipher such as AES. She then encrypts \(K_S\) itself with Bob's public key, \(K_B^+(K_S)\), and sends the two parts together. Bob uses his private key to recover \(K_S\), then decrypts the message. Only Bob can open the envelope that holds the key.
Worked example: wrapping a toy session key
Use Bob's toy RSA key from "Principles of cryptography": n = 253, e = 3, and private d = 147. Real session keys are 128 or 256 bits; here the session key is the number 17. 1. Alice encrypts the message body with the session key, using AES. 2. She wraps the key: \(17^3 = 4913 = 19 \times 253 + 106\), so the wrapped key is 106. 3. She sends the encrypted body and the value 106. 4. Bob computes pow(106, 147, 253), which returns 17. 5. He decrypts the body with key 17. Check: anyone who intercepts 106 needs d to unwrap it, and the slow public-key step touched only one small number.
Authentication and integrity: a signed digest
If secrecy does not matter but Bob must know the message is genuine and unchanged, Alice signs it. She computes the hash \(H(m)\) with a function such as SHA-256, applies her private key to get the signature \(K_A^-(H(m))\), and sends the message with the signature attached. Bob hashes the message he received, applies Alice's public key to the signature, and compares the two digests. A match shows that the holder of Alice's private key signed exactly this text. A signed message can be read by anyone, which suits announcements and software release notes.
Doing both at once
For a message that is secret as well as signed, Alice combines the two designs. She first signs: she computes \(K_A^-(H(m))\) and attaches it to \(m\). Then she encrypts the message and its signature together with a fresh session key \(K_S\), and wraps \(K_S\) with Bob's public key. Alice therefore uses three keys: her own private key to sign, a new session key to encrypt, and Bob's public key to protect the session key. All of this depends on public keys that really belong to their owners, so each party must obtain the other's key through a channel or certificate they trust.
Worked example: what Bob does on arrival
Bob receives a signed and encrypted message from Alice. 1. He applies his private key to the wrapped session key and recovers \(K_S\). 2. He decrypts the body with \(K_S\), revealing the message and Alice's signature. 3. He computes the hash of the message himself. 4. He applies Alice's public key, obtained earlier from a source he trusts, to the signature, which yields the digest Alice signed. 5. He compares the two digests. Check: if they match, the message is from Alice and unchanged; if Trudy altered even one character, the digests differ and Bob rejects it. Bob's steps undo Alice's in reverse order.
PGP and the web of trust
Pretty Good Privacy, released by Phil Zimmermann in 1991, packaged exactly this design: a session key for the body, public-key wrapping of that key, and signed hashes. Its format became the open standard OpenPGP, now RFC 9580, published in 2024, and the free GnuPG program implements it. PGP took an unusual approach to certifying keys. Instead of relying on certificate authorities, users sign each other's public keys after checking identities in person, building a web of trust. If Alice trusts Carol, and Carol has signed Bob's key, Alice may accept that key as Bob's.
S/MIME and the limits of end-to-end mail
S/MIME provides the same signing and encryption, but certifies keys with X.509 certificates issued by certificate authorities, so it fits organisations that already run such a system and is built into many business mail programs. PGP and S/MIME are end-to-end: only Alice and Bob ever see the plaintext. Both remain little used by the public, mainly because every correspondent needs a key pair and must find the other's public key. Both also leave the headers readable, so the sender, recipient and usually the subject line are still exposed to every server the message passes.
Protecting each hop with TLS
Most mail today is protected differently, one hop at a time. When two mail servers talk SMTP, the command STARTTLS upgrades the connection to TLS, encrypting the message while it crosses that link. On its own this is opportunistic: an active attacker can strip the STARTTLS offer so that the servers fall back to plain text. MTA-STS lets a receiving domain publish a policy saying TLS with a valid certificate is required. Hop-by-hop TLS stops eavesdroppers on the links, but every mail server along the way still sees and stores the plaintext, which end-to-end encryption avoids.
Checking the sending domain
Forged sender addresses are the basis of most phishing, and three DNS-based standards help receiving servers detect them. SPF lets a domain publish which servers may send its mail. DKIM has the sending server sign each message with a domain key whose public half is published in DNS, so changes to the signed parts are detected. DMARC tells receivers what to do when a message fails these checks, and requires the passing domain to match the visible From address. Since 2024 large mailbox providers have required them from bulk senders. They authenticate the domain, not the individual person, and they encrypt nothing.
Common mistakes to avoid
First, encrypting a long message directly with public-key methods instead of using a session key. Second, wrapping the session key with Alice's own public key; it must be Bob's, or Bob cannot open it. Third, signing with the public key instead of the private key. Fourth, assuming STARTTLS means end-to-end encryption; servers still see the plaintext. Fifth, thinking PGP or S/MIME hides the sender, recipient and subject. Sixth, treating a passed DKIM or SPF check as proof that a particular person wrote the message, or that the message is safe.
Key takeaways
Mail is store-and-forward, so protection travels inside the message. For confidentiality, Alice encrypts the body with a fresh session key and wraps that key with Bob's public key. For authentication and integrity, she signs the message's hash with her private key. For both, she signs first, then encrypts message and signature. PGP, standardised as OpenPGP, and S/MIME implement this end to end, certifying keys by a web of trust or by CAs. STARTTLS and MTA-STS protect each server-to-server hop, and SPF, DKIM and DMARC check the sending domain.
Flashcards
Flashcard
Sender and receiver need not be online together
Test your understanding
Question 1 of 5
Alice wants to send Bob a long confidential e-mail with attachments. Which design is standard?
Question 2 of 5
Bob's toy RSA public key is n = 253, e = 3. Alice wraps the session key 17. What value does she send?
Question 3 of 5
Alice sends a message that is both signed and encrypted. In what order should Bob process it?
Question 4 of 5
Two mail servers use STARTTLS for every hop between Alice and Bob. What does this protect against?
Question 5 of 5
A message passes SPF, DKIM and DMARC checks for the domain example.org. What does that show?
