1# $OpenBSD: agent.sh,v 1.10 2014/02/27 21:21:25 djm Exp $ 2# Placed in the Public Domain. 3 4tid="simple agent test" 5 6SSH_AUTH_SOCK=/nonexistent ${SSHADD} -l > /dev/null 2>&1 7if [ $? -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" 22 printf '' > $OBJ/authorized_keys_$USER 23 for t in ed25519 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 r=$? 38 if [ $r -ne 0 ]; then 39 fail "ssh-add -l failed: exit code $r" 40 fi 41 # the same for full pubkey output 42 ${SSHADD} -L > /dev/null 2>&1 43 r=$? 44 if [ $r -ne 0 ]; then 45 fail "ssh-add -L failed: exit code $r" 46 fi 47 48 trace "simple connect via agent" 49 for p in 1 2; do 50 ${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p 51 r=$? 52 if [ $r -ne 5$p ]; then 53 fail "ssh connect with protocol $p failed (exit code $r)" 54 fi 55 done 56 57 trace "agent forwarding" 58 for p in 1 2; do 59 ${SSH} -A -$p -F $OBJ/ssh_proxy somehost ${SSHADD} -l > /dev/null 2>&1 60 r=$? 61 if [ $r -ne 0 ]; then 62 fail "ssh-add -l via agent fwd proto $p failed (exit code $r)" 63 fi 64 ${SSH} -A -$p -F $OBJ/ssh_proxy somehost \ 65 "${SSH} -$p -F $OBJ/ssh_proxy somehost exit 5$p" 66 r=$? 67 if [ $r -ne 5$p ]; then 68 fail "agent fwd proto $p failed (exit code $r)" 69 fi 70 done 71 72 trace "delete all agent keys" 73 ${SSHADD} -D > /dev/null 2>&1 74 r=$? 75 if [ $r -ne 0 ]; then 76 fail "ssh-add -D failed: exit code $r" 77 fi 78 79 trace "kill agent" 80 ${SSHAGENT} -k > /dev/null 81fi 82