make-client-certs.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. #
  3. # make-client-certs.sh - creates the client certs for registering with Mumble
  4. #
  5. # Usage:
  6. #
  7. # make-client-certs.sh <username>
  8. #
  9. # make-client-certs.sh <userprefix> <count>
  10. #
  11. # Notes:
  12. #
  13. # * The certs are self-signed and are not passphrase protected. Depending on
  14. # the target environment and usage, this may or may not be OK. If you need
  15. # a passphrase, you'll need to hack Mumlib.
  16. #
  17. # * The names are hard-coded in mumsi to match <username>-key.pem and
  18. # <username>-cert.pem. This is done to make it easier to configure multi-line
  19. # functionality.
  20. #
  21. # * When generating files for a series of users, the counter is appended to the
  22. # user name, from '0' to one less than the COUNT.
  23. function usage {
  24. cat <<EOF
  25. Usage:
  26. $0 username
  27. $0 user-prefix count
  28. EOF
  29. exit 1
  30. }
  31. USER="$1"
  32. COUNT="$2"
  33. # In this 'format', the %s is replaced with the user name generated in
  34. # the for loop.
  35. SUBJFMT="/C=DE/ST=HE/L=Ffm/O=Mumble Ext./CN=%s"
  36. if [ -z "$USER" ]; then
  37. usage
  38. fi
  39. if [ -n "$3" ]; then
  40. usage
  41. fi
  42. if [ -z "$COUNT" ]; then
  43. COUNT=1
  44. fi
  45. for ((i=0; i<$COUNT; i++)) {
  46. prefix="${USER}${i}"
  47. subj=$(printf "$SUBJFMT" $prefix)
  48. openssl req \
  49. -nodes \
  50. -new \
  51. -x509 \
  52. -keyout ${prefix}-key.pem \
  53. -out ${prefix}-cert.pem \
  54. -subj "$subj"
  55. }