xref: /freebsd/crypto/openssh/regress/agent.sh (revision db5fd092dbb7b749118a95752fb8393939329cd6)
1#	$OpenBSD: agent.sh,v 1.6 2002/03/15 13:08:56 markus Exp $
2#	Placed in the Public Domain.
3
4tid="simple agent test"
5
6SSH_AUTH_SOCK=/nonexistant ${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	echo -n > $OBJ/authorized_keys_$USER
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
75fi
76