File: astgenkey

package info (click to toggle)
asterisk 1:1.6.2.9-2+squeeze12
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 67,296 kB
  • ctags: 65,026
  • sloc: ansic: 327,660; sh: 11,153; cpp: 5,940; perl: 3,078; makefile: 2,594; yacc: 2,140; asm: 642; xml: 309; sql: 290; tcl: 113; php: 62
file content (65 lines) | stat: -rw-r--r-- 1,495 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
#
# Usage: astgenkey [ -q ] [ -n ] [keyname]
#
DES3=-des3
if [ "$1" = "-q" ]; then
	QUIET='y'
	if [ "$2" = "-n" ]; then
		DES3=
		KEY=$3
	else
		KEY=$2
	fi
elif [ "$1" = "-n" ]; then
	DES3=
	if [ "$2" = "-q" ]; then
		QUIET='y'
		KEY=$3
	else
		KEY=$2
	fi
else
	KEY=$1
fi

if [ "$QUIET" != 'y' ]; then
	echo ""
	echo "This script generates an RSA private and public key pair"
	echo "in PEM format for use by Asterisk.  You will be asked to"
	echo "enter a passcode for your key multiple times.  Please"
	echo "enter the same code each time.  The resulting files will"
	echo "need to be moved to /var/lib/asterisk/keys if you want"
	echo "to use them, and any private keys (.key files) will"
	echo "need to be initialized at runtime either by running"
	echo "Asterisk with the '-i' option, or with the 'init keys'"
	echo "command once Asterisk is running."
	echo ""
	echo "Press ENTER to continue or ^C to cancel."
	read BLAH
fi

while [ "$KEY" = "" ]; do
	echo -n "Enter key name: "
	read KEY
done

rm -f ${KEY}.key ${KEY}.pub

echo "Generating SSL key '$KEY': "
oldumask="`umask`"
umask 0077
openssl genrsa -out ${KEY}.key ${DES3} 1024
[ "$(id -u)" = 0 ] && chown asterisk: ${KEY}.key
umask $oldumask
openssl rsa -in ${KEY}.key -pubout -out ${KEY}.pub

if [ -f "${KEY}.key" ] && [ -f "${KEY}.pub" ]; then
	if [ "$QUIET" != 'y' ]; then
		echo "Key creation successful."
		echo "Public key:  ${KEY}.pub"
		echo "Private key: ${KEY}.key"
	fi
else
	echo "Unknown error creating keys."
fi