如何生成 TLSA 记录并修复 3 1 1 不匹配问题
How to Generate a TLSA Record and Fix the 3 1 1 Mismatch

原始链接: https://dmarcguard.io/blog/tlsa-record-setup/

### 摘要:SMTP 的 DANE 与 TLSA 实现 DANE (基于 DNS 的命名实体身份验证) 通过在 DNS 中使用 **TLSA 记录**锁定邮件服务器证书,从而保障 SMTP 传输安全。尽管由于其必须依赖 DNSSEC 的严苛前提而较为少见,但它仍是目前最稳健的传输身份验证手段。 **“3 1 1” 标准** 对于 SMTP,推荐的配置为 `3 1 1`: * **3 (DANE-EE):** 锁定叶子证书(终端实体)。 * **1 (SPKI):** 对公钥而非完整证书进行哈希(允许无缝密钥复用)。 * **1 (SHA-256):** 哈希算法。 **实施流程** 1. **生成:** 使用 OpenSSL 提取公钥,将其转换为 DER 格式,并生成 SHA-256 哈希值。 2. **DNSSEC:** 您的域名必须已通过 DNSSEC 签名,且在域名注册商处拥有有效的 DS 记录。未经签名的 TLSA 记录将被忽略。 3. **发布:** 在 `_25._tcp.<您的 MX 主机名>` 处创建 TLSA 记录,值设为 `3 1 1 <哈希值>`。 4. **验证:** 使用 `dig +dnssec` 进行验证,确保响应中包含 `ad` (authenticated data) 标志。 **避免配置不匹配** 大多数故障发生在证书更新导致生成新密钥时。**请务必复用您的密钥对**(例如使用 `certbot --reuse-key`),并遵循“先发布后更换”的轮换策略:在转换完成前,请确保当前哈希值和下一代哈希值同时存在于 DNS 中。

Hacker News 最新 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 如何生成 TLSA 记录并修复 3 1 1 不匹配问题 (dmarcguard.io) 4 分,由 meysamazad 发布于 2 小时前 | 隐藏 | 过往 | 收藏 | 讨论 | 帮助 考虑申请 YC 2026 年秋季批次!申请截止日期为 7 月 27 日。 准则 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

A TLSA record pins your mail server’s TLS certificate in DNS so a sending server either reaches the right key over SMTP or refuses to deliver — and its most common form, 3 1 1, is the heart of DANE (DNS-Based Authentication of Named Entities, RFC 6698; for mail, RFC 7672). This guide shows you how to generate a TLSA record with OpenSSL, publish it, verify it resolves and validates, and fix the 3 1 1 mismatch that breaks most deployments. No theory — just the commands.

Who this is for: Postfix and Exim operators and Microsoft 365 admins adding inbound DANE, plus anyone whose dane tlsa 3 1 1 mismatch search landed them here. For what a TLSA record is and where DANE fits in the wider picture, see our DANE protocol guide; this post stays operational.

Key finding

30 of 5.5M scanned domains publish a DANE TLSA record (0.0%)

Source: DMARCguard, State of Email Authentication 2026 (February 2026)

DANE is rare. But for SMTP it is the strongest transport-authentication option there is, and the reason so few domains publish a TLSA record is the DNSSEC prerequisite, not the record itself. If your zone is already signed, the work below takes about three commands and one DNS record.

What Does 3 1 1 Mean? DANE-EE, SPKI, and SHA-256

In a TLSA record, 3 1 1 is three numeric fields: certificate usage 3 (DANE-EE), selector 1 (the SubjectPublicKeyInfo — the public key, not the whole certificate), and matching type 1 (a SHA-256 hash). Together they tell a sending server one thing: this exact public key, hashed with SHA-256, is the only one my mail server will present (RFC 6698 §2.1.1–2.1.3).

