Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Mail.MTASTS

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)

Classes, interfaces and records

classeMtaStsError

inherits from Exception

(no public members)

recordtMtaStsPolicy

Valid: Boolean; Id: string; Mode: tMtaStsMode; Mx: TArray<string>; MaxAge: Integer; Fetched: TDateTime;
When this copy was fetched, for the cache's expiry arithmetic.

interfaceiMtaStsFetcher

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;
aDomain is the POLICY domain, not the host: the implementation builds mta-sts.<domain> itself, so no caller can point the fetch elsewhere. False with aWhy means no policy could be retrieved - which is NOT the same as a policy that says none, and the cache must treat it differently.

recordtMtaStsCacheEntry

The parsed policy for one domain, with the arrival time the cache needs.

Domain: string; Policy: tMtaStsPolicy;

recordtMtaStsVerdict

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;
The policy in force, if any.
Enforce: Boolean;
True when the policy is msmEnforce, i.e. a TLS failure must stop the delivery rather than fall back.
Testing: Boolean;
True when the policy exists and is msmTesting: report, deliver anyway.
Why: string;

classtMtaStsResolver

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;
The policy for aDomain, from cache when it is still fresh and its id has not changed, otherwise fetched. A domain with no TXT record has no policy, which is reported as a verdict with Enforce and Testing both False.
function CheckMx(const aDomain, aMxHost: string): tMtaStsVerdict;
The whole question a delivery agent asks: may this MX host be used, and must TLS succeed?
procedure ClearCache; property Lookups: Integer read fLookups;
Counters, for a test that asserts the cache actually prevented work.
property Fetches: Integer read fFetches;

Types (enumerations, sets, aliases)

enumtMtaStsMode

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.

  tMtaStsMode = (msmNone, msmTesting, msmEnforce);

Routines