xref: /freebsd/crypto/openssh/regress/dhgex.sh (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1#	$OpenBSD: dhgex.sh,v 1.7 2020/12/21 22:48:41 dtucker Exp $
2#	Placed in the Public Domain.
3
4tid="dhgex"
5
6LOG=${TEST_SSH_LOGFILE}
7rm -f ${LOG}
8cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
9
10kexs=`${SSH} -Q kex | grep diffie-hellman-group-exchange`
11
12ssh_test_dhgex()
13{
14	bits="$1"; shift
15	cipher="$1"; shift
16	kex="$1"; shift
17
18	cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
19	echo "KexAlgorithms=$kex" >> $OBJ/sshd_proxy
20	echo "Ciphers=$cipher" >> $OBJ/sshd_proxy
21	rm -f ${LOG}
22	opts="-oKexAlgorithms=$kex -oCiphers=$cipher"
23	min=2048
24	max=8192
25	groupsz="$min<$bits<$max"
26	verbose "$tid bits $bits $kex $cipher"
27	${SSH} ${opts} $@ -vvv -F ${OBJ}/ssh_proxy somehost true
28	if [ $? -ne 0 ]; then
29		fail "ssh failed ($@)"
30	fi
31	# check what we request
32	grep "SSH2_MSG_KEX_DH_GEX_REQUEST($groupsz) sent" ${LOG} >/dev/null
33	if [ $? != 0 ]; then
34		got=`egrep "SSH2_MSG_KEX_DH_GEX_REQUEST(.*) sent" ${LOG}`
35		fail "$tid unexpected GEX sizes, expected $groupsz, got $got"
36	fi
37	# check what we got.
38	gotbits="`awk 'BEGIN{FS="/"}/bits set:/{print $2}' ${LOG} |
39	    head -1 | tr -d '\r\n'`"
40	trace "expected '$bits' got '$gotbits'"
41	if [ -z "$gotbits" ] || [ "$gotbits" -lt "$bits" ]; then
42		fatal "$tid expected $bits bit group, got $gotbits"
43	fi
44}
45
46check()
47{
48	bits="$1"; shift
49
50	for c in $@; do
51		for k in $kexs; do
52			ssh_test_dhgex $bits $c $k
53		done
54	done
55}
56
57check 3072 3des-cbc  # 112 bits.
58check 3072 `${SSH} -Q cipher | grep 128`
59check 7680 `${SSH} -Q cipher | grep 192`
60check 8192 `${SSH} -Q cipher | grep 256`
61check 8192 chacha20-poly1305@openssh.com
62