astgenkey 1.4 KB

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