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