summaryrefslogtreecommitdiff
path: root/regress/usr.bin/ssh/agent.sh
blob: 900eaa2c89c90bd1c2cb53d0d7460aa50b621942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
tid="simple agent test"

SSH_AUTH_SOCK=/nonexistant ssh-add -l > /dev/null 2>&1
if [ $? -ne 2 ]; then
	fail "ssh-add -l did not fail with exit code 2"
fi

trace "start agent"
eval `ssh-agent -s` > /dev/null
r=$?
if [ $r -ne 0 ]; then
	fail "could not start ssh-agent: exit code $r"
else
	ssh-add -l > /dev/null 2>&1
	if [ $? -ne 1 ]; then
		fail "ssh-add -l did not fail with exit code 1"
	fi
	trace "overwrite authorized keys"
	echo -n > $OBJ/authorized_keys_$USER
	for t in rsa rsa1; do
		# generate user key for agent
		rm -f $OBJ/$t-agent
		ssh-keygen -q -N '' -t $t -f $OBJ/$t-agent ||\
			 fail "ssh-keygen for $t-agent failed"
		# add to authorized keys
		cat $OBJ/$t-agent.pub >> $OBJ/authorized_keys_$USER
		# add privat key to agent
		ssh-add $OBJ/$t-agent > /dev/null 2>&1
		if [ $? -ne 0 ]; then
			fail "ssh-add did succeed exit code 0"
		fi
	done
	ssh-add -l > /dev/null 2>&1
	if [ $? -ne 0 ]; then
		fail "ssh-add -l failed: exit code $?"
	fi
	# the same for full pubkey output
	ssh-add -L > /dev/null 2>&1
	if [ $? -ne 0 ]; then
		fail "ssh-add -L failed: exit code $?"
	fi

	trace  "simple connect via agent"
	for p in 1 2; do
		ssh -o "Protocol=$p" -F $OBJ/ssh_config somehost exit 5$p
		if [ $? -ne 5$p ]; then
			fail "ssh connect with protocol $p failed (exit code $?)"
		fi
	done

	trace  "delete all agent keys"
	ssh-add -D > /dev/null 2>&1
	if [ $? -ne 0 ]; then
		fail "ssh-add -D failed: exit code $?"
	fi

	trace "kill agent"
	ssh-agent -k > /dev/null
fi