bin/make-ca-key, lib/func.sh: Make user and group names configurable.
[ca] / bin / make-cert
CommitLineData
b294f6b5
MW
1#! /bin/sh
2
3set -e
4certroot=$(cd ${0%/*}/..; pwd)
5. "$certroot"/lib/func.sh
6runas_ca "$@"
7
8## Parse the command line.
9case "$#" in
10 3) ;;
11 *) echo >&2 "Usage: $0 TAG PROFILE FILE"; exit 1 ;;
12esac
13tag=$1 profile=$2 file=$3
14
15## Make sure we're not overwriting anything. Put sequence numbers
16## into labels to prevent bad things from happening.
17if [ -f "$certroot"/certs/"$tag".cert ]; then
18 echo >&2 "$0: certificate $tag already exists"
19 exit 1
20fi
21
22## Make a temporary copy of the certificate. This prevents a race, and
23## more importantly lets us change directory.
24cp "$file" "$certroot"/tmp/"$tag".req
25cd "$certroot"
26
27## Make the certificate.
28openssl ca -config openssl.conf -extensions $profile-extensions \
29 -in tmp/"$tag".req -out tmp/"$tag".cert
30
31## Install a hash link the benefit of OpenSSL's `verify' command and
32## similar, and install the completed request and certificate in the
33## archive.
34mv tmp/"$tag".req tmp/"$tag".cert certs/
35linkserial certs/"$tag".cert
36linkhash certs/"$tag".cert
37rm tmp/*.pem
38
39## Output the certificate.
40openssl x509 -in certs/"$tag".cert