summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-05-31 20:30:53 -0400
committerAndrew Cady <d@jerkface.net>2020-05-31 20:30:53 -0400
commit42f619457d58e3c34237d7d3fe55d5bb19a2ba90 (patch)
tree47878c2baae55d8332fffe81653a029df602a2ea
parentcede3f14a47999fc54fb6bcec1749e6da82bc4b0 (diff)
"hostname.cryptonomic.net" shows the cryptonomic hostname of the current system
-rwxr-xr-xsrc/hostname.cryptonomic.net43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/hostname.cryptonomic.net b/src/hostname.cryptonomic.net
new file mode 100755
index 0000000..913948a
--- /dev/null
+++ b/src/hostname.cryptonomic.net
@@ -0,0 +1,43 @@
1#!/bin/dash
2
3die() { echo "$0: Error: $*" >&2; exit 1; }
4
5DEFAULT_PEM_FILE=/etc/ssh/ssh_host_rsa_key.pub
6if [ "$1" = -h ]
7then
8 cat >&2 <<EOF
9Usage: $0 [pem-file]
10
11 Default pem-file is $DEFAULT_PEM_FILE
12EOF
13 exit
14fi
15
16b16_to_b32()
17{
18 echo -n "$1" | basez -x -d | basez -j -l | tr -d =
19}
20
21pem_to_host()
22{
23 local INPUT="$1"
24 DNS_FMT=$(ssh-keygen -r . -f "$INPUT")
25 HEX_FMT=$(echo -n "$DNS_FMT" | sed -ne 's/^. IN SSHFP [0-9]* 2 //p')
26 B32_FMT=$(b16_to_b32 "$HEX_FMT")
27
28 read keytype keydata < "${INPUT}" || die "reading from INPUT=$INPUT"
29 case "$keytype" in
30 ssh-rsa|ssh-dss|ecdsa-sha2-nistp256|ssh-ed25519)
31 domain=$keytype.cryptonomic.net ;;
32 *)
33 die "Unsupported key type: $keytype" ;;
34 esac
35# echo $HEX_FMT.$domain
36 echo $B32_FMT.$domain
37}
38
39INPUT=${1:-$DEFAULT_PEM_FILE}
40[ -f "$INPUT" ] || die "not a file: $INPUT"
41
42pem_to_host "$INPUT"
43