Damien Miller | d666d8e | 2008-03-12 23:58:55 +1100 | [diff] [blame] | 1 | # $OpenBSD: agent.sh,v 1.7 2007/11/25 15:35:09 jmc Exp $ |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="simple agent test" |
| 5 | |
Damien Miller | d666d8e | 2008-03-12 23:58:55 +1100 | [diff] [blame] | 6 | SSH_AUTH_SOCK=/nonexistent ${SSHADD} -l > /dev/null 2>&1 |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 7 | if [ $? -ne 2 ]; then |
| 8 | fail "ssh-add -l did not fail with exit code 2" |
| 9 | fi |
| 10 | |
| 11 | trace "start agent" |
| 12 | eval `${SSHAGENT} -s` > /dev/null |
| 13 | r=$? |
| 14 | if [ $r -ne 0 ]; then |
| 15 | fail "could not start ssh-agent: exit code $r" |
| 16 | else |
| 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 Tucker | 53c55f4 | 2003-09-04 15:16:56 +1000 | [diff] [blame] | 22 | echon > $OBJ/authorized_keys_$USER |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 23 | for t in rsa rsa1; do |
| 24 | # 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 |
| 37 | if [ $? -ne 0 ]; then |
| 38 | fail "ssh-add -l failed: exit code $?" |
| 39 | fi |
| 40 | # the same for full pubkey output |
| 41 | ${SSHADD} -L > /dev/null 2>&1 |
| 42 | if [ $? -ne 0 ]; then |
| 43 | fail "ssh-add -L failed: exit code $?" |
| 44 | fi |
| 45 | |
| 46 | trace "simple connect via agent" |
| 47 | for p in 1 2; do |
| 48 | ${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p |
| 49 | if [ $? -ne 5$p ]; then |
| 50 | fail "ssh connect with protocol $p failed (exit code $?)" |
| 51 | fi |
| 52 | done |
| 53 | |
| 54 | trace "agent forwarding" |
| 55 | for p in 1 2; do |
| 56 | ${SSH} -A -$p -F $OBJ/ssh_proxy somehost ${SSHADD} -l > /dev/null 2>&1 |
| 57 | if [ $? -ne 0 ]; then |
| 58 | fail "ssh-add -l via agent fwd proto $p failed (exit code $?)" |
| 59 | fi |
| 60 | ${SSH} -A -$p -F $OBJ/ssh_proxy somehost \ |
| 61 | "${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p" |
| 62 | if [ $? -ne 5$p ]; then |
| 63 | fail "agent fwd proto $p failed (exit code $?)" |
| 64 | fi |
| 65 | done |
| 66 | |
| 67 | trace "delete all agent keys" |
| 68 | ${SSHADD} -D > /dev/null 2>&1 |
| 69 | if [ $? -ne 0 ]; then |
| 70 | fail "ssh-add -D failed: exit code $?" |
| 71 | fi |
| 72 | |
| 73 | trace "kill agent" |
| 74 | ${SSHAGENT} -k > /dev/null |
| 75 | fi |