1# $OpenBSD: knownhosts-command.sh,v 1.3 2021/08/30 01:15:45 djm Exp $ 2# Placed in the Public Domain. 3 4tid="known hosts command " 5 6rm -f $OBJ/knownhosts_command $OBJ/ssh_proxy_khc 7cp $OBJ/ssh_proxy $OBJ/ssh_proxy_orig 8 9( grep -vi GlobalKnownHostsFile $OBJ/ssh_proxy_orig | \ 10 grep -vi UserKnownHostsFile; 11 echo "GlobalKnownHostsFile none" ; 12 echo "UserKnownHostsFile none" ; 13 echo "KnownHostsCommand $OBJ/knownhosts_command '%t' '%K' '%u'" ; 14) > $OBJ/ssh_proxy 15 16verbose "simple connection" 17cat > $OBJ/knownhosts_command << _EOF 18#!/bin/sh 19cat $OBJ/known_hosts 20_EOF 21chmod a+x $OBJ/knownhosts_command 22${SSH} -F $OBJ/ssh_proxy x true || fail "ssh connect failed" 23 24verbose "no keys" 25cat > $OBJ/knownhosts_command << _EOF 26#!/bin/sh 27exit 0 28_EOF 29chmod a+x $OBJ/knownhosts_command 30${SSH} -F $OBJ/ssh_proxy x true && fail "ssh connect succeeded with no keys" 31 32verbose "bad exit status" 33cat > $OBJ/knownhosts_command << _EOF 34#!/bin/sh 35cat $OBJ/known_hosts 36exit 1 37_EOF 38chmod a+x $OBJ/knownhosts_command 39${SSH} -F $OBJ/ssh_proxy x true && fail "ssh connect succeeded with bad exit" 40 41for keytype in ${SSH_HOSTKEY_TYPES} ; do 42 algs=$keytype 43 test "x$keytype" = "xssh-dss" && continue 44 test "x$keytype" = "xssh-rsa" && algs=ssh-rsa,rsa-sha2-256,rsa-sha2-512 45 verbose "keytype $keytype" 46 cat > $OBJ/knownhosts_command << _EOF 47#!/bin/sh 48die() { echo "\$@" 1>&2 ; exit 1; } 49test "x\$1" = "x$keytype" || die "wrong keytype \$1 (expected $keytype)" 50test "x\$3" = "x$LOGNAME" || die "wrong username \$3 (expected $LOGNAME)" 51grep -- "\$1.*\$2" $OBJ/known_hosts 52_EOF 53 ${SSH} -F $OBJ/ssh_proxy -oHostKeyAlgorithms=$algs x true || 54 fail "ssh connect failed for keytype $x" 55done 56