blob: 608cde0fede6f484f8ba68b722fa88d708adf5d7 [file] [log] [blame]
Damien Miller846dc7f2013-01-12 22:46:26 +11001# $OpenBSD: integrity.sh,v 1.2 2013/01/12 11:23:53 djm Exp $
Damien Miller1fb593a2012-12-12 10:54:37 +11002# 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"
Damien Miller846dc7f2013-01-12 22:46:26 +110017# The following are not MACs, but ciphers with integrated integrity. They are
18# handled specially below.
19config_defined OPENSSL_HAVE_EVPGCM &&
20 macs="$macs aes128-gcm@openssh.com aes256-gcm@openssh.com"
Damien Miller1fb593a2012-12-12 10:54:37 +110021
22# sshd-command for proxy (see test-exec.sh)
23cmd="sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSH_LOGFILE} -i -f $OBJ/sshd_proxy"
24
Damien Miller9fec2962012-12-12 12:10:10 +110025jot() {
Damien Miller37461d72012-12-12 12:37:32 +110026 awk "BEGIN { for (i = $2; i < $2 + $1; i++) { printf \"%d\n\", i } }"
Damien Miller9fec2962012-12-12 12:10:10 +110027}
Damien Miller37461d72012-12-12 12:37:32 +110028
Damien Miller1fb593a2012-12-12 10:54:37 +110029for m in $macs; do
30 trace "test $tid: mac $m"
31 elen=0
32 epad=0
33 emac=0
34 ecnt=0
35 skip=0
36 for off in $(jot $tries $startoffset); do
Damien Miller9fec2962012-12-12 12:10:10 +110037 skip=$((skip - 1))
38 if [ $skip -gt 0 ]; then
Damien Miller1fb593a2012-12-12 10:54:37 +110039 # avoid modifying the high bytes of the length
40 continue
41 fi
42 # modify output from sshd at offset $off
43 pxy="proxycommand=$cmd | $OBJ/modpipe -m xor:$off:1"
Damien Miller846dc7f2013-01-12 22:46:26 +110044 case $m in
45 aes*gcm*) macopt="-c $m";;
46 *) macopt="-m $m";;
47 esac
48 output=$(${SSH} $macopt -2F $OBJ/ssh_proxy -o "$pxy" \
Damien Miller1fb593a2012-12-12 10:54:37 +110049 999.999.999.999 true 2>&1)
50 if [ $? -eq 0 ]; then
51 fail "ssh -m $m succeeds with bit-flip at $off"
52 fi
53 ecnt=$((ecnt+1))
54 output=$(echo $output | tr -s '\r\n' '.')
55 verbose "test $tid: $m @$off $output"
56 case "$output" in
Damien Miller37461d72012-12-12 12:37:32 +110057 Bad?packet*) elen=$((elen+1)); skip=3;;
Damien Miller846dc7f2013-01-12 22:46:26 +110058 Corrupted?MAC* | Decryption?integrity?check?failed*)
Damien Miller1fb593a2012-12-12 10:54:37 +110059 padding*) epad=$((epad+1)); skip=0;;
60 *) fail "unexpected error mac $m at $off";;
61 esac
62 done
63 verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen"
64 if [ $emac -eq 0 ]; then
65 fail "$m: no mac errors"
66 fi
67 expect=$((ecnt-epad-elen))
68 if [ $emac -ne $expect ]; then
69 fail "$m: expected $expect mac errors, got $emac"
70 fi
71done