Zonemaster/Test/DNSSEC.pm untested

filter: Statementstmt 0.0% 0 / 363 Branchbran 0.0% 0 / 172 Conditioncond 0.0% 0 / 63 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 25 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 639 CC 87 SCAR 46.5
CC
87
Cov
0%
dnssec10
272.0
all
210.0
dnssec11
110.0
CRAP 104.7
1 package Zonemaster::Test::DNSSEC v1.0.2;
2  
3 ###
4 ### This test module implements DNSSEC tests.
5 ###
6  
7 use 5.14.2;
8 use strict;
9 use warnings;
10  
11 use Zonemaster;
12 use Zonemaster::Util;
13 use Zonemaster::Constants qw[:algo :soa];
14 use List::Util qw[min];
15 use List::MoreUtils qw[none];
16  
17 use Carp;
18  
19 ### Table fetched from IANA on 2014-09-12
20 Readonly::Hash our %algo_properties => (
21 0 => {
22 status => $ALGO_STATUS_RESERVED,
23 description => q{Reserved},
24 },
25 1 => {
26 status => $ALGO_STATUS_DEPRECATED,
27 description => q{RSA/MD5},
28 mnemonic => q{RSAMD5},
29 },
30 2 => {
31 status => $ALGO_STATUS_VALID,
32 description => q{Diffie-Hellman},
33 mnemonic => q{DH},
34 },
35 3 => {
36 status => $ALGO_STATUS_VALID,
37 description => q{DSA/SHA1},
38 mnemonic => q{DSA},
39 },
40 4 => {
41 status => $ALGO_STATUS_RESERVED,
42 description => q{Reserved},
43 },
44 5 => {
45 status => $ALGO_STATUS_VALID,
46 description => q{RSA/SHA1},
47 mnemonic => q{RSASHA1},
48 },
49 6 => {
50 status => $ALGO_STATUS_VALID,
51 description => q{DSA-NSEC3-SHA1},
52 mnemonic => q{DSA-NSEC3-SHA1},
53 },
54 7 => {
55 status => $ALGO_STATUS_VALID,
56 description => q{RSASHA1-NSEC3-SHA1},
57 mnemonic => q{RSASHA1-NSEC3-SHA1},
58 },
59 8 => {
60 status => $ALGO_STATUS_VALID,
61 description => q{RSA/SHA-256},
62 mnemonic => q{RSA/SHA256},
63 },
64 9 => {
65 status => $ALGO_STATUS_RESERVED,
66 description => q{Reserved},
67 },
68 10 => {
69 status => $ALGO_STATUS_VALID,
70 description => q{RSA/SHA-512},
71 mnemonic => q{RSA/SHA512},
72 },
73 11 => {
74 status => $ALGO_STATUS_RESERVED,
75 description => q{Reserved},
76 },
77 12 => {
78 status => $ALGO_STATUS_VALID,
79 description => q{GOST R 34.10-2001},
80 mnemonic => q{ECC-GOST},
81 },
82 13 => {
83 status => $ALGO_STATUS_VALID,
84 description => q{ECDSA Curve P-256 with SHA-256},
85 mnemonic => q{ECDSAP256SHA256},
86 },
87 14 => {
88 status => $ALGO_STATUS_VALID,
89 description => q{ECDSA Curve P-384 with SHA-384},
90 mnemonic => q{ECDSAP384SHA384},
91 },
92 (
93 map { $_ => { status => $ALGO_STATUS_UNASSIGNED, description => q{Unassigned}, } } ( 15 .. 122 )
94 ),
95 (
96 map { $_ => { status => $ALGO_STATUS_RESERVED, description => q{Reserved}, } } ( 123 .. 251 )
97 ),
98 252 => {
99 status => $ALGO_STATUS_RESERVED,
100 description => q{Reserved for Indirect Keys},
101 mnemonic => q{INDIRECT},
102 },
103 253 => {
104 status => $ALGO_STATUS_PRIVATE,
105 description => q{private algorithm},
106 mnemonic => q{PRIVATEDNS},
107 },
108 254 => {
109 status => $ALGO_STATUS_PRIVATE,
110 description => q{private algorithm OID},
111 mnemonic => q{PRIVATEOID},
112 },
113 255 => {
114 status => $ALGO_STATUS_RESERVED,
115 description => q{Reserved},
116 },
117 );
118  
119 ###
120 ### Entry points
121 ###
122  
123 sub all {
124 my ( $class, $zone ) = @_;
125 my @results;
126  
127 push @results, $class->dnssec01( $zone ) if Zonemaster->config->should_run('dnssec01');
128 if ( none { $_->tag eq 'NO_DS' } @results ) {
129 push @results, $class->dnssec02( $zone ) if Zonemaster->config->should_run('dnssec02');
130 }
131 push @results, $class->dnssec03( $zone ) if Zonemaster->config->should_run('dnssec03');
132 push @results, $class->dnssec04( $zone ) if Zonemaster->config->should_run('dnssec04');
133 push @results, $class->dnssec05( $zone ) if Zonemaster->config->should_run('dnssec05');
134 push @results, $class->dnssec07( $zone ) if Zonemaster->config->should_run('dnssec07');
135 if ( grep { $_->tag eq q{DNSKEY_BUT_NOT_DS} or $_->tag eq q{DNSKEY_AND_DS} } @results ) {
136 push @results, $class->dnssec06( $zone ) if Zonemaster->config->should_run('dnssec06');
137 }
138 else {
139 push @results,
140 info( ADDITIONAL_DNSKEY_SKIPPED => {} );
141 }
142 push @results, $class->dnssec08( $zone ) if Zonemaster->config->should_run('dnssec08');
143 push @results, $class->dnssec09( $zone ) if Zonemaster->config->should_run('dnssec09');
144 push @results, $class->dnssec10( $zone ) if Zonemaster->config->should_run('dnssec10');
145 push @results, $class->dnssec11( $zone ) if Zonemaster->config->should_run('dnssec11');
146  
147 return @results;
148 } ## end sub all
149  
150 ###
151 ### Metadata Exposure
152 ###
153  
154 sub metadata {
155 my ( $class ) = @_;
156  
157 return {
158 dnssec01 => [
159 qw(
160 DS_DIGTYPE_OK
161 DS_DIGTYPE_NOT_OK
162 NO_DS
163 )
164 ],
165 dnssec02 => [
166 qw(
167 NO_DS
168 DS_FOUND
169 NO_DNSKEY
170 COMMON_KEYTAGS
171 DS_MATCHES_DNSKEY
172 DS_DOES_NOT_MATCH_DNSKEY
173 DS_MATCH_FOUND
174 DS_MATCH_NOT_FOUND
175 NO_COMMON_KEYTAGS
176 )
177 ],
178 dnssec03 => [
179 qw(
180 NO_NSEC3PARAM
181 MANY_ITERATIONS
182 TOO_MANY_ITERATIONS
183 ITERATIONS_OK
184 )
185 ],
186 dnssec04 => [
187 qw(
188 RRSIG_EXPIRED
189 REMAINING_SHORT
190 REMAINING_LONG
191 DURATION_LONG
192 DURATION_OK
193 )
194 ],
195 dnssec05 => [
196 qw(
197 ALGORITHM_DEPRECATED
198 ALGORITHM_RESERVED
199 ALGORITHM_UNASSIGNED
200 ALGORITHM_PRIVATE
201 ALGORITHM_OK
202 ALGORITHM_UNKNOWN
203 )
204 ],
205 dnssec06 => [
206 qw(
207 EXTRA_PROCESSING_OK
208 EXTRA_PROCESSING_BROKEN
209 )
210 ],
211 dnssec07 => [
212 qw(
213 ADDITIONAL_DNSKEY_SKIPPED
214 DNSKEY_BUT_NOT_DS
215 DNSKEY_AND_DS
216 NEITHER_DNSKEY_NOR_DS
217 DS_BUT_NOT_DNSKEY
218 )
219 ],
220 dnssec08 => [
221 qw(
222 DNSKEY_SIGNATURE_OK
223 DNSKEY_SIGNATURE_NOT_OK
224 DNSKEY_SIGNED
225 DNSKEY_NOT_SIGNED
226 NO_KEYS_OR_NO_SIGS
227 )
228 ],
229 dnssec09 => [
230 qw(
231 NO_KEYS_OR_NO_SIGS_OR_NO_SOA
232 SOA_SIGNATURE_OK
233 SOA_SIGNATURE_NOT_OK
234 SOA_SIGNED
235 SOA_NOT_SIGNED
236 )
237 ],
238 dnssec10 => [
239 qw(
240 INVALID_NAME_RCODE
241 NSEC_COVERS
242 NSEC_COVERS_NOT
243 NSEC_SIG_VERIFY_ERROR
244 NSEC_SIGNED
245 NSEC_NOT_SIGNED
246 HAS_NSEC
247 NSEC3_COVERS
248 NSEC3_COVERS_NOT
249 NSEC3_SIG_VERIFY_ERROR
250 NSEC3_SIGNED
251 NSEC3_NOT_SIGNED
252 HAS_NSEC3 )
253 ],
254 dnssec11 => [
255 qw(
256 DELEGATION_NOT_SIGNED
257 DELEGATION_SIGNED
258 ),
259 ],
260 };
261 } ## end sub metadata
262  
263 sub translation {
264 return {
265 "ADDITIONAL_DNSKEY_SKIPPED" => "No DNSKEYs found. Additional tests skipped.",
266 "ALGORITHM_DEPRECATED" =>
267 "The DNSKEY with tag {keytag} uses deprecated algorithm number {algorithm}/({description}).",
268 "ALGORITHM_OK" =>
269 "The DNSKEY with tag {keytag} uses algorithm number {algorithm}/({description}), which is OK.",
270 "ALGORITHM_RESERVED" =>
271 "The DNSKEY with tag {keytag} uses reserved algorithm number {algorithm}/({description}).",
272 "ALGORITHM_UNASSIGNED" =>
273 "The DNSKEY with tag {keytag} uses unassigned algorithm number {algorithm}/({description}).",
274 "ALGORITHM_PRIVATE" =>
275 "The DNSKEY with tag {keytag} uses private algorithm number {algorithm}/({description}).",
276 "ALGORITHM_UNKNOWN" => "The DNSKEY with tag {keytag} uses unknown algorithm number {algorithm}.",
277 "COMMON_KEYTAGS" => "There are both DS and DNSKEY records with key tags {keytags}.",
278 "DNSKEY_AND_DS" => "{parent} sent a DS record, and {child} a DNSKEY record.",
279 "DNSKEY_BUT_NOT_DS" => "{child} sent a DNSKEY record, but {parent} did not send a DS record.",
280 "DNSKEY_NOT_SIGNED" => "The apex DNSKEY RRset was not correctly signed.",
281 "DNSKEY_SIGNATURE_NOT_OK" => "Signature for DNSKEY with tag {signature} failed to verify with error '{error}'.",
282 "DNSKEY_SIGNATURE_OK" => "A signature for DNSKEY with tag {signature} was correctly signed.",
283 "DNSKEY_SIGNED" => "The apex DNSKEY RRset was correcly signed.",
284 "DS_BUT_NOT_DNSKEY" => "{parent} sent a DS record, but {child} did not send a DNSKEY record.",
285 "DS_DIGTYPE_NOT_OK" => "DS record with keytag {keytag} uses forbidden digest type {digtype}.",
286 "DS_DIGTYPE_OK" => "DS record with keytag {keytag} uses digest type {digtype}, which is OK.",
287 "DS_DOES_NOT_MATCH_DNSKEY" => "DS record with keytag {keytag} does not match the DNSKEY with the same tag.",
288 "DS_FOUND" => "Found DS records with tags {keytags}.",
289 "DS_MATCHES_DNSKEY" => "DS record with keytag {keytag} matches the DNSKEY with the same tag.",
290 "DS_MATCH_FOUND" => "At least one DS record with a matching DNSKEY record was found.",
291 "DS_MATCH_NOT_FOUND" => "No DS record with a matching DNSKEY record was found.",
292 "DURATION_LONG" =>
293 "RRSIG with keytag {tag} and covering type(s) {types} has a duration of {duration} seconds, which is too long.",
294 "DURATION_OK" =>
295 "RRSIG with keytag {tag} and covering type(s) {types} has a duration of {duration} seconds, which is just fine.",
296 "RRSIG_EXPIRED" =>
297 "RRSIG with keytag {tag} and covering type(s) {types} has already expired (expiration is: {expiration}).",
298 "REMAINING_SHORT" =>
299 "RRSIG with keytag {tag} and covering type(s) {types} has a remaining validity of {duration} seconds, which is too short.",
300 "REMAINING_LONG" =>
301 "RRSIG with keytag {tag} and covering type(s) {types} has a remaining validity of {duration} seconds, which is too long.",
302 "EXTRA_PROCESSING_BROKEN" => "Server at {server} sent {keys} DNSKEY records, and {sigs} RRSIG records.",
303 "EXTRA_PROCESSING_OK" => "Server at {server} sent {keys} DNSKEY records and {sigs} RRSIG records.",
304 "HAS_NSEC" => "The zone has NSEC records.",
305 "HAS_NSEC3" => "The zone has NSEC3 records.",
306 "INVALID_NAME_RCODE" => "When asked for the name {name}, which must not exist, the response had RCODE {rcode}.",
307 "ITERATIONS_OK" => "The number of NSEC3 iterations is {count}, which is OK.",
308 "MANY_ITERATIONS" => "The number of NSEC3 iterations is {count}, which is on the high side.",
309 "NEITHER_DNSKEY_NOR_DS" => "There are neither DS nor DNSKEY records for the zone.",
310 "NO_COMMON_KEYTAGS" => "No DS record had a DNSKEY with a matching keytag.",
311 "NO_DNSKEY" => "No DNSKEYs were returned.",
312 "NO_DS" => "{from} returned no DS records for {zone}.",
313 "NO_KEYS_OR_NO_SIGS" =>
314 "Cannot test DNSKEY signatures, because we got {keys} DNSKEY records and {sigs} RRSIG records.",
315 "NO_KEYS_OR_NO_SIGS_OR_NO_SOA" =>
316 "Cannot test SOA signatures, because we got {keys} DNSKEY records, {sigs} RRSIG records and {soas} SOA records.",
317 "NO_NSEC3PARAM" => "{server} returned no NSEC3PARAM records.",
318 "NSEC3_SIG_VERIFY_ERROR" => "Trying to verify NSEC3 RRset with RRSIG {sig} gave error '{error}'.",
319 "NSEC3_COVERS" => "NSEC3 record covers {name}.",
320 "NSEC3_COVERS_NOT" => "NSEC3 record does not cover {name}.",
321 "NSEC3_NOT_SIGNED" => "No signature correctly signed the NSEC3 RRset.",
322 "NSEC3_SIGNED" => "At least one signature correctly signed the NSEC3 RRset.",
323 "NSEC_COVERS" => "NSEC covers {name}.",
324 "NSEC_COVERS_NOT" => "NSEC does not cover {name}.",
325 "NSEC_NOT_SIGNED" => "No signature correctly signed the NSEC RRset.",
326 "NSEC_SIGNED" => "At least one signature correctly signed the NSEC RRset.",
327 "NSEC_SIG_VERIFY_ERROR" => "Trying to verify NSEC RRset with RRSIG {sig} gave error '{error}'.",
328 "SOA_NOT_SIGNED" => "No RRSIG correctly signed the SOA RRset.",
329 "SOA_SIGNATURE_NOT_OK" => "Trying to verify SOA RRset with signature {signature} gave error '{error}'.",
330 "SOA_SIGNATURE_OK" => "RRSIG {signature} correctly signs SOA RRset.",
331 "SOA_SIGNED" => "At least one RRSIG correctly signs the SOA RRset.",
332 "TOO_MANY_ITERATIONS" =>
333 "The number of NSEC3 iterations is {count}, which is too high for key length {keylength}.",
334 "DELEGATION_NOT_SIGNED" => "Delegation from parent to child is not properly signed {reason}.",
335 "DELEGATION_SIGNED" => "Delegation from parent to child is properly signed.",
336 };
337 } ## end sub translation
338  
339 sub policy {
340 return {
341 "ADDITIONAL_DNSKEY_SKIPPED" => "DEBUG",
342 "ALGORITHM_DEPRECATED" => "WARNING",
343 "ALGORITHM_OK" => "INFO",
344 "ALGORITHM_RESERVED" => "ERROR",
345 "ALGORITHM_UNASSIGNED" => "ERROR",
346 "COMMON_KEYTAGS" => "INFO",
347 "DNSKEY_AND_DS" => "DEBUG",
348 "DNSKEY_BUT_NOT_DS" => "WARNING",
349 "DNSKEY_NOT_SIGNED" => "ERROR",
350 "DNSKEY_SIGNATURE_NOT_OK" => "ERROR",
351 "DNSKEY_SIGNATURE_OK" => "DEBUG",
352 "DNSKEY_SIGNED" => "DEBUG",
353 "DS_BUT_NOT_DNSKEY" => "ERROR",
354 "DS_DIGTYPE_NOT_OK" => "ERROR",
355 "DS_DIGTYPE_OK" => "DEBUG",
356 "DS_DOES_NOT_MATCH_DNSKEY" => "ERROR",
357 "DS_FOUND" => "INFO",
358 "DS_MATCHES_DNSKEY" => "INFO",
359 "DS_MATCH_FOUND" => "INFO",
360 "DS_MATCH_NOT_FOUND" => "ERROR",
361 "DURATION_LONG" => "WARNING",
362 "DURATION_OK" => "DEBUG",
363 "EXTRA_PROCESSING_BROKEN" => "ERROR",
364 "EXTRA_PROCESSING_OK" => "DEBUG",
365 "HAS_NSEC" => "INFO",
366 "HAS_NSEC3" => "INFO",
367 "INVALID_NAME_RCODE" => "NOTICE",
368 "ITERATIONS_OK" => "DEBUG",
369 "MANY_ITERATIONS" => "NOTICE",
370 "NEITHER_DNSKEY_NOR_DS" => "DEBUG",
371 "NO_COMMON_KEYTAGS" => "ERROR",
372 "NO_DNSKEY" => "WARNING",
373 "NO_DS" => "NOTICE",
374 "NO_KEYS_OR_NO_SIGS" => "DEBUG",
375 "NO_KEYS_OR_NO_SIGS_OR_NO_SOA" => "DEBUG",
376 "NO_NSEC3PARAM" => "DEBUG",
377 "NSEC3_SIG_VERIFY_ERROR" => "ERROR",
378 "NSEC3_COVERS" => "DEBUG",
379 "NSEC3_COVERS_NOT" => "WARNING",
380 "NSEC3_NOT_SIGNED" => "ERROR",
381 "NSEC3_SIGNED" => "DEBUG",
382 "NSEC_COVERS" => "DEBUG",
383 "NSEC_COVERS_NOT" => "WARNING",
384 "NSEC_NOT_SIGNED" => "ERROR",
385 "NSEC_SIGNED" => "DEBUG",
386 "NSEC_SIG_VERIFY_ERROR" => "ERROR",
387 "REMAINING_LONG" => "WARNING",
388 "REMAINING_SHORT" => "WARNING",
389 "RRSIG_EXPIRED" => "ERROR",
390 "SOA_NOT_SIGNED" => "ERROR",
391 "SOA_SIGNATURE_NOT_OK" => "ERROR",
392 "SOA_SIGNATURE_OK" => "DEBUG",
393 "SOA_SIGNED" => "DEBUG",
394 "TOO_MANY_ITERATIONS" => "WARNING",
395 "DELEGATION_NOT_SIGNED" => "NOTICE",
396 "DELEGATION_SIGNED" => "INFO",
397 };
398 } ## end sub policy
399  
400 sub version {
401 return "$Zonemaster::Test::DNSSEC::VERSION";
402 }
403  
404 ###
405 ### Tests
406 ###
407  
408 sub dnssec01 {
409 my ( $class, $zone ) = @_;
410 my @results;
411  
412 my %type = ( 1 => 'SHA-1', 2 => 'SHA-256', 3 => 'GOST R 34.11-94', 4 => 'SHA-384' );
413  
414 return if not $zone->parent;
415 my $ds_p = $zone->parent->query_one( $zone->name, 'DS', { dnssec => 1 } );
416 die "No response from parent nameservers" if not $ds_p;
417 my @ds = $ds_p->get_records( 'DS', 'answer' );
418  
419 if ( @ds == 0 ) {
420 push @results,
421 info(
422 NO_DS => {
423 zone => q{} . $zone->name,
424 from => $ds_p->answerfrom
425 }
426 );
427 }
428 else {
429 foreach my $ds ( @ds ) {
430 if ( $type{ $ds->digtype } ) {
431 push @results,
432 info(
433 DS_DIGTYPE_OK => {
434 keytag => $ds->keytag,
435 digtype => $type{ $ds->digtype },
436 }
437 );
438 }
439 else {
440 push @results,
441 info(
442 DS_DIGTYPE_NOT_OK => {
443 keytag => $ds->keytag,
444 digtype => $ds->digtype
445 }
446 );
447 }
448 } ## end foreach my $ds ( @ds )
449 } ## end else [ if ( @ds == 0 ) ]
450  
451 return @results;
452 } ## end sub dnssec01
453  
454 sub dnssec02 {
455 my ( $class, $zone ) = @_;
456 my @results;
457  
458 return if not $zone->parent;
459 my $ds_p = $zone->parent->query_one( $zone->name, 'DS', { dnssec => 1 } );
460 die "No response from parent nameservers" if not $ds_p;
461 my %ds = map { $_->keytag => $_ } $ds_p->get_records( 'DS', 'answer' );
462  
463 if ( scalar( keys %ds ) == 0 ) {
464 push @results,
465 info(
466 NO_DS => {
467 zone => q{} . $zone->name,
468 from => $ds_p->answerfrom,
469 }
470 );
471 }
472 else {
473 push @results,
474 info(
475 DS_FOUND => {
476 keytags => join( q{:}, map { $_->keytag } values %ds ),
477 }
478 );
479 my $dnskey_p = $zone->query_one( $zone->name, 'DNSKEY', { dnssec => 1 } );
480  
481 my %dnskey;
482 %dnskey = map { $_->keytag => $_ } $dnskey_p->get_records( 'DNSKEY', 'answer' ) if $dnskey_p;
483  
484 if ( scalar( keys %dnskey ) == 0 ) {
485 push @results,
486 info( NO_DNSKEY => {} );
487 return @results;
488 }
489  
490 # Pick out keys with a tag that a DS has using a hash slice
491 my @common = grep { $_ } @dnskey{ keys %ds };
492 if ( @common ) {
493 push @results,
494 info(
495 COMMON_KEYTAGS => {
496 keytags => join( q{:}, map { $_->keytag } @common ),
497 }
498 );
499 my $found = 0;
500 foreach my $key ( @common ) {
501 if ( $ds{ $key->keytag }->verify( $key ) ) {
502 push @results,
503 info(
504 DS_MATCHES_DNSKEY => {
505 keytag => $key->keytag,
506 }
507 );
508 $found = 1;
509 }
510 else {
511 push @results,
512 info(
513 DS_DOES_NOT_MATCH_DNSKEY => {
514 keytag => $key->keytag,
515 }
516 );
517 }
518 }
519 if ( $found ) {
520 push @results,
521 info( DS_MATCH_FOUND => {} );
522 }
523 else {
524 push @results,
525 info( DS_MATCH_NOT_FOUND => {} );
526 }
527 } ## end if ( @common )
528 else {
529 push @results,
530 info(
531 NO_COMMON_KEYTAGS => {
532 dstags => join( q{:}, keys %ds ),
533 dnskeytags => join( q{:}, keys %dnskey ),
534 }
535 );
536 }
537 } ## end else [ if ( scalar( keys %ds ...))]
538  
539 return @results;
540 } ## end sub dnssec02
541  
542 sub dnssec03 {
543 my ( $self, $zone ) = @_;
544 my @results;
545  
546 my $param_p = $zone->query_one( $zone->name, 'NSEC3PARAM', { dnssec => 1 } );
547  
548 my @nsec3params;
549 @nsec3params = $param_p->get_records( 'NSEC3PARAM', 'answer' ) if $param_p;
550  
551 my $dk_p = $zone->query_one( $zone->name, 'DNSKEY', { dnssec => 1 } );
552  
553 my @dnskey;
554 @dnskey = $dk_p->get_records( 'DNSKEY', 'answer' ) if $dk_p;
555 my $min_len = min map { $_->keysize } @dnskey;
556  
557 if ( @nsec3params == 0 ) {
558 push @results,
559 info(
560 NO_NSEC3PARAM => {
561 server => ( $param_p ? $param_p->answerfrom : '<no response>' ),
562 }
563 );
564 }
565 else {
566 foreach my $n3p ( @nsec3params ) {
567 my $iter = $n3p->iterations;
568 if ( $iter > 100 ) {
569 push @results,
570 info(
571 MANY_ITERATIONS => {
572 count => $iter,
573 }
574 );
575 if ( ( $min_len >= 4096 and $iter > 2500 )
576 or ( $min_len < 4096 and $min_len >= 2048 and $iter > 500 )
577 or ( $min_len < 2048 and $min_len >= 1024 and $iter > 150 ) )
578 {
579 push @results,
580 info(
581 TOO_MANY_ITERATIONS => {
582 count => $iter,
583 keylength => $min_len,
584 }
585 );
586 }
587 } ## end if ( $iter > 100 )
588 else {
589 push @results,
590 info(
591 ITERATIONS_OK => {
592 count => $iter,
593 }
594 );
595 }
596 } ## end foreach my $n3p ( @nsec3params)
597 } ## end else [ if ( @nsec3params == 0)]
598  
599 return @results;
600 } ## end sub dnssec03
601  
602 sub dnssec04 {
603 my ( $self, $zone ) = @_;
604 my @results;
605  
606 my $key_p = $zone->query_one( $zone->name, 'DNSKEY', { dnssec => 1 } );
607 if ( not $key_p ) {
608 return;
609 }
610 my @keys = $key_p->get_records( 'DNSKEY', 'answer' );
611 my @key_sigs = $key_p->get_records( 'RRSIG', 'answer' );
612  
613 my $soa_p = $zone->query_one( $zone->name, 'SOA', { dnssec => 1 } );
614 if ( not $soa_p ) {
615 return;
616 }
617 my @soas = $soa_p->get_records( 'SOA', 'answer' );
618 my @soa_sigs = $soa_p->get_records( 'RRSIG', 'answer' );
619  
620 foreach my $sig ( @key_sigs, @soa_sigs ) {
621 my $duration = $sig->expiration - $sig->inception;
622 my $remaining = $sig->expiration - int( $key_p->timestamp );
623 if ( $remaining < 0 ) { # already expired
624 push @results,
625 info(
626 RRSIG_EXPIRED => {
627 expiration => $sig->expiration,
628 tag => $sig->keytag,
629 types => $sig->typecovered,
630 }
631 );
632 }
633 elsif ( $remaining < ( $DURATION_12_HOURS_IN_SECONDS ) ) {
634 push @results,
635 info(
636 REMAINING_SHORT => {
637 duration => $remaining,
638 tag => $sig->keytag,
639 types => $sig->typecovered,
640 }
641 );
642 }
643 elsif ( $remaining > ( $DURATION_180_DAYS_IN_SECONDS ) ) {
644 push @results,
645 info(
646 REMAINING_LONG => {
647 duration => $remaining,
648 tag => $sig->keytag,
649 types => $sig->typecovered,
650 }
651 );
652 }
653 elsif ( $duration > ( $DURATION_180_DAYS_IN_SECONDS ) ) {
654 push @results,
655 info(
656 DURATION_LONG => {
657 duration => $duration,
658 tag => $sig->keytag,
659 types => $sig->typecovered,
660 }
661 );
662 }
663 else {
664 push @results,
665 info(
666 DURATION_OK => {
667 duration => $duration,
668 tag => $sig->keytag,
669 types => $sig->typecovered,
670 }
671 );
672 }
673 } ## end foreach my $sig ( @key_sigs...)
674  
675 return @results;
676 } ## end sub dnssec04
677  
678 sub dnssec05 {
679 my ( $self, $zone ) = @_;
680 my @results;
681  
682 my $key_p = $zone->query_one( $zone->name, 'DNSKEY', { dnssec => 1 } );
683 if ( not $key_p ) {
684 return;
685 }
686 my @keys = $key_p->get_records( 'DNSKEY', 'answer' );
687  
688 foreach my $key ( @keys ) {
689 my $algo = $key->algorithm;
690 if ( $algo_properties{$algo}{status} == $ALGO_STATUS_DEPRECATED ) {
691 push @results,
692 info(
693 ALGORITHM_DEPRECATED => {
694 algorithm => $algo,
695 keytag => $key->keytag,
696 description => $algo_properties{$algo}{description},
697 }
698 );
699 }
700 elsif ( $algo_properties{$algo}{status} == $ALGO_STATUS_RESERVED ) {
701 push @results,
702 info(
703 ALGORITHM_RESERVED => {
704 algorithm => $algo,
705 keytag => $key->keytag,
706 description => $algo_properties{$algo}{description},
707 }
708 );
709 }
710 elsif ( $algo_properties{$algo}{status} == $ALGO_STATUS_UNASSIGNED ) {
711 push @results,
712 info(
713 ALGORITHM_UNASSIGNED => {
714 algorithm => $algo,
715 keytag => $key->keytag,
716 description => $algo_properties{$algo}{description},
717 }
718 );
719 }
720 elsif ( $algo_properties{$algo}{status} == $ALGO_STATUS_PRIVATE ) {
721 push @results,
722 info(
723 ALGORITHM_PRIVATE => {
724 algorithm => $algo,
725 keytag => $key->keytag,
726 description => $algo_properties{$algo}{description},
727 }
728 );
729 }
730 elsif ( $algo_properties{$algo}{status} == $ALGO_STATUS_VALID ) {
731 push @results,
732 info(
733 ALGORITHM_OK => {
734 algorithm => $algo,
735 keytag => $key->keytag,
736 description => $algo_properties{$algo}{description},
737 }
738 );
739 }
740 else {
741 push @results,
742 info(
743 ALGORITHM_UNKNOWN => {
744 algorithm => $algo,
745 keytag => $key->keytag,
746 }
747 );
748 }
749 } ## end foreach my $key ( @keys )
750  
751 return @results;
752 } ## end sub dnssec05
753  
754 sub dnssec06 {
755 my ( $self, $zone ) = @_;
756 my @results;
757  
758 my $key_aref = $zone->query_all( $zone->name, 'DNSKEY', { dnssec => 1 } );
759 foreach my $key_p ( @{$key_aref} ) {
760 next if not $key_p;
761  
762 my @keys = $key_p->get_records( 'DNSKEY', 'answer' );
763 my @sigs = $key_p->get_records( 'RRSIG', 'answer' );
764 if ( @sigs > 0 and @keys > 0 ) {
765 push @results,
766 info(
767 EXTRA_PROCESSING_OK => {
768 server => $key_p->answerfrom,
769 keys => scalar( @keys ),
770 sigs => scalar( @sigs ),
771 }
772 );
773 }
774 else {
775 push @results,
776 info(
777 EXTRA_PROCESSING_BROKEN => {
778 server => $key_p->answerfrom,
779 keys => scalar( @keys ),
780 sigs => scalar( @sigs )
781 }
782 );
783 }
784 } ## end foreach my $key_p ( @{$key_aref...})
785  
786 return @results;
787 } ## end sub dnssec06
788  
789 sub dnssec07 {
790 my ( $self, $zone ) = @_;
791 my @results;
792  
793 return if not $zone->parent;
794 my $key_p = $zone->query_one( $zone->name, 'DNSKEY', { dnssec => 1 } );
795 if ( not $key_p ) {
796 return;
797 }
798 my ( $dnskey ) = $key_p->get_records( 'DNSKEY', 'answer' );
799  
800 my $ds_p = $zone->parent->query_one( $zone->name, 'DS', { dnssec => 1 } );
801 if ( not $ds_p ) {
802 return;
803 }
804 my ( $ds ) = $ds_p->get_records( 'DS', 'answer' );
805  
806 if ( $dnskey and not $ds ) {
807 push @results,
808 info(
809 DNSKEY_BUT_NOT_DS => {
810 child => $key_p->answerfrom,
811 parent => $ds_p->answerfrom,
812 }
813 );
814 }
815 elsif ( $dnskey and $ds ) {
816 push @results,
817 info(
818 DNSKEY_AND_DS => {
819 child => $key_p->answerfrom,
820 parent => $ds_p->answerfrom,
821 }
822 );
823 }
824 elsif ( not $dnskey and $ds ) {
825 push @results,
826 info(
827 DS_BUT_NOT_DNSKEY => {
828 child => $key_p->answerfrom,
829 parent => $ds_p->answerfrom,
830 }
831 );
832 }
833 else {
834 push @results,
835 info(
836 NEITHER_DNSKEY_NOR_DS => {
837 child => $key_p->answerfrom,
838 parent => $ds_p->answerfrom,
839 }
840 );
841 }
842  
843 return @results;
844 } ## end sub dnssec07
845  
846 sub dnssec08 {
847 my ( $self, $zone ) = @_;
848 my @results;
849  
850 my $key_p = $zone->query_one( $zone->name, 'DNSKEY', { dnssec => 1 } );
851 if ( not $key_p ) {
852 return;
853 }
854 my @dnskeys = $key_p->get_records( 'DNSKEY', 'answer' );
855 my @sigs = $key_p->get_records( 'RRSIG', 'answer' );
856  
857 if ( @dnskeys == 0 or @sigs == 0 ) {
858 push @results,
859 info(
860 NO_KEYS_OR_NO_SIGS => {
861 keys => scalar( @dnskeys ),
862 sigs => scalar( @sigs ),
863 }
864 );
865 return @results;
866 }
867  
868 my $ok = 0;
869 foreach my $sig ( @sigs ) {
870 my $msg = q{};
871 my $time = $key_p->timestamp;
872 if ( $sig->verify_time( \@dnskeys, \@dnskeys, $time, $msg ) ) {
873 push @results,
874 info(
875 DNSKEY_SIGNATURE_OK => {
876 signature => $sig->keytag,
877 }
878 );
879 $ok = $sig->keytag;
880 }
881 else {
882 if ($sig->algorithm == 12 and $msg =~ /Unknown cryptographic algorithm/) {
883 $msg = 'no GOST support';
884 }
885 push @results,
886 info(
887 DNSKEY_SIGNATURE_NOT_OK => {
888 signature => $sig->keytag,
889 error => $msg,
890 time => $time,
891 }
892 );
893 }
894 } ## end foreach my $sig ( @sigs )
895  
896 if ( $ok ) {
897 push @results,
898 info(
899 DNSKEY_SIGNED => {
900 keytag => $ok,
901 }
902 );
903 }
904 else {
905 push @results,
906 info( DNSKEY_NOT_SIGNED => {} );
907 }
908  
909 return @results;
910 } ## end sub dnssec08
911  
912 sub dnssec09 {
913 my ( $self, $zone ) = @_;
914 my @results;
915  
916 my $key_p = $zone->query_one( $zone->name, 'DNSKEY', { dnssec => 1 } );
917 if ( not $key_p ) {
918 return;
919 }
920 my @dnskeys = $key_p->get_records( 'DNSKEY', 'answer' );
921  
922 my $soa_p = $zone->query_one( $zone->name, 'SOA', { dnssec => 1 } );
923 if ( not $soa_p ) {
924 return;
925 }
926 my @soa = $soa_p->get_records( 'SOA', 'answer' );
927 my @sigs = $soa_p->get_records( 'RRSIG', 'answer' );
928  
929 if ( @dnskeys == 0 or @sigs == 0 or @soa == 0 ) {
930 push @results,
931 info(
932 NO_KEYS_OR_NO_SIGS_OR_NO_SOA => {
933 keys => scalar( @dnskeys ),
934 sigs => scalar( @sigs ),
935 soas => scalar( @soa ),
936 }
937 );
938 return @results;
939 }
940  
941 my $ok = 0;
942 foreach my $sig ( @sigs ) {
943 my $msg = q{};
944 my $time = $soa_p->timestamp;
945 if ( $sig->verify_time( \@soa, \@dnskeys, $time, $msg ) ) {
946 push @results,
947 info(
948 SOA_SIGNATURE_OK => {
949 signature => $sig->keytag,
950 }
951 );
952 $ok = $sig->keytag;
953 }
954 else {
955 if ($sig->algorithm == 12 and $msg =~ /Unknown cryptographic algorithm/) {
956 $msg = 'no GOST support';
957 }
958 push @results,
959 info(
960 SOA_SIGNATURE_NOT_OK => {
961 signature => $sig->keytag,
962 error => $msg,
963 }
964 );
965 }
966 } ## end foreach my $sig ( @sigs )
967  
968 if ( $ok ) {
969 push @results,
970 info(
971 SOA_SIGNED => {
972 keytag => $ok,
973 }
974 );
975 }
976 else {
977 push @results,
978 info( SOA_NOT_SIGNED => {} );
979 }
980  
981 return @results;
982 } ## end sub dnssec09
983  
984 sub dnssec10 {
985 my ( $self, $zone ) = @_;
986 my @results;
987  
988 my $key_p = $zone->query_one( $zone->name, 'DNSKEY', { dnssec => 1 } );
989 if ( not $key_p ) {
990 return;
991 }
992 my @dnskeys = $key_p->get_records( 'DNSKEY', 'answer' );
993  
994 my $name = $zone->name->prepend( 'xx--example' );
995 my $test_p = $zone->query_one( $name, 'A', { dnssec => 1 } );
996 if ( not $test_p ) {
997 return;
998 }
999  
1000 if ( $test_p->rcode ne 'NXDOMAIN' and $test_p->rcode ne 'NOERROR' ) {
1001 push @results,
1002 info(
1003 INVALID_NAME_RCODE => {
1004 name => $name,
1005 rcode => $test_p->rcode,
1006 }
1007 );
1008 return @results;
1009 }
1010  
1011 my @nsec = $test_p->get_records( 'NSEC', 'authority' );
1012 if ( @nsec ) {
1013 push @results, info( HAS_NSEC => {} );
1014 my $covered = 0;
1015 foreach my $nsec ( @nsec ) {
1016  
1017 if ( $nsec->covers( $name ) ) {
1018 $covered = 1;
1019  
1020 my @sigs = grep { $_->typecovered eq 'NSEC' } $test_p->get_records_for_name( 'RRSIG', $nsec->name );
1021 my $ok = 0;
1022 foreach my $sig ( @sigs ) {
1023 my $msg = q{};
1024 if (
1025 $sig->verify_time(
1026 [ grep { name( $_->name ) eq name( $sig->name ) } @nsec ],
1027 \@dnskeys, $test_p->timestamp, $msg
1028 )
1029 )
1030 {
1031 $ok = 1;
1032 }
1033 else {
1034 if ($sig->algorithm == 12 and $msg =~ /Unknown cryptographic algorithm/) {
1035 $msg = 'no GOST support';
1036 }
1037 push @results,
1038 info(
1039 NSEC_SIG_VERIFY_ERROR => {
1040 error => $msg,
1041 sig => $sig->keytag,
1042 }
1043 );
1044 }
1045  
1046 if ( $ok ) {
1047 push @results,
1048 info( NSEC_SIGNED => {} );
1049 }
1050 else {
1051 push @results,
1052 info( NSEC_NOT_SIGNED => {} );
1053 }
1054 } ## end foreach my $sig ( @sigs )
1055 } ## end if ( $nsec->covers( $name...))
1056 } ## end foreach my $nsec ( @nsec )
1057 if ( $covered ) {
1058 push @results,
1059 info(
1060 NSEC_COVERS => {
1061 name => $name,
1062 }
1063 );
1064 }
1065 else {
1066 push @results,
1067 info(
1068 NSEC_COVERS_NOT => {
1069 name => $name,
1070 }
1071 );
1072 }
1073 } ## end if ( @nsec )
1074  
1075 my @nsec3 = $test_p->get_records( 'NSEC3', 'authority' );
1076 if ( @nsec3 ) {
1077 my $covered = 0;
1078 push @results, info( HAS_NSEC3 => {} );
1079 foreach my $nsec3 ( @nsec3 ) {
1080  
1081 if ( $nsec3->covers( $name ) ) {
1082 $covered = 1;
1083  
1084 my @sigs = grep { $_->typecovered eq 'NSEC3' } $test_p->get_records_for_name( 'RRSIG', $nsec3->name );
1085 my $ok = 0;
1086 foreach my $sig ( @sigs ) {
1087 my $msg = q{};
1088 if (
1089 $sig->verify_time(
1090 [ grep { name( $_->name ) eq name( $sig->name ) } @nsec3 ],
1091 \@dnskeys, $test_p->timestamp, $msg
1092 )
1093 )
1094 {
1095 $ok = 1;
1096 }
1097 else {
1098 if ($sig->algorithm == 12 and $msg =~ /Unknown cryptographic algorithm/) {
1099 $msg = 'no GOST support';
1100 }
1101 push @results,
1102 info(
1103 NSEC3_SIG_VERIFY_ERROR => {
1104 sig => $sig->keytag,
1105 error => $msg,
1106 }
1107 );
1108 }
1109 if ( $ok ) {
1110 push @results,
1111 info( NSEC3_SIGNED => {} );
1112 }
1113 else {
1114 push @results,
1115 info( NSE3C_NOT_SIGNED => {} );
1116 }
1117 } ## end foreach my $sig ( @sigs )
1118 } ## end if ( $nsec3->covers( $name...))
1119 } ## end foreach my $nsec3 ( @nsec3 )
1120 if ( $covered ) {
1121 push @results,
1122 info(
1123 NSEC3_COVERS => {
1124 name => $name,
1125 }
1126 );
1127 }
1128 else {
1129 push @results,
1130 info(
1131 NSEC3_COVERS_NOT => {
1132 name => $name,
1133 }
1134 );
1135 }
1136 } ## end if ( @nsec3 )
1137  
1138 return @results;
1139 } ## end sub dnssec10
1140  
1141 ### The error reporting in dnssec11 is deliberately simple, since the point of
1142 ### the test case is to give a pass/fail test for the delegation step from the
1143 ### parent as a whole.
1144 sub dnssec11 {
1145 my ( $class, $zone ) = @_;
1146 my @results;
1147  
1148 my $ds_p = $zone->parent->query_auth( $zone->name->string, 'DS' );
1149 if ( not $ds_p ) {
1150 return info( DELEGATION_NOT_SIGNED => { keytag => 'none', reason => 'no_ds_packet' } );
1151 }
1152  
1153 my $dnskey_p = $zone->query_auth( $zone->name->string, 'DNSKEY', { dnssec => 1 } );
1154 if ( not $dnskey_p ) {
1155 return info( DELEGATION_NOT_SIGNED => { keytag => 'none', reason => 'no_dnskey_packet' } );
1156 }
1157  
1158 my %ds = map { $_->keytag => $_ } $ds_p->get_records_for_name( 'DS', $zone->name->string );
1159 my %dnskey = map { $_->keytag => $_ } $dnskey_p->get_records_for_name( 'DNSKEY', $zone->name->string );
1160 my %rrsig = map { $_->keytag => $_ } $dnskey_p->get_records_for_name( 'RRSIG', $zone->name->string );
1161  
1162 my $pass = 0;
1163 my @fail;
1164 if ( scalar( keys %ds ) > 0 ) {
1165 foreach my $tag ( keys %ds ) {
1166 my $ds = $ds{$tag};
1167 my $key = $dnskey{$tag};
1168 my $sig = $rrsig{$tag};
1169  
1170 if ( $key ) {
1171 if ( $ds->verify( $key ) ) {
1172 if ( $sig ) {
1173 my $msg = '';
1174 my $ok =
1175 $sig->verify_time( [ values %dnskey ], [ values %dnskey ], $dnskey_p->timestamp, $msg );
1176 if ( $ok ) {
1177 $pass = $tag;
1178 }
1179 else {
1180 if ($sig->algorithm == 12 and $msg =~ /Unknown cryptographic algorithm/) {
1181 $msg = 'no GOST support';
1182 }
1183 push @fail, "signature: $msg" ;
1184 }
1185 }
1186 else {
1187 push @fail, 'no_signature';
1188 }
1189 }
1190 else {
1191 push @fail, 'dnskey_no_match';
1192 }
1193 } ## end if ( $key )
1194 else {
1195 push @fail, 'no_dnskey';
1196 }
1197 } ## end foreach my $tag ( keys %ds )
1198 } ## end if ( scalar( keys %ds ...))
1199 else {
1200 push @fail, 'no_ds';
1201 }
1202  
1203 if ($pass) {
1204 push @results, info( DELEGATION_SIGNED => { keytag => $pass } )
1205 } else {
1206 push @results, info( DELEGATION_NOT_SIGNED => { keytag => 'info', reason => join(';', @fail) } )
1207 }
1208  
1209 return @results;
1210 } ## end sub dnssec11
1211  
1212 1;
1213  
1214 =head1 NAME
1215  
1216 Zonemaster::Test::DNSSEC - dnssec module showing the expected structure of Zonemaster test modules
1217  
1218 =head1 SYNOPSIS
1219  
1220 my @results = Zonemaster::Test::DNSSEC->all($zone);
1221  
1222 =head1 METHODS
1223  
1224 =over
1225  
1226 =item all($zone)
1227  
1228 Runs the default set of tests and returns a list of log entries made by the tests.
1229  
1230 =item metadata()
1231  
1232 Returns a reference to a hash, the keys of which are the names of all test methods in the module, and the corresponding values are references to
1233 lists with all the tags that the method can use in log entries.
1234  
1235 =item translation()
1236  
1237 Returns a reference to a nested hash, where the outermost keys are language
1238 codes, the keys below that are message tags and their values are translation
1239 strings.
1240  
1241 =item policy()
1242  
1243 Returns a reference to a hash with the default policy for the module. The keys
1244 are message tags, and the corresponding values are their default log levels.
1245  
1246 =item version()
1247  
1248 Returns a version string for the module.
1249  
1250 =back
1251  
1252 =head1 TESTS
1253  
1254 =over
1255  
1256 =item dnssec01($zone)
1257  
1258 Verifies that all DS records have digest types registered with IANA.
1259  
1260 =item dnssec02($zone)
1261  
1262 Verifies that all DS records have a matching DNSKEY.
1263  
1264 =item dnssec03($zone)
1265  
1266 Check iteration counts for NSEC3.
1267  
1268 =item dnssec04($zone)
1269  
1270 Checks the durations of the signatures for the DNSKEY and SOA RRsets.
1271  
1272 =item dnssec05($zone)
1273  
1274 Check DNSKEY algorithms.
1275  
1276 =item dnssec06($zone)
1277  
1278 Check for DNSSEC extra processing at child nameservers.
1279  
1280 =item dnssec07($zone)
1281  
1282 Check that both DS and DNSKEY are present.
1283  
1284 =item dnssec08($zone)
1285  
1286 Check that the DNSKEY RRset is signed.
1287  
1288 =item dnssec09($zone)
1289  
1290 Check that the SOA RRset is signed.
1291  
1292 =item dnssec10($zone)
1293  
1294 Check for the presence of either NSEC or NSEC3, with proper coverage and signatures.
1295  
1296 =item dnssec11($zone)
1297  
1298 Check that the delegation step from parent is properly signed.
1299  
1300 =back
1301  
1302 =cut