1 # $OpenBSD: integrity.sh,v 1.20 2017/01/06 02:26:10 dtucker Exp $
2 # Placed in the Public Domain.
5 cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
7 # start at byte 2900 (i.e. after kex) and corrupt at different offsets
11 # The following are not MACs, but ciphers with integrated integrity. They are
12 # handled specially below.
13 macs="$macs `${SSH} -Q cipher-auth`"
15 # avoid DH group exchange as the extra traffic makes it harder to get the
16 # offset into the stream right.
17 echo "KexAlgorithms diffie-hellman-group14-sha1,diffie-hellman-group1-sha1" \
20 # sshd-command for proxy (see test-exec.sh)
21 cmd="$SUDO sh ${SRC}/sshd-log-wrapper.sh ${TEST_SSHD_LOGFILE} ${SSHD} -i -f $OBJ/sshd_proxy"
24 trace "test $tid: mac $m"
31 for off in `jot $tries $startoffset`; do
33 if [ $skip -gt 0 ]; then
34 # avoid modifying the high bytes of the length
37 cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
38 # modify output from sshd at offset $off
39 pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
40 if ${SSH} -Q cipher-auth | grep "^${m}\$" >/dev/null 2>&1 ; then
41 echo "Ciphers=$m" >> $OBJ/sshd_proxy
44 echo "Ciphers=aes128-ctr" >> $OBJ/sshd_proxy
45 echo "MACs=$m" >> $OBJ/sshd_proxy
46 macopt="-m $m -c aes128-ctr"
48 verbose "test $tid: $m @$off"
49 ${SSH} $macopt -2F $OBJ/ssh_proxy -o "$pxy" \
50 -oServerAliveInterval=1 -oServerAliveCountMax=30 \
51 999.999.999.999 'printf "%4096s" " "' >/dev/null
53 fail "ssh -m $m succeeds with bit-flip at $off"
56 out=$(egrep -v "^debug" $TEST_SSH_LOGFILE | tail -2 | \
59 Bad?packet*) elen=`expr $elen + 1`; skip=3;;
60 Corrupted?MAC* | *message?authentication?code?incorrect*)
61 emac=`expr $emac + 1`; skip=0;;
62 padding*) epad=`expr $epad + 1`; skip=0;;
63 *) fail "unexpected error mac $m at $off: $out";;
66 verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen"
67 if [ $emac -eq 0 ]; then
68 fail "$m: no mac errors"
70 expect=`expr $ecnt - $epad - $elen`
71 if [ $emac -ne $expect ]; then
72 fail "$m: expected $expect mac errors, got $emac"