Each field is a single octet on the wire:

  • Certificate usage (RFC 6698 §2.1.1)0 PKIX-TA, 1 PKIX-EE, 2 DANE-TA, 3 DANE-EE. For SMTP, only 2 and 3 are usable. Postfix treats usages 0 and 1 as unusable, and RFC 7672 §3.1.3 says SMTP TLSA records SHOULD NOT use PKIX-TA(0) or PKIX-EE(1) — there is no agreed-upon CA list across MTAs and no human present to click through a warning.
  • Selector (RFC 6698 §2.1.2)0 is the full certificate; 1 is the SubjectPublicKeyInfo (SPKI), the public key only. Selector 1 survives a certificate renewal as long as you reuse the same key pair.
  • Matching type (RFC 6698 §2.1.3)0 is an exact match of the selected data, 1 is its SHA-256 hash, 2 is SHA-512.

So 3 1 1 reads as “DANE-EE, SPKI, SHA-256.” RFC 7672 §3.1 names exactly this combination — DANE-EE(3) SPKI(1) SHA2-256(1) — as the primary recommendation for SMTP, because it pins the leaf public key, needs no CA, and explicitly ignores certificate expiry and hostname checks (§3.1.1, §3.1.3). The one alternative worth knowing is 2 1 1 (DANE-TA), which pins the issuing CA instead of the leaf — covered in the examples below.

How to Generate a TLSA Record with OpenSSL

To generate a 3 1 1 TLSA record, extract your certificate’s public key, convert it to DER, and SHA-256 hash it. The 64-character hex digest is the record’s third value:

The first pipe (openssl x509 -noout -pubkey) pulls the SubjectPublicKeyInfo out of the certificate; openssl pkey -pubin -outform DER re-encodes it as the DER bytes the matching type hashes; openssl dgst -sha256 produces the digest. That is selector 1 — you are hashing the public key, so the value stays constant across renewals whenever you reuse the key.

Selector 0 is the trap. Hashing the whole certificate (openssl x509 -outform DER | openssl dgst -sha256, giving a 3 0 1 record) produces a value that changes on every renewal even if the key never moves — which is why selector 1 is the operational default. A second, related mistake is just as common: publishing selector 1 but computing the digest over the whole certificate. The record is syntactically valid and will never match, a top error documented by the DANE SMTP Validator’s “Common Mistakes” list.

Prefer not to run OpenSSL at all? Paste a certificate or hostname into our TLSA/DANE record generator and it computes the 3 1 1 value for you, ready to publish.

TLSA Record Examples: 3 1 1 vs 2 1 1 vs 3 0 1

Use 3 1 1 for almost all SMTP mail: it pins the leaf public key and survives certificate renewal if you reuse the key. Use 2 1 1 only when you must pin the issuing CA across leaf rotations; avoid 3 0 1, because the full-cert hash changes on every renewal. Here are all three as live records:

When to use each TLSA record flavor for SMTP

The owner name always follows the same shape: _25._tcp.<MX hostname> — port 25, TCP, then the MX host that actually accepts mail (RFC 7672 §2.1). DANE binds to each MX host independently, not to the org domain, so a domain with two MX hosts needs a TLSA record under each. (RFC 7672 §3.1 lists DANE-TA(2) Cert(0) SHA2-256(1) — the 2 0 1 full-CA form — as its documented second choice; operators more often publish the 2 1 1 SPKI variant to pin just the CA’s key.)

How to Publish the TLSA Record at Your DNS Provider

Publish the record at the owner name _25._tcp.<your-mx-hostname> as record type TLSA (or generic type TYPE52 if your provider lacks a TLSA field), with the three fields and the hash as the value. The zone MUST be DNSSEC-signed and the DS record published at your registrar — otherwise validating senders ignore the record entirely.

