multipubkey.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # $OpenBSD: multipubkey.sh,v 1.3 2019/12/11 18:47:14 djm Exp $
  2. # Placed in the Public Domain.
  3. tid="multiple pubkey"
  4. rm -f $OBJ/authorized_keys_$USER $OBJ/user_ca_key* $OBJ/user_key*
  5. rm -f $OBJ/authorized_principals_$USER $OBJ/cert_user_key*
  6. mv $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
  7. mv $OBJ/ssh_proxy $OBJ/ssh_proxy.orig
  8. # Create a CA key
  9. ${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_ca_key ||
  10. fatal "ssh-keygen failed"
  11. # Make some keys and a certificate.
  12. ${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_key1 ||
  13. fatal "ssh-keygen failed"
  14. ${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/user_key2 ||
  15. fatal "ssh-keygen failed"
  16. ${SSHKEYGEN} -q -s $OBJ/user_ca_key -I "regress user key for $USER" \
  17. -z $$ -n ${USER},mekmitasdigoat $OBJ/user_key1 ||
  18. fail "couldn't sign user_key1"
  19. # Copy the private key alongside the cert to allow better control of when
  20. # it is offered.
  21. mv $OBJ/user_key1-cert.pub $OBJ/cert_user_key1.pub
  22. cp -p $OBJ/user_key1 $OBJ/cert_user_key1
  23. grep -v IdentityFile $OBJ/ssh_proxy.orig > $OBJ/ssh_proxy
  24. opts="-oProtocol=2 -F $OBJ/ssh_proxy -oIdentitiesOnly=yes"
  25. opts="$opts -i $OBJ/cert_user_key1 -i $OBJ/user_key1 -i $OBJ/user_key2"
  26. for privsep in yes; do
  27. (
  28. grep -v "Protocol" $OBJ/sshd_proxy.orig
  29. echo "Protocol 2"
  30. echo "UsePrivilegeSeparation $privsep"
  31. echo "AuthenticationMethods publickey,publickey"
  32. echo "TrustedUserCAKeys $OBJ/user_ca_key.pub"
  33. echo "AuthorizedPrincipalsFile $OBJ/authorized_principals_%u"
  34. ) > $OBJ/sshd_proxy
  35. # Single key should fail.
  36. rm -f $OBJ/authorized_principals_$USER
  37. cat $OBJ/user_key1.pub > $OBJ/authorized_keys_$USER
  38. ${SSH} $opts proxy true && fail "ssh succeeded with key"
  39. # Single key with same-public cert should fail.
  40. echo mekmitasdigoat > $OBJ/authorized_principals_$USER
  41. cat $OBJ/user_key1.pub > $OBJ/authorized_keys_$USER
  42. ${SSH} $opts proxy true && fail "ssh succeeded with key+cert"
  43. # Multiple plain keys should succeed.
  44. rm -f $OBJ/authorized_principals_$USER
  45. cat $OBJ/user_key1.pub $OBJ/user_key2.pub > \
  46. $OBJ/authorized_keys_$USER
  47. ${SSH} $opts proxy true || fail "ssh failed with multiple keys"
  48. # Cert and different key should succeed
  49. # Key and different-public cert should succeed.
  50. echo mekmitasdigoat > $OBJ/authorized_principals_$USER
  51. cat $OBJ/user_key2.pub > $OBJ/authorized_keys_$USER
  52. ${SSH} $opts proxy true || fail "ssh failed with key/cert"
  53. done