Contents of /mcore-src/trunk/mcore-tools/src/generate-certificate.in
Parent Directory | Revision Log
Revision 2808 -
(show annotations)
(download)
Mon Apr 3 17:00:40 2017 UTC (7 years, 5 months ago) by niro
File size: 1137 byte(s)
Mon Apr 3 17:00:40 2017 UTC (7 years, 5 months ago) by niro
File size: 1137 byte(s)
-honor existing ssl keys
1 | #!/bin/bash |
2 | |
3 | die() { echo "Error: $@"; exit 1; } |
4 | |
5 | usage() |
6 | { |
7 | echo "Usage:" |
8 | echo " $0" |
9 | echo |
10 | echo "The environment variables \$SSLCONFIG and \$SSLDIR will be respected too." |
11 | echo |
12 | die "No certificate name given!" |
13 | } |
14 | |
15 | SSLDIR="${SSLDIR-@@SSLDIR@@}" |
16 | SSLCONFIG="${SSLCONFIG-${SSLDIR}/openssl.cnf}" |
17 | CERTDIR="${SSLDIR}/certs" |
18 | KEYDIR="${SSLDIR}/private" |
19 | CERTNAME="mcored" |
20 | CERTFILE="${CERTDIR}/${CERTNAME}.pem" |
21 | KEYFILE="${KEYDIR}/${CERTNAME}.key" |
22 | |
23 | type -P openssl > /dev/null || die "openssl not found!" |
24 | [[ $(id -u) -ne 0 ]] && die "You must be root!" |
25 | [ ! -d ${CERTDIR} ] && die "${CERTDIR} directory doesn't exist!" |
26 | [ ! -d ${KEYDIR} ] && die "${KEYDIR} directory doesn't exist!" |
27 | [ -f ${CERTFILE} ] && die "${CERTFILE} already exists, won't overwrite!" |
28 | if [ -f ${KEYFILE} ] |
29 | then |
30 | echo "Using existing KEYFILE '${KEYFILE}'" |
31 | KEYOPT="-key" |
32 | else |
33 | echo "Creating a new KEYFILE '${KEYFILE}'" |
34 | KEYOPT="-keyout" |
35 | fi |
36 | |
37 | openssl req -new -x509 -sha1 -nodes -config ${SSLCONFIG} -out ${CERTFILE} ${KEYOPT} ${KEYFILE} -days 365 || die "Certificate request failed!" |
38 | openssl x509 -sha1 -subject -fingerprint -noout -in ${CERTFILE} || die "Fingerprint failed!" |