blob: 03d80618cc5ad65f5585b968d940027fce346aad [file] [log] [blame]
Damien Milleredb1af52014-05-15 15:07:53 +10001# $OpenBSD: integrity.sh,v 1.13 2014/04/21 22:15:37 djm 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)
Darren Tucker75129022013-05-17 09:19:10 +100023cmd="$SUDO sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -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"
Damien Miller8a073cf2013-11-21 14:26:18 +110041 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`
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100057 output=$(tail -2 $TEST_SSH_LOGFILE | egrep -v "^debug" | \
58 tr -s '\r\n' '.')
Damien Miller1fb593a2012-12-12 10:54:37 +110059 case "$output" in
Tim Ricef9e20602013-02-26 20:27:29 -080060 Bad?packet*) elen=`expr $elen + 1`; skip=3;;
Damien Miller846dc7f2013-01-12 22:46:26 +110061 Corrupted?MAC* | Decryption?integrity?check?failed*)
Tim Ricef9e20602013-02-26 20:27:29 -080062 emac=`expr $emac + 1`; skip=0;;
63 padding*) epad=`expr $epad + 1`; skip=0;;
Damien Miller1fb593a2012-12-12 10:54:37 +110064 *) fail "unexpected error mac $m at $off";;
65 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