blob: 811b6b9ab25a56cdd0303cf04f8d37757089d0d5 [file] [log] [blame]
djm@openbsd.orgdd369322017-04-30 23:34:55 +00001# $OpenBSD: hostkey-agent.sh,v 1.7 2017/04/30 23:34:55 djm Exp $
djm@openbsd.org26b34252015-01-17 18:54:30 +00002# Placed in the Public Domain.
3
4tid="hostkey agent"
5
djm@openbsd.org1d6424a2015-01-20 08:02:33 +00006rm -f $OBJ/agent-key.* $OBJ/ssh_proxy.orig $OBJ/known_hosts.orig
djm@openbsd.org26b34252015-01-17 18:54:30 +00007
8trace "start agent"
9eval `${SSHAGENT} -s` > /dev/null
10r=$?
11[ $r -ne 0 ] && fatal "could not start ssh-agent: exit code $r"
12
13grep -vi 'hostkey' $OBJ/sshd_proxy > $OBJ/sshd_proxy.orig
14echo "HostKeyAgent $SSH_AUTH_SOCK" >> $OBJ/sshd_proxy.orig
djm@openbsd.org26b34252015-01-17 18:54:30 +000015
16trace "load hostkeys"
djm@openbsd.orgd85e0622015-01-19 06:01:32 +000017for k in `${SSH} -Q key-plain` ; do
djm@openbsd.org1d6424a2015-01-20 08:02:33 +000018 ${SSHKEYGEN} -qt $k -f $OBJ/agent-key.$k -N '' || fatal "ssh-keygen $k"
djm@openbsd.org26b34252015-01-17 18:54:30 +000019 (
djm@openbsd.orge56aa872015-01-27 12:01:36 +000020 printf 'localhost-with-alias,127.0.0.1,::1 '
djm@openbsd.org1d6424a2015-01-20 08:02:33 +000021 cat $OBJ/agent-key.$k.pub
djm@openbsd.orgd85e0622015-01-19 06:01:32 +000022 ) >> $OBJ/known_hosts.orig
djm@openbsd.org1d6424a2015-01-20 08:02:33 +000023 ${SSHADD} $OBJ/agent-key.$k >/dev/null 2>&1 || \
24 fatal "couldn't load key $OBJ/agent-key.$k"
djm@openbsd.org1a779a02015-02-21 20:51:02 +000025 echo "Hostkey $OBJ/agent-key.${k}" >> $OBJ/sshd_proxy.orig
djm@openbsd.org26b34252015-01-17 18:54:30 +000026 # Remove private key so the server can't use it.
djm@openbsd.org1d6424a2015-01-20 08:02:33 +000027 rm $OBJ/agent-key.$k || fatal "couldn't rm $OBJ/agent-key.$k"
djm@openbsd.org26b34252015-01-17 18:54:30 +000028done
djm@openbsd.orgd85e0622015-01-19 06:01:32 +000029cp $OBJ/known_hosts.orig $OBJ/known_hosts
djm@openbsd.org26b34252015-01-17 18:54:30 +000030
31unset SSH_AUTH_SOCK
32
33for ps in no yes; do
djm@openbsd.orgd85e0622015-01-19 06:01:32 +000034 for k in `${SSH} -Q key-plain` ; do
djm@openbsd.org26b34252015-01-17 18:54:30 +000035 verbose "key type $k privsep=$ps"
markus@openbsd.org5bf09332015-07-10 06:23:25 +000036 cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy
37 echo "UsePrivilegeSeparation $ps" >> $OBJ/sshd_proxy
38 echo "HostKeyAlgorithms $k" >> $OBJ/sshd_proxy
djm@openbsd.org26b34252015-01-17 18:54:30 +000039 opts="-oHostKeyAlgorithms=$k -F $OBJ/ssh_proxy"
djm@openbsd.orgd85e0622015-01-19 06:01:32 +000040 cp $OBJ/known_hosts.orig $OBJ/known_hosts
djm@openbsd.org26b34252015-01-17 18:54:30 +000041 SSH_CONNECTION=`${SSH} $opts host 'echo $SSH_CONNECTION'`
42 if [ $? -ne 0 ]; then
djm@openbsd.orgdd369322017-04-30 23:34:55 +000043 fail "privsep=$ps failed"
djm@openbsd.org26b34252015-01-17 18:54:30 +000044 fi
45 if [ "$SSH_CONNECTION" != "UNKNOWN 65535 UNKNOWN 65535" ]; then
46 fail "bad SSH_CONNECTION key type $k privsep=$ps"
47 fi
48 done
49done
50
51trace "kill agent"
52${SSHAGENT} -k > /dev/null
53