]> git.pld-linux.org Git - packages/djbdns.git/blobdiff - add-sshfp.sh
- slower, but without perl dependency
[packages/djbdns.git] / add-sshfp.sh
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.06493 seconds and 4 git commands to generate.