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
|
#!/usr/bin/perl
#
# Copyright 2008-2012 SPARTA, Inc. All rights reserved. See the COPYING
# file distributed with this software for details.
#
#
# getds
#
use Net::DNS;
use Net::DNS::SEC;
use Data::Dumper;
use Net::DNS::SEC::Tools::QWPrimitives;
my %opts =
( 'a' => 'SHA256,SHA1'
);
DTGetOptions(\%opts,
['GUI:VERSION',"DNSSEC-Tools Version: 1.13"],
['a|hash-algorithm=s',
'Comma separated hash algorithm to use (eg, SHA256,SHA1)'],
['z|print-zsks', 'Print ZSK DS records as well as KSKs'],
['p|dont-check-parent', 'Don\'t check for the parent\'s published DS record'],
['q|quiet', 'Just display minimal results'],
['GUI:otherargs_text',"DOMAIN_NAME"],
) || exit;
# Generate a list of all the algorithms to use:
my @algorithms = split(/,\s*/, uc($opts{'a'}));
Exit("no algorithms specified with the -a switch") if ($#algorithms == -1);
# query the DNSKEY from the net
my $res = Net::DNS::Resolver->new;
Exit("Failed to create a Net::DNS::Resolver") if (!$res);
my $q = $res->query($ARGV[0], "DNSKEY");
Exit("Failed to query '$ARGV[0]' for its DNSKEY records") if (!$q);
my @keys = $q->answer;
#
# for each of the keys found, print out the DS record
#
my @childds;
my %childds;
print "--- DS records generated from queried keys of $ARGV[0]:\n"
if (!$opts{'q'});
foreach my $key (@keys) {
next if (!$opts{'z'} && ($key->flags & 0x1) == 0); # KSKs only
foreach my $algorithm (@algorithms) {
my $ds = create Net::DNS::RR::DS($key,
digtype => $algorithm,
);
push @childds, $ds;
print make_printing_ds($ds);
$childds{make_matching_ds($ds)} = make_printing_ds($ds);
}
}
exit if ($opts{'p'} || $opts{'q'}); # exit if we either EITHER Ps or Qs!
# query the DNSKEY from the net
$q = $res->query($ARGV[0], "DS");
my @dses;
if ($q) {
@dses = $q->answer;
}
my @errors;
print "\n--- DS records pulled from the parent of $ARGV[0]:\n";
foreach my $ds (@dses) {
print make_printing_ds($ds);
my $parentds = make_matching_ds($ds);
if (exists($childds{$parentds})) {
delete $childds{$parentds};
} else {
push @errors, "The following DS record exists in the parent, but no child key matches it: \n" . make_printing_ds($ds) . "\n";
}
}
foreach my $ds (keys(%childds)) {
push @errors, "The following DS record for a child key is not published by the parent:\n" . "$childds{$ds}\n";
}
if ($#errors == -1) {
print "\nErrors Found: NONE (everything matches)\n";
exit 0;
}
print "\nERRORS (" . ($#errors+1) . "):\n";
my $errorcount = 1;
foreach my $error (@errors) {
print $errorcount++, ") ", $error,"\n";
}
sub make_matching_ds {
my $changethis = $_[0];
$changethis = $changethis->string;
$changethis = lc($changethis);
$changethis =~ s/.*\sds\s+//;
$changethis =~ s/\;.*//;
return $changethis;
}
sub make_printing_ds {
my $changethis = $_[0];
$changethis = $changethis->string;
$changethis = uc($changethis);
$changethis =~ s/\;.*//;
$changethis = " " . $changethis . "\n";
return $changethis;
}
sub Exit {
if ($#_ > -1) {
print STDERR @_, "\n";
}
exit 1;
}
exit 1;
=head1 NAME
getds - Create a DS record from DNSKEYing information
=head1 SYNOPSIS
getds <domain>
=head1 DESCRIPTION
B<getds> will create a DS record from DNSKEYs for the specified DNS
domain. It does this by converting DNSKEYs to DS records using the
specified hashing algorithm. The results can then be passed to
upstream DNSSEC-supporting parents or to DLV registries.
B<getds> will also pull the parent's published DS records and compare
them against the existing keys. It will then list any DS records not
published in the parent, as well as any DS records that are published
in the parent but which don't match an existing key.
=head1 OPTIONS
B<getds> takes the following options:
=over 4
=item B<-a ALGORITHMS>
=item B<--hash-algorithm algorithm ALGORITHMS>
This option specifies the hash algorithm to use when converting
DNSKEYs to DS records. It may be a comma-separated list if multiple
algorithms are desired. The algorithms to choose from may be either
SHA256 or SHA1.
The default is SHA256,SHA1
=item B<-z>
=item B<--print-zsks>
This option causes B<getds> to print ZSK DS records, as well as KSK records.
=item B<-p>
=item B<--dont-check-parent>
Instructs B<getds> to not check the records in the parent for their
published DS records.
=item B<-q>
=item B<--quiet>
Produces quiet output with no explanatory headers. In other words, it only
prints the DS records generated from the DNSKEYs.
Note: Running with -q implies -p.
=back
=head1 SECURITY CONSIDERATIONS
By default, B<getds> pulls data from the live DNS. If your DNS resolver
isn't configured so that this is pulled securely, then the results
can't be trusted.
=head1 COPYRIGHT
Copyright 2008-2012 SPARTA, Inc. All rights reserved.
See the COPYING file included with the DNSSEC-Tools package for details.
=head1 AUTHOR
Wes Hardaker, hardaker AT AT AT users.sourceforge.net
=cut
|