Publish a TLSA record for mail services

  1. Pick the owner name per MX host. For mail.example.com that is _25._tcp.mail.example.com. Repeat for every MX hostname you run.

  2. Choose the record type. Select TLSA if your panel offers it; if not, use the generic TYPE52 form, which is the same record under its numeric name.

  3. Paste the value 3 1 1 <your-64-char-hash> — three space-separated fields followed by the digest from the OpenSSL step.

  4. Set a short-ish TTL (300–3600 seconds). A lower TTL makes the publish-before-swap rollover later in this guide propagate faster.

  5. Confirm DNSSEC is live. Your zone must be signed and the DS record present at your registrar. Without it, the TLSA is invisible to senders (RFC 6698 §4).

DNSSEC is the hard prerequisite, not an optional extra. A TLSA record in an unsigned zone is treated as insecure and ignored (RFC 6698 §4); an expired RRSIG takes the whole zone bogus, so even A/AAAA and MX stop resolving. Sign the zone and publish the DS record before you publish the TLSA. Provider support varies — some registrars are slow to accept DS records for external nameservers, and some DNS panels only expose the generic TYPE52 form — so confirm both ends of the chain before you rely on the record.

How to Check and Validate Your TLSA Record

Verify a TLSA record with dig +dnssec TLSA _25._tcp.mail.example.com — confirm the record returns and that the ad (authenticated-data) flag is set, which proves the DNSSEC chain validated. Then confirm the record actually matches the served certificate before you enforce anything:

The ad flag is the part operators miss. A record can resolve perfectly and still be worthless if it is unsigned — conforming MTAs ignore any TLSA that DNSSEC did not authenticate (RFC 6698 §4). posttls-finger -l dane-only goes one step further: it connects to the live MX, negotiates STARTTLS, and logs which TLSA record matched, so you confirm the hash matches the served certificate before you commit. It is an unsupported Postfix test program, but it is the canonical pre-deploy check.

If you would rather not assemble the commands, run your mail host through our free DANE/TLSA checker — it resolves the record, validates the DNSSEC chain, and tells you whether the hash matches the live certificate.

How to Fix a TLSA 3 1 1 Mismatch

A TLSA 3 1 1 mismatch almost always means the published hash no longer equals the public key your server now presents — usually because a certificate renewal generated a new key. Fix it by re-generating the 3 1 1 hash from the live certificate, or prevent it by reusing the key (certbot --reuse-key) and always running two records — current plus next. Work through the causes in order; the first one accounts for most production failures.

  1. A renewal generated a new key pair. This is the single most common cause. Certbot’s default renewal issues a fresh key each cycle, so a selector-1 hash stops matching the served leaf at the first renewal — often weeks after a clean deploy. Fix: re-hash the live certificate and republish, then switch renewals to certbot --reuse-key so the SPKI stays stable.
  2. You hashed the wrong object. Publishing selector 1 but computing the digest over the whole certificate (or over a non-DER encoding) produces a valid-looking record that never matches. Fix: re-run the SPKI pipeline from the generate section — x509 -pubkeypkey -pubin -outform DERdgst -sha256.
  3. The usage is unusable for SMTP. A 1 x x (PKIX-EE) record is treated as unusable by Postfix, which withdrew its silent 13 mapping in version 3.2 — so the record behaves as if no TLSA exists (Postfix TLS_README). Fix: use usage 3 (or 2).
  4. An ACME intermediate “jumped.” Let’s Encrypt periodically rotates which intermediate signs your leaf (for example R10 ↔ R11), which breaks a 2 1 1 DANE-TA record even when the leaf key is unchanged (mailcow community, August 2024). Fix: publish a stable 3 1 1 leaf record, and if you also pin the CA, publish a 2 1 1 for every intermediate that can sign you.
  5. The zone is not DNSSEC-signed, or the signature is broken. An unsigned zone makes the TLSA invisible; an expired RRSIG turns the zone bogus; and an NSEC3 “proof of non-existence” on the _tcp ancestor label can make a QNAME-minimizing resolver conclude the _25._tcp record does not exist. Fix: sign the zone, keep signatures fresh, and re-test with dig +dnssec.
  6. The TTL has not flushed during a rollover. Activating the new certificate before the old TLSA record’s TTL expires leaves senders matching against a cached hash that no longer applies. Fix: use the publish-before-swap pattern below.

