blob: 261e9f9a9c1667e20bca0ba2b5f8844ddd6c1efa [file] [log] [blame]
Damien Miller0dc3bc92013-02-19 09:28:32 +11001# $OpenBSD: integrity.sh,v 1.5 2013/02/18 22:26:47 djm 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
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.
Damien Millerb26699b2013-01-17 14:31:57 +110019config_defined OPENSSL_HAVE_EVPGCM && \
Damien Miller846dc7f2013-01-12 22:46:26 +110020 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 Miller33d52562013-02-18 10:18:05 +110049 999.999.999.999 'printf "%2048s" " "' 2>&1)
Damien Miller1fb593a2012-12-12 10:54:37 +110050 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 Millerefa1c952013-01-12 23:10:47 +110059 emac=$((emac+1)); skip=0;;
Damien Miller1fb593a2012-12-12 10:54:37 +110060 padding*) epad=$((epad+1)); skip=0;;
61 *) fail "unexpected error mac $m at $off";;
62 esac
63 done
64 verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen"
65 if [ $emac -eq 0 ]; then
66 fail "$m: no mac errors"
67 fi
68 expect=$((ecnt-epad-elen))
69 if [ $emac -ne $expect ]; then
70 fail "$m: expected $expect mac errors, got $emac"
71 fi
72done