Transport Security
TLS, and what it does not protect.
TLS protects each hop. It does not protect the message.
Three ports, two models
| Port | Model | Used for |
|---|---|---|
| 25 | plaintext, then STARTTLS |
server to server |
| 587 | plaintext, then STARTTLS |
submission |
| 465 | TLS from the first byte | submission |
25 and 587 start in the clear and upgrade. 465 negotiates TLS before any SMTP.
STARTTLS
The server advertises it in the EHLO list:
{ printf 'EHLO mail.example.com\r\n'; sleep 3; printf 'QUIT\r\n'; sleep 1; } \
| nc -w 6 gmail-smtp-in.l.google.com 25 \
| grep -E 'STARTTLS|8BITMIME|SMTPUTF8' | tr '\n' ' 'The sequence is EHLO, STARTTLS, handshake, then EHLO again — the capability list may
differ once encrypted.
Our local server advertises no STARTTLS at all:
EHLO test.local
QUITAsk it to upgrade anyway and it does not know the command:
EHLO test.local
STARTTLS
QUITReading a handshake
openssl s_client does the upgrade and prints what was agreed:
openssl s_client -starttls smtp -brief \
-connect gmail-smtp-in.l.google.com:25 </dev/null 2>&1 \
| grep -E 'ESTABLISHED|Protocol version|Ciphersuite|Peer cert|Verification'Verification: OK means the certificate chains to a trusted root and the name matches.
No credentials are sent, so it is safe against any mail server — and the first command to reach for when you suspect TLS.
Implicit TLS
Port 465 needs no -starttls because there is no plaintext phase:
openssl s_client -brief -connect smtp.gmail.com:465 </dev/null 2>&1 \
| grep -E 'Protocol version|Peer cert|Verification'Use 465 from an application when you can: no plaintext phase means nothing to downgrade.
Opportunistic encryption
Server-to-server TLS is optional. If STARTTLS is missing from the list, the sender
delivers in plaintext rather than failing.
That is the trade — optional encryption delivers mail that mandatory encryption would bounce.
MTA-STS and DANE
Two ways to say “TLS is required for my domain”:
| Published in | Trust comes from | |
|---|---|---|
| MTA-STS | HTTPS, with a DNS pointer | the web PKI |
| DANE | DNSSEC-signed TLSA records | DNSSEC |
The DNS record is only a pointer. The policy itself is fetched over HTTPS:
dig +short TXT _mta-sts.gmail.comcurl -s https://mta-sts.gmail.com/.well-known/mta-sts.txt | head -4mode: enforce means a sender that honours MTA-STS must use TLS to those hosts or not
deliver at all. DANE publishes the same intent as a DNSSEC-signed TLSA record:
dig +short TLSA _25._tcp.mail.protonmail.ch | head -1Both are opt-in by the receiving domain. Publishing one protects mail sent to you, not mail you send.
Hop-by-hop
TLS encrypts the connection between two servers, and every server in the path decrypts the message to route it.
curl -s localhost:8025/api/v2/messages | python3 -c '
import json, sys
d = json.load(sys.stdin)
m = [x for x in d["items"]
if "Thread" in str(x["Content"]["Headers"].get("Subject", ""))][0]
print(m["Content"]["Headers"]["Received"][0].split("\n")[0].strip())'Every Received header from chapter 3 is a server that held the plaintext.
S/MIME and PGP are the end-to-end options — the body is encrypted before it enters SMTP. Both are a different subject, and neither is widely used.