1 # $OpenBSD: multipubkey.sh,v 1.1 2014/12/22 08:06:03 djm Exp $
2 # Placed in the Public Domain.
6 rm -f $OBJ/authorized_keys_$USER $OBJ/user_ca_key* $OBJ/user_key*
7 rm -f $OBJ/authorized_principals_$USER $OBJ/cert_user_key*
9 mv $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
10 mv $OBJ/ssh_proxy $OBJ/ssh_proxy.orig
13 ${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_ca_key ||\
14 fatal "ssh-keygen failed"
16 # Make some keys and a certificate.
17 ${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_key1 || \
18 fatal "ssh-keygen failed"
19 ${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_key2 || \
20 fatal "ssh-keygen failed"
21 ${SSHKEYGEN} -q -s $OBJ/user_ca_key -I "regress user key for $USER" \
22 -z $$ -n ${USER},mekmitasdigoat $OBJ/user_key1 ||
23 fail "couldn't sign user_key1"
24 # Copy the private key alongside the cert to allow better control of when
26 mv $OBJ/user_key1-cert.pub $OBJ/cert_user_key1.pub
27 cp -p $OBJ/user_key1 $OBJ/cert_user_key1
29 grep -v IdentityFile $OBJ/ssh_proxy.orig > $OBJ/ssh_proxy
31 opts="-oProtocol=2 -F $OBJ/ssh_proxy -oIdentitiesOnly=yes"
32 opts="$opts -i $OBJ/cert_user_key1 -i $OBJ/user_key1 -i $OBJ/user_key2"
34 for privsep in no yes; do
36 grep -v "Protocol" $OBJ/sshd_proxy.orig
38 echo "UsePrivilegeSeparation $privsep"
39 echo "AuthenticationMethods publickey,publickey"
40 echo "TrustedUserCAKeys $OBJ/user_ca_key.pub"
41 echo "AuthorizedPrincipalsFile $OBJ/authorized_principals_%u"
44 # Single key should fail.
45 rm -f $OBJ/authorized_principals_$USER
46 cat $OBJ/user_key1.pub > $OBJ/authorized_keys_$USER
47 ${SSH} $opts proxy true && fail "ssh succeeded with key"
49 # Single key with same-public cert should fail.
50 echo mekmitasdigoat > $OBJ/authorized_principals_$USER
51 cat $OBJ/user_key1.pub > $OBJ/authorized_keys_$USER
52 ${SSH} $opts proxy true && fail "ssh succeeded with key+cert"
54 # Multiple plain keys should succeed.
55 rm -f $OBJ/authorized_principals_$USER
56 cat $OBJ/user_key1.pub $OBJ/user_key2.pub > \
57 $OBJ/authorized_keys_$USER
58 ${SSH} $opts proxy true || fail "ssh failed with multiple keys"
59 # Cert and different key should succeed
61 # Key and different-public cert should succeed.
62 echo mekmitasdigoat > $OBJ/authorized_principals_$USER
63 cat $OBJ/user_key2.pub > $OBJ/authorized_keys_$USER
64 ${SSH} $opts proxy true || fail "ssh failed with key/cert"