freebsd-dev/regress/key-options.sh

64 lines
1.7 KiB
Bash
Raw Normal View History

2018-05-06 12:24:45 +00:00
# $OpenBSD: key-options.sh,v 1.4 2017/04/30 23:34:55 djm Exp $
2008-07-23 09:33:08 +00:00
# Placed in the Public Domain.
tid="key options"
origkeys="$OBJ/authkeys_orig"
authkeys="$OBJ/authorized_keys_${USER}"
cp $authkeys $origkeys
# Test command= forced command
2018-05-06 12:24:45 +00:00
for c in 'command="echo bar"' 'no-pty,command="echo bar"'; do
2008-07-23 09:33:08 +00:00
sed "s/.*/$c &/" $origkeys >$authkeys
2018-05-06 12:24:45 +00:00
verbose "key option $c"
r=`${SSH} -q -F $OBJ/ssh_proxy somehost echo foo`
2008-07-23 09:33:08 +00:00
if [ "$r" = "foo" ]; then
fail "key option forced command not restricted"
fi
if [ "$r" != "bar" ]; then
fail "key option forced command not executed"
fi
done
# Test no-pty
sed 's/.*/no-pty &/' $origkeys >$authkeys
2018-05-06 12:24:45 +00:00
verbose "key option proto no-pty"
r=`${SSH} -q -F $OBJ/ssh_proxy somehost tty`
if [ -f "$r" ]; then
fail "key option failed no-pty (pty $r)"
fi
2008-07-23 09:33:08 +00:00
# Test environment=
echo 'PermitUserEnvironment yes' >> $OBJ/sshd_proxy
sed 's/.*/environment="FOO=bar" &/' $origkeys >$authkeys
2018-05-06 12:24:45 +00:00
verbose "key option environment"
r=`${SSH} -q -F $OBJ/ssh_proxy somehost 'echo $FOO'`
if [ "$r" != "bar" ]; then
fail "key option environment not set"
fi
2008-07-23 09:33:08 +00:00
# Test from= restriction
start_sshd
2018-05-06 12:24:45 +00:00
for f in 127.0.0.1 '127.0.0.0\/8'; do
2008-07-23 09:33:08 +00:00
cat $origkeys >$authkeys
2018-05-06 12:24:45 +00:00
${SSH} -q -F $OBJ/ssh_proxy somehost true
2008-07-23 09:33:08 +00:00
if [ $? -ne 0 ]; then
2018-05-06 12:24:45 +00:00
fail "key option failed without restriction"
2008-07-23 09:33:08 +00:00
fi
sed 's/.*/from="'"$f"'" &/' $origkeys >$authkeys
from=`head -1 $authkeys | cut -f1 -d ' '`
2018-05-06 12:24:45 +00:00
verbose "key option $from"
r=`${SSH} -q -F $OBJ/ssh_proxy somehost 'echo true'`
2008-07-23 09:33:08 +00:00
if [ "$r" = "true" ]; then
2018-05-06 12:24:45 +00:00
fail "key option $from not restricted"
2008-07-23 09:33:08 +00:00
fi
2018-05-06 12:24:45 +00:00
r=`${SSH} -q -F $OBJ/ssh_config somehost 'echo true'`
2008-07-23 09:33:08 +00:00
if [ "$r" != "true" ]; then
2018-05-06 12:24:45 +00:00
fail "key option $from not allowed but should be"
2008-07-23 09:33:08 +00:00
fi
done
rm -f "$origkeys"