blob: de2b8d05a873cf01f7e1a108fa3db2b78cf05c89 [file] [log] [blame]
Darren Tuckera9550412013-11-07 15:21:19 +11001# $OpenBSD: integrity.sh,v 1.11 2013/11/07 02:48:38 dtucker Exp $
Damien Miller1fb593a2012-12-12 10:54:37 +11002# Placed in the Public Domain.
3
4tid="integrity"
5
Damien Miller0dc3bc92013-02-19 09:28:32 +11006# start at byte 2900 (i.e. after kex) and corrupt at different offsets
Damien Miller1fb593a2012-12-12 10:54:37 +11007# XXX the test hangs if we modify the low bytes of the packet length
8# XXX and ssh tries to read...
9tries=10
Damien Miller0dc3bc92013-02-19 09:28:32 +110010startoffset=2900
Darren Tuckera9550412013-11-07 15:21:19 +110011macs=`${SSH} -Q mac`
Damien Miller846dc7f2013-01-12 22:46:26 +110012# The following are not MACs, but ciphers with integrated integrity. They are
13# handled specially below.
Darren Tuckera9550412013-11-07 15:21:19 +110014macs="$macs `${SSH} -Q cipher | grep gcm@openssh.com`"
Damien Miller1fb593a2012-12-12 10:54:37 +110015
Darren Tucker91af05c2013-05-17 13:16:59 +100016# avoid DH group exchange as the extra traffic makes it harder to get the
17# offset into the stream right.
18echo "KexAlgorithms diffie-hellman-group14-sha1,diffie-hellman-group1-sha1" \
19 >> $OBJ/ssh_proxy
20
Damien Miller1fb593a2012-12-12 10:54:37 +110021# sshd-command for proxy (see test-exec.sh)
Darren Tucker75129022013-05-17 09:19:10 +100022cmd="$SUDO sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -i -f $OBJ/sshd_proxy"
Damien Miller1fb593a2012-12-12 10:54:37 +110023
24for m in $macs; do
25 trace "test $tid: mac $m"
26 elen=0
27 epad=0
28 emac=0
29 ecnt=0
30 skip=0
Tim Ricef9e20602013-02-26 20:27:29 -080031 for off in `jot $tries $startoffset`; do
32 skip=`expr $skip - 1`
Damien Miller9fec2962012-12-12 12:10:10 +110033 if [ $skip -gt 0 ]; then
Damien Miller1fb593a2012-12-12 10:54:37 +110034 # avoid modifying the high bytes of the length
35 continue
36 fi
37 # modify output from sshd at offset $off
Damien Miller1e657d52013-02-26 18:58:06 +110038 pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
Damien Miller846dc7f2013-01-12 22:46:26 +110039 case $m in
40 aes*gcm*) macopt="-c $m";;
41 *) macopt="-m $m";;
42 esac
Darren Tucker34035be2013-05-17 14:47:51 +100043 verbose "test $tid: $m @$off"
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100044 ${SSH} $macopt -2F $OBJ/ssh_proxy -o "$pxy" \
45 999.999.999.999 'printf "%4096s" " "' >/dev/null
Damien Miller1fb593a2012-12-12 10:54:37 +110046 if [ $? -eq 0 ]; then
47 fail "ssh -m $m succeeds with bit-flip at $off"
48 fi
Tim Ricef9e20602013-02-26 20:27:29 -080049 ecnt=`expr $ecnt + 1`
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100050 output=$(tail -2 $TEST_SSH_LOGFILE | egrep -v "^debug" | \
51 tr -s '\r\n' '.')
Damien Miller1fb593a2012-12-12 10:54:37 +110052 case "$output" in
Tim Ricef9e20602013-02-26 20:27:29 -080053 Bad?packet*) elen=`expr $elen + 1`; skip=3;;
Damien Miller846dc7f2013-01-12 22:46:26 +110054 Corrupted?MAC* | Decryption?integrity?check?failed*)
Tim Ricef9e20602013-02-26 20:27:29 -080055 emac=`expr $emac + 1`; skip=0;;
56 padding*) epad=`expr $epad + 1`; skip=0;;
Damien Miller1fb593a2012-12-12 10:54:37 +110057 *) fail "unexpected error mac $m at $off";;
58 esac
59 done
60 verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen"
61 if [ $emac -eq 0 ]; then
62 fail "$m: no mac errors"
63 fi
Tim Ricef9e20602013-02-26 20:27:29 -080064 expect=`expr $ecnt - $epad - $elen`
Damien Miller1fb593a2012-12-12 10:54:37 +110065 if [ $emac -ne $expect ]; then
66 fail "$m: expected $expect mac errors, got $emac"
67 fi
68done