diff options
author | Andrew Cady <d@jerkface.net> | 2020-05-31 20:30:53 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-05-31 20:30:53 -0400 |
commit | 42f619457d58e3c34237d7d3fe55d5bb19a2ba90 (patch) | |
tree | 47878c2baae55d8332fffe81653a029df602a2ea /src | |
parent | cede3f14a47999fc54fb6bcec1749e6da82bc4b0 (diff) |
"hostname.cryptonomic.net" shows the cryptonomic hostname of the current system
Diffstat (limited to 'src')
-rwxr-xr-x | src/hostname.cryptonomic.net | 43 |
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 | |||
3 | die() { echo "$0: Error: $*" >&2; exit 1; } | ||
4 | |||
5 | DEFAULT_PEM_FILE=/etc/ssh/ssh_host_rsa_key.pub | ||
6 | if [ "$1" = -h ] | ||
7 | then | ||
8 | cat >&2 <<EOF | ||
9 | Usage: $0 [pem-file] | ||
10 | |||
11 | Default pem-file is $DEFAULT_PEM_FILE | ||
12 | EOF | ||
13 | exit | ||
14 | fi | ||
15 | |||
16 | b16_to_b32() | ||
17 | { | ||
18 | echo -n "$1" | basez -x -d | basez -j -l | tr -d = | ||
19 | } | ||
20 | |||
21 | pem_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 | |||
39 | INPUT=${1:-$DEFAULT_PEM_FILE} | ||
40 | [ -f "$INPUT" ] || die "not a file: $INPUT" | ||
41 | |||
42 | pem_to_host "$INPUT" | ||
43 | |||