blob: 2adee6833475bfc82cafc17157f9df8675833273 [file] [log] [blame]
djm@openbsd.orgdd369322017-04-30 23:34:55 +00001# $OpenBSD: key-options.sh,v 1.4 2017/04/30 23:34:55 djm Exp $
Darren Tuckere045e0c2008-06-11 09:38:12 +10002# Placed in the Public Domain.
3
4tid="key options"
5
6origkeys="$OBJ/authkeys_orig"
7authkeys="$OBJ/authorized_keys_${USER}"
8cp $authkeys $origkeys
9
10# Test command= forced command
djm@openbsd.orgdd369322017-04-30 23:34:55 +000011for c in 'command="echo bar"' 'no-pty,command="echo bar"'; do
Darren Tuckere045e0c2008-06-11 09:38:12 +100012 sed "s/.*/$c &/" $origkeys >$authkeys
djm@openbsd.orgdd369322017-04-30 23:34:55 +000013 verbose "key option $c"
14 r=`${SSH} -q -F $OBJ/ssh_proxy somehost echo foo`
Darren Tuckere045e0c2008-06-11 09:38:12 +100015 if [ "$r" = "foo" ]; then
16 fail "key option forced command not restricted"
17 fi
18 if [ "$r" != "bar" ]; then
19 fail "key option forced command not executed"
20 fi
Darren Tuckere045e0c2008-06-11 09:38:12 +100021done
22
23# Test no-pty
24sed 's/.*/no-pty &/' $origkeys >$authkeys
djm@openbsd.orgdd369322017-04-30 23:34:55 +000025verbose "key option proto no-pty"
26r=`${SSH} -q -F $OBJ/ssh_proxy somehost tty`
27if [ -f "$r" ]; then
28 fail "key option failed no-pty (pty $r)"
29fi
Darren Tuckere045e0c2008-06-11 09:38:12 +100030
31# Test environment=
32echo 'PermitUserEnvironment yes' >> $OBJ/sshd_proxy
33sed 's/.*/environment="FOO=bar" &/' $origkeys >$authkeys
djm@openbsd.orgdd369322017-04-30 23:34:55 +000034verbose "key option environment"
35r=`${SSH} -q -F $OBJ/ssh_proxy somehost 'echo $FOO'`
36if [ "$r" != "bar" ]; then
37 fail "key option environment not set"
38fi
Darren Tuckere045e0c2008-06-11 09:38:12 +100039
40# Test from= restriction
41start_sshd
djm@openbsd.orgdd369322017-04-30 23:34:55 +000042for f in 127.0.0.1 '127.0.0.0\/8'; do
Darren Tuckere045e0c2008-06-11 09:38:12 +100043 cat $origkeys >$authkeys
djm@openbsd.orgdd369322017-04-30 23:34:55 +000044 ${SSH} -q -F $OBJ/ssh_proxy somehost true
Darren Tuckere045e0c2008-06-11 09:38:12 +100045 if [ $? -ne 0 ]; then
djm@openbsd.orgdd369322017-04-30 23:34:55 +000046 fail "key option failed without restriction"
Darren Tuckere045e0c2008-06-11 09:38:12 +100047 fi
48
Darren Tucker8c7a14e2008-07-04 17:08:58 +100049 sed 's/.*/from="'"$f"'" &/' $origkeys >$authkeys
Darren Tuckere045e0c2008-06-11 09:38:12 +100050 from=`head -1 $authkeys | cut -f1 -d ' '`
djm@openbsd.orgdd369322017-04-30 23:34:55 +000051 verbose "key option $from"
52 r=`${SSH} -q -F $OBJ/ssh_proxy somehost 'echo true'`
Darren Tucker8c7a14e2008-07-04 17:08:58 +100053 if [ "$r" = "true" ]; then
djm@openbsd.orgdd369322017-04-30 23:34:55 +000054 fail "key option $from not restricted"
Darren Tuckere045e0c2008-06-11 09:38:12 +100055 fi
56
djm@openbsd.orgdd369322017-04-30 23:34:55 +000057 r=`${SSH} -q -F $OBJ/ssh_config somehost 'echo true'`
Darren Tuckere045e0c2008-06-11 09:38:12 +100058 if [ "$r" != "true" ]; then
djm@openbsd.orgdd369322017-04-30 23:34:55 +000059 fail "key option $from not allowed but should be"
Darren Tuckere045e0c2008-06-11 09:38:12 +100060 fi
Darren Tuckere045e0c2008-06-11 09:38:12 +100061done
62
63rm -f "$origkeys"