knownhosts-command.sh 1.6 KB

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