Skip to content

Instantly share code, notes, and snippets.

@DavidGoodwin
Created March 14, 2014 12:26
Show Gist options
  • Save DavidGoodwin/9546745 to your computer and use it in GitHub Desktop.
Save DavidGoodwin/9546745 to your computer and use it in GitHub Desktop.
convert BIND style SSHFP record into something TinyDNS can understand
#!/usr/bin/perl
use strict;
# Take in, e.g. :
# foobar.palepurple.co.uk IN SSHFP 1 1 9676BB7A92C7E11B90E9508A343A4CAE9888B43D";
# foobar.palepurple.co.uk IN SSHFP 2 1 D4F49CE2195A0BF531275B889ED6ABFF2F24C2BC
# on standard input, and output the appropriate tinydns records for sshfp -
# e.g.
# :foobar.palepurple.co.uk:44:\001\001\226\166\273\172\222\307\341\033\220\351\120\212\064\072\114\256\230\210\264\075:
# :foobar.palepurple.co.uk:44:\002\001\324\364\234\342\031\132\013\365\061\047\133\210\236\326\253\377\057\044\302\274:
#
# Example: sshfp -qs foobar.palepurple.co.uk | perl sshfp-tinydns.pl
# @see http://nick-black.com/dankwiki/index.php/SSHFP
while(<STDIN>) {
chop;
my ($host, $in, $sshfp, $alg, $fptype, $fp) = split " ", $_;
my $out = sprintf("\\%03o\\%03o", $alg, $fptype);
for (my $i = 0; $i < length($fp); $i += 2) {
$out .= sprintf("\\%03o", hex substr($fp, $i, 2));
}
printf(":%s:44:%s:\n", $host, $out);
}
@DavidGoodwin
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment