]> git.pld-linux.org Git - packages/djbdns.git/blob - add-sshfp.sh
tinydns-log: add sample to log only fatals and startup messages
[packages/djbdns.git] / add-sshfp.sh
1 #!/bin/sh
2 # Script to convert SSHFP Bind format records to djbdns tinydns.
3 #
4 # Author: Elan Ruusamäe <glen@pld-linux.org>
5 #
6 # Inspired from Perl version
7 # http://dank.qemfd.net/dankwiki/index.php/SSHFP
8
9 # convert decimal to octal
10 dec2oct() {
11         echo "ibase=10; obase=8; $1" | bc -l
12 }
13
14 # convert hex to octal
15 hex2oct() {
16         # bc wants uppercase hex
17         local i=$(echo "$1" | tr [a-f] [A-F])
18         echo "ibase=16; obase=8; $i" | bc -l
19 }
20
21 hostalias=$1
22 ssh-keygen -f /etc/ssh/ssh_host_rsa_key.pub -r $hostalias | \
23 while read host in sshfp alg fptype fp; do
24         out="\\"$(printf "%03d" $(dec2oct $alg))
25         out=$out"\\"$(printf "%03d" $(dec2oct $fptype))
26
27         while [ "$fp" ]; do
28                 # temp chop off two bytes
29                 t=${fp#??}
30                 # take the bytes
31                 ch=${fp%$t}
32                 out=$out"\\"$(printf "%03d" $(hex2oct $ch))
33                 # continue fp
34                 fp=$t
35         done
36         printf ":%s:44:%s:\n" $host $out
37 done
This page took 0.087867 seconds and 3 git commands to generate.