summaryrefslogtreecommitdiff
path: root/regress/principals-command.sh
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2016-09-21 01:35:12 +0000
committerDamien Miller <djm@mindrot.org>2016-09-21 11:43:57 +1000
commit119b7a2ca0ef2bf3f81897ae10301b8ca8cba844 (patch)
tree1cf32f08600e1760d3a01b2997975d6b1055f55c /regress/principals-command.sh
parentbfa9d969ab6235d4938ce069d4db7e5825c56a19 (diff)
upstream commit
test all the AuthorizedPrincipalsCommand % expansions Upstream-Regress-ID: 0a79a84dfaa59f958e46b474c3db780b454d30e3
Diffstat (limited to 'regress/principals-command.sh')
-rw-r--r--regress/principals-command.sh38
1 files changed, 27 insertions, 11 deletions
diff --git a/regress/principals-command.sh b/regress/principals-command.sh
index c0be7e747..19d7d6c96 100644
--- a/regress/principals-command.sh
+++ b/regress/principals-command.sh
@@ -1,4 +1,4 @@
1# $OpenBSD: principals-command.sh,v 1.1 2015/05/21 06:44:25 djm Exp $ 1# $OpenBSD: principals-command.sh,v 1.2 2016/09/21 01:35:12 djm Exp $
2# Placed in the Public Domain. 2# Placed in the Public Domain.
3 3
4tid="authorized principals command" 4tid="authorized principals command"
@@ -12,12 +12,36 @@ if test -z "$SUDO" ; then
12 exit 0 12 exit 0
13fi 13fi
14 14
15SERIAL=$$
16
17# Create a CA key and a user certificate.
18${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_ca_key || \
19 fatal "ssh-keygen of user_ca_key failed"
20${SSHKEYGEN} -q -N '' -t rsa -f $OBJ/cert_user_key || \
21 fatal "ssh-keygen of cert_user_key failed"
22${SSHKEYGEN} -q -s $OBJ/user_ca_key -I "Joanne User" \
23 -z $$ -n ${USER},mekmitasdigoat $OBJ/cert_user_key || \
24 fatal "couldn't sign cert_user_key"
25
26CERT_BODY=`cat $OBJ/cert_user_key-cert.pub | awk '{ print $2 }'`
27CA_BODY=`cat $OBJ/user_ca_key.pub | awk '{ print $2 }'`
28CERT_FP=`${SSHKEYGEN} -lf $OBJ/cert_user_key-cert.pub | awk '{ print $2 }'`
29CA_FP=`${SSHKEYGEN} -lf $OBJ/user_ca_key.pub | awk '{ print $2 }'`
30
15# Establish a AuthorizedPrincipalsCommand in /var/run where it will have 31# Establish a AuthorizedPrincipalsCommand in /var/run where it will have
16# acceptable directory permissions. 32# acceptable directory permissions.
17PRINCIPALS_CMD="/var/run/principals_command_${LOGNAME}" 33PRINCIPALS_CMD="/var/run/principals_command_${LOGNAME}"
18cat << _EOF | $SUDO sh -c "cat > '$PRINCIPALS_CMD'" 34cat << _EOF | $SUDO sh -c "cat > '$PRINCIPALS_CMD'"
19#!/bin/sh 35#!/bin/sh
20test "x\$1" != "x${LOGNAME}" && exit 1 36test "x\$1" != "x${LOGNAME}" && exit 1
37test "x\$2" != "xssh-rsa-cert-v01@openssh.com" && exit 1
38test "x\$3" != "xssh-ed25519" && exit 1
39test "x\$4" != "xJoanne User" && exit 1
40test "x\$5" != "x${SERIAL}" && exit 1
41test "x\$6" != "x${CA_FP}" && exit 1
42test "x\$7" != "x${CERT_FP}" && exit 1
43test "x\$8" != "x${CERT_BODY}" && exit 1
44test "x\$9" != "x${CA_BODY}" && exit 1
21test -f "$OBJ/authorized_principals_${LOGNAME}" && 45test -f "$OBJ/authorized_principals_${LOGNAME}" &&
22 exec cat "$OBJ/authorized_principals_${LOGNAME}" 46 exec cat "$OBJ/authorized_principals_${LOGNAME}"
23_EOF 47_EOF
@@ -31,15 +55,6 @@ if ! $OBJ/check-perm -m keys-command $PRINCIPALS_CMD ; then
31 exit 0 55 exit 0
32fi 56fi
33 57
34# Create a CA key and a user certificate.
35${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_ca_key || \
36 fatal "ssh-keygen of user_ca_key failed"
37${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/cert_user_key || \
38 fatal "ssh-keygen of cert_user_key failed"
39${SSHKEYGEN} -q -s $OBJ/user_ca_key -I "regress user key for $USER" \
40 -z $$ -n ${USER},mekmitasdigoat $OBJ/cert_user_key || \
41 fatal "couldn't sign cert_user_key"
42
43if [ -x $PRINCIPALS_CMD ]; then 58if [ -x $PRINCIPALS_CMD ]; then
44 # Test explicitly-specified principals 59 # Test explicitly-specified principals
45 for privsep in yes no ; do 60 for privsep in yes no ; do
@@ -51,7 +66,8 @@ if [ -x $PRINCIPALS_CMD ]; then
51 cat $OBJ/sshd_proxy_bak 66 cat $OBJ/sshd_proxy_bak
52 echo "UsePrivilegeSeparation $privsep" 67 echo "UsePrivilegeSeparation $privsep"
53 echo "AuthorizedKeysFile none" 68 echo "AuthorizedKeysFile none"
54 echo "AuthorizedPrincipalsCommand $PRINCIPALS_CMD %u" 69 echo "AuthorizedPrincipalsCommand $PRINCIPALS_COMMAND" \
70 "%u %t %T %i %s %F %f %k %K"
55 echo "AuthorizedPrincipalsCommandUser ${LOGNAME}" 71 echo "AuthorizedPrincipalsCommandUser ${LOGNAME}"
56 echo "TrustedUserCAKeys $OBJ/user_ca_key.pub" 72 echo "TrustedUserCAKeys $OBJ/user_ca_key.pub"
57 ) > $OBJ/sshd_proxy 73 ) > $OBJ/sshd_proxy