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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
#!/bin/sh
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
SYSTEMTESTTOP=..
# shellcheck source=conf.sh
. "$SYSTEMTESTTOP/conf.sh"
DIGCMD="$DIG @10.53.0.2 -p ${PORT}"
RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
if ! $FEATURETEST --have-json-c; then
unset PERL_JSON
echo_i "JSON was not configured; skipping" >&2
elif $PERL -e 'use JSON;' 2>/dev/null; then
PERL_JSON=1
else
unset PERL_JSON
echo_i "JSON tests require JSON library; skipping" >&2
fi
if ! $FEATURETEST --have-libxml2; then
unset PERL_XML
echo_i "XML was not configured; skipping" >&2
elif $PERL -e 'use XML::Simple;' 2>/dev/null; then
PERL_XML=1
else
unset PERL_XML
echo_i "XML tests require XML::Simple; skipping" >&2
fi
if [ ! "$PERL_JSON" -a ! "$PERL_XML" ]; then
echo_i "skipping all tests"
exit 0
fi
getzones() {
sleep 1
echo_i "... using $1"
case $1 in
xml) path='xml/v3/zones' ;;
json) path='json/v1/zones' ;;
*) return 1 ;;
esac
file=$($PERL fetch.pl -p ${EXTRAPORT1} $path)
cp $file $file.$1.$3
$PERL zones-${1}.pl $file $2 2>/dev/null | sort >zones.out.$3
result=$?
return $result
}
# TODO: Move loadkeys_on to conf.sh.common
loadkeys_on() {
nsidx=$1
zone=$2
nextpart ns${nsidx}/named.run >/dev/null
$RNDCCMD 10.53.0.${nsidx} loadkeys ${zone} | sed "s/^/ns${nsidx} /" | cat_i
wait_for_log 20 "next key event" ns${nsidx}/named.run
}
status=0
n=1
ret=0
echo_i "checking consistency between named.stats and xml/json ($n)"
rm -f ns2/named.stats
$DIGCMD +tcp example ns >dig.out.$n || ret=1
$RNDCCMD 10.53.0.2 stats 2>&1 | sed 's/^/I:ns1 /'
query_count=$(awk '/QUERY/ {print $1}' ns2/named.stats)
txt_count=$(awk '/TXT/ {print $1}' ns2/named.stats)
noerror_count=$(awk '/NOERROR/ {print $1}' ns2/named.stats)
if [ $PERL_XML ]; then
file=$($PERL fetch.pl -p ${EXTRAPORT1} xml/v3/server)
mv $file xml.stats
$PERL server-xml.pl >xml.fmtstats 2>/dev/null
xml_query_count=$(awk '/opcode QUERY/ { print $NF }' xml.fmtstats)
xml_query_count=${xml_query_count:-0}
[ "$query_count" -eq "$xml_query_count" ] || ret=1
xml_txt_count=$(awk '/qtype TXT/ { print $NF }' xml.fmtstats)
xml_txt_count=${xml_txt_count:-0}
[ "$txt_count" -eq "$xml_txt_count" ] || ret=1
xml_noerror_count=$(awk '/rcode NOERROR/ { print $NF }' xml.fmtstats)
xml_noerror_count=${xml_noerror_count:-0}
[ "$noerror_count" -eq "$xml_noerror_count" ] || ret=1
fi
if [ $PERL_JSON ]; then
file=$($PERL fetch.pl -p ${EXTRAPORT1} json/v1/server)
mv $file json.stats
$PERL server-json.pl >json.fmtstats 2>/dev/null
json_query_count=$(awk '/opcode QUERY/ { print $NF }' json.fmtstats)
json_query_count=${json_query_count:-0}
[ "$query_count" -eq "$json_query_count" ] || ret=1
json_txt_count=$(awk '/qtype TXT/ { print $NF }' json.fmtstats)
json_txt_count=${json_txt_count:-0}
[ "$txt_count" -eq "$json_txt_count" ] || ret=1
json_noerror_count=$(awk '/rcode NOERROR/ { print $NF }' json.fmtstats)
json_noerror_count=${json_noerror_count:-0}
[ "$noerror_count" -eq "$json_noerror_count" ] || ret=1
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$(expr $status + $ret)
n=$(expr $n + 1)
ret=0
echo_i "checking malloced memory statistics xml/json ($n)"
if [ $PERL_XML ]; then
file=$($PERL fetch.pl -p ${EXTRAPORT1} xml/v3/mem)
mv $file xml.mem
$PERL mem-xml.pl $file >xml.fmtmem
grep "'Malloced' => '[0-9][0-9]*'" xml.fmtmem >/dev/null || ret=1
grep "'malloced' => '[0-9][0-9]*'" xml.fmtmem >/dev/null || ret=1
grep "'maxmalloced' => '[0-9][0-9]*'" xml.fmtmem >/dev/null || ret=1
fi
if [ $PERL_JSON ]; then
file=$($PERL fetch.pl -p ${EXTRAPORT1} json/v1/mem)
mv $file json.mem
grep '"malloced":[0-9][0-9]*,' json.mem >/dev/null || ret=1
grep '"maxmalloced":[0-9][0-9]*,' json.mem >/dev/null || ret=1
grep '"Malloced":[0-9][0-9]*,' json.mem >/dev/null || ret=1
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$(expr $status + $ret)
n=$(expr $n + 1)
echo_i "checking consistency between regular and compressed output ($n)"
for i in 1 2 3 4 5; do
ret=0
if $FEATURETEST --have-libxml2; then
URL=http://10.53.0.2:${EXTRAPORT1}/xml/v3/server
filter_str='s#<current-time>.*</current-time>##g'
else
URL=http://10.53.0.2:${EXTRAPORT1}/json/v1/server
filter_str='s#"current-time.*",##g'
fi
$CURL -D regular.headers $URL 2>/dev/null \
| sed -e "$filter_str" >regular.out
$CURL -D compressed.headers --compressed $URL 2>/dev/null \
| sed -e "$filter_str" >compressed.out
diff regular.out compressed.out >/dev/null || ret=1
if [ $ret != 0 ]; then
echo_i "failed on try $i, probably a timing issue, trying again"
sleep 1
else
break
fi
done
status=$(expr $status + $ret)
n=$(expr $n + 1)
ret=0
echo_i "checking if compressed output is really compressed ($n)"
if $FEATURETEST --with-zlib; then
REGSIZE=$(cat regular.headers \
| grep -i Content-Length | sed -e "s/.*: \([0-9]*\).*/\1/")
COMPSIZE=$(cat compressed.headers \
| grep -i Content-Length | sed -e "s/.*: \([0-9]*\).*/\1/")
if [ ! $(expr $REGSIZE / $COMPSIZE) -gt 2 ]; then
ret=1
fi
else
echo_i "skipped"
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$(expr $status + $ret)
n=$(expr $n + 1)
# Test dnssec sign statistics.
zone="dnssec"
sign_prefix="dnssec-sign operations"
refresh_prefix="dnssec-refresh operations"
ksk_id=$(cat ns2/$zone.ksk.id)
zsk_id=$(cat ns2/$zone.zsk.id)
# Test sign operations for scheduled resigning.
ret=0
# The dnssec zone has 10 RRsets to sign (including NSEC) with the ZSK and one
# RRset (DNSKEY) with the KSK. So starting named with signatures that expire
# almost right away, this should trigger 10 zsk and 1 ksk sign operations.
echo "${refresh_prefix} ${zsk_id}: 10" >zones.expect
echo "${refresh_prefix} ${ksk_id}: 1" >>zones.expect
echo "${sign_prefix} ${zsk_id}: 10" >>zones.expect
echo "${sign_prefix} ${ksk_id}: 1" >>zones.expect
cat zones.expect | sort >zones.expect.$n
rm -f zones.expect
# Fetch and check the dnssec sign statistics.
echo_i "fetching zone '$zone' stats data after zone maintenance at startup ($n)"
if [ $PERL_XML ]; then
getzones xml $zone x$n || ret=1
cmp zones.out.x$n zones.expect.$n || ret=1
fi
if [ $PERL_JSON ]; then
getzones json 0 j$n || ret=1
cmp zones.out.j$n zones.expect.$n || ret=1
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$(expr $status + $ret)
n=$(expr $n + 1)
# Test sign operations after dynamic update.
ret=0
(
# Update dnssec zone to trigger signature creation.
echo zone $zone
echo server 10.53.0.2 "$PORT"
echo update add $zone. 300 in txt "nsupdate added me"
echo send
) | $NSUPDATE
# This should trigger the resign of SOA, TXT and NSEC (+3 zsk).
echo "${refresh_prefix} ${zsk_id}: 10" >zones.expect
echo "${refresh_prefix} ${ksk_id}: 1" >>zones.expect
echo "${sign_prefix} ${zsk_id}: 13" >>zones.expect
echo "${sign_prefix} ${ksk_id}: 1" >>zones.expect
cat zones.expect | sort >zones.expect.$n
rm -f zones.expect
# Fetch and check the dnssec sign statistics.
echo_i "fetching zone '$zone' stats data after dynamic update ($n)"
if [ $PERL_XML ]; then
getzones xml $zone x$n || ret=1
cmp zones.out.x$n zones.expect.$n || ret=1
fi
if [ $PERL_JSON ]; then
getzones json 0 j$n || ret=1
cmp zones.out.j$n zones.expect.$n || ret=1
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$(expr $status + $ret)
n=$(expr $n + 1)
# Test sign operations of KSK.
ret=0
echo_i "fetch zone '$zone' stats data after updating DNSKEY RRset ($n)"
# Add a standby DNSKEY, this triggers resigning the DNSKEY RRset.
zsk=$("$KEYGEN" -K ns2 -q -a "$DEFAULT_ALGORITHM" -b "$DEFAULT_BITS" "$zone")
$SETTIME -K ns2 -P now -A never $zsk.key >/dev/null
loadkeys_on 2 $zone || ret=1
# This should trigger the resign of SOA (+1 zsk) and DNSKEY (+1 ksk).
echo "${refresh_prefix} ${zsk_id}: 11" >zones.expect
echo "${refresh_prefix} ${ksk_id}: 2" >>zones.expect
echo "${sign_prefix} ${zsk_id}: 14" >>zones.expect
echo "${sign_prefix} ${ksk_id}: 2" >>zones.expect
cat zones.expect | sort >zones.expect.$n
rm -f zones.expect
# Fetch and check the dnssec sign statistics.
if [ $PERL_XML ]; then
getzones xml $zone x$n || ret=1
cmp zones.out.x$n zones.expect.$n || ret=1
fi
if [ $PERL_JSON ]; then
getzones json 0 j$n || ret=1
cmp zones.out.j$n zones.expect.$n || ret=1
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$(expr $status + $ret)
n=$(expr $n + 1)
# Test sign operations for scheduled resigning (many keys).
ret=0
zone="manykeys"
ksk8_id=$(cat ns2/$zone.ksk8.id)
zsk8_id=$(cat ns2/$zone.zsk8.id)
ksk13_id=$(cat ns2/$zone.ksk13.id)
zsk13_id=$(cat ns2/$zone.zsk13.id)
ksk14_id=$(cat ns2/$zone.ksk14.id)
zsk14_id=$(cat ns2/$zone.zsk14.id)
num_ids=$( (
echo $ksk8_id
echo $zsk8_id
echo $ksk13_id
echo $zsk13_id
echo $ksk14_id
echo $zsk14_id
) | sort -u | wc -l)
# The dnssec zone has 10 RRsets to sign (including NSEC) with the ZSKs and one
# RRset (DNSKEY) with the KSKs. So starting named with signatures that expire
# almost right away, this should trigger 10 zsk and 1 ksk sign operations per
# key.
echo "${refresh_prefix} ${zsk8_id}: 10" >zones.expect
echo "${refresh_prefix} ${zsk13_id}: 10" >>zones.expect
echo "${refresh_prefix} ${zsk14_id}: 10" >>zones.expect
echo "${refresh_prefix} ${ksk8_id}: 1" >>zones.expect
echo "${refresh_prefix} ${ksk13_id}: 1" >>zones.expect
echo "${refresh_prefix} ${ksk14_id}: 1" >>zones.expect
echo "${sign_prefix} ${zsk8_id}: 10" >>zones.expect
echo "${sign_prefix} ${zsk13_id}: 10" >>zones.expect
echo "${sign_prefix} ${zsk14_id}: 10" >>zones.expect
echo "${sign_prefix} ${ksk8_id}: 1" >>zones.expect
echo "${sign_prefix} ${ksk13_id}: 1" >>zones.expect
echo "${sign_prefix} ${ksk14_id}: 1" >>zones.expect
cat zones.expect | sort >zones.expect.$n
rm -f zones.expect
# Fetch and check the dnssec sign statistics.
echo_i "fetching zone '$zone' stats data after zone maintenance at startup ($n)"
if test $num_ids -eq 6; then
if [ $PERL_XML ]; then
getzones xml $zone x$n || ret=1
cmp zones.out.x$n zones.expect.$n || ret=1
fi
if [ $PERL_JSON ]; then
getzones json 2 j$n || ret=1
cmp zones.out.j$n zones.expect.$n || ret=1
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
else
echo_i "skipped: duplicate key id detected (fixed in BIND 9.19)"
fi
status=$(expr $status + $ret)
n=$(expr $n + 1)
# Test sign operations after dynamic update (many keys).
ret=0
(
# Update dnssec zone to trigger signature creation.
echo zone $zone
echo server 10.53.0.2 "$PORT"
echo update add $zone. 300 in txt "nsupdate added me"
echo send
) | $NSUPDATE
# This should trigger the resign of SOA, TXT and NSEC (+3 zsk).
echo "${refresh_prefix} ${zsk8_id}: 10" >zones.expect
echo "${refresh_prefix} ${zsk13_id}: 10" >>zones.expect
echo "${refresh_prefix} ${zsk14_id}: 10" >>zones.expect
echo "${refresh_prefix} ${ksk8_id}: 1" >>zones.expect
echo "${refresh_prefix} ${ksk13_id}: 1" >>zones.expect
echo "${refresh_prefix} ${ksk14_id}: 1" >>zones.expect
echo "${sign_prefix} ${zsk8_id}: 13" >>zones.expect
echo "${sign_prefix} ${zsk13_id}: 13" >>zones.expect
echo "${sign_prefix} ${zsk14_id}: 13" >>zones.expect
echo "${sign_prefix} ${ksk8_id}: 1" >>zones.expect
echo "${sign_prefix} ${ksk13_id}: 1" >>zones.expect
echo "${sign_prefix} ${ksk14_id}: 1" >>zones.expect
cat zones.expect | sort >zones.expect.$n
rm -f zones.expect
# Fetch and check the dnssec sign statistics.
echo_i "fetching zone '$zone' stats data after dynamic update ($n)"
if test $num_ids -eq 6; then
if [ $PERL_XML ]; then
getzones xml $zone x$n || ret=1
cmp zones.out.x$n zones.expect.$n || ret=1
fi
if [ $PERL_JSON ]; then
getzones json 2 j$n || ret=1
cmp zones.out.j$n zones.expect.$n || ret=1
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
else
echo_i "skipped: duplicate key id detected (fixed in BIND 9.19)"
fi
status=$(expr $status + $ret)
n=$(expr $n + 1)
# Test sign operations after dnssec-policy change (removing keys).
ret=0
copy_setports ns2/named2.conf.in ns2/named.conf
$RNDCCMD 10.53.0.2 reload 2>&1 | sed 's/^/I:ns2 /'
# This should trigger the resign of DNSKEY (+1 ksk), and SOA, NSEC,
# TYPE65534 (+3 zsk). The dnssec-sign statistics for the removed keys should
# be cleared and thus no longer visible. But NSEC and SOA are (mistakenly)
# counted double, one time because of zone_resigninc and one time because of
# zone_nsec3chain. So +5 zsk in total.
echo "${refresh_prefix} ${zsk8_id}: 15" >zones.expect
echo "${refresh_prefix} ${ksk8_id}: 2" >>zones.expect
echo "${sign_prefix} ${zsk8_id}: 18" >>zones.expect
echo "${sign_prefix} ${ksk8_id}: 2" >>zones.expect
cat zones.expect | sort >zones.expect.$n
rm -f zones.expect
# Fetch and check the dnssec sign statistics.
echo_i "fetching zone '$zone' stats data after dnssec-policy change ($n)"
if [ $PERL_XML ]; then
getzones xml $zone x$n || ret=1
cmp zones.out.x$n zones.expect.$n || ret=1
fi
if [ $PERL_JSON ]; then
getzones json 2 j$n || ret=1
cmp zones.out.j$n zones.expect.$n || ret=1
fi
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$(expr $status + $ret)
n=$(expr $n + 1)
echo_i "exit status: $status"
[ $status -eq 0 ] || exit 1
|