2017-05-01 01:34:55 +02:00
|
|
|
# $OpenBSD: key-options.sh,v 1.4 2017/04/30 23:34:55 djm Exp $
|
2008-06-11 01:38:12 +02: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
|
2017-05-01 01:34:55 +02:00
|
|
|
for c in 'command="echo bar"' 'no-pty,command="echo bar"'; do
|
2008-06-11 01:38:12 +02:00
|
|
|
sed "s/.*/$c &/" $origkeys >$authkeys
|
2017-05-01 01:34:55 +02:00
|
|
|
verbose "key option $c"
|
|
|
|
r=`${SSH} -q -F $OBJ/ssh_proxy somehost echo foo`
|
2008-06-11 01:38:12 +02: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
|
2017-05-01 01:34:55 +02: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-06-11 01:38:12 +02:00
|
|
|
|
|
|
|
# Test environment=
|
|
|
|
echo 'PermitUserEnvironment yes' >> $OBJ/sshd_proxy
|
|
|
|
sed 's/.*/environment="FOO=bar" &/' $origkeys >$authkeys
|
2017-05-01 01:34:55 +02: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-06-11 01:38:12 +02:00
|
|
|
|
|
|
|
# Test from= restriction
|
|
|
|
start_sshd
|
2017-05-01 01:34:55 +02:00
|
|
|
for f in 127.0.0.1 '127.0.0.0\/8'; do
|
2008-06-11 01:38:12 +02:00
|
|
|
cat $origkeys >$authkeys
|
2017-05-01 01:34:55 +02:00
|
|
|
${SSH} -q -F $OBJ/ssh_proxy somehost true
|
2008-06-11 01:38:12 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
2017-05-01 01:34:55 +02:00
|
|
|
fail "key option failed without restriction"
|
2008-06-11 01:38:12 +02:00
|
|
|
fi
|
|
|
|
|
2008-07-04 09:08:58 +02:00
|
|
|
sed 's/.*/from="'"$f"'" &/' $origkeys >$authkeys
|
2008-06-11 01:38:12 +02:00
|
|
|
from=`head -1 $authkeys | cut -f1 -d ' '`
|
2017-05-01 01:34:55 +02:00
|
|
|
verbose "key option $from"
|
|
|
|
r=`${SSH} -q -F $OBJ/ssh_proxy somehost 'echo true'`
|
2008-07-04 09:08:58 +02:00
|
|
|
if [ "$r" = "true" ]; then
|
2017-05-01 01:34:55 +02:00
|
|
|
fail "key option $from not restricted"
|
2008-06-11 01:38:12 +02:00
|
|
|
fi
|
|
|
|
|
2017-05-01 01:34:55 +02:00
|
|
|
r=`${SSH} -q -F $OBJ/ssh_config somehost 'echo true'`
|
2008-06-11 01:38:12 +02:00
|
|
|
if [ "$r" != "true" ]; then
|
2017-05-01 01:34:55 +02:00
|
|
|
fail "key option $from not allowed but should be"
|
2008-06-11 01:38:12 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -f "$origkeys"
|