2019-12-16 03:39:05 +01:00
|
|
|
# $OpenBSD: hostkey-agent.sh,v 1.11 2019/12/16 02:39:05 djm Exp $
|
2015-01-17 19:54:30 +01:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
tid="hostkey agent"
|
|
|
|
|
2015-01-20 09:02:33 +01:00
|
|
|
rm -f $OBJ/agent-key.* $OBJ/ssh_proxy.orig $OBJ/known_hosts.orig
|
2015-01-17 19:54:30 +01:00
|
|
|
|
|
|
|
trace "start agent"
|
2019-11-27 00:43:10 +01:00
|
|
|
eval `${SSHAGENT} ${EXTRA_AGENT_ARGS} -s` > /dev/null
|
2015-01-17 19:54:30 +01:00
|
|
|
r=$?
|
|
|
|
[ $r -ne 0 ] && fatal "could not start ssh-agent: exit code $r"
|
|
|
|
|
|
|
|
grep -vi 'hostkey' $OBJ/sshd_proxy > $OBJ/sshd_proxy.orig
|
|
|
|
echo "HostKeyAgent $SSH_AUTH_SOCK" >> $OBJ/sshd_proxy.orig
|
|
|
|
|
|
|
|
trace "load hostkeys"
|
2019-12-16 03:39:05 +01:00
|
|
|
for k in $SSH_KEYTYPES ; do
|
2015-01-20 09:02:33 +01:00
|
|
|
${SSHKEYGEN} -qt $k -f $OBJ/agent-key.$k -N '' || fatal "ssh-keygen $k"
|
2015-01-17 19:54:30 +01:00
|
|
|
(
|
2015-01-27 13:01:36 +01:00
|
|
|
printf 'localhost-with-alias,127.0.0.1,::1 '
|
2015-01-20 09:02:33 +01:00
|
|
|
cat $OBJ/agent-key.$k.pub
|
2015-01-19 07:01:32 +01:00
|
|
|
) >> $OBJ/known_hosts.orig
|
2015-01-20 09:02:33 +01:00
|
|
|
${SSHADD} $OBJ/agent-key.$k >/dev/null 2>&1 || \
|
|
|
|
fatal "couldn't load key $OBJ/agent-key.$k"
|
2015-02-21 21:51:02 +01:00
|
|
|
echo "Hostkey $OBJ/agent-key.${k}" >> $OBJ/sshd_proxy.orig
|
2015-01-17 19:54:30 +01:00
|
|
|
# Remove private key so the server can't use it.
|
2015-01-20 09:02:33 +01:00
|
|
|
rm $OBJ/agent-key.$k || fatal "couldn't rm $OBJ/agent-key.$k"
|
2015-01-17 19:54:30 +01:00
|
|
|
done
|
2015-01-19 07:01:32 +01:00
|
|
|
cp $OBJ/known_hosts.orig $OBJ/known_hosts
|
2015-01-17 19:54:30 +01:00
|
|
|
|
|
|
|
unset SSH_AUTH_SOCK
|
|
|
|
|
2019-12-11 19:47:14 +01:00
|
|
|
for ps in yes; do
|
2019-12-16 03:39:05 +01:00
|
|
|
for k in $SSH_KEYTYPES ; do
|
2015-01-17 19:54:30 +01:00
|
|
|
verbose "key type $k privsep=$ps"
|
2015-07-10 08:23:25 +02:00
|
|
|
cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy
|
|
|
|
echo "UsePrivilegeSeparation $ps" >> $OBJ/sshd_proxy
|
|
|
|
echo "HostKeyAlgorithms $k" >> $OBJ/sshd_proxy
|
2015-01-17 19:54:30 +01:00
|
|
|
opts="-oHostKeyAlgorithms=$k -F $OBJ/ssh_proxy"
|
2015-01-19 07:01:32 +01:00
|
|
|
cp $OBJ/known_hosts.orig $OBJ/known_hosts
|
2015-01-17 19:54:30 +01:00
|
|
|
SSH_CONNECTION=`${SSH} $opts host 'echo $SSH_CONNECTION'`
|
|
|
|
if [ $? -ne 0 ]; then
|
2017-05-01 01:34:55 +02:00
|
|
|
fail "privsep=$ps failed"
|
2015-01-17 19:54:30 +01:00
|
|
|
fi
|
|
|
|
if [ "$SSH_CONNECTION" != "UNKNOWN 65535 UNKNOWN 65535" ]; then
|
|
|
|
fail "bad SSH_CONNECTION key type $k privsep=$ps"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
trace "kill agent"
|
|
|
|
${SSHAGENT} -k > /dev/null
|
|
|
|
|