blob: bfadc6b488c4d95807d4579f56727c8e0078935f [file] [log] [blame]
dtucker@openbsd.org331b8e02016-03-04 02:48:06 +00001# $OpenBSD: integrity.sh,v 1.18 2016/03/04 02:48:06 dtucker Exp $
Damien Miller1fb593a2012-12-12 10:54:37 +11002# Placed in the Public Domain.
3
4tid="integrity"
Damien Milleredb1af52014-05-15 15:07:53 +10005cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
Damien Miller1fb593a2012-12-12 10:54:37 +11006
Damien Miller0dc3bc92013-02-19 09:28:32 +11007# start at byte 2900 (i.e. after kex) and corrupt at different offsets
Damien Miller1fb593a2012-12-12 10:54:37 +11008# XXX the test hangs if we modify the low bytes of the packet length
9# XXX and ssh tries to read...
10tries=10
Damien Miller0dc3bc92013-02-19 09:28:32 +110011startoffset=2900
Darren Tuckera9550412013-11-07 15:21:19 +110012macs=`${SSH} -Q mac`
Damien Miller846dc7f2013-01-12 22:46:26 +110013# The following are not MACs, but ciphers with integrated integrity. They are
14# handled specially below.
Damien Miller8a073cf2013-11-21 14:26:18 +110015macs="$macs `${SSH} -Q cipher-auth`"
Damien Miller1fb593a2012-12-12 10:54:37 +110016
Darren Tucker91af05c2013-05-17 13:16:59 +100017# avoid DH group exchange as the extra traffic makes it harder to get the
18# offset into the stream right.
19echo "KexAlgorithms diffie-hellman-group14-sha1,diffie-hellman-group1-sha1" \
20 >> $OBJ/ssh_proxy
21
Damien Miller1fb593a2012-12-12 10:54:37 +110022# sshd-command for proxy (see test-exec.sh)
Damien Millerbd588532015-02-25 16:58:22 -080023cmd="$SUDO sh ${SRC}/sshd-log-wrapper.sh ${TEST_SSHD_LOGFILE} ${SSHD} -i -f $OBJ/sshd_proxy"
Damien Miller1fb593a2012-12-12 10:54:37 +110024
25for m in $macs; do
26 trace "test $tid: mac $m"
27 elen=0
28 epad=0
29 emac=0
30 ecnt=0
31 skip=0
Tim Ricef9e20602013-02-26 20:27:29 -080032 for off in `jot $tries $startoffset`; do
33 skip=`expr $skip - 1`
Damien Miller9fec2962012-12-12 12:10:10 +110034 if [ $skip -gt 0 ]; then
Damien Miller1fb593a2012-12-12 10:54:37 +110035 # avoid modifying the high bytes of the length
36 continue
37 fi
Damien Milleredb1af52014-05-15 15:07:53 +100038 cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
Damien Miller1fb593a2012-12-12 10:54:37 +110039 # modify output from sshd at offset $off
Damien Miller1e657d52013-02-26 18:58:06 +110040 pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
markus@openbsd.org9e1777a2015-03-24 20:19:15 +000041 if ${SSH} -Q cipher-auth | grep "^${m}\$" >/dev/null 2>&1 ; then
Damien Milleredb1af52014-05-15 15:07:53 +100042 echo "Ciphers=$m" >> $OBJ/sshd_proxy
Damien Miller8a073cf2013-11-21 14:26:18 +110043 macopt="-c $m"
44 else
Damien Milleredb1af52014-05-15 15:07:53 +100045 echo "Ciphers=aes128-ctr" >> $OBJ/sshd_proxy
46 echo "MACs=$m" >> $OBJ/sshd_proxy
Damien Miller8a073cf2013-11-21 14:26:18 +110047 macopt="-m $m -c aes128-ctr"
48 fi
Darren Tucker34035be2013-05-17 14:47:51 +100049 verbose "test $tid: $m @$off"
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100050 ${SSH} $macopt -2F $OBJ/ssh_proxy -o "$pxy" \
Damien Miller8a073cf2013-11-21 14:26:18 +110051 -oServerAliveInterval=1 -oServerAliveCountMax=30 \
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100052 999.999.999.999 'printf "%4096s" " "' >/dev/null
Damien Miller1fb593a2012-12-12 10:54:37 +110053 if [ $? -eq 0 ]; then
54 fail "ssh -m $m succeeds with bit-flip at $off"
55 fi
Tim Ricef9e20602013-02-26 20:27:29 -080056 ecnt=`expr $ecnt + 1`
dtucker@openbsd.org331b8e02016-03-04 02:48:06 +000057 out=$(egrep -v "^debug" $TEST_SSH_LOGFILE | tail -2 | \
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100058 tr -s '\r\n' '.')
Damien Miller43d3ed22014-07-02 17:01:08 +100059 case "$out" in
Tim Ricef9e20602013-02-26 20:27:29 -080060 Bad?packet*) elen=`expr $elen + 1`; skip=3;;
markus@openbsd.org31821d72015-01-19 20:42:31 +000061 Corrupted?MAC* | *message?authentication?code?incorrect*)
Tim Ricef9e20602013-02-26 20:27:29 -080062 emac=`expr $emac + 1`; skip=0;;
63 padding*) epad=`expr $epad + 1`; skip=0;;
Damien Miller43d3ed22014-07-02 17:01:08 +100064 *) fail "unexpected error mac $m at $off: $out";;
Damien Miller1fb593a2012-12-12 10:54:37 +110065 esac
66 done
67 verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen"
68 if [ $emac -eq 0 ]; then
69 fail "$m: no mac errors"
70 fi
Tim Ricef9e20602013-02-26 20:27:29 -080071 expect=`expr $ecnt - $epad - $elen`
Damien Miller1fb593a2012-12-12 10:54:37 +110072 if [ $emac -ne $expect ]; then
73 fail "$m: expected $expect mac errors, got $emac"
74 fi
75done