2013-02-26 07:58:06 +00:00
|
|
|
# $OpenBSD: integrity.sh,v 1.7 2013/02/20 08:27:50 djm Exp $
|
2012-12-11 23:54:37 +00:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
tid="integrity"
|
|
|
|
|
2013-02-18 22:28:32 +00:00
|
|
|
# start at byte 2900 (i.e. after kex) and corrupt at different offsets
|
2012-12-11 23:54:37 +00:00
|
|
|
# XXX the test hangs if we modify the low bytes of the packet length
|
|
|
|
# XXX and ssh tries to read...
|
|
|
|
tries=10
|
2013-02-18 22:28:32 +00:00
|
|
|
startoffset=2900
|
2012-12-11 23:54:37 +00:00
|
|
|
macs="hmac-sha1 hmac-md5 umac-64@openssh.com umac-128@openssh.com
|
2013-02-19 03:27:44 +00:00
|
|
|
hmac-sha1-96 hmac-md5-96
|
2012-12-11 23:54:37 +00:00
|
|
|
hmac-sha1-etm@openssh.com hmac-md5-etm@openssh.com
|
|
|
|
umac-64-etm@openssh.com umac-128-etm@openssh.com
|
2013-02-19 03:27:44 +00:00
|
|
|
hmac-sha1-96-etm@openssh.com hmac-md5-96-etm@openssh.com"
|
|
|
|
config_defined HAVE_EVP_SHA256 &&
|
|
|
|
macs="$macs hmac-sha2-256 hmac-sha2-512
|
|
|
|
hmac-sha2-256-etm@openssh.com hmac-sha2-512-etm@openssh.com"
|
2013-01-12 11:46:26 +00:00
|
|
|
# The following are not MACs, but ciphers with integrated integrity. They are
|
|
|
|
# handled specially below.
|
2013-01-17 03:31:57 +00:00
|
|
|
config_defined OPENSSL_HAVE_EVPGCM && \
|
2013-01-12 11:46:26 +00:00
|
|
|
macs="$macs aes128-gcm@openssh.com aes256-gcm@openssh.com"
|
2012-12-11 23:54:37 +00:00
|
|
|
|
|
|
|
# sshd-command for proxy (see test-exec.sh)
|
2013-02-26 08:41:30 +00:00
|
|
|
cmd="$SUDO sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSH_LOGFILE} -i -f $OBJ/sshd_proxy"
|
2012-12-11 23:54:37 +00:00
|
|
|
|
2012-12-12 01:10:10 +00:00
|
|
|
jot() {
|
2012-12-12 01:37:32 +00:00
|
|
|
awk "BEGIN { for (i = $2; i < $2 + $1; i++) { printf \"%d\n\", i } }"
|
2012-12-12 01:10:10 +00:00
|
|
|
}
|
2012-12-12 01:37:32 +00:00
|
|
|
|
2012-12-11 23:54:37 +00:00
|
|
|
for m in $macs; do
|
|
|
|
trace "test $tid: mac $m"
|
|
|
|
elen=0
|
|
|
|
epad=0
|
|
|
|
emac=0
|
|
|
|
ecnt=0
|
|
|
|
skip=0
|
2013-02-27 04:27:29 +00:00
|
|
|
for off in `jot $tries $startoffset`; do
|
|
|
|
skip=`expr $skip - 1`
|
2012-12-12 01:10:10 +00:00
|
|
|
if [ $skip -gt 0 ]; then
|
2012-12-11 23:54:37 +00:00
|
|
|
# avoid modifying the high bytes of the length
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# modify output from sshd at offset $off
|
2013-02-26 07:58:06 +00:00
|
|
|
pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
|
2013-01-12 11:46:26 +00:00
|
|
|
case $m in
|
|
|
|
aes*gcm*) macopt="-c $m";;
|
|
|
|
*) macopt="-m $m";;
|
|
|
|
esac
|
2013-02-27 04:27:29 +00:00
|
|
|
output=`${SSH} $macopt -2F $OBJ/ssh_proxy -o "$pxy" \
|
|
|
|
999.999.999.999 'printf "%4096s" " "' 2>&1`
|
2012-12-11 23:54:37 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
fail "ssh -m $m succeeds with bit-flip at $off"
|
|
|
|
fi
|
2013-02-27 04:27:29 +00:00
|
|
|
ecnt=`expr $ecnt + 1`
|
|
|
|
output=`echo $output | tr -s '\r\n' '.'`
|
2012-12-11 23:54:37 +00:00
|
|
|
verbose "test $tid: $m @$off $output"
|
|
|
|
case "$output" in
|
2013-02-27 04:27:29 +00:00
|
|
|
Bad?packet*) elen=`expr $elen + 1`; skip=3;;
|
2013-01-12 11:46:26 +00:00
|
|
|
Corrupted?MAC* | Decryption?integrity?check?failed*)
|
2013-02-27 04:27:29 +00:00
|
|
|
emac=`expr $emac + 1`; skip=0;;
|
|
|
|
padding*) epad=`expr $epad + 1`; skip=0;;
|
2012-12-11 23:54:37 +00:00
|
|
|
*) fail "unexpected error mac $m at $off";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen"
|
|
|
|
if [ $emac -eq 0 ]; then
|
|
|
|
fail "$m: no mac errors"
|
|
|
|
fi
|
2013-02-27 04:27:29 +00:00
|
|
|
expect=`expr $ecnt - $epad - $elen`
|
2012-12-11 23:54:37 +00:00
|
|
|
if [ $emac -ne $expect ]; then
|
|
|
|
fail "$m: expected $expect mac errors, got $emac"
|
|
|
|
fi
|
|
|
|
done
|