blob: f6e5c196341b5a7c1803c75b022e2ce3caa8f669 [file] [log] [blame]
Damien Miller1fb593a2012-12-12 10:54:37 +11001# $OpenBSD: integrity.sh,v 1.1 2012/12/11 22:42:11 markus Exp $
2# Placed in the Public Domain.
3
4tid="integrity"
5
6# start at byte 2300 (i.e. after kex) and corrupt at different offsets
7# XXX the test hangs if we modify the low bytes of the packet length
8# XXX and ssh tries to read...
9tries=10
10startoffset=2300
11macs="hmac-sha1 hmac-md5 umac-64@openssh.com umac-128@openssh.com
12 hmac-sha1-96 hmac-md5-96 hmac-sha2-256 hmac-sha2-512
13 hmac-sha1-etm@openssh.com hmac-md5-etm@openssh.com
14 umac-64-etm@openssh.com umac-128-etm@openssh.com
15 hmac-sha1-96-etm@openssh.com hmac-md5-96-etm@openssh.com
16 hmac-sha2-256-etm@openssh.com hmac-sha2-512-etm@openssh.com"
17
18# sshd-command for proxy (see test-exec.sh)
19cmd="sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSH_LOGFILE} -i -f $OBJ/sshd_proxy"
20
Damien Miller9fec2962012-12-12 12:10:10 +110021jot() {
22 awk 'BEGIN { for (i = $2; i < $2 + $1; i++) { printf "%d\n", i } }'
23}
24set -x
Damien Miller1fb593a2012-12-12 10:54:37 +110025for 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
32 for off in $(jot $tries $startoffset); do
Damien Miller9fec2962012-12-12 12:10:10 +110033 skip=$((skip - 1))
34 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
38 # modify output from sshd at offset $off
39 pxy="proxycommand=$cmd | $OBJ/modpipe -m xor:$off:1"
40 output=$(${SSH} -m $m -2F $OBJ/ssh_proxy -o "$pxy" \
41 999.999.999.999 true 2>&1)
42 if [ $? -eq 0 ]; then
43 fail "ssh -m $m succeeds with bit-flip at $off"
44 fi
45 ecnt=$((ecnt+1))
46 output=$(echo $output | tr -s '\r\n' '.')
47 verbose "test $tid: $m @$off $output"
48 case "$output" in
49 Bad?packet*) elen=$((elen+1)); skip=2;;
50 Corrupted?MAC*) emac=$((emac+1)); skip=0;;
51 padding*) epad=$((epad+1)); skip=0;;
52 *) fail "unexpected error mac $m at $off";;
53 esac
54 done
55 verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen"
56 if [ $emac -eq 0 ]; then
57 fail "$m: no mac errors"
58 fi
59 expect=$((ecnt-epad-elen))
60 if [ $emac -ne $expect ]; then
61 fail "$m: expected $expect mac errors, got $emac"
62 fi
63done