Magellan Linux

Contents of /mcore-src/trunk/mcore-tools/src/generate-certificate.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2746 - (show annotations) (download)
Fri Jan 29 08:44:06 2016 UTC (8 years, 3 months ago) by niro
File size: 1039 byte(s)
-fixed certificate name
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 [ -f ${KEYFILE} ] && die "${KEYFILE} already exists, won't overwrite!"
29
30 openssl req -new -x509 -nodes -config ${SSLCONFIG} -out ${CERTFILE} -keyout ${KEYFILE} -days 365 || die "Certificate request failed!"
31 openssl x509 -subject -fingerprint -noout -in ${CERTFILE} || die "Fingerprint failed!"