summaryrefslogtreecommitdiff
path: root/regress/knownhosts-command.sh
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-12-22 06:03:36 +0000
committerDamien Miller <djm@mindrot.org>2020-12-22 17:07:38 +1100
commit2873f19570d4d8758be24dbf78332be9a779009b (patch)
tree0b2af2c4053a325f0de37897baea679a027a07ca /regress/knownhosts-command.sh
parent0121aa87bab9ad2365de2d07f2832b56d5ff9871 (diff)
downloadopenssh-git-2873f19570d4d8758be24dbf78332be9a779009b.tar.gz
upstream: regress test for KnownHostsCommand
OpenBSD-Regress-ID: ffc77464320b6dabdcfa0a72e0df02659233a38a
Diffstat (limited to 'regress/knownhosts-command.sh')
-rw-r--r--regress/knownhosts-command.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/regress/knownhosts-command.sh b/regress/knownhosts-command.sh
new file mode 100644
index 00000000..6881d607
--- /dev/null
+++ b/regress/knownhosts-command.sh
@@ -0,0 +1,53 @@
+# $OpenBSD: knownhosts-command.sh,v 1.1 2020/12/22 06:03:36 djm Exp $
+# Placed in the Public Domain.
+
+tid="known hosts command "
+
+rm -f $OBJ/knownhosts_command $OBJ/ssh_proxy_khc
+cp $OBJ/ssh_proxy $OBJ/ssh_proxy_orig
+
+( grep -vi GlobalKnownHostsFile $OBJ/ssh_proxy_orig | \
+ grep -vi UserKnownHostsFile;
+ echo "GlobalKnownHostsFile none" ;
+ echo "UserKnownHostsFile none" ;
+ echo "KnownHostsCommand $OBJ/knownhosts_command '%t' '%K' '%u'" ;
+) > $OBJ/ssh_proxy
+
+verbose "simple connection"
+cat > $OBJ/knownhosts_command << _EOF
+#!/bin/sh
+cat $OBJ/known_hosts
+_EOF
+chmod a+x $OBJ/knownhosts_command
+${SSH} -F $OBJ/ssh_proxy x true || fail "ssh connect failed"
+
+verbose "no keys"
+cat > $OBJ/knownhosts_command << _EOF
+#!/bin/sh
+exit 0
+_EOF
+chmod a+x $OBJ/knownhosts_command
+${SSH} -F $OBJ/ssh_proxy x true && fail "ssh connect succeeded with no keys"
+
+verbose "bad exit status"
+cat > $OBJ/knownhosts_command << _EOF
+#!/bin/sh
+cat $OBJ/known_hosts
+exit 1
+_EOF
+chmod a+x $OBJ/knownhosts_command
+${SSH} -F $OBJ/ssh_proxy x true && fail "ssh connect succeeded with bad exit"
+
+for keytype in ${SSH_HOSTKEY_TYPES} ; do
+ test "x$keytype" = "xssh-dss" && continue
+ verbose "keytype $keytype"
+ cat > $OBJ/knownhosts_command << _EOF
+#!/bin/sh
+die() { echo "\$@" 1>&2 ; exit 1; }
+test "x\$1" = "x$keytype" || die "wrong keytype \$1"
+test "x\$3" = "x$LOGNAME" || die "wrong username \$3"
+grep -- "\$1.*\$2" $OBJ/known_hosts
+_EOF
+ ${SSH} -F $OBJ/ssh_proxy -oHostKeyAlgorithms=$keytype x true ||
+ fail "ssh connect failed for keytype $x"
+done