Can you trust a DNS answer?
DNS Security Extensions (DNSSEC) add digital signatures to DNS records, so a resolver can check that an answer really came from the zone's owner.
It matters because plain DNS answers carry no proof. A forged answer can send a whole college to the wrong mail server or the wrong sign-in page.
By the end of this lesson
Note
I can sign a DNS zone and show that a changed record no longer verifies.
Key words
| Word | What it means | Example |
|---|---|---|
| Zone | the set of DNS records one owner looks after | example.test |
| DNSKEY | a record holding a zone's public key | |
| RRSIG | a record holding the signature of a set of records | |
| DS record | a hash of a child zone's key, kept by its parent | |
| Chain of trust | each parent vouching for its child's key, down from the root |
The cells students fill in are left blank in this preview.
Starter
Have a go
Starter
4 questionsEach zone signs, and its parent vouches
A signed zone publishes its public key in a DNSKEY record and signs every set of records with an RRSIG. A resolver checks each RRSIG with the DNSKEY.
But why trust the DNSKEY? Because the parent zone holds a DS record, a hash of it, signed by the parent. Each parent vouches for its child, up to the root.
Worked example: the records DNSSEC adds
| Record | Where | What it does |
|---|---|---|
| DNSKEY 257 | example.test | The key-signing key: signs the zone's keys |
| DNSKEY 256 | example.test | The zone-signing key: signs every other record |
| RRSIG | Beside each set | The signature, with dates and the key tag |
| NSEC | Between names | Proves a name does not exist |
| DS | In the parent, test. | A hash of the key-signing key |
The cells students fill in are left blank in this preview.
Check
Have a go
Check
3 questionsInstall the signing tools
sudo apt-get install -y -qq bind9-utilsShown here, not run. Press Start lab to type it into your own lab’s terminal.
Write the zone for example.test
mkdir -p mail && printf '%s\n' 'example.test. 3600 IN SOA ns1.example.test. hostmaster.example.test. 1 7200 900 1209600 300' 'example.test. 3600 IN NS ns1.example.test.' 'example.test. 3600 IN MX 10 mail.example.test.' 'example.test. 3600 IN TXT "v=spf1 mx -all"' 'ns1.example.test. 3600 IN A 10.0.10.1' 'mail.example.test. 3600 IN A 10.0.10.25' > mail/example.test.zoneShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check the zone file
named-checkzone example.test mail/example.test.zoneShown here, not run. Press Start lab to type it into your own lab’s terminal.
Make the key-signing key
dnssec-keygen -K mail -a ECDSAP256SHA256 -f KSK example.testShown here, not run. Press Start lab to type it into your own lab’s terminal.
Make the zone-signing key
dnssec-keygen -K mail -a ECDSAP256SHA256 example.testShown here, not run. Press Start lab to type it into your own lab’s terminal.
Sign the zone
dnssec-signzone -K mail -S -O full -o example.test -f mail/signed.zone mail/example.test.zoneShown here, not run. Press Start lab to type it into your own lab’s terminal.
Look at the mail server's records
grep '^mail' mail/signed.zone | cut -c1-90Shown here, not run. Press Start lab to type it into your own lab’s terminal.
Check the Run
Have a go
Check the Run
3 questionsVerify the signed zone
dnssec-verify -o example.test mail/signed.zoneShown here, not run. Press Start lab to type it into your own lab’s terminal.
Change one address in the signed file
sed -i 's/10.0.10.25/10.0.10.99/' mail/signed.zoneShown here, not run. Press Start lab to type it into your own lab’s terminal.
Verify the changed zone
dnssec-verify -o example.test mail/signed.zoneShown here, not run. Press Start lab to type it into your own lab’s terminal.
What the two checks printed
| Run | Printed | Meaning |
|---|---|---|
| Before the change | Zone fully signed: Algorithm: ECDSAP256SHA256: KSKs: 1 active ... ZSKs: 1 active | Every signature checks |
| After the change | No correct ECDSAP256SHA256 signature for mail.example.test A | The address no longer matches its RRSIG |
| After the change | DNSSEC completeness test failed. | A validating resolver would refuse the answer |
The cells students fill in are left blank in this preview.
A common mistake
Warning
Many people think DNSSEC encrypts DNS. It signs answers and hides nothing: anyone can still read the question and the answer. Encryption is a different tool, DNS over TLS or HTTPS.
The parent needs the DS record
Signing is not enough on its own. Until the parent zone publishes a DS record for the key-signing key, resolvers have no reason to trust the DNSKEY.
The owner gives the DS record to the registrar. When keys change, the old DS must stay until the new one is everywhere, or the zone stops resolving for validating resolvers.
Make the DS record for the parent
dnssec-dsfromkey -2 -f mail/signed.zone example.testShown here, not run. Press Start lab to type it into your own lab’s terminal.
Show the key-signing key
grep 'DNSKEY.*257' mail/signed.zoneShown here, not run. Press Start lab to type it into your own lab’s terminal.
Try it: a hash changes completely
# A DS record is a hash of the child's signing key, kept by the parent.
import hashlib
key_a = b"pretend key of example.test"
key_b = b"pretend key of example.test!"
print(hashlib.sha256(key_a).hexdigest()[:16])
print(hashlib.sha256(key_b).hexdigest()[:16])
# One character more gives a completely different hash.
# Change key_b back to match key_a, then press Run.
Make a free account to save your work and track your progress.
Assignment: key tag and DS digest
Work out what dnssec-dsfromkey prints, from a DNSKEY record. A DNSKEY's data is its flags (2 bytes), protocol (1 byte), algorithm (1 byte) and the key decoded from base64; the base64 may contain spaces.
key_tag(flags, protocol, algorithm, key) adds the data's bytes, the even-numbered ones (0, 2, 4 ...) times 256 and the odd ones as they are, then adds the total divided by 65536 (whole number) to itself and keeps the remainder after dividing by 65536.
ds_digest(owner, flags, protocol, algorithm, key) returns the SHA-256, in capital hex, of the owner name in wire form followed by the data. Wire form is each label in lower case after a byte holding its length, then a zero byte; a final dot is ignored.
import base64
import hashlib
def key_tag(flags, protocol, algorithm, key):
return 0
def ds_digest(owner, flags, protocol, algorithm, key):
return ""
Make a free account to save your work and track your progress.
Exit quiz
Have a go