TLS
Stalwart implements TLS support to ensure secure transmission of emails over the internet. TLS (Transport Layer Security) is essential for protecting data in transit, providing encryption, authentication, and integrity to prevent unauthorized access and tampering of email messages. Stalwart’s TLS configuration is built on rustls, a modern, high-performance TLS library that prioritizes safety and correctness.
A TLS strategy defines the transport security policies and TLS configuration to use when establishing encrypted connections to remote mail servers. While connection strategies control the basic mechanics of establishing a session, TLS strategies determine the security requirements for that session.
Each TLS strategy allows fine-grained control over several key parameters related to encryption and certificate validation. These include:
- DANE enforcement: Specifies whether to validate the recipient domain's TLSA DNS records, allowing for cryptographically verified STARTTLS connections using DANE.
- MTA-STS enforcement: Enables enforcement of MTA-STS policies, which require the recipient domain to publish a secure transport policy via HTTPS.
- STARTTLS handling: Determines whether STARTTLS must be required, opportunistic, or disabled entirely for a connection.
- Certificate validation: Controls whether invalid or self-signed certificates should be accepted, rejected, or conditionally allowed.
- TLS timeouts: Configures time limits for TLS negotiation and handshake completion.
TLS strategies are defined under the queue.tls.<id> section of the configuration, where <id> is the name of the TLS strategy. As with other strategies, a specific TLS strategy is selected at runtime using an expression assigned to the TLS strategy setting.
TLS strategies help ensure that message delivery complies with the transport security expectations of both the sending and receiving parties, while allowing flexibility in how these policies are applied across different delivery contexts. For example, administrators might configure strict TLS settings for domains that support DANE or MTA-STS, while using more permissive settings for legacy systems that do not fully support modern TLS features.
Policy Enforcement
Stalwart MTA allows administrators to enforce transport security policies on outbound SMTP connections through configurable TLS strategy settings. These settings control how the MTA handles DANE, MTA-STS, and STARTTLS, each of which plays a role in ensuring secure message delivery over the network.
Policy enforcement is configured in the TLS strategy using the following queue.tls.<id>.dane, queue.tls.<id>.mta-sts and queue.tls.<id>.starttls parameters. Each of these parameters accepts one of the following values:
optional: Use the security mechanism if available, but do not require it.require: Enforce the mechanism strictly; delivery fails if it cannot be used.disable: Do not attempt to use the mechanism at all.
DANE
DANE (DNS-Based Authentication of Named Entities) allows SMTP clients to validate a recipient server’s TLS certificate using DNSSEC-protected TLSA records. If queue.tls.<id>.dane is set to require, the MTA will only deliver messages to servers that publish valid and verifiable TLSA records. If set to optional, it will attempt DANE validation when possible but fall back to regular STARTTLS if the records are missing or invalid.
Example:
[queue.tls.secure]
dane = "require"
This enforces strict DANE validation and ensures that delivery only proceeds if a secure, DNSSEC-validated path is available.
MTA-STS
MTA-STS (Mail Transfer Agent Strict Transport Security) is a policy mechanism that allows recipient domains to publish a required TLS policy over HTTPS. When queue.tls.<id>.mta-sts is set to require, the MTA will enforce the domain’s published policy and refuse to deliver if a secure connection cannot be negotiated. Setting it to optional allows delivery to proceed even if the policy can't be validated.
Example:
[queue.tls.default]
mta-sts = "optional"
In this case, MTA-STS is used when supported but not enforced, making it suitable for general-purpose delivery to a variety of domains.