blob: 3eda40f0a3d348559a2d7a5ec1dbce8fdc07248c [file] [log] [blame]
djm@openbsd.orgdd369322017-04-30 23:34:55 +00001# $OpenBSD: integrity.sh,v 1.23 2017/04/30 23:34:55 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 +11008tries=10
Damien Miller0dc3bc92013-02-19 09:28:32 +11009startoffset=2900
Darren Tuckera9550412013-11-07 15:21:19 +110010macs=`${SSH} -Q mac`
Damien Miller846dc7f2013-01-12 22:46:26 +110011# The following are not MACs, but ciphers with integrated integrity. They are
12# handled specially below.
Damien Miller8a073cf2013-11-21 14:26:18 +110013macs="$macs `${SSH} -Q cipher-auth`"
Damien Miller1fb593a2012-12-12 10:54:37 +110014
Darren Tucker91af05c2013-05-17 13:16:59 +100015# avoid DH group exchange as the extra traffic makes it harder to get the
16# offset into the stream right.
17echo "KexAlgorithms diffie-hellman-group14-sha1,diffie-hellman-group1-sha1" \
18 >> $OBJ/ssh_proxy
19
Damien Miller1fb593a2012-12-12 10:54:37 +110020# sshd-command for proxy (see test-exec.sh)
Damien Millerbd588532015-02-25 16:58:22 -080021cmd="$SUDO sh ${SRC}/sshd-log-wrapper.sh ${TEST_SSHD_LOGFILE} ${SSHD} -i -f $OBJ/sshd_proxy"
Damien Miller1fb593a2012-12-12 10:54:37 +110022
23for m in $macs; do
24 trace "test $tid: mac $m"
25 elen=0
26 epad=0
27 emac=0
dtucker@openbsd.orge5c7ec62017-01-06 02:26:10 +000028 etmo=0
Damien Miller1fb593a2012-12-12 10:54:37 +110029 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
Damien Milleredb1af52014-05-15 15:07:53 +100037 cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
Damien Miller1fb593a2012-12-12 10:54:37 +110038 # modify output from sshd at offset $off
Damien Miller1e657d52013-02-26 18:58:06 +110039 pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
markus@openbsd.org9e1777a2015-03-24 20:19:15 +000040 if ${SSH} -Q cipher-auth | grep "^${m}\$" >/dev/null 2>&1 ; then
Damien Milleredb1af52014-05-15 15:07:53 +100041 echo "Ciphers=$m" >> $OBJ/sshd_proxy
Damien Miller8a073cf2013-11-21 14:26:18 +110042 macopt="-c $m"
43 else
Damien Milleredb1af52014-05-15 15:07:53 +100044 echo "Ciphers=aes128-ctr" >> $OBJ/sshd_proxy
45 echo "MACs=$m" >> $OBJ/sshd_proxy
Damien Miller8a073cf2013-11-21 14:26:18 +110046 macopt="-m $m -c aes128-ctr"
47 fi
Darren Tucker34035be2013-05-17 14:47:51 +100048 verbose "test $tid: $m @$off"
djm@openbsd.orgdd369322017-04-30 23:34:55 +000049 ${SSH} $macopt -F $OBJ/ssh_proxy -o "$pxy" \
Damien Miller8a073cf2013-11-21 14:26:18 +110050 -oServerAliveInterval=1 -oServerAliveCountMax=30 \
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100051 999.999.999.999 'printf "%4096s" " "' >/dev/null
Damien Miller1fb593a2012-12-12 10:54:37 +110052 if [ $? -eq 0 ]; then
53 fail "ssh -m $m succeeds with bit-flip at $off"
54 fi
Tim Ricef9e20602013-02-26 20:27:29 -080055 ecnt=`expr $ecnt + 1`
dtucker@openbsd.org331b8e02016-03-04 02:48:06 +000056 out=$(egrep -v "^debug" $TEST_SSH_LOGFILE | tail -2 | \
Darren Tuckerdfea3bc2013-05-17 09:31:39 +100057 tr -s '\r\n' '.')
Damien Miller43d3ed22014-07-02 17:01:08 +100058 case "$out" in
Tim Ricef9e20602013-02-26 20:27:29 -080059 Bad?packet*) elen=`expr $elen + 1`; skip=3;;
markus@openbsd.org31821d72015-01-19 20:42:31 +000060 Corrupted?MAC* | *message?authentication?code?incorrect*)
Tim Ricef9e20602013-02-26 20:27:29 -080061 emac=`expr $emac + 1`; skip=0;;
62 padding*) epad=`expr $epad + 1`; skip=0;;
Darren Tucker9504ea62017-04-28 14:33:43 +100063 *Timeout,?server*)
64 etmo=`expr $etmo + 1`; skip=0;;
Damien Miller43d3ed22014-07-02 17:01:08 +100065 *) fail "unexpected error mac $m at $off: $out";;
Damien Miller1fb593a2012-12-12 10:54:37 +110066 esac
67 done
Darren Tucker9504ea62017-04-28 14:33:43 +100068 verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen timeout $etmo"
Damien Miller1fb593a2012-12-12 10:54:37 +110069 if [ $emac -eq 0 ]; then
70 fail "$m: no mac errors"
71 fi
Darren Tucker9504ea62017-04-28 14:33:43 +100072 expect=`expr $ecnt - $epad - $elen - $etmo`
Damien Miller1fb593a2012-12-12 10:54:37 +110073 if [ $emac -ne $expect ]; then
74 fail "$m: expected $expect mac errors, got $emac"
75 fi
76done