djm@openbsd.org | dd36932 | 2017-04-30 23:34:55 +0000 | [diff] [blame] | 1 | # $OpenBSD: agent.sh,v 1.12 2017/04/30 23:34:55 djm 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" |
djm@openbsd.org | dd36932 | 2017-04-30 23:34:55 +0000 | [diff] [blame] | 49 | ${SSH} -F $OBJ/ssh_proxy somehost exit 52 |
| 50 | r=$? |
| 51 | if [ $r -ne 52 ]; then |
| 52 | fail "ssh connect with failed (exit code $r)" |
| 53 | fi |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 54 | |
| 55 | trace "agent forwarding" |
djm@openbsd.org | dd36932 | 2017-04-30 23:34:55 +0000 | [diff] [blame] | 56 | ${SSH} -A -F $OBJ/ssh_proxy somehost ${SSHADD} -l > /dev/null 2>&1 |
| 57 | r=$? |
| 58 | if [ $r -ne 0 ]; then |
| 59 | fail "ssh-add -l via agent fwd failed (exit code $r)" |
| 60 | fi |
| 61 | ${SSH} -A -F $OBJ/ssh_proxy somehost \ |
| 62 | "${SSH} -F $OBJ/ssh_proxy somehost exit 52" |
| 63 | r=$? |
| 64 | if [ $r -ne 52 ]; then |
| 65 | fail "agent fwd failed (exit code $r)" |
| 66 | fi |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 67 | |
| 68 | trace "delete all agent keys" |
| 69 | ${SSHADD} -D > /dev/null 2>&1 |
Tim Rice | 6f917ad | 2014-01-28 10:26:25 -0800 | [diff] [blame] | 70 | r=$? |
| 71 | if [ $r -ne 0 ]; then |
| 72 | fail "ssh-add -D failed: exit code $r" |
Damien Miller | 38cd435 | 2002-05-01 13:17:33 +1000 | [diff] [blame] | 73 | fi |
| 74 | |
| 75 | trace "kill agent" |
| 76 | ${SSHAGENT} -k > /dev/null |
| 77 | fi |