1# $OpenBSD: knownhosts-command.sh,v 1.2 2020/12/22 06:47:24 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 test "x$keytype" = "xssh-dss" && continue 43 verbose "keytype $keytype" 44 cat > $OBJ/knownhosts_command << _EOF 45#!/bin/sh 46die() { echo "\$@" 1>&2 ; exit 1; } 47test "x\$1" = "x$keytype" || die "wrong keytype \$1 (expected $keytype)" 48test "x\$3" = "x$LOGNAME" || die "wrong username \$3 (expected $LOGNAME)" 49grep -- "\$1.*\$2" $OBJ/known_hosts 50_EOF 51 ${SSH} -F $OBJ/ssh_proxy -oHostKeyAlgorithms=$keytype x true || 52 fail "ssh connect failed for keytype $x" 53done 54