~evybongers/dotfiles

9770d0b88527f631643c9813707c40892650a131 — Evy Bongers a month ago cd503f1
[ssh] Fix host keys lookup
2 files changed, 7 insertions(+), 6 deletions(-)

M .config/ssh/config
M .local/bin/get_host_keys
M .config/ssh/config => .config/ssh/config +1 -1
@@ 12,7 12,7 @@ Host                    *
    ForwardAgent        no
    ForwardX11          no
    HashKnownHosts      no
    KnownHostsCommand   /home/ebongers/.local/bin/get_host_keys -C "%C" -H "%H" -I "%I" -K "%K" -h "%h" -t "%t"
    KnownHostsCommand   /home/ebongers/.local/bin/get_host_keys -C "%C" -H "%H" -I "%I" -K "%K" -k "%k" -t "%t"
    ServerAliveInterval 120
    UserKnownHostsFile  /dev/null


M .local/bin/get_host_keys => .local/bin/get_host_keys +6 -5
@@ 1,21 1,22 @@
#!/usr/bin/zsh
# %C  Hash of %l%h%p%r%j.
# %H  The known_hosts hostname or address that is being searched for.
# %h  The remote hostname.
# %I  A  string describing the reason for a KnownHostsCommand execution: either
#     ADDRESS when looking up a host by address (only when CheckHostIP  is  en‐
#     abled),  HOSTNAME when searching by hostname, or ORDER when preparing the
#     host key algorithm preference list to use for the destination host.
# %K  The base64 encoded host key.
# %k  The  host  key alias if specified, otherwise the original remote hostname
#     given on the command line.
# %t  The type of the server host key, e.g.  ssh-ed25519.

while getopts C:H:I:f:h:K:t: OPTNAME; do
while getopts C:H:I:K:f:k:t: OPTNAME; do
    case $OPTNAME in
    C) hash="${OPTARG}" ;;
    H) hostSearch="${OPTARG}" ;;
    h) hostname="${OPTARG}" ;;
    H) hostname="${OPTARG}" ;;
    I) reason="${OPTARG}" ;;
    K) encodedHostKey="${OPTARG}" ;;
    k) hostKeyAlias="${OPTARG}" ;;
    t) hostKeyType="${OPTARG}" ;;
    esac
done


@@ 28,7 29,7 @@ ADDRESS)
HOSTNAME)
    knownHostsFiles=( "${XDG_STATE_HOME}"/ssh/{${hostname},${hostname#*.}}.keys(N) )
    [[ -n ${knownHostsFiles} ]] || exit 0
    for _search in $hostSearch $hash; do
    for _search in $hostKeyAlias $hostname $hash; do
        grep --no-filename "^${(q)_search} ${hostKeyType} ${encodedHostKey}" "${knownHostsFiles[@]}" || true
    done
    ;;