blob: a57ec87f97c1d8163a2bdb590759581e3ed850fc [file] [log] [blame]
Damien Miller1e657d52013-02-26 18:58:06 +11001# $OpenBSD: integrity.sh,v 1.7 2013/02/20 08:27:50 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
Damien Millerdae85cc2013-02-19 14:27:44 +110012 hmac-sha1-96 hmac-md5-96
Damien Miller1fb593a2012-12-12 10:54:37 +110013 hmac-sha1-etm@openssh.com hmac-md5-etm@openssh.com
14 umac-64-etm@openssh.com umac-128-etm@openssh.com
Damien Millerdae85cc2013-02-19 14:27:44 +110015 hmac-sha1-96-etm@openssh.com hmac-md5-96-etm@openssh.com"
16config_defined HAVE_EVP_SHA256 &&
17 macs="$macs hmac-sha2-256 hmac-sha2-512
18 hmac-sha2-256-etm@openssh.com hmac-sha2-512-etm@openssh.com"
Damien Miller846dc7f2013-01-12 22:46:26 +110019# The following are not MACs, but ciphers with integrated integrity. They are
20# handled specially below.
Damien Millerb26699b2013-01-17 14:31:57 +110021config_defined OPENSSL_HAVE_EVPGCM && \
Damien Miller846dc7f2013-01-12 22:46:26 +110022 macs="$macs aes128-gcm@openssh.com aes256-gcm@openssh.com"
Damien Miller1fb593a2012-12-12 10:54:37 +110023
24# sshd-command for proxy (see test-exec.sh)
25cmd="sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSH_LOGFILE} -i -f $OBJ/sshd_proxy"
26
Damien Miller9fec2962012-12-12 12:10:10 +110027jot() {
Damien Miller37461d72012-12-12 12:37:32 +110028 awk "BEGIN { for (i = $2; i < $2 + $1; i++) { printf \"%d\n\", i } }"
Damien Miller9fec2962012-12-12 12:10:10 +110029}
Damien Miller37461d72012-12-12 12:37:32 +110030
Damien Miller1fb593a2012-12-12 10:54:37 +110031for m in $macs; do
32 trace "test $tid: mac $m"
33 elen=0
34 epad=0
35 emac=0
36 ecnt=0
37 skip=0
38 for off in $(jot $tries $startoffset); do
Damien Miller9fec2962012-12-12 12:10:10 +110039 skip=$((skip - 1))
40 if [ $skip -gt 0 ]; then
Damien Miller1fb593a2012-12-12 10:54:37 +110041 # avoid modifying the high bytes of the length
42 continue
43 fi
44 # modify output from sshd at offset $off
Damien Miller1e657d52013-02-26 18:58:06 +110045 pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
Damien Miller846dc7f2013-01-12 22:46:26 +110046 case $m in
47 aes*gcm*) macopt="-c $m";;
48 *) macopt="-m $m";;
49 esac
50 output=$(${SSH} $macopt -2F $OBJ/ssh_proxy -o "$pxy" \
Damien Millerb3764e12013-02-19 13:15:01 +110051 999.999.999.999 'printf "%4096s" " "' 2>&1)
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
55 ecnt=$((ecnt+1))
56 output=$(echo $output | tr -s '\r\n' '.')
57 verbose "test $tid: $m @$off $output"
58 case "$output" in
Damien Miller37461d72012-12-12 12:37:32 +110059 Bad?packet*) elen=$((elen+1)); skip=3;;
Damien Miller846dc7f2013-01-12 22:46:26 +110060 Corrupted?MAC* | Decryption?integrity?check?failed*)
Damien Millerefa1c952013-01-12 23:10:47 +110061 emac=$((emac+1)); skip=0;;
Damien Miller1fb593a2012-12-12 10:54:37 +110062 padding*) epad=$((epad+1)); skip=0;;
63 *) fail "unexpected error mac $m at $off";;
64 esac
65 done
66 verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen"
67 if [ $emac -eq 0 ]; then
68 fail "$m: no mac errors"
69 fi
70 expect=$((ecnt-epad-elen))
71 if [ $emac -ne $expect ]; then
72 fail "$m: expected $expect mac errors, got $emac"
73 fi
74done