Debian Codegraph @

contrib/scripts/astgenkey

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
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 oldumask="`umask`"
51 umask 0077
52 openssl genrsa -out ${KEY}.key ${DES3} 1024
•53 [ "$(id -u)" = 0 ] && chown asterisk: ${KEY}.key
54 umask $oldumask
55 openssl rsa -in ${KEY}.key -pubout -out ${KEY}.pub
56
57 if [ -f "${KEY}.key" ] && [ -f "${KEY}.pub" ]; then
58 if [ "$QUIET" != 'y' ]; then
59 echo "Key creation successful."
60 echo "Public key: ${KEY}.pub"
61 echo "Private key: ${KEY}.key"
62 fi
63 else
64 echo "Unknown error creating keys."
65 fi