blob: 913948a1605271a0ce148c6d8ddc1006c323ff4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/bin/dash
die() { echo "$0: Error: $*" >&2; exit 1; }
DEFAULT_PEM_FILE=/etc/ssh/ssh_host_rsa_key.pub
if [ "$1" = -h ]
then
cat >&2 <<EOF
Usage: $0 [pem-file]
Default pem-file is $DEFAULT_PEM_FILE
EOF
exit
fi
b16_to_b32()
{
echo -n "$1" | basez -x -d | basez -j -l | tr -d =
}
pem_to_host()
{
local INPUT="$1"
DNS_FMT=$(ssh-keygen -r . -f "$INPUT")
HEX_FMT=$(echo -n "$DNS_FMT" | sed -ne 's/^. IN SSHFP [0-9]* 2 //p')
B32_FMT=$(b16_to_b32 "$HEX_FMT")
read keytype keydata < "${INPUT}" || die "reading from INPUT=$INPUT"
case "$keytype" in
ssh-rsa|ssh-dss|ecdsa-sha2-nistp256|ssh-ed25519)
domain=$keytype.cryptonomic.net ;;
*)
die "Unsupported key type: $keytype" ;;
esac
# echo $HEX_FMT.$domain
echo $B32_FMT.$domain
}
INPUT=${1:-$DEFAULT_PEM_FILE}
[ -f "$INPUT" ] || die "not a file: $INPUT"
pem_to_host "$INPUT"
|