The prevention pattern is two records and patience. Publish the current and next 3 1 1 records together, leave both in place through the transition, deploy the new chain, then drop the old record — RFC 6698’s key-rollover guidance and RFC 7672’s deployment checklist (step 5) both put the new record in DNS before the new certificate goes live:

One more caveat for larger setups: if a host presents more than one chain — say an RSA and an ECDSA certificate, or you run multiple MX hosts — a single 3 1 1 cannot match every chain a sender might negotiate. Provision a current-plus-next pair per algorithm and per MX host before you enforce. Then re-run the check from the previous section to confirm the fix landed.

Is DANE Right for Your Domain?

DANE only protects mail when both sides cooperate: your zone must be DNSSEC-signed, and the sending server must validate DANE. Postfix (built-in), Exim 4.91+ (built with SUPPORT_DANE=yes), Microsoft 365 / Exchange Online (inbound DANE GA in 2024, outbound since March 2022), Proton Mail and Comcast all honor it — but Gmail and Google Workspace do not validate inbound DANE and rely on MTA-STS instead. Publishing a TLSA record does not mean every sender checks it; if your senders are Gmail-hosted, deploy MTA-STS as well, and decide which to publish.

Adoption is real but fragile. Even in the highest-adoption market, the Netherlands, only about 14% of domains supported DANE in September 2025, and 33 regressed to no standard within two months. So a TLSA record is not set-and-forget — pair it with TLS-RPT to catch a silent mismatch (RFC 8460) before a renewal turns into lost mail.

FAQ

How do I generate a TLSA record with OpenSSL?

Pipe your certificate through three commands: openssl x509 -noout -pubkey, openssl pkey -pubin -outform DER, then openssl dgst -sha256. The 64-character hex digest becomes the third field of a 3 1 1 record. A generator tool produces the same value without OpenSSL.

What does 3 1 1 mean in a TLSA record?

Three fields: usage 3 (DANE-EE — pin this end-entity certificate), selector 1 (hash the public key, not the whole certificate), and matching type 1 (SHA-256). RFC 7672 names it the recommended configuration for SMTP DANE on port 25.

How do I check if my TLSA record is valid?

Run dig +dnssec TLSA _25._tcp.mail.example.com and confirm both the record and the ad (authenticated-data) flag appear, then check the hash matches the live certificate with a DANE checker or posttls-finger. An unsigned TLSA is ignored by senders.

Why does my TLSA record keep mismatching after certificate renewal?

Renewal usually generates a new key, so a selector-1 hash stops matching on the first renewal. Reuse the key with certbot --reuse-key and always publish two records — current plus next — so a renewal can never leave a zero-match record set.

Should I use 3 1 1 or 2 1 1 for email?

Use 3 1 1 for most SMTP mail — it pins your leaf public key and survives renewal when you reuse the key. Use 2 1 1 only to pin the issuing CA across leaf rotations; it breaks if the signing intermediate changes, as Let’s Encrypt’s does.

Conclusion

Generating a TLSA record is three commands; keeping it matching is the real work. The four moves are always the same:

  • Generate the 3 1 1 hash from the SPKI, not the full certificate.
  • Publish it at _25._tcp.<mx> in a DNSSEC-signed zone, with the DS record live at your registrar.
  • Verify the ad flag and confirm the hash matches the served certificate before you enforce.
  • Prevent mismatches with key reuse and a publish-before-swap rollover — two records, current and next, every time.

A TLSA record only protects mail when it matches the key your server actually serves. Check it the day you publish it, and check it again after every renewal.

联系我们 contact @ memedata.com