2014-02-28 00:25:16 +01:00
|
|
|
# $OpenBSD: agent.sh,v 1.10 2014/02/27 21:21:25 djm Exp $
|
2002-05-01 05:17:33 +02:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
tid="simple agent test"
|
|
|
|
|
2008-03-12 13:58:55 +01:00
|
|
|
SSH_AUTH_SOCK=/nonexistent ${SSHADD} -l > /dev/null 2>&1
|
2002-05-01 05:17:33 +02:00
|
|
|
if [ $? -ne 2 ]; then
|
|
|
|
fail "ssh-add -l did not fail with exit code 2"
|
|
|
|
fi
|
|
|
|
|
|
|
|
trace "start agent"
|
|
|
|
eval `${SSHAGENT} -s` > /dev/null
|
|
|
|
r=$?
|
|
|
|
if [ $r -ne 0 ]; then
|
|
|
|
fail "could not start ssh-agent: exit code $r"
|
|
|
|
else
|
|
|
|
${SSHADD} -l > /dev/null 2>&1
|
|
|
|
if [ $? -ne 1 ]; then
|
|
|
|
fail "ssh-add -l did not fail with exit code 1"
|
|
|
|
fi
|
|
|
|
trace "overwrite authorized keys"
|
2013-05-17 05:28:36 +02:00
|
|
|
printf '' > $OBJ/authorized_keys_$USER
|
2013-12-07 06:32:44 +01:00
|
|
|
for t in ed25519 rsa rsa1; do
|
2002-05-01 05:17:33 +02:00
|
|
|
# generate user key for agent
|
|
|
|
rm -f $OBJ/$t-agent
|
|
|
|
${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t-agent ||\
|
|
|
|
fail "ssh-keygen for $t-agent failed"
|
|
|
|
# add to authorized keys
|
|
|
|
cat $OBJ/$t-agent.pub >> $OBJ/authorized_keys_$USER
|
|
|
|
# add privat key to agent
|
|
|
|
${SSHADD} $OBJ/$t-agent > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
fail "ssh-add did succeed exit code 0"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
${SSHADD} -l > /dev/null 2>&1
|
2014-01-28 19:26:25 +01:00
|
|
|
r=$?
|
|
|
|
if [ $r -ne 0 ]; then
|
|
|
|
fail "ssh-add -l failed: exit code $r"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
# the same for full pubkey output
|
|
|
|
${SSHADD} -L > /dev/null 2>&1
|
2014-01-28 19:26:25 +01:00
|
|
|
r=$?
|
|
|
|
if [ $r -ne 0 ]; then
|
|
|
|
fail "ssh-add -L failed: exit code $r"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
trace "simple connect via agent"
|
|
|
|
for p in 1 2; do
|
|
|
|
${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p
|
2014-01-28 19:26:25 +01:00
|
|
|
r=$?
|
|
|
|
if [ $r -ne 5$p ]; then
|
|
|
|
fail "ssh connect with protocol $p failed (exit code $r)"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
trace "agent forwarding"
|
|
|
|
for p in 1 2; do
|
|
|
|
${SSH} -A -$p -F $OBJ/ssh_proxy somehost ${SSHADD} -l > /dev/null 2>&1
|
2014-01-28 19:26:25 +01:00
|
|
|
r=$?
|
|
|
|
if [ $r -ne 0 ]; then
|
|
|
|
fail "ssh-add -l via agent fwd proto $p failed (exit code $r)"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
${SSH} -A -$p -F $OBJ/ssh_proxy somehost \
|
|
|
|
"${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p"
|
2014-01-28 19:26:25 +01:00
|
|
|
r=$?
|
|
|
|
if [ $r -ne 5$p ]; then
|
|
|
|
fail "agent fwd proto $p failed (exit code $r)"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
trace "delete all agent keys"
|
|
|
|
${SSHADD} -D > /dev/null 2>&1
|
2014-01-28 19:26:25 +01:00
|
|
|
r=$?
|
|
|
|
if [ $r -ne 0 ]; then
|
|
|
|
fail "ssh-add -D failed: exit code $r"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
trace "kill agent"
|
|
|
|
${SSHAGENT} -k > /dev/null
|
|
|
|
fi
|