Skip to content
Sign inGet all access
Chapter 6·8 minFree

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:

terminal
{ 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' ' '
Output250-8BITMIME 250-STARTTLS 250-SMTPUTF8

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
QUIT
Output220 mailhog.example ESMTP MailHog250-Hello test.local250-PIPELINING250 AUTH PLAIN221 Bye

Ask it to upgrade anyway and it does not know the command:

EHLO test.local
STARTTLS
QUIT
Output500 Unrecognised command221 Bye

Reading a handshake

openssl s_client does the upgrade and prints what was agreed:

terminal
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'
OutputCONNECTION ESTABLISHEDProtocol version: TLSv1.3Ciphersuite: TLS_AES_256_GCM_SHA384Peer certificate: CN=mx.google.comVerification: OK

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:

terminal
openssl s_client -brief -connect smtp.gmail.com:465 </dev/null 2>&1 \
  | grep -E 'Protocol version|Peer cert|Verification'
OutputProtocol version: TLSv1.3Peer certificate: CN=smtp.gmail.comVerification: OK

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:

terminal
dig +short TXT _mta-sts.gmail.com
Output"v=STSv1; id=20190429T010101;"
terminal
curl -s https://mta-sts.gmail.com/.well-known/mta-sts.txt | head -4
Outputversion: STSv1mode: enforcemx: smtp.google.commx: gmail-smtp-in.l.google.com

mode: 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:

terminal
dig +short TLSA _25._tcp.mail.protonmail.ch | head -1
Output3 1 1 6111A5698D23C89E09C36FF833C1487EDC1B0C841F87C49DAE8F7A09 E11E979E

Both 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.

terminal
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())'
Outputfrom test.local by mailhog.example (MailHog)

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.