2013-11-07 05:21:19 +01:00
|
|
|
# $OpenBSD: integrity.sh,v 1.11 2013/11/07 02:48:38 dtucker Exp $
|
2012-12-12 00:54:37 +01:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
tid="integrity"
|
|
|
|
|
2013-02-18 23:28:32 +01:00
|
|
|
# start at byte 2900 (i.e. after kex) and corrupt at different offsets
|
2012-12-12 00:54:37 +01: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 23:28:32 +01:00
|
|
|
startoffset=2900
|
2013-11-07 05:21:19 +01:00
|
|
|
macs=`${SSH} -Q mac`
|
2013-01-12 12:46:26 +01:00
|
|
|
# The following are not MACs, but ciphers with integrated integrity. They are
|
|
|
|
# handled specially below.
|
2013-11-07 05:21:19 +01:00
|
|
|
macs="$macs `${SSH} -Q cipher | grep gcm@openssh.com`"
|
2012-12-12 00:54:37 +01:00
|
|
|
|
2013-05-17 05:16:59 +02:00
|
|
|
# avoid DH group exchange as the extra traffic makes it harder to get the
|
|
|
|
# offset into the stream right.
|
|
|
|
echo "KexAlgorithms diffie-hellman-group14-sha1,diffie-hellman-group1-sha1" \
|
|
|
|
>> $OBJ/ssh_proxy
|
|
|
|
|
2012-12-12 00:54:37 +01:00
|
|
|
# sshd-command for proxy (see test-exec.sh)
|
2013-05-17 01:19:10 +02:00
|
|
|
cmd="$SUDO sh ${SRC}/sshd-log-wrapper.sh ${SSHD} ${TEST_SSHD_LOGFILE} -i -f $OBJ/sshd_proxy"
|
2012-12-12 00:54:37 +01:00
|
|
|
|
|
|
|
for m in $macs; do
|
|
|
|
trace "test $tid: mac $m"
|
|
|
|
elen=0
|
|
|
|
epad=0
|
|
|
|
emac=0
|
|
|
|
ecnt=0
|
|
|
|
skip=0
|
2013-02-27 05:27:29 +01:00
|
|
|
for off in `jot $tries $startoffset`; do
|
|
|
|
skip=`expr $skip - 1`
|
2012-12-12 02:10:10 +01:00
|
|
|
if [ $skip -gt 0 ]; then
|
2012-12-12 00:54:37 +01:00
|
|
|
# avoid modifying the high bytes of the length
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# modify output from sshd at offset $off
|
2013-02-26 08:58:06 +01:00
|
|
|
pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
|
2013-01-12 12:46:26 +01:00
|
|
|
case $m in
|
|
|
|
aes*gcm*) macopt="-c $m";;
|
|
|
|
*) macopt="-m $m";;
|
|
|
|
esac
|
2013-05-17 06:47:51 +02:00
|
|
|
verbose "test $tid: $m @$off"
|
2013-05-17 01:31:39 +02:00
|
|
|
${SSH} $macopt -2F $OBJ/ssh_proxy -o "$pxy" \
|
|
|
|
999.999.999.999 'printf "%4096s" " "' >/dev/null
|
2012-12-12 00:54:37 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
fail "ssh -m $m succeeds with bit-flip at $off"
|
|
|
|
fi
|
2013-02-27 05:27:29 +01:00
|
|
|
ecnt=`expr $ecnt + 1`
|
2013-05-17 01:31:39 +02:00
|
|
|
output=$(tail -2 $TEST_SSH_LOGFILE | egrep -v "^debug" | \
|
|
|
|
tr -s '\r\n' '.')
|
2012-12-12 00:54:37 +01:00
|
|
|
case "$output" in
|
2013-02-27 05:27:29 +01:00
|
|
|
Bad?packet*) elen=`expr $elen + 1`; skip=3;;
|
2013-01-12 12:46:26 +01:00
|
|
|
Corrupted?MAC* | Decryption?integrity?check?failed*)
|
2013-02-27 05:27:29 +01:00
|
|
|
emac=`expr $emac + 1`; skip=0;;
|
|
|
|
padding*) epad=`expr $epad + 1`; skip=0;;
|
2012-12-12 00:54:37 +01: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 05:27:29 +01:00
|
|
|
expect=`expr $ecnt - $epad - $elen`
|
2012-12-12 00:54:37 +01:00
|
|
|
if [ $emac -ne $expect ]; then
|
|
|
|
fail "$m: expected $expect mac errors, got $emac"
|
|
|
|
fi
|
|
|
|
done
|