hostkey-agent.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # $OpenBSD: hostkey-agent.sh,v 1.11 2019/12/16 02:39:05 djm Exp $
  2. # Placed in the Public Domain.
  3. tid="hostkey agent"
  4. rm -f $OBJ/agent-key.* $OBJ/ssh_proxy.orig $OBJ/known_hosts.orig
  5. trace "start agent"
  6. eval $(${SSHAGENT} ${EXTRA_AGENT_ARGS} -s) > /dev/null
  7. r=$?
  8. [ $r -ne 0 ] && fatal "could not start ssh-agent: exit code $r"
  9. grep -vi 'hostkey' $OBJ/sshd_proxy > $OBJ/sshd_proxy.orig
  10. echo "HostKeyAgent $SSH_AUTH_SOCK" >> $OBJ/sshd_proxy.orig
  11. trace "load hostkeys"
  12. for k in $SSH_KEYTYPES; do
  13. ${SSHKEYGEN} -qt $k -f $OBJ/agent-key.$k -N '' || fatal "ssh-keygen $k"
  14. (
  15. printf 'localhost-with-alias,127.0.0.1,::1 '
  16. cat $OBJ/agent-key.$k.pub
  17. ) >> $OBJ/known_hosts.orig
  18. ${SSHADD} $OBJ/agent-key.$k > /dev/null 2>&1 ||
  19. fatal "couldn't load key $OBJ/agent-key.$k"
  20. echo "Hostkey $OBJ/agent-key.${k}" >> $OBJ/sshd_proxy.orig
  21. # Remove private key so the server can't use it.
  22. rm $OBJ/agent-key.$k || fatal "couldn't rm $OBJ/agent-key.$k"
  23. done
  24. cp $OBJ/known_hosts.orig $OBJ/known_hosts
  25. unset SSH_AUTH_SOCK
  26. for ps in yes; do
  27. for k in $SSH_KEYTYPES; do
  28. verbose "key type $k privsep=$ps"
  29. cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy
  30. echo "UsePrivilegeSeparation $ps" >> $OBJ/sshd_proxy
  31. echo "HostKeyAlgorithms $k" >> $OBJ/sshd_proxy
  32. opts="-oHostKeyAlgorithms=$k -F $OBJ/ssh_proxy"
  33. cp $OBJ/known_hosts.orig $OBJ/known_hosts
  34. SSH_CONNECTION=$(${SSH} $opts host 'echo $SSH_CONNECTION')
  35. if [ $? -ne 0 ]; then
  36. fail "privsep=$ps failed"
  37. fi
  38. if [ "$SSH_CONNECTION" != "UNKNOWN 65535 UNKNOWN 65535" ]; then
  39. fail "bad SSH_CONNECTION key type $k privsep=$ps"
  40. fi
  41. done
  42. done
  43. trace "kill agent"
  44. ${SSHAGENT} -k > /dev/null