]> git.pld-linux.org Git - packages/djbdns.git/blame - add-sshfp.sh
- slower, but without perl dependency
[packages/djbdns.git] / add-sshfp.sh
CommitLineData
0bf8d2b5
ER
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
10dec2oct() {
11 echo "ibase=10; obase=8; $1" | bc -l
12}
13
14# convert hex to octal
15hex2oct() {
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
21hostalias=$1
22ssh-keygen -f /etc/ssh/ssh_host_rsa_key.pub -r $hostalias | \
23while 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
37done
This page took 0.031507 seconds and 4 git commands to generate.