-
Notifications
You must be signed in to change notification settings - Fork 1
/
dnskey_test.go
136 lines (124 loc) · 8.07 KB
/
dnskey_test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"strings"
"testing"
//"github.com/spf13/viper"
"github.com/miekg/dns"
)
var dnskeyZone0 string = `
test. 300 IN SOA master.ns.test. mail.nic.test. 12345 1800 3600 7200 14400
test. 300 IN RRSIG SOA 13 1 300 20220130235959 20220101000000 11082 test. b1ACEv+pTeBYgeQ7ZZxloV7qssb8a17azszTfxoRB0NbqnI+x4uD9BgTFGnp2tpo1TykmRGiUtNSAHk5EqFUPg==
test. 300 IN NS a.ns.test.
test. 300 IN NS ns.test.
test. 300 IN RRSIG DNSKEY 13 1 300 20220130235959 20220101000000 32290 test. Y5B9IvpOrLsWk9UBTv8IJXhYHH2cZ6xzoW1mGBHXisjyh5AnCvaTRQD75kwe96zaH42ZNeqVdUi9CQ29qjH0/g==
test. 300 IN NSEC brokensig.test. NS SOA RRSIG NSEC DNSKEY
test. 300 IN RRSIG NSEC 13 1 300 20220130235959 20220101000000 11082 test. ggcZp9vWnRPcX2noMta0dPv4KjsYTugO2ODW3jaBacf5QQfz3DYq/KIZprqsTZf2DThXKmQV+qRsUY4hcrNbJw==
`
var dnskeyZone1 string = `
test. 300 IN SOA master.ns.test. mail.nic.test. 12345 1800 3600 7200 14400
test. 300 IN RRSIG SOA 13 1 300 20220130235959 20220101000000 11082 test. b1ACEv+pTeBYgeQ7ZZxloV7qssb8a17azszTfxoRB0NbqnI+x4uD9BgTFGnp2tpo1TykmRGiUtNSAHk5EqFUPg==
test. 300 IN NS a.ns.test.
test. 300 IN NS ns.test.
test. 300 IN DNSKEY 256 3 13 IcKbK9FMlIsJSzC2o53aPsWGELPvWpWbKnZ2zJiID6nY6TFpMy31z60TNNbbfgJsGloL+zrOZwuV+h6darXNUw== ;{id = 11082 (zsk), size = 256b}
test. 300 IN DNSKEY 257 3 13 t2LVP+yZIiE9JPorgUdZNesR9fYl+715hSjItwxqzxgdH4ApBhqpA/lu/xF9ADmtUAZeU1PbIHXtbwP2HMOyoA== ;{id = 32290 (ksk), size = 256b}
test. 300 IN RRSIG DNSKEY 13 1 300 20220130235959 20220101000000 32290 test. Y5B9IvpOrLsWk9UBTv8IJXhYHH2cZ6xzoW1mGBHXisjyh5AnCvaTRQD75kwe96zaH42ZNeqVdUi9CQ29qjH0/g==
test. 300 IN NSEC brokensig.test. NS SOA RRSIG NSEC DNSKEY
test. 300 IN RRSIG NSEC 13 1 300 20220130235959 20220101000000 11082 test. ggcZp9vWnRPcX2noMta0dPv4KjsYTugO2ODW3jaBacf5QQfz3DYq/KIZprqsTZf2DThXKmQV+qRsUY4hcrNbJw==
brokensig.test. 300 IN A 10.0.0.0
`
var dnskeyZone2 string = `
test. 300 IN SOA master.ns.test. mail.nic.test. 12345 1800 3600 7200 14400
test. 300 IN RRSIG SOA 13 1 300 20220130235959 20220101000000 11082 test. b1ACEv+pTeBYgeQ7ZZxloV7qssb8a17azszTfxoRB0NbqnI+x4uD9BgTFGnp2tpo1TykmRGiUtNSAHk5EqFUPg==
test. 300 IN NS a.ns.test.
test. 300 IN NS ns.test.
test. 300 IN DNSKEY 256 3 13 IcKbK9FMlIsJSzC2o53aPsWGELPvWpWbKnZ2zJiID6nY6TFpMy31z60TNNbbfgJsGloL+zrOZwuV+h6darXNUw== ;{id = 11082 (zsk), size = 256b}
test. 300 IN DNSKEY 257 3 13 t2LVP+yZIiE9JPorgUdZNesR9fYl+715hSjItwxqzxgdH4ApBhqpA/lu/xF9ADmtUAZeU1PbIHXtbwP2HMOyoA== ;{id = 32290 (ksk), size = 256b}
test. 300 IN DNSKEY 257 3 13 +s9JyBVaDVllZjVM1sgpXZxjo13cz/KHiYfQ0P14BaUYcy8/L8b57AU3AoZ0/Ken5lG+ZO9biPC8Ek+XVn55BQ== ;{id = 185 (ksk), size = 256b}
test. 300 IN DNSKEY 257 3 13 muZog6Q/E0r76zzPY7sN6hlE/LyKwaw/ymjhlBUbN6pTjm0DlQ5YkxjhliihD8wGJ0Jc35y0ETzDZSMEyA6msg== ;{id = 185 (ksk), size = 256b}
test. 300 IN RRSIG DNSKEY 13 1 300 20220130235959 20220101000000 32290 test. Y5B9IvpOrLsWk9UBTv8IJXhYHH2cZ6xzoW1mGBHXisjyh5AnCvaTRQD75kwe96zaH42ZNeqVdUi9CQ29qjH0/g==
test. 300 IN NSEC brokensig.test. NS SOA RRSIG NSEC DNSKEY
test. 300 IN RRSIG NSEC 13 1 300 20220130235959 20220101000000 11082 test. ggcZp9vWnRPcX2noMta0dPv4KjsYTugO2ODW3jaBacf5QQfz3DYq/KIZprqsTZf2DThXKmQV+qRsUY4hcrNbJw==
brokensig.test. 300 IN A 10.0.0.0
`
var dnskeyZone3 string = `
test. 300 IN SOA master.ns.test. mail.nic.test. 12345 1800 3600 7200 14400
test. 300 IN RRSIG SOA 13 1 300 20220130235959 20220101000000 11082 test. b1ACEv+pTeBYgeQ7ZZxloV7qssb8a17azszTfxoRB0NbqnI+x4uD9BgTFGnp2tpo1TykmRGiUtNSAHk5EqFUPg==
test. 300 IN NS a.ns.test.
test. 300 IN NS ns.test.
test. 300 IN DNSKEY 256 3 13 IcKbK9FMlIsJSzC2o53aPsWGELPvWpWbKnZ2zJiID6nY6TFpMy31z60TNNbbfgJsGloL+zrOZwuV+h6darXNUw== ;{id = 11082 (zsk), size = 256b}
test. 300 IN DNSKEY 257 3 13 t2LVP+yZIiE9JPorgUdZNesR9fYl+715hSjItwxqzxgdH4ApBhqpA/lu/xF9ADmtUAZeU1PbIHXtbwP2HMOyoA== ;{id = 32290 (ksk), size = 256b}
test. 300 IN DNSKEY 256 3 8 IcKbK9FMlIsJSzC2o53aPsWGELPvWpWbKnZ2zJiID6nY6TFpMy31z60TNNbbfgJsGloL+zrOZwuV+h6darXNUw== ;{id = 11082 (zsk), size = 256b}
test. 300 IN RRSIG DNSKEY 13 1 300 20220130235959 20220101000000 32290 test. Y5B9IvpOrLsWk9UBTv8IJXhYHH2cZ6xzoW1mGBHXisjyh5AnCvaTRQD75kwe96zaH42ZNeqVdUi9CQ29qjH0/g==
test. 300 IN NSEC brokensig.test. NS SOA RRSIG NSEC DNSKEY
test. 300 IN RRSIG NSEC 13 1 300 20220130235959 20220101000000 11082 test. ggcZp9vWnRPcX2noMta0dPv4KjsYTugO2ODW3jaBacf5QQfz3DYq/KIZprqsTZf2DThXKmQV+qRsUY4hcrNbJw==
brokensig.test. 300 IN A 10.0.0.0
`
var dnskeyZone4 string = `
test. 300 IN SOA master.ns.test. mail.nic.test. 12345 1800 3600 7200 14400
test. 300 IN RRSIG SOA 13 1 300 20220130235959 20220101000000 11082 test. b1ACEv+pTeBYgeQ7ZZxloV7qssb8a17azszTfxoRB0NbqnI+x4uD9BgTFGnp2tpo1TykmRGiUtNSAHk5EqFUPg==
test. 300 IN NS a.ns.test.
test. 300 IN NS ns.test.
test. 300 IN DNSKEY 256 3 13 IcKbK9FMlIsJSzC2o53aPsWGELPvWpWbKnZ2zJiID6nY6TFpMy31z60TNNbbfgJsGloL+zrOZwuV+h6darXNUw== ;{id = 11082 (zsk), size = 256b}
test. 300 IN DNSKEY 257 3 13 t2LVP+yZIiE9JPorgUdZNesR9fYl+715hSjItwxqzxgdH4ApBhqpA/lu/xF9ADmtUAZeU1PbIHXtbwP2HMOyoA== ;{id = 32290 (ksk), size = 256b}
test. 300 IN DNSKEY 256 3 27 IcKbK9FMlIsJSzC2o53aPsWGELPvWpWbKnZ2zJiID6nY6TFpMy31z60TNNbbfgJsGloL+zrOZwuV+h6darXNUw== ;{id = 11082 (zsk), size = 256b}
test. 300 IN RRSIG DNSKEY 13 1 300 20220130235959 20220101000000 32290 test. Y5B9IvpOrLsWk9UBTv8IJXhYHH2cZ6xzoW1mGBHXisjyh5AnCvaTRQD75kwe96zaH42ZNeqVdUi9CQ29qjH0/g==
test. 300 IN NSEC brokensig.test. NS SOA RRSIG NSEC DNSKEY
test. 300 IN RRSIG NSEC 13 1 300 20220130235959 20220101000000 11082 test. ggcZp9vWnRPcX2noMta0dPv4KjsYTugO2ODW3jaBacf5QQfz3DYq/KIZprqsTZf2DThXKmQV+qRsUY4hcrNbJw==
brokensig.test. 300 IN A 10.0.0.0
`
func TestCheckDNSKEY(t *testing.T) {
cases := []struct {
Zone string
Expected Result
}{
{dnskeyZone0, Result{1, 0}},
{dnskeyZone1, Result{0, 0}},
{dnskeyZone2, Result{0, 4}},
{dnskeyZone3, Result{0, 2}},
{dnskeyZone4, Result{0, 3}},
}
for i, c := range cases {
myReader := strings.NewReader(c.Zone)
origin, cache := readZonefile(myReader)
if r := checkDNSKEY(cache, origin); r != c.Expected {
t.Logf("Test case %d: checkDNSKEY expected %d errors and %d warnings, found %d errors and %d warnings.\n.", i, c.Expected.errors, c.Expected.warnings, r.errors, r.warnings)
t.Fail()
}
}
}
var signsKeyZone0 string = `
test. 300 IN SOA master.ns.test. mail.nic.test. 12345 1800 3600 7200 14400
test. 300 IN RRSIG SOA 13 1 300 20220130235959 20220101000000 11082 test. b1ACEv+pTeBYgeQ7ZZxloV7qssb8a17azszTfxoRB0NbqnI+x4uD9BgTFGnp2tpo1TykmRGiUtNSAHk5EqFUPg==
test. 300 IN NS a.ns.test.
test. 300 IN NS ns.test.
test. 300 IN DNSKEY 256 3 13 IcKbK9FMlIsJSzC2o53aPsWGELPvWpWbKnZ2zJiID6nY6TFpMy31z60TNNbbfgJsGloL+zrOZwuV+h6darXNUw== ;{id = 11082 (zsk), size = 256b}
test. 300 IN DNSKEY 257 3 13 t2LVP+yZIiE9JPorgUdZNesR9fYl+715hSjItwxqzxgdH4ApBhqpA/lu/xF9ADmtUAZeU1PbIHXtbwP2HMOyoA== ;{id = 32290 (ksk), size = 256b}
test. 300 IN DNSKEY 256 3 27 IcKbK9FMlIsJSzC2o53aPsWGELPvWpWbKnZ2zJiID6nY6TFpMy31z60TNNbbfgJsGloL+zrOZwuV+h6darXNUw== ;{id = 11082 (zsk), size = 256b}
test. 300 IN RRSIG DNSKEY 13 1 300 20220130235959 20220101000000 32290 test. Y5B9IvpOrLsWk9UBTv8IJXhYHH2cZ6xzoW1mGBHXisjyh5AnCvaTRQD75kwe96zaH42ZNeqVdUi9CQ29qjH0/g==
test. 300 IN NSEC brokensig.test. NS SOA RRSIG NSEC DNSKEY
test. 300 IN RRSIG NSEC 13 1 300 20220130235959 20220101000000 11082 test. ggcZp9vWnRPcX2noMta0dPv4KjsYTugO2ODW3jaBacf5QQfz3DYq/KIZprqsTZf2DThXKmQV+qRsUY4hcrNbJw==
brokensig.test. 300 IN A 10.0.0.0
`
func TestSignsKey(t *testing.T) {
myReader := strings.NewReader(signsKeyZone0)
origin, cache := readZonefile(myReader)
// 2nd parameter not rr set
myset := append(cache[origin]["NS"], cache[origin]["SOA"][0])
_, err := keySigns(cache[origin]["DNSKEY"][0].(*dns.DNSKEY), myset, cache[origin]["RRSIGDNSKEY"])
if err == nil {
t.Log("Test case 0: signsKey expected errors, got none")
t.Fail()
}
// 3rd parameter not rr set
_, err = keySigns(cache[origin]["DNSKEY"][0].(*dns.DNSKEY), cache[origin]["NS"], cache[origin]["NS"])
if err == nil {
t.Log("Test case 1: signsKey expected errors, got none")
t.Fail()
}
// not type covered
_, err = keySigns(cache[origin]["DNSKEY"][0].(*dns.DNSKEY), cache[origin]["NS"], cache[origin]["RRSIGDNSKEY"])
if err == nil {
t.Log("Test case 2: signsKey expected errors, got none")
t.Fail()
}
}