-
Notifications
You must be signed in to change notification settings - Fork 1
/
cdscdnskey.go
60 lines (54 loc) · 1.32 KB
/
cdscdnskey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"github.com/apex/log"
"github.com/miekg/dns"
)
// checks that CDS and CDNSKEY point to the same keys or both use algorithm zero
func checkCDSCDNSKEY(cache Cache, origin string) (r Result) {
if _, ok := cache[origin]["CDS"]; !ok {
log.Debug("NO CDS records at apex.")
return
}
if _, ok := cache[origin]["CDNSKEY"]; !ok {
log.Debug("NO CDNSKEY records at apex.")
return
}
for _,rr := range cache[origin]["CDNSKEY"] {
cdnskey := rr.(*dns.CDNSKEY)
found := false
for _,rc := range cache[origin]["CDS"] {
cds := rc.(*dns.CDS)
if cds.Algorithm != cdnskey.Algorithm {
continue
}
if cds.KeyTag != cdnskey.KeyTag() {
continue
}
found = true
}
if !found {
log.Errorf("CDNSKEY record with alg=%d and keytag=%d, had no matching CDS record", cdnskey.Algorithm, cdnskey.KeyTag())
r.errors++
}
}
for _,rc := range cache[origin]["CDS"] {
cds := rc.(*dns.CDS)
found := false
for _,rr := range cache[origin]["CDNSKEY"] {
cdnskey := rr.(*dns.CDNSKEY)
cds := rc.(*dns.CDS)
if cds.Algorithm != cdnskey.Algorithm {
continue
}
if cds.KeyTag != cdnskey.KeyTag() {
continue
}
found = true
}
if !found {
log.Errorf("CDS record with alg=%d and keytag=%d, had no matching CDNSKEY record", cds.Algorithm, cds.KeyTag)
r.errors++
}
}
return
}