sip_to_pjsip.py: Fix comment typo and tabs.
[asterisk/asterisk.git] / contrib / scripts / astgenkey
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
26 if [ "$QUIET" != 'y' ]; then
27         echo ""
28         echo "This script generates an RSA private and public key pair"
29         echo "in PEM format for use by Asterisk.  You will be asked to"
30         echo "enter a passcode for your key multiple times.  Please"
31         echo "enter the same code each time.  The resulting files will"
32         echo "need to be moved to /var/lib/asterisk/keys if you want"
33         echo "to use them, and any private keys (.key files) will"
34         echo "need to be initialized at runtime either by running"
35         echo "Asterisk with the '-i' option, or with the 'keys init'"
36         echo "command once Asterisk is running."
37         echo ""
38         echo "Press ENTER to continue or ^C to cancel."
39         read BLAH
40 fi
41
42 while [ "$KEY" = "" ]; do
43         echo -n "Enter key name: "
44         read KEY
45 done
46
47 rm -f ${KEY}.key ${KEY}.pub
48
49 echo "Generating SSL key '$KEY': "
50 openssl genrsa -out ${KEY}.key ${DES3} 1024
51 openssl rsa -in ${KEY}.key -pubout -out ${KEY}.pub
52
53 if [ -f "${KEY}.key" ] && [ -f "${KEY}.pub" ]; then
54         if [ "$QUIET" != 'y' ]; then
55                 echo "Key creation successful."
56                 echo "Public key:  ${KEY}.pub"
57                 echo "Private key: ${KEY}.key"
58         fi
59 else
60         echo "Unknown error creating keys."
61 fi