1*8c22023cSEd Maste# $OpenBSD: knownhosts-command.sh,v 1.3 2021/08/30 01:15:45 djm Exp $ 219261079SEd Maste# Placed in the Public Domain. 319261079SEd Maste 419261079SEd Mastetid="known hosts command " 519261079SEd Maste 619261079SEd Masterm -f $OBJ/knownhosts_command $OBJ/ssh_proxy_khc 719261079SEd Mastecp $OBJ/ssh_proxy $OBJ/ssh_proxy_orig 819261079SEd Maste 919261079SEd Maste( grep -vi GlobalKnownHostsFile $OBJ/ssh_proxy_orig | \ 1019261079SEd Maste grep -vi UserKnownHostsFile; 1119261079SEd Maste echo "GlobalKnownHostsFile none" ; 1219261079SEd Maste echo "UserKnownHostsFile none" ; 1319261079SEd Maste echo "KnownHostsCommand $OBJ/knownhosts_command '%t' '%K' '%u'" ; 1419261079SEd Maste) > $OBJ/ssh_proxy 1519261079SEd Maste 1619261079SEd Masteverbose "simple connection" 1719261079SEd Mastecat > $OBJ/knownhosts_command << _EOF 1819261079SEd Maste#!/bin/sh 1919261079SEd Mastecat $OBJ/known_hosts 2019261079SEd Maste_EOF 2119261079SEd Mastechmod a+x $OBJ/knownhosts_command 2219261079SEd Maste${SSH} -F $OBJ/ssh_proxy x true || fail "ssh connect failed" 2319261079SEd Maste 2419261079SEd Masteverbose "no keys" 2519261079SEd Mastecat > $OBJ/knownhosts_command << _EOF 2619261079SEd Maste#!/bin/sh 2719261079SEd Masteexit 0 2819261079SEd Maste_EOF 2919261079SEd Mastechmod a+x $OBJ/knownhosts_command 3019261079SEd Maste${SSH} -F $OBJ/ssh_proxy x true && fail "ssh connect succeeded with no keys" 3119261079SEd Maste 3219261079SEd Masteverbose "bad exit status" 3319261079SEd Mastecat > $OBJ/knownhosts_command << _EOF 3419261079SEd Maste#!/bin/sh 3519261079SEd Mastecat $OBJ/known_hosts 3619261079SEd Masteexit 1 3719261079SEd Maste_EOF 3819261079SEd Mastechmod a+x $OBJ/knownhosts_command 3919261079SEd Maste${SSH} -F $OBJ/ssh_proxy x true && fail "ssh connect succeeded with bad exit" 4019261079SEd Maste 4119261079SEd Mastefor keytype in ${SSH_HOSTKEY_TYPES} ; do 42*8c22023cSEd Maste algs=$keytype 4319261079SEd Maste test "x$keytype" = "xssh-dss" && continue 44*8c22023cSEd Maste test "x$keytype" = "xssh-rsa" && algs=ssh-rsa,rsa-sha2-256,rsa-sha2-512 4519261079SEd Maste verbose "keytype $keytype" 4619261079SEd Maste cat > $OBJ/knownhosts_command << _EOF 4719261079SEd Maste#!/bin/sh 4819261079SEd Mastedie() { echo "\$@" 1>&2 ; exit 1; } 4919261079SEd Mastetest "x\$1" = "x$keytype" || die "wrong keytype \$1 (expected $keytype)" 5019261079SEd Mastetest "x\$3" = "x$LOGNAME" || die "wrong username \$3 (expected $LOGNAME)" 5119261079SEd Mastegrep -- "\$1.*\$2" $OBJ/known_hosts 5219261079SEd Maste_EOF 53*8c22023cSEd Maste ${SSH} -F $OBJ/ssh_proxy -oHostKeyAlgorithms=$algs x true || 5419261079SEd Maste fail "ssh connect failed for keytype $x" 5519261079SEd Mastedone 56