#!/bin/bash -e profile_ca=(-t CT,C,C -v 120) profile_server=(-t ,, -v 12) crl_path=${crl_path-$(readlink -f $dbdir)} gen_cert() { local profile="$1" nick="$2" subject="$3" ca options pwfile noise csr crt shift 3 echo "gen_cert(profile=$profile nick=$nick subject=$subject)" ca="$(dirname $nick)" if [ "$ca" = "." ]; then ca="$nick" fi eval "options=(\"\${profile_$profile[@]}\")" if [ "$ca" = "$nick" ]; then options=("${options[@]}" -x -m 1) else options=("${options[@]}" -c "$ca") fi pwfile="$(mktemp)" echo "$dbpassword" >"$pwfile" noise="$(mktemp)" head -c 20 /dev/urandom >"$noise" if [ ! -d "$dbdir" ]; then mkdir "$dbdir" certutil -N -d "$dbdir" -f "$pwfile" fi csr="$(mktemp)" crt="$(mktemp)" certutil -R -d "$dbdir" -s "$subject" -f "$pwfile" -z "$noise" -o "$csr" -4 >/dev/null <"$pwfile" if ! crlutil -L -d "$dbdir" -n "$ca" &>/dev/null; then crlutil -G -d "$dbdir" -n "$ca" -c /dev/null -f "$pwfile" fi sleep 1 mkdir -p "$(dirname $dbdir/$ca.crl)" serial=$(certutil -L -d "$dbdir" -n "$nick" | awk '/^\s+Serial Number: / { print $3 }') crlutil -M -d "$dbdir" -n "$ca" -c /dev/stdin -f "$pwfile" -o "$dbdir/$ca.crl" <