xref: /freebsd/crypto/openssh/regress/ssh-com-client.sh (revision 71fe318b852b8dfb3e799cb12ef184750f7f8eac)
1#	$OpenBSD: ssh-com-client.sh,v 1.3 2002/04/10 08:45:30 markus Exp $
2#	Placed in the Public Domain.
3
4tid="connect with ssh.com client"
5
6#TEST_COMBASE=/path/to/ssh/com/binaries
7if [ "X${TEST_COMBASE}" = "X" ]; then
8	fatal '$TEST_COMBASE is not set'
9fi
10
11VERSIONS="
12	2.1.0
13	2.2.0
14	2.3.0
15	2.3.1
16	2.4.0
17	3.0.0
18	3.1.0"
19
20# 2.0.10 2.0.12 2.0.13 don't like the test setup
21
22# setup authorized keys
23SRC=`dirname ${SCRIPT}`
24cp ${SRC}/dsa_ssh2.prv ${OBJ}/id.com
25chmod 600 ${OBJ}/id.com
26${SSHKEYGEN} -i -f ${OBJ}/id.com	> $OBJ/id.openssh
27chmod 600 ${OBJ}/id.openssh
28${SSHKEYGEN} -y -f ${OBJ}/id.openssh	> $OBJ/authorized_keys_$USER
29${SSHKEYGEN} -e -f ${OBJ}/id.openssh	> $OBJ/id.com.pub
30echo IdKey ${OBJ}/id.com > ${OBJ}/id.list
31
32# we need a DSA host key
33t=dsa
34rm -f                             ${OBJ}/$t ${OBJ}/$t.pub
35${SSHKEYGEN} -q -N '' -t $t -f	  ${OBJ}/$t
36$SUDO cp $OBJ/$t $OBJ/host.$t
37echo HostKey $OBJ/host.$t >> $OBJ/sshd_config
38
39# add hostkeys to known hosts
40mkdir -p ${OBJ}/${USER}/hostkeys
41HK=${OBJ}/${USER}/hostkeys/key_${PORT}_127.0.0.1
42${SSHKEYGEN} -e -f ${OBJ}/rsa.pub > ${HK}.ssh-rsa.pub
43${SSHKEYGEN} -e -f ${OBJ}/dsa.pub > ${HK}.ssh-dss.pub
44
45cat > ${OBJ}/ssh2_config << EOF
46*:
47	QuietMode			yes
48	StrictHostKeyChecking		yes
49	Port				${PORT}
50	User				${USER}
51	Host				127.0.0.1
52	IdentityFile			${OBJ}/id.list
53	RandomSeedFile			${OBJ}/random_seed
54        UserConfigDirectory             ${OBJ}/%U
55	AuthenticationSuccessMsg	no
56	BatchMode			yes
57	ForwardX11			no
58EOF
59
60# we need a real server (no ProxyConnect option)
61start_sshd
62
63DATA=/bin/ls
64COPY=${OBJ}/copy
65rm -f ${COPY}
66
67# go for it
68for v in ${VERSIONS}; do
69	ssh2=${TEST_COMBASE}/${v}/ssh2
70	if [ ! -x ${ssh2} ]; then
71		continue
72	fi
73	verbose "ssh2 ${v}"
74	key=ssh-dss
75	skipcat=0
76        case $v in
77        2.1.*|2.3.0)
78                skipcat=1
79                ;;
80        3.0.*)
81                key=ssh-rsa
82                ;;
83        esac
84	cp ${HK}.$key.pub ${HK}.pub
85
86	# check exit status
87	${ssh2} -q -F ${OBJ}/ssh2_config somehost exit 42
88	r=$?
89        if [ $r -ne 42 ]; then
90                fail "ssh2 ${v} exit code test failed (got $r, expected 42)"
91        fi
92
93	# data transfer
94	rm -f ${COPY}
95	${ssh2} -F ${OBJ}/ssh2_config somehost cat ${DATA} > ${COPY}
96        if [ $? -ne 0 ]; then
97                fail "ssh2 ${v} cat test (receive) failed"
98        fi
99	cmp ${DATA} ${COPY}	|| fail "ssh2 ${v} cat test (receive) data mismatch"
100
101	# data transfer, again
102	if [ $skipcat -eq 0 ]; then
103		rm -f ${COPY}
104		cat ${DATA} | \
105			${ssh2} -F ${OBJ}/ssh2_config host "cat > ${COPY}"
106		if [ $? -ne 0 ]; then
107			fail "ssh2 ${v} cat test (send) failed"
108		fi
109		cmp ${DATA} ${COPY}	|| \
110			fail "ssh2 ${v} cat test (send) data mismatch"
111	fi
112
113	# no stderr after eof
114	rm -f ${COPY}
115	${ssh2} -F ${OBJ}/ssh2_config somehost \
116		exec sh -c \'"exec > /dev/null; sleep 1; echo bla 1>&2; exit 0"\' \
117		2> /dev/null
118        if [ $? -ne 0 ]; then
119                fail "ssh2 ${v} stderr test failed"
120        fi
121done
122
123rm -rf ${OBJ}/${USER}
124for i in ssh2_config random_seed dsa.pub dsa host.dsa \
125    id.list id.com id.com.pub id.openssh; do
126	rm -f ${OBJ}/$i
127done
128