blob: e9d15306ff2f19908eb9453f5c52e0845fd6a980 [file] [log] [blame]
djm@openbsd.org4bea0ab2014-12-22 08:06:03 +00001# $OpenBSD: multipubkey.sh,v 1.1 2014/12/22 08:06:03 djm Exp $
2# Placed in the Public Domain.
3
4tid="multiple pubkey"
5
6rm -f $OBJ/authorized_keys_$USER $OBJ/user_ca_key* $OBJ/user_key*
7rm -f $OBJ/authorized_principals_$USER $OBJ/cert_user_key*
8
9mv $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
10mv $OBJ/ssh_proxy $OBJ/ssh_proxy.orig
11
12# Create a CA key
13${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_ca_key ||\
14 fatal "ssh-keygen failed"
15
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
25# it is offered.
26mv $OBJ/user_key1-cert.pub $OBJ/cert_user_key1.pub
27cp -p $OBJ/user_key1 $OBJ/cert_user_key1
28
29grep -v IdentityFile $OBJ/ssh_proxy.orig > $OBJ/ssh_proxy
30
31opts="-oProtocol=2 -F $OBJ/ssh_proxy -oIdentitiesOnly=yes"
32opts="$opts -i $OBJ/cert_user_key1 -i $OBJ/user_key1 -i $OBJ/user_key2"
33
34for privsep in no yes; do
35 (
36 grep -v "Protocol" $OBJ/sshd_proxy.orig
37 echo "Protocol 2"
38 echo "UsePrivilegeSeparation $privsep"
39 echo "AuthenticationMethods publickey,publickey"
40 echo "TrustedUserCAKeys $OBJ/user_ca_key.pub"
41 echo "AuthorizedPrincipalsFile $OBJ/authorized_principals_%u"
42 ) > $OBJ/sshd_proxy
43
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"
48
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"
53
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
60
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"
65done
66