Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1248 - (hide annotations) (download) (as text)
Wed Feb 2 20:20:24 2011 UTC (13 years, 3 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/generate-certificate.sh
File MIME type: application/x-sh
File size: 1082 byte(s)
-initial version
1 niro 1248 #!/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     which openssl $> /dev/null || die "openssl not found!"
16     [[ $(id -u) -ne 0 ]] && die "You must be root!"
17     [ ! -d ${CERTDIR} ] && die "${CERTDIR} directory doesn't exist!"
18     [ ! -d ${KEYDIR} ] && die "${KEYDIR} directory doesn't exist!"
19     [ -f ${CERTFILE} ] && die "${CERTFILE} already exists, won't overwrite!"
20     [ -f ${KEYFILE} ] && die "${KEYFILE} already exists, won't overwrite!"
21    
22     SSLDIR="${SSLDIR-/etc/ssl}"
23     SSLCONFIG="${SSLCONFIG-${SSLDIR}/openssl.cnf}"
24     CERTDIR="${SSLDIR}/certs"
25     KEYDIR="${SSLDIR}/private"
26     CERTNAME="mcore"
27     CERTFILE="${CERTDIR}/${CERTNAME}.pem"
28     KEYFILE="${KEYDIR}/${CERTNAME}.key"
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!"