2024-08-28 12:08:26 +00:00
|
|
|
# $OpenBSD: rekey.sh,v 1.30 2024/08/28 12:08:26 djm Exp $
|
2003-06-18 12:18:57 +00:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
2013-05-16 23:45:12 +00:00
|
|
|
tid="rekey"
|
2003-06-18 12:18:57 +00:00
|
|
|
|
2013-05-16 23:19:10 +00:00
|
|
|
LOG=${TEST_SSH_LOGFILE}
|
2024-08-20 12:36:59 +00:00
|
|
|
COPY2=$OBJ/copy2
|
2003-06-18 12:18:57 +00:00
|
|
|
|
2013-05-17 05:32:29 +00:00
|
|
|
rm -f ${LOG}
|
2014-05-15 05:07:53 +00:00
|
|
|
cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
|
2003-06-18 12:18:57 +00:00
|
|
|
|
2024-08-20 07:52:43 +00:00
|
|
|
echo "Compression no" >> $OBJ/ssh_proxy
|
2024-08-20 09:02:45 +00:00
|
|
|
echo "RekeyLimit 256k" >> $OBJ/ssh_proxy
|
2024-08-21 06:59:08 +00:00
|
|
|
echo "KexAlgorithms curve25519-sha256" >> ssh_proxy
|
2024-08-20 07:52:43 +00:00
|
|
|
|
2013-11-07 04:08:02 +00:00
|
|
|
# Test rekeying based on data volume only.
|
2024-08-20 12:36:59 +00:00
|
|
|
# Arguments: rekeylimit, kex method, optional remaining opts are passed to ssh.
|
2013-11-07 04:08:02 +00:00
|
|
|
ssh_data_rekeying()
|
|
|
|
{
|
2024-08-20 12:36:59 +00:00
|
|
|
_bytes=$1 ; shift
|
2014-05-15 05:07:53 +00:00
|
|
|
_kexopt=$1 ; shift
|
|
|
|
_opts="$@"
|
2024-08-20 12:36:59 +00:00
|
|
|
if test -z "$_bytes"; then
|
|
|
|
_bytes=32k
|
|
|
|
fi
|
2024-05-22 04:20:00 +00:00
|
|
|
if ! test -z "$_kexopt" ; then
|
2014-05-15 05:07:53 +00:00
|
|
|
cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
|
|
|
|
echo "$_kexopt" >> $OBJ/sshd_proxy
|
|
|
|
_opts="$_opts -o$_kexopt"
|
|
|
|
fi
|
2024-08-22 10:21:02 +00:00
|
|
|
case "$_kexopt" in
|
|
|
|
MACs=*)
|
|
|
|
# default chacha20-poly1305 cipher has implicit MAC
|
|
|
|
_opts="$_opts -oCiphers=aes128-ctr" ;;
|
|
|
|
esac
|
2024-08-20 12:36:59 +00:00
|
|
|
trace bytes $_bytes kex $_kexopt opts $_opts
|
|
|
|
rm -f ${COPY} ${COPY2} ${LOG}
|
|
|
|
# Create data file just big enough to reach rekey threshold.
|
|
|
|
dd if=${DATA} of=${COPY} bs=$_bytes count=1 2>/dev/null
|
2024-08-21 06:59:08 +00:00
|
|
|
${SSH} <${COPY} $_opts -vv \
|
2024-08-20 12:36:59 +00:00
|
|
|
-oRekeyLimit=$_bytes -F $OBJ/ssh_proxy somehost "cat >${COPY2}"
|
2013-11-07 04:08:02 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
fail "ssh failed ($@)"
|
|
|
|
fi
|
2024-08-20 12:36:59 +00:00
|
|
|
cmp ${COPY} ${COPY2} || fail "corrupted copy ($@)"
|
2013-11-07 04:08:02 +00:00
|
|
|
n=`grep 'NEWKEYS sent' ${LOG} | wc -l`
|
|
|
|
n=`expr $n - 1`
|
2024-08-22 10:21:02 +00:00
|
|
|
_want=`echo $_kexopt | cut -f2 -d=`
|
|
|
|
_got=""
|
2024-08-21 06:59:08 +00:00
|
|
|
case "$_kexopt" in
|
2024-08-22 10:21:02 +00:00
|
|
|
KexAlgorithms=*)
|
2024-08-21 10:33:27 +00:00
|
|
|
_got=`awk '/kex: algorithm: /{print $4}' ${LOG} | \
|
2024-08-22 10:21:02 +00:00
|
|
|
tr -d '\r' | sort -u` ;;
|
|
|
|
Ciphers=*)
|
|
|
|
_got=`awk '/kex: client->server cipher:/{print $5}' ${LOG} | \
|
|
|
|
tr -d '\r' | sort -u` ;;
|
|
|
|
MACs=*)
|
|
|
|
_got=`awk '/kex: client->server cipher:/{print $7}' ${LOG} | \
|
|
|
|
tr -d '\r' | sort -u` ;;
|
2024-08-21 06:59:08 +00:00
|
|
|
esac
|
2024-08-22 10:21:02 +00:00
|
|
|
if [ "$_want" != "$_got" ]; then
|
|
|
|
fail "unexpected algorithm, want $_want, got $_got"
|
|
|
|
fi
|
2013-11-07 04:08:02 +00:00
|
|
|
trace "$n rekeying(s)"
|
|
|
|
if [ $n -lt 1 ]; then
|
2018-04-10 00:14:10 +00:00
|
|
|
fail "no rekeying occurred ($@)"
|
2013-11-07 04:08:02 +00:00
|
|
|
fi
|
2024-08-20 12:36:59 +00:00
|
|
|
cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
|
2013-11-07 04:08:02 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 05:55:03 +00:00
|
|
|
increase_datafile_size 300
|
|
|
|
|
2013-11-07 04:04:44 +00:00
|
|
|
opts=""
|
2024-08-20 07:41:35 +00:00
|
|
|
|
|
|
|
# Filter out duplicate curve algo
|
|
|
|
kexs=`${SSH} -Q kex | grep -v curve25519-sha256@libssh.org`
|
|
|
|
ciphers=`${SSH} -Q cipher`
|
|
|
|
macs=`${SSH} -Q mac`
|
|
|
|
|
|
|
|
for i in $kexs; do
|
2013-11-07 04:04:44 +00:00
|
|
|
opts="$opts KexAlgorithms=$i"
|
|
|
|
done
|
2024-08-20 07:41:35 +00:00
|
|
|
for i in $ciphers; do
|
2013-11-07 04:04:44 +00:00
|
|
|
opts="$opts Ciphers=$i"
|
|
|
|
done
|
2024-08-20 07:41:35 +00:00
|
|
|
for i in $macs; do
|
2013-11-07 04:04:44 +00:00
|
|
|
opts="$opts MACs=$i"
|
|
|
|
done
|
2013-11-07 04:00:51 +00:00
|
|
|
|
2013-11-07 04:04:44 +00:00
|
|
|
for opt in $opts; do
|
|
|
|
verbose "client rekey $opt"
|
2024-08-20 09:15:49 +00:00
|
|
|
if ${SSH} -Q cipher-auth | sed 's/^/Ciphers=/' | \
|
|
|
|
grep $opt >/dev/null; then
|
|
|
|
trace AEAD cipher, testing all KexAlgorithms
|
|
|
|
for kex in $kexs; do
|
2024-08-20 12:36:59 +00:00
|
|
|
ssh_data_rekeying "" "KexAlgorithms=$kex" "-o$opt"
|
2024-08-20 09:15:49 +00:00
|
|
|
done
|
|
|
|
else
|
2024-08-20 12:36:59 +00:00
|
|
|
ssh_data_rekeying "" "$opt"
|
2024-08-20 09:15:49 +00:00
|
|
|
fi
|
2013-11-07 04:04:44 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for s in 16 1k 128k 256k; do
|
|
|
|
verbose "client rekeylimit ${s}"
|
2024-08-20 12:36:59 +00:00
|
|
|
ssh_data_rekeying "$s" ""
|
2003-06-18 12:18:57 +00:00
|
|
|
done
|
2013-05-16 23:42:34 +00:00
|
|
|
|
2013-05-16 23:43:33 +00:00
|
|
|
for s in 5 10; do
|
2013-05-16 23:44:20 +00:00
|
|
|
verbose "client rekeylimit default ${s}"
|
2013-05-16 23:42:34 +00:00
|
|
|
rm -f ${COPY} ${LOG}
|
2024-08-20 07:52:43 +00:00
|
|
|
${SSH} < ${DATA} -oRekeyLimit="default $s" -F \
|
2021-07-19 05:08:54 +00:00
|
|
|
$OBJ/ssh_proxy somehost "cat >${COPY};sleep $s;sleep 10"
|
2013-05-16 23:42:34 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
fail "ssh failed"
|
|
|
|
fi
|
2013-11-07 04:08:02 +00:00
|
|
|
cmp ${DATA} ${COPY} || fail "corrupted copy"
|
2013-05-16 23:42:34 +00:00
|
|
|
n=`grep 'NEWKEYS sent' ${LOG} | wc -l`
|
|
|
|
n=`expr $n - 1`
|
|
|
|
trace "$n rekeying(s)"
|
|
|
|
if [ $n -lt 1 ]; then
|
2018-04-10 00:14:10 +00:00
|
|
|
fail "no rekeying occurred"
|
2013-05-16 23:42:34 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2013-05-16 23:43:33 +00:00
|
|
|
for s in 5 10; do
|
2013-05-16 23:44:20 +00:00
|
|
|
verbose "client rekeylimit default ${s} no data"
|
2013-05-16 23:43:33 +00:00
|
|
|
rm -f ${COPY} ${LOG}
|
2024-08-20 07:52:43 +00:00
|
|
|
${SSH} -oRekeyLimit="default $s" -F \
|
2021-07-19 05:08:54 +00:00
|
|
|
$OBJ/ssh_proxy somehost "sleep $s;sleep 10"
|
2013-05-16 23:43:33 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
fail "ssh failed"
|
|
|
|
fi
|
|
|
|
n=`grep 'NEWKEYS sent' ${LOG} | wc -l`
|
|
|
|
n=`expr $n - 1`
|
|
|
|
trace "$n rekeying(s)"
|
|
|
|
if [ $n -lt 1 ]; then
|
2018-04-10 00:14:10 +00:00
|
|
|
fail "no rekeying occurred"
|
2013-05-16 23:43:33 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2015-02-14 12:43:16 +00:00
|
|
|
for s in 16 1k 128k 256k; do
|
|
|
|
verbose "server rekeylimit ${s}"
|
|
|
|
cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
|
|
|
|
echo "rekeylimit ${s}" >>$OBJ/sshd_proxy
|
2024-08-20 12:36:59 +00:00
|
|
|
rm -f ${COPY} ${COPY2} ${LOG}
|
|
|
|
dd if=${DATA} of=${COPY} bs=$s count=1 2>/dev/null
|
|
|
|
${SSH} -F $OBJ/ssh_proxy somehost "cat ${COPY}" >${COPY2}
|
2015-02-14 12:43:16 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
fail "ssh failed"
|
|
|
|
fi
|
2024-08-20 12:36:59 +00:00
|
|
|
cmp ${COPY} ${COPY2} || fail "corrupted copy"
|
2015-02-14 12:43:16 +00:00
|
|
|
n=`grep 'NEWKEYS sent' ${LOG} | wc -l`
|
|
|
|
n=`expr $n - 1`
|
|
|
|
trace "$n rekeying(s)"
|
|
|
|
if [ $n -lt 1 ]; then
|
2018-04-10 00:14:10 +00:00
|
|
|
fail "no rekeying occurred"
|
2015-02-14 12:43:16 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2013-05-16 23:44:20 +00:00
|
|
|
for s in 5 10; do
|
|
|
|
verbose "server rekeylimit default ${s} no data"
|
2015-02-14 12:43:16 +00:00
|
|
|
cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
|
|
|
|
echo "rekeylimit default ${s}" >>$OBJ/sshd_proxy
|
2013-05-16 23:44:20 +00:00
|
|
|
rm -f ${COPY} ${LOG}
|
2024-08-20 07:52:43 +00:00
|
|
|
${SSH} -F $OBJ/ssh_proxy somehost "sleep $s;sleep 10"
|
2013-05-16 23:44:20 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
fail "ssh failed"
|
|
|
|
fi
|
|
|
|
n=`grep 'NEWKEYS sent' ${LOG} | wc -l`
|
|
|
|
n=`expr $n - 1`
|
|
|
|
trace "$n rekeying(s)"
|
|
|
|
if [ $n -lt 1 ]; then
|
2018-04-10 00:14:10 +00:00
|
|
|
fail "no rekeying occurred"
|
2013-05-16 23:44:20 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-08-20 07:27:25 +00:00
|
|
|
verbose "rekeylimit parsing: bytes"
|
2016-01-29 05:18:15 +00:00
|
|
|
for size in 16 1k 1K 1m 1M 1g 1G 4G 8G; do
|
2013-05-16 23:45:12 +00:00
|
|
|
case $size in
|
|
|
|
16) bytes=16 ;;
|
|
|
|
1k|1K) bytes=1024 ;;
|
|
|
|
1m|1M) bytes=1048576 ;;
|
|
|
|
1g|1G) bytes=1073741824 ;;
|
2016-01-29 05:18:15 +00:00
|
|
|
4g|4G) bytes=4294967296 ;;
|
|
|
|
8g|8G) bytes=8589934592 ;;
|
2013-05-16 23:45:12 +00:00
|
|
|
esac
|
2024-08-28 12:08:26 +00:00
|
|
|
b=`${SSH} -G -o "rekeylimit $size" -F $OBJ/ssh_proxy host | \
|
2024-08-20 07:27:25 +00:00
|
|
|
awk '/rekeylimit/{print $2}'`
|
|
|
|
if [ "$bytes" != "$b" ]; then
|
|
|
|
fatal "rekeylimit size: expected $bytes bytes got $b"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
verbose "rekeylimit parsing: time"
|
|
|
|
for time in 1 1m 1M 1h 1H 1d 1D 1w 1W; do
|
2013-05-16 23:45:12 +00:00
|
|
|
case $time in
|
|
|
|
1) seconds=1 ;;
|
|
|
|
1m|1M) seconds=60 ;;
|
|
|
|
1h|1H) seconds=3600 ;;
|
|
|
|
1d|1D) seconds=86400 ;;
|
|
|
|
1w|1W) seconds=604800 ;;
|
|
|
|
esac
|
2024-08-28 12:08:26 +00:00
|
|
|
s=`${SSH} -G -o "rekeylimit default $time" -F $OBJ/ssh_proxy host | \
|
2013-05-16 23:45:12 +00:00
|
|
|
awk '/rekeylimit/{print $3}'`
|
|
|
|
if [ "$seconds" != "$s" ]; then
|
2013-11-21 03:26:18 +00:00
|
|
|
fatal "rekeylimit time: expected $time seconds got $s"
|
2013-05-16 23:45:12 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-08-20 12:36:59 +00:00
|
|
|
rm -f ${COPY} ${COPY2} ${DATA}
|