]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - crypto/openssh/regress/knownhosts-command.sh
Import OpenCSD v.1.4.0.
[FreeBSD/FreeBSD.git] / crypto / openssh / regress / knownhosts-command.sh
1 #       $OpenBSD: knownhosts-command.sh,v 1.3 2021/08/30 01:15:45 djm Exp $
2 #       Placed in the Public Domain.
3
4 tid="known hosts command "
5
6 rm -f $OBJ/knownhosts_command $OBJ/ssh_proxy_khc
7 cp $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
16 verbose "simple connection"
17 cat > $OBJ/knownhosts_command << _EOF
18 #!/bin/sh
19 cat $OBJ/known_hosts
20 _EOF
21 chmod a+x $OBJ/knownhosts_command
22 ${SSH} -F $OBJ/ssh_proxy x true || fail "ssh connect failed"
23
24 verbose "no keys"
25 cat > $OBJ/knownhosts_command << _EOF
26 #!/bin/sh
27 exit 0
28 _EOF
29 chmod a+x $OBJ/knownhosts_command
30 ${SSH} -F $OBJ/ssh_proxy x true && fail "ssh connect succeeded with no keys"
31
32 verbose "bad exit status"
33 cat > $OBJ/knownhosts_command << _EOF
34 #!/bin/sh
35 cat $OBJ/known_hosts
36 exit 1
37 _EOF
38 chmod a+x $OBJ/knownhosts_command
39 ${SSH} -F $OBJ/ssh_proxy x true && fail "ssh connect succeeded with bad exit"
40
41 for 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
48 die() { echo "\$@" 1>&2 ; exit 1; }
49 test "x\$1" = "x$keytype" || die "wrong keytype \$1 (expected $keytype)"
50 test "x\$3" = "x$LOGNAME" || die "wrong username \$3 (expected $LOGNAME)"
51 grep -- "\$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"
55 done