astgenkey 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. #
  3. # Usage: astgenkey [ -q ] [keyname]
  4. #
  5. if [ "$1" = "-q" ]; then
  6. QUIET='y'
  7. KEY=$2
  8. else
  9. KEY=$1
  10. fi
  11. if [ "$QUIET" != 'y' ]; then
  12. echo ""
  13. echo "This script generates an RSA private and public key pair"
  14. echo "in PEM format for use by Asterisk. You will be asked to"
  15. echo "enter a passcode for your key multiple times. Please"
  16. echo "enter the same code each time. The resulting files will"
  17. echo "need to be moved to /var/lib/asterisk/keys if you want"
  18. echo "to use them, and any private keys (.key files) will"
  19. echo "need to be initialized at runtime either by running"
  20. echo "Asterisk with the '-i' option, or with the 'init keys'"
  21. echo "command once Asterisk is running."
  22. echo ""
  23. echo "Press ENTER to continue or ^C to cancel."
  24. read BLAH
  25. fi
  26. while [ "$KEY" = "" ]; do
  27. echo -n "Enter key name: "
  28. read KEY
  29. done
  30. rm -f ${KEY}.key ${KEY}.pub
  31. echo "Generating SSL key '$KEY': "
  32. openssl genrsa -out ${KEY}.key -des3 1024
  33. openssl rsa -in ${KEY}.key -pubout -out ${KEY}.pub
  34. if [ -f "${KEY}.key" ] && [ -f "${KEY}.pub" ]; then
  35. if [ "$QUIET" != 'y' ]; then
  36. echo "Key creation successful."
  37. echo "Public key: ${KEY}.pub"
  38. echo "Private key: ${KEY}.key"
  39. fi
  40. else
  41. echo "Unknown error creating keys."
  42. fi