blob: c5e2794b763ccf03b674ef9135dc3578594de06c [file] [log] [blame] [raw]
markus@openbsd.orgdad2b182015-03-03 22:35:19 +00001# $OpenBSD: agent.sh,v 1.11 2015/03/03 22:35:19 markus Exp $
Damien Miller38cd4352002-05-01 13:17:33 +10002# Placed in the Public Domain.
3
4tid="simple agent test"
5
Damien Millerd666d8e2008-03-12 23:58:55 +11006SSH_AUTH_SOCK=/nonexistent ${SSHADD} -l > /dev/null 2>&1
Damien Miller38cd4352002-05-01 13:17:33 +10007if [ $? -ne 2 ]; then
8 fail "ssh-add -l did not fail with exit code 2"
9fi
10
11trace "start agent"
12eval `${SSHAGENT} -s` > /dev/null
13r=$?
14if [ $r -ne 0 ]; then
15 fail "could not start ssh-agent: exit code $r"
16else
17 ${SSHADD} -l > /dev/null 2>&1
18 if [ $? -ne 1 ]; then
19 fail "ssh-add -l did not fail with exit code 1"
20 fi
21 trace "overwrite authorized keys"
Darren Tucker56347ef2013-05-17 13:28:36 +100022 printf '' > $OBJ/authorized_keys_$USER
markus@openbsd.orgdad2b182015-03-03 22:35:19 +000023 for t in ${SSH_KEYTYPES}; do
Damien Miller38cd4352002-05-01 13:17:33 +100024 # generate user key for agent
25 rm -f $OBJ/$t-agent
26 ${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t-agent ||\
27 fail "ssh-keygen for $t-agent failed"
28 # add to authorized keys
29 cat $OBJ/$t-agent.pub >> $OBJ/authorized_keys_$USER
30 # add privat key to agent
31 ${SSHADD} $OBJ/$t-agent > /dev/null 2>&1
32 if [ $? -ne 0 ]; then
33 fail "ssh-add did succeed exit code 0"
34 fi
35 done
36 ${SSHADD} -l > /dev/null 2>&1
Tim Rice6f917ad2014-01-28 10:26:25 -080037 r=$?
38 if [ $r -ne 0 ]; then
39 fail "ssh-add -l failed: exit code $r"
Damien Miller38cd4352002-05-01 13:17:33 +100040 fi
41 # the same for full pubkey output
42 ${SSHADD} -L > /dev/null 2>&1
Tim Rice6f917ad2014-01-28 10:26:25 -080043 r=$?
44 if [ $r -ne 0 ]; then
45 fail "ssh-add -L failed: exit code $r"
Damien Miller38cd4352002-05-01 13:17:33 +100046 fi
47
48 trace "simple connect via agent"
markus@openbsd.orgdad2b182015-03-03 22:35:19 +000049 for p in ${SSH_PROTOCOLS}; do
Damien Miller38cd4352002-05-01 13:17:33 +100050 ${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p
Tim Rice6f917ad2014-01-28 10:26:25 -080051 r=$?
52 if [ $r -ne 5$p ]; then
53 fail "ssh connect with protocol $p failed (exit code $r)"
Damien Miller38cd4352002-05-01 13:17:33 +100054 fi
55 done
56
57 trace "agent forwarding"
markus@openbsd.orgdad2b182015-03-03 22:35:19 +000058 for p in ${SSH_PROTOCOLS}; do
Damien Miller38cd4352002-05-01 13:17:33 +100059 ${SSH} -A -$p -F $OBJ/ssh_proxy somehost ${SSHADD} -l > /dev/null 2>&1
Tim Rice6f917ad2014-01-28 10:26:25 -080060 r=$?
61 if [ $r -ne 0 ]; then
62 fail "ssh-add -l via agent fwd proto $p failed (exit code $r)"
Damien Miller38cd4352002-05-01 13:17:33 +100063 fi
64 ${SSH} -A -$p -F $OBJ/ssh_proxy somehost \
65 "${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p"
Tim Rice6f917ad2014-01-28 10:26:25 -080066 r=$?
67 if [ $r -ne 5$p ]; then
68 fail "agent fwd proto $p failed (exit code $r)"
Damien Miller38cd4352002-05-01 13:17:33 +100069 fi
70 done
71
72 trace "delete all agent keys"
73 ${SSHADD} -D > /dev/null 2>&1
Tim Rice6f917ad2014-01-28 10:26:25 -080074 r=$?
75 if [ $r -ne 0 ]; then
76 fail "ssh-add -D failed: exit code $r"
Damien Miller38cd4352002-05-01 13:17:33 +100077 fi
78
79 trace "kill agent"
80 ${SSHAGENT} -k > /dev/null
81fi