icinga2/pki/icinga2-build-key.in

28 lines
720 B
Bash

#!/bin/bash
prefix=@prefix@
datarootdir=@datarootdir@
datadir=@datadir@
ICINGA2PKIDIR=$datadir/icinga2/pki
source $ICINGA2PKIDIR/pkifuncs
if [ -z "$1" ]; then
echo "Syntax: $0 <name>" >&2
exit 1
fi
name=$1
check_pki_dir
if [ ! -f $ICINGA_CA/ca.crt -o ! -f $ICINGA_CA/ca.key ]; then
echo "Please build a CA certificate first." >&2
exit 1
fi
CN_DEFAULT=$name KEY_DIR=$ICINGA_CA openssl req -config $ICINGA2PKIDIR/openssl.cnf -new -newkey rsa:4096 -keyform PEM -keyout $ICINGA_CA/$name.key -outform PEM -out $ICINGA_CA/$name.csr -nodes && \
openssl x509 -days 3650 -CA $ICINGA_CA/ca.crt -CAkey $ICINGA_CA/ca.key -req -in $ICINGA_CA/$name.csr -outform PEM -out $ICINGA_CA/$name.crt -CAserial $ICINGA_CA/serial