markus@openbsd.org | dad2b18 | 2015-03-03 22:35:19 +0000 | [diff] [blame] | 1 | # $OpenBSD: agent.sh,v 1.11 2015/03/03 22:35:19 markus 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 | 56347ef | 2013-05-17 13:28:36 +1000 | [diff] [blame] | 22 | printf '' > $OBJ/authorized_keys_$USER |
markus@openbsd.org | dad2b18 | 2015-03-03 22:35:19 +0000 | [diff] [blame] | 23 | for t in ${SSH_KEYTYPES}; do |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 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 |
Tim Rice | 6f917ad | 2014-01-28 10:26:25 -0800 | [diff] [blame] | 37 | r=$? |
| 38 | if [ $r -ne 0 ]; then |
| 39 | fail "ssh-add -l failed: exit code $r" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 40 | fi |
| 41 | # the same for full pubkey output |
| 42 | ${SSHADD} -L > /dev/null 2>&1 |
Tim Rice | 6f917ad | 2014-01-28 10:26:25 -0800 | [diff] [blame] | 43 | r=$? |
| 44 | if [ $r -ne 0 ]; then |
| 45 | fail "ssh-add -L failed: exit code $r" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 46 | fi |
| 47 | |
| 48 | trace "simple connect via agent" |
markus@openbsd.org | dad2b18 | 2015-03-03 22:35:19 +0000 | [diff] [blame] | 49 | for p in ${SSH_PROTOCOLS}; do |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 50 | ${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p |
Tim Rice | 6f917ad | 2014-01-28 10:26:25 -0800 | [diff] [blame] | 51 | r=$? |
| 52 | if [ $r -ne 5$p ]; then |
| 53 | fail "ssh connect with protocol $p failed (exit code $r)" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 54 | fi |
| 55 | done |
| 56 | |
| 57 | trace "agent forwarding" |
markus@openbsd.org | dad2b18 | 2015-03-03 22:35:19 +0000 | [diff] [blame] | 58 | for p in ${SSH_PROTOCOLS}; do |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 59 | ${SSH} -A -$p -F $OBJ/ssh_proxy somehost ${SSHADD} -l > /dev/null 2>&1 |
Tim Rice | 6f917ad | 2014-01-28 10:26:25 -0800 | [diff] [blame] | 60 | r=$? |
| 61 | if [ $r -ne 0 ]; then |
| 62 | fail "ssh-add -l via agent fwd proto $p failed (exit code $r)" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 63 | fi |
| 64 | ${SSH} -A -$p -F $OBJ/ssh_proxy somehost \ |
| 65 | "${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p" |
Tim Rice | 6f917ad | 2014-01-28 10:26:25 -0800 | [diff] [blame] | 66 | r=$? |
| 67 | if [ $r -ne 5$p ]; then |
| 68 | fail "agent fwd proto $p failed (exit code $r)" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 69 | fi |
| 70 | done |
| 71 | |
| 72 | trace "delete all agent keys" |
| 73 | ${SSHADD} -D > /dev/null 2>&1 |
Tim Rice | 6f917ad | 2014-01-28 10:26:25 -0800 | [diff] [blame] | 74 | r=$? |
| 75 | if [ $r -ne 0 ]; then |
| 76 | fail "ssh-add -D failed: exit code $r" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 77 | fi |
| 78 | |
| 79 | trace "kill agent" |
| 80 | ${SSHAGENT} -k > /dev/null |
| 81 | fi |