WHAT THIS IS FOR, and it is the only thing that makes "the MX does not support
TLS" a DECIDABLE statement rather than an observation.
Opportunistic STARTTLS between MTAs protects against a passive observer and
nothing else: an active attacker strips STARTTLS from the EHLO response and
the sender delivers in the clear, by design and without complaint. Verifying
the certificate does not help either - the MX name came from unsigned DNS, so
whoever forged the MX answer also chose the name that would be checked
(RFC 7672 sec.1.3.1).
MTA-STS closes that by letting the RECIPIENT DOMAIN publish, over a channel
the attacker does not control, that TLS is mandatory and which hostnames may
serve it. A stripped STARTTLS then becomes a detected attack instead of a
guess.
THE TRUST IS ENTIRELY IN THE HTTPS FETCH. The TXT record only carries an id;
the policy itself is fetched from https://mta-sts.<domain>/.well-known/
mta-sts.txt, and it is the WEB PKI CERTIFICATE FOR THAT HOST that makes the
policy authentic. So:
- the fetch must verify the certificate against mta-sts.<domain>. A fetcher
that does not is not implementing MTA-STS, it is implementing a way to be
told what to do by whoever answers;
- redirects MUST NOT be followed (RFC 8461 sec.3.3), because a redirect
moves the name the certificate is checked against;
- a fetch FAILURE MUST NOT downgrade a policy already cached (sec.5.1).
That rule is the whole anti-downgrade property: an attacker who can block
port 443 would otherwise turn enforcement off by making the fetch fail.
WHAT THIS UNIT DOES NOT DO. It performs no delivery and makes no TLS decision;
it answers what the domain's policy IS and whether a given MX host is
permitted by it. Acting on that belongs to the delivery agent, where the
connection is.Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)
inherits from Exception
(no public members)
Valid: Boolean;
Id: string;
Mode: tMtaStsMode;
Mx: TArray<string>;
MaxAge: Integer;
Fetched: TDateTime;
HOW THE POLICY FILE IS RETRIEVED. A seam, so a test can supply the text and so a deployment can substitute a fetcher with its own proxy or trust settings - but NOT so it can skip the certificate check, which is the only thing making the answer worth anything.
function Fetch(const aDomain: string; out aText: string; var aWhy: string): Boolean;
The parsed policy for one domain, with the arrival time the cache needs.
Domain: string;
Policy: tMtaStsPolicy;
WHAT A CALLER ASKS ABOUT ONE DELIVERY. Kept as a record so the reason travels with the verdict - a delivery agent that only learns "no" cannot log anything an operator could act on.
Policy: tMtaStsPolicy;
Enforce: Boolean;
Testing: Boolean;
Why: string;
Policy discovery with caching, over an injected resolver and fetcher. NOT thread-safe by itself; a spool that delivers on several threads must give each its own or guard this one.
constructor Create(const aResolver: iDnsResolver; const aFetcher: iMtaStsFetcher);
function PolicyFor(const aDomain: string): tMtaStsVerdict;
function CheckMx(const aDomain, aMxHost: string): tMtaStsVerdict;
procedure ClearCache;
property Lookups: Integer read fLookups;
property Fetches: Integer read fFetches;
sec.3.2. msmNone is a domain saying it HAS a policy and that policy is "do not enforce" - which is not the same as having no policy at all, and is how a domain turns enforcement off without waiting for caches to expire.