1 # $OpenBSD: key-options.sh,v 1.8 2018/03/14 05:35:40 djm Exp $
2 # Placed in the Public Domain.
6 origkeys="$OBJ/authkeys_orig"
7 authkeys="$OBJ/authorized_keys_${USER}"
10 # Test command= forced command
11 for c in 'command="echo bar"' 'no-pty,command="echo bar"'; do
12 sed "s/.*/$c &/" $origkeys >$authkeys
13 verbose "key option $c"
14 r=`${SSH} -q -F $OBJ/ssh_proxy somehost echo foo`
15 if [ "$r" = "foo" ]; then
16 fail "key option forced command not restricted"
18 if [ "$r" != "bar" ]; then
19 fail "key option forced command not executed"
24 expect_pty_succeed() {
28 sed "s/.*/$opts &/" $origkeys >$authkeys
29 verbose "key option pty $which"
30 ${SSH} -ttq -F $OBJ/ssh_proxy somehost "tty > $OBJ/data; exit 0"
31 if [ $? -ne 0 ] ; then
32 fail "key option failed $which"
37 *) fail "key option failed $which (pty $r)" ;;
45 sed "s/.*/$opts &/" $origkeys >$authkeys
46 verbose "key option pty $which"
47 ${SSH} -ttq -F $OBJ/ssh_proxy somehost "tty > $OBJ/data; exit 0"
51 fail "key option failed $which (pty $r)"
54 /dev/*) fail "key option failed $which (pty $r)" ;;
59 # First ensure that we can allocate a pty by default.
60 expect_pty_succeed "default" ""
61 expect_pty_fail "no-pty" "no-pty"
62 expect_pty_fail "restrict" "restrict"
63 expect_pty_succeed "restrict,pty" "restrict,pty"
66 echo 'PermitUserEnvironment yes' >> $OBJ/sshd_proxy
67 sed 's/.*/environment="FOO=bar" &/' $origkeys >$authkeys
68 verbose "key option environment"
69 r=`${SSH} -q -F $OBJ/ssh_proxy somehost 'echo $FOO'`
70 if [ "$r" != "bar" ]; then
71 fail "key option environment not set"
74 # Test from= restriction
76 for f in 127.0.0.1 '127.0.0.0\/8'; do
77 cat $origkeys >$authkeys
78 ${SSH} -q -F $OBJ/ssh_proxy somehost true
80 fail "key option failed without restriction"
83 sed 's/.*/from="'"$f"'" &/' $origkeys >$authkeys
84 from=`head -1 $authkeys | cut -f1 -d ' '`
85 verbose "key option $from"
86 r=`${SSH} -q -F $OBJ/ssh_proxy somehost 'echo true'`
87 if [ "$r" = "true" ]; then
88 fail "key option $from not restricted"
91 r=`${SSH} -q -F $OBJ/ssh_config somehost 'echo true'`
92 if [ "$r" != "true" ]; then
93 fail "key option $from not allowed but should be"
97 check_valid_before() {
101 sed "s/.*/$opts &/" $origkeys >$authkeys
102 verbose "key option expiry-time $which"
103 ${SSH} -q -F $OBJ/ssh_proxy somehost true
106 fail) test $r -eq 0 && fail "key option succeeded $which" ;;
107 pass) test $r -ne 0 && fail "key option failed $which" ;;
108 *) fatal "unknown expectation $expect" ;;
111 check_valid_before "default" "" "pass"
112 check_valid_before "invalid" 'expiry-time="INVALID"' "fail"
113 check_valid_before "expired" 'expiry-time="19990101"' "fail"
114 check_valid_before "valid" 'expiry-time="20380101"' "pass"