skip to content

After a 2048-bit DKIM key is pasted into a DNS panel, signatures start failing; why does the key's length matter, and how do you check the record?

level: seniorimportance: nice to knowfreq 16%

answer

  1. a per-string octet limit
  2. about 400 characters of base64
  3. several strings, one record
  4. joined with nothing between
  5. compare against the private key

basics

~20 s

A 2048-bit RSA key is about 392 base64 characters, more than one 255-octet TXT string holds, so it is published as several strings in one record, joined with no separator. Panels that truncate, quote or split it wrongly break p=.

solid answer

~50 s

A single TXT string holds at most 255 octets, and a 2048-bit RSA public key in base64 is about 392 characters before `v=DKIM1; k=rsa; p=` is added, so the value must be stored as two or more strings inside one record. RFC 6376 section 3.6.2.2 has verifiers concatenate the strings with no intervening whitespace, so the split may fall anywhere. Typical breakage: a panel that silently cuts the value at 255 characters, literal quote marks pasted into the value, or the pieces entered as separate TXT records, which RFC 6376 says gives undefined results. Check by querying the selector name, joining the strings, and comparing `p=` with the public half derived from the signing private key; then send a test message and look for `dkim=pass` with the expected `header.s`. Ed25519 keys are 44 characters and fit in one string (RFC 8463).

code

dns · 5 lines
dns
; one TXT record, three strings; verifiers join them with nothing between
s2026a._domainkey.example.com. 3600 IN TXT (
    "v=DKIM1; k=rsa; "
    "p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."
    "...IDAQAB" )

go deeper

for a junior

Recall that one TXT string holds at most 255 octets, so a 2048-bit DKIM key has to be published as several strings in one record.

for a middle

Explain that verifiers join the strings with no separator, so the split can fall anywhere, and why two separate records at one selector are a fault.

for a senior

Show the full check: query, join, compare p= end to end with the key derived from the signing private key, then confirm dkim=pass with the expected selector.

for a principal

Decide which provisioning paths may publish DKIM records, and make a read-back check mandatory for every key change rather than trusting the panel.

## Why a 2048-bit key does not fit in one string A **DKIM key record** is a TXT record at `<selector>._domainkey.<d=>` whose `p=` tag holds the public key in **base64**. DNS stores TXT data as one or more character strings of **at most 255 octets each**; the record-type mechanics are covered with DNS record types, but the arithmetic matters here. The RSA key in `p=` is the DER-encoded public key that RFC 6376's own example places in the record: | Key | Approximate `p=` length | Fits one 255-octet string? | |---|---|---| | RSA 1024-bit | about 216 characters | yes, just, with short tags | | RSA 2048-bit | about 392 characters | no, needs at least two strings | | RSA 4096-bit | about 736 characters | no, and RFC 6376 warns it may exceed a 512-byte UDP DNS response | | Ed25519 | 44 characters (RFC 8463) | yes, easily | RFC 8301 (January 2018) says signers MUST use RSA keys of at least 1024 bits and SHOULD use at least 2048, so the common, recommended key is exactly the one that does not fit in a single string. ## How the record is meant to look The value is published as **one TXT record holding several strings**. RFC 6376 section 3.6.2.2 says the strings MUST be concatenated before use with no intervening whitespace, so the boundary can fall anywhere, even inside the base64. RFC 6376's own example splits a key across five strings. In zone-file form the strings are quoted and grouped in parentheses; a web panel usually does the splitting itself when given the whole value. ## How panels and people break it - **Silent truncation.** The panel accepts only 255 characters in one field and drops the rest; `p=` loses its tail and no longer decodes to a valid key. - **Quote marks inside the value.** Someone pastes the zone-file form, quotes included, into a panel field that adds its own quoting, so literal `"` characters land inside `p=`. - **Two records instead of two strings.** Each chunk is entered as its own TXT record. RFC 6376 says TXT records MUST be unique for a selector name and that several records in one RRset give undefined results; a verifier may see one half-key or the other. - **Falling back to a shorter key.** Shrinking the key to fit is no fix: RFC 8301 says verifiers MUST NOT consider signatures from RSA keys under 1024 bits valid. - **The wrong key.** The record is complete but holds the public half of a different key pair, for example a test key. ## Checking the published record against the signing key 1. **Query** the TXT record at the exact selector name the signer puts in `s=`, under the `d=` domain. 2. **Join** the returned strings with nothing between them and confirm there is exactly one record. 3. **Parse** the tags: `v=DKIM1` first if present, `k=` matching the signer's algorithm, `p=` non-empty. 4. **Derive** the public half from the private key the signer actually uses, encode it the same way, and compare it with `p=` in full, end included: truncation always damages the end. 5. **Send** an ordinary test message to a mailbox you control and read `Authentication-Results`: `dkim=pass` with `header.d` and `header.s` naming this domain and selector shows a receiver found and used the record. ## Reading the symptom When the record is truncated or malformed, every message signed with that selector fails, not a sample, and the failure is permanent rather than intermittent. The exception is the two-records mistake, where the outcome depends on which record a verifier happens to use, so failures can look random. An intermittent temporary error points instead at DNS reachability, which belongs with signature verification. A truncated or malformed key gives the verifier nothing usable, and RFC 6376 treats an unusable key record as a permanent failure. ## Avoiding the problem - Use a panel or provisioning tool that accepts long TXT values and splits them itself, and read the result back. - Know that an **Ed25519** key record, at its own selector, sidesteps the limit: RFC 8463 notes that its 44-character key fits in a single string and works even with provisioning software that cannot handle multi-string TXT records. Whether and when to add one is a key-policy decision, not a DNS workaround. - Make the record check part of every key change, not just the first deployment.

  • Why does an Ed25519 DKIM key record avoid the string-length problem?
    An Ed25519 public key is 256 bits, so its base64 form is 44 octets. RFC 8463 (September 2018) notes that the record will generally fit in a single 255-byte TXT string and work even with DNS provisioning software that does not handle multi-string TXT records. Not every verifier supports `k=ed25519`, so it is published beside an RSA key, not instead of one.
  • Would a 4096-bit RSA key be the safer choice for a DKIM record?
    Not automatically. RFC 8301 requires verifiers to handle 1024 to 4096 bits and recommends signers use at least 2048. RFC 6376 section 3.3.3 notes that 4096-bit keys might not fit a 512-byte UDP DNS response and cost more CPU to sign and verify. A 2048-bit key meets the recommendation with less DNS size and processing cost.
  • How can you tell a 1024-bit RSA key from a 2048-bit one by reading the published DKIM record?
    By the length of `p=`: in the DER-encoded form RFC 6376's example publishes, a 1024-bit key is about 216 base64 characters and begins `MIGf`, while a 2048-bit key is about 392. RFC 8301 (January 2018) allows 1024 bits but recommends 2048, so a short `p=` is a finding to hand to the key-replacement plan.

  • Verifiers insert a space between TXT strings, so split only at a tag boundary.
  • Entering the key as two TXT records is the same as two strings in one record.
  • If the key is too long for the panel, a 512-bit key is an acceptable fallback.
  • Comparing the first characters of p= with the key file proves the record is right.
  • A truncated key record makes only some messages fail DKIM.