blob: 982eced21734de676f82171094ffe469a0b618fe [file] [log] [blame]
Darren Tucker34035be2013-05-17 14:47:51 +10001# $OpenBSD: integrity.sh,v 1.10 2013/05/17 01:32:11 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
Damien Miller1fb593a2012-12-12 10:54:37 +110011macs="hmac-sha1 hmac-md5 umac-64@openssh.com umac-128@openssh.com
Damien Millerdae85cc2013-02-19 14:27:44 +110012 hmac-sha1-96 hmac-md5-96
Damien Miller1fb593a2012-12-12 10:54:37 +110013 hmac-sha1-etm@openssh.com hmac-md5-etm@openssh.com
14 umac-64-etm@openssh.com umac-128-etm@openssh.com
Damien Millerdae85cc2013-02-19 14:27:44 +110015 hmac-sha1-96-etm@openssh.com hmac-md5-96-etm@openssh.com"
16config_defined HAVE_EVP_SHA256 &&
17 macs="$macs hmac-sha2-256 hmac-sha2-512
18 hmac-sha2-256-etm@openssh.com hmac-sha2-512-etm@openssh.com"
Damien Miller846dc7f2013-01-12 22:46:26 +110019# The following are not MACs, but ciphers with integrated integrity. They are
20# handled specially below.
Damien Millerb26699b2013-01-17 14:31:57 +110021config_defined OPENSSL_HAVE_EVPGCM && \
Damien Miller846dc7f2013-01-12 22:46:26 +110022 macs="$macs aes128-gcm@openssh.com aes256-gcm@openssh.com"
Damien Miller1fb593a2012-12-12 10:54:37 +110023
Darren Tucker91af05c2013-05-17 13:16:59 +100024# avoid DH group exchange as the extra traffic makes it harder to get the
25# offset into the stream right.
26echo "KexAlgorithms diffie-hellman-group14-sha1,diffie-hellman-group1-sha1" \
27 >> $OBJ/ssh_proxy
28
Damien Miller1fb593a2012-12-12 10:54:37 +110029# sshd-command for proxy (see test-exec.sh)
Darren Tucker75129022013-05-17 09:19:10 +100030cmd="$SUDO sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -i -f $OBJ/sshd_proxy"
Damien Miller1fb593a2012-12-12 10:54:37 +110031
Damien Miller9fec2962012-12-12 12:10:10 +110032jot() {
Tim Riceada7e172013-02-26 21:49:09 -080033 awk "BEGIN { for (i = $2; i < $2 + $1; i++) { printf \"%d\n\", i } exit }"
Damien Miller9fec2962012-12-12 12:10:10 +110034}
Damien Miller37461d72012-12-12 12:37:32 +110035
Damien Miller1fb593a2012-12-12 10:54:37 +110036for m in $macs; do
37 trace "test $tid: mac $m"
38 elen=0
39 epad=0
40 emac=0
41 ecnt=0
42 skip=0
Tim Ricef9e20602013-02-26 20:27:29 -080043 for off in `jot $tries $startoffset`; do
44 skip=`expr $skip - 1`
Damien Miller9fec2962012-12-12 12:10:10 +110045 if [ $skip -gt 0 ]; then
Damien Miller1fb593a2012-12-12 10:54:37 +110046 # avoid modifying the high bytes of the length
47 continue
48 fi
49 # modify output from sshd at offset $off
Damien Miller1e657d52013-02-26 18:58:06 +110050 pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
Damien Miller846dc7f2013-01-12 22:46:26 +110051 case $m in
52 aes*gcm*) macopt="-c $m";;
53 *) macopt="-m $m";;
54 esac
Darren Tucker34035be2013-05-17 14:47:51 +100055 verbose "test $tid: $m @$off"
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100056 ${SSH} $macopt -2F $OBJ/ssh_proxy -o "$pxy" \
57 999.999.999.999 'printf "%4096s" " "' >/dev/null
Damien Miller1fb593a2012-12-12 10:54:37 +110058 if [ $? -eq 0 ]; then
59 fail "ssh -m $m succeeds with bit-flip at $off"
60 fi
Tim Ricef9e20602013-02-26 20:27:29 -080061 ecnt=`expr $ecnt + 1`
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100062 output=$(tail -2 $TEST_SSH_LOGFILE | egrep -v "^debug" | \
63 tr -s '\r\n' '.')
Damien Miller1fb593a2012-12-12 10:54:37 +110064 case "$output" in
Tim Ricef9e20602013-02-26 20:27:29 -080065 Bad?packet*) elen=`expr $elen + 1`; skip=3;;
Damien Miller846dc7f2013-01-12 22:46:26 +110066 Corrupted?MAC* | Decryption?integrity?check?failed*)
Tim Ricef9e20602013-02-26 20:27:29 -080067 emac=`expr $emac + 1`; skip=0;;
68 padding*) epad=`expr $epad + 1`; skip=0;;
Damien Miller1fb593a2012-12-12 10:54:37 +110069 *) fail "unexpected error mac $m at $off";;
70 esac
71 done
72 verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen"
73 if [ $emac -eq 0 ]; then
74 fail "$m: no mac errors"
75 fi
Tim Ricef9e20602013-02-26 20:27:29 -080076 expect=`expr $ecnt - $epad - $elen`
Damien Miller1fb593a2012-12-12 10:54:37 +110077 if [ $emac -ne $expect ]; then
78 fail "$m: expected $expect mac errors, got $emac"
79 fi
80done