Speed

The Signed Data Is Canonical

The signature covers the RRSIG header and the records in canonical form and order with the original TTL; the first published Ed25519 signature verifies over exactly 74 bytes.

The question

An RRSIG signs the RRset, but a resolver may hold the records in any order, with any letter case and with a TTL that has been counting down. What exactly are the bytes that the signature covers, so that every validator builds the same ones?

The page uses the first published Ed25519 example of RFC 8080, section 6.1, and constructed records under names ending in .test. All of it is public test material that protects nothing. The signed data is the RRSIG RDATA without the signature followed by the records of the RRset in canonical form and canonical order (RFC 4034, 3.1.8, 6.2 and 6.3).

Work it by hand

Each record is written as its owner name, the type, the class, the TTL, the length of the RDATA and the RDATA. In canonical form the names are expanded and lower case, as in Answer Reuses Question Name, and for an MX record the exchange name inside the RDATA is lower case too (RFC 4034, 6.2, item 3).

The TTL is the original TTL of the RRSIG, not the number a cache hands out after some time (A Cache Subtracts the Time). The records of one RRset are sorted by their RDATA as unsigned bytes (RFC 4034, 6.3).

The published example is one MX record: the owner with the labels example and com (13 bytes), type 000f, class 0001, TTL 00000e10 (3600), length 0014 (20), preference 000a and the exchange with the labels mail, example and com (18 bytes). That is 43 bytes, after the 31 bytes of the RRSIG header: 74 signed bytes.

Run it

The command verifies the published signature over exactly those 74 bytes with the DNSKEY's public key. -rawin hands the bytes to the signature algorithm itself, which for Ed25519 needs no digest option. The inputs are the public key (test material, in pub), the data (data) and the signature (sig) of RFC 8080, section 6.1.

The first 16 bytes of the 74 signed bytes 00 0f 0f 03, the first 16 bytes of the 64-byte signature 11 d9 3e 20 and the verdict Signature Verified Successfully.

Public test material, generated for this lesson. Never use it for anything real.

# Verify the published RRSIG signature over the signed data.
# in/data.bin holds the 74 signed bytes, in/sig.bin the 64 signature bytes.
# in/pub.txt is the public key of the DNSKEY (published test material).
pkeyutl -verify -pubin -inkey in/pub.txt -rawin -in in/data.bin \
  -sigfile in/sig.bin
{
  "answer": "Signature Verified Successfully"
}

It prints Signature Verified Successfully. Change one byte of the data and the command exits with status 1 after printing Signature Verification Failure; the page shows OpenSSL's reason, OpenSSL: provider signature failure. The published record prints 3 in the Labels field, and the data above uses 3; with 2, the value that RFC 4034, 3.1.3 gives for an owner of two labels, the same signature fails in the same way.

Your turn

A signer builds the records of an MX RRset for the signed data. The program below is meant to return the canonical bytes of the two records, without the RRSIG header, as hex: name is the owner name, records has two lines of the form preference exchange in any letter case, and ttl is the original TTL. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on five others. All names are built for this page under .test.

An owner name in mixed case, two lines with a preference and an exchange name in mixed case, and the TTL 3600.

Public test material, generated for this lesson. Never use it for anything real.

fn wire(t: string) -> string {
  let w = ""; let p = str_split(t, ".");
  for (i in range(0, p.len())) {
    w = w + hex_byte(str_len(p.at(i))) + ssl.hex(p.at(i));
  }
  return w + "00";
}
fn after(a: string, b: string) -> bool {
  let res = 0;
  for (i in range(0, math_min(hex_len(a), hex_len(b)))) {
    let d = hex_u8(a, i) - hex_u8(b, i);
    if (res == 0 && d != 0) { res = d; }
  }
  return res > 0 || (res == 0 && hex_len(a) > hex_len(b));
}
let rows = str_split(str_lower(records), "\n");
let p1 = str_split(rows.at(0), " "); let p2 = str_split(rows.at(1), " ");
let first = u16_hex(str_to_int(p1.at(0))) + wire(p1.at(1));
let second = u16_hex(str_to_int(p2.at(0))) + wire(p2.at(1));
if (after(first, second)) { let tmp = first; first = second; second = tmp; }
let head = wire(str_lower(name)) + "000f0001" + u32_hex(ttl);
let answer = head + u16_hex(str_len(first)) + first;
answer = answer + head + u16_hex(str_len(second)) + second;
{
  "answer": "04686f7374076578616d706c65047465737400000f000100000e10002c000a056d61696c31076578616d706c6504746573740004686f7374076578616d706c65047465737400000f000100000e10002c0014056d61696c32076578616d706c65047465737400"
}

Return the canonical signed bytes of the two MX records as hex, without the RRSIG header: for each record the lower-case owner name in wire format, type 000f, class 0001, the TTL as 4 bytes, the length of the RDATA as 2 bytes and the RDATA (preference and the lower-case exchange name in wire format). The records come in canonical order, sorted by their RDATA as unsigned bytes.

Read the result carefully

A signature that verifies shows that these bytes were signed with the key; the page shows nothing of how a validator gets the RRset, and the exercise builds bytes and signs nothing. The TTL in the data is a field of the signature: a cache that counts the TTL down must keep the original one for validation, which is why it is in the RRSIG.

This lesson reports one thing about the published example and does not explain it: its Labels field is 3 for an owner of two labels, and the signature verifies with that value only. The records and the key are test material; no claim is made about any algorithm's strength.

Recap

  • The signed data is the RRSIG RDATA without the signature, then the records in canonical form and order.
  • A canonical record has a lower-case expanded owner, the original TTL, and lower-case names in an MX RDATA.
  • The records of an RRset are sorted by RDATA as unsigned bytes.
  • One changed byte of the signed data makes the signature fail.