]> git.pld-linux.org Git - packages/djbdns.git/commitdiff
- slower, but without perl dependency
authorElan Ruusamäe <glen@pld-linux.org>
Fri, 6 Aug 2010 08:35:59 +0000 (08:35 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    add-sshfp.pl -> 1.2
    add-sshfp.sh -> 1.1

add-sshfp.pl [deleted file]
add-sshfp.sh [new file with mode: 0644]

diff --git a/add-sshfp.pl b/add-sshfp.pl
deleted file mode 100644 (file)
index 07ba5a8..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-
-open IN, "ssh-keygen -f /etc/ssh/ssh_host_rsa_key.pub -r $ARGV[0] |";
-my $FP = <IN>;
-close IN;
-chop $FP;
-my ($host, $in, $sshfp, $alg, $fptype, $fp) = split " ", $FP;
-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);
diff --git a/add-sshfp.sh b/add-sshfp.sh
new file mode 100644 (file)
index 0000000..73a5f9f
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+# Script to convert SSHFP Bind format records to djbdns tinydns.
+#
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+#
+# Inspired from Perl version
+# http://dank.qemfd.net/dankwiki/index.php/SSHFP
+
+# convert decimal to octal
+dec2oct() {
+       echo "ibase=10; obase=8; $1" | bc -l
+}
+
+# convert hex to octal
+hex2oct() {
+       # bc wants uppercase hex
+       local i=$(echo "$1" | tr [a-f] [A-F])
+       echo "ibase=16; obase=8; $i" | bc -l
+}
+
+hostalias=$1
+ssh-keygen -f /etc/ssh/ssh_host_rsa_key.pub -r $hostalias | \
+while read host in sshfp alg fptype fp; do
+       out="\\"$(printf "%03d" $(dec2oct $alg))
+       out=$out"\\"$(printf "%03d" $(dec2oct $fptype))
+
+       while [ "$fp" ]; do
+               # temp chop off two bytes
+               t=${fp#??}
+               # take the bytes
+               ch=${fp%$t}
+               out=$out"\\"$(printf "%03d" $(hex2oct $ch))
+               # continue fp
+               fp=$t
+       done
+       printf ":%s:44:%s:\n" $host $out
+done
This page took 0.103829 seconds and 4 git commands to generate.