<p>Python anyone? :-) </p>
<div class="gmail_quote">On Dec 17, 2011 6:10 AM, "Olaf Kolkman" <<a href="mailto:olaf@nlnetlabs.nl">olaf@nlnetlabs.nl</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
And then there is the keytag method in Net::DNS see <a href="http://search.cpan.org/~olaf/Net-DNS-SEC-0.16/RR/DNSKEY.pm" target="_blank">http://search.cpan.org/~olaf/Net-DNS-SEC-0.16/RR/DNSKEY.pm</a><br>
<br>
Sent from my iPhone<br>
<br>
On Dec 17, 2011, at 12:19 AM, Lutz Donnerhacke <<a href="mailto:lutz@iks-jena.de">lutz@iks-jena.de</a>> wrote:<br>
<br>
> In iks.lists.dns-operations, you wrote:<br>
>> I realise I'm probably the only person in the world who would ever<br>
>> want to do such a thing<br>
><br>
> No, you are not that alone.<br>
><br>
>> It seems to generate the right keytags for the zones I have been<br>
>> playing with.<br>
><br>
> Fine!<br>
><br>
> #! /usr/bin/perl<br>
><br>
> package dnskey2ds;<br>
><br>
> use strict;<br>
> use warnings;<br>
><br>
> use Digest;<br>
> use MIME::Base64;<br>
><br>
> BEGIN {<br>
> use Exporter ();<br>
> use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);<br>
><br>
> $VERSION = 1.00;<br>
> @ISA = qw(Exporter);<br>
> @EXPORT = qw(&generate_ds);<br>
> %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],<br>
><br>
> # your exported package globals go here,<br>
> # as well as any optionally exported functions<br>
> @EXPORT_OK = qw(&generate_ds);<br>
><br>
> }<br>
><br>
> use vars @EXPORT_OK;<br>
> my $sha1 = Digest->new("SHA-1");<br>
><br>
> sub generate_ds($$) {<br>
> my $fqdn = shift;<br>
> my ($flags, $prot, $algo, $key) = split(/\s+/, shift, 4);<br>
> my $rdata = join("", map {decode_base64 $_} (split /\s+/, $key));<br>
><br>
> local $_;<br>
> $sha1->reset();<br>
><br>
> $fqdn =~ s/\.$//;<br>
> foreach (split (/\./,$fqdn)) { $sha1->add(pack("c/a*",$_)); }<br>
> $sha1->add(pack("c/a*",""));<br>
><br>
> my $wire = pack("ncc", $flags, 3, $algo) . $rdata;<br>
> $sha1->add($wire);<br>
><br>
> my $keytag;<br>
> if($algo == 1) {<br>
> $keytag = 0xffff & unpack("n", substr($wire,-3,2)) ;<br>
> } else {<br>
> my ($sum, $i);<br>
> for($sum = $i = 0; $i < length $wire; $i++) {<br>
> $_ = unpack("C", substr($wire,$i,1));<br>
> $sum += ($i & 1) ? $_ : $_ << 8;<br>
> }<br>
> $keytag = 0xffff & ($sum + ($sum >> 16));<br>
> }<br>
><br>
> my $comment = "";<br>
> if($algo == 3) {<br>
> $_ = $rdata;<br>
> my $len = 8*(64 + 8*unpack("C", substr($_,0,1)));<br>
> $comment = "; Modulus = $len bit";<br>
> } elsif($algo == 5 || $algo == 1) {<br>
> $_ = $rdata;<br>
> my ($len, $exponent);<br>
> $len = unpack("C", substr($_,0,1));<br>
> $_ = substr($_,1);<br>
> unless($len) {<br>
> $len = unpack("n", substr($_,0,2));<br>
> $_ = substr($_,2);<br>
> }<br>
> if($len == 1) {<br>
> $exponent = unpack("C", substr($_,0,1));<br>
> } elsif($len == 2) {<br>
> $exponent = unpack("n", substr($_,0,2));<br>
> } elsif($len == 3) {<br>
> $exponent = unpack("n", substr($_,0,2)) * 256<br>
> + unpack("C", substr($_,2,1));<br>
> } elsif($len == 4) {<br>
> $exponent = unpack("N", substr($_,0,4));<br>
> } elsif($len == 5) {<br>
> $exponent = unpack("N", substr($_,0,4)) * 256<br>
> + unpack("C", substr($_,4,1));<br>
> }<br>
> $_ = substr($_,$len);<br>
> $_ = 8*(length $_);<br>
> $comment = "; Modulus = $_ bit";<br>
> if($exponent) {<br>
> $comment .= ", Exponent = $exponent";<br>
> } else {<br>
> $comment .= ", Exponent = $len byte";<br>
> }<br>
> }<br>
> return "$keytag $algo 1 ${\$sha1->hexdigest()} $comment";<br>
> }<br>
><br>
> 1;<br>
> _______________________________________________<br>
> dns-operations mailing list<br>
> <a href="mailto:dns-operations@lists.dns-oarc.net">dns-operations@lists.dns-oarc.net</a><br>
> <a href="https://lists.dns-oarc.net/mailman/listinfo/dns-operations" target="_blank">https://lists.dns-oarc.net/mailman/listinfo/dns-operations</a><br>
> dns-jobs mailing list<br>
> <a href="https://lists.dns-oarc.net/mailman/listinfo/dns-jobs" target="_blank">https://lists.dns-oarc.net/mailman/listinfo/dns-jobs</a><br>
_______________________________________________<br>
dns-operations mailing list<br>
<a href="mailto:dns-operations@lists.dns-oarc.net">dns-operations@lists.dns-oarc.net</a><br>
<a href="https://lists.dns-oarc.net/mailman/listinfo/dns-operations
dns-jobs" target="_blank">https://lists.dns-oarc.net/mailman/listinfo/dns-operations<br>
dns-jobs</a> mailing list<br>
<a href="https://lists.dns-oarc.net/mailman/listinfo/dns-jobs" target="_blank">https://lists.dns-oarc.net/mailman/listinfo/dns-jobs</a><br>
</blockquote></div>