bin/make-ca-key, lib/func.sh: Make user and group names configurable.
[ca] / bin / make-ca-key
CommitLineData
b294f6b5
MW
1#! /bin/sh
2
3set -e
4certroot=$(cd ${0%/*}/..; pwd)
5cd "$certroot"
ab54a4bc 6. lib/func.sh
b294f6b5
MW
7umask 022
8
9## Archive any existing CA.
10if [ -f ca.cert ]; then
11 mkdir -p archive
12 if [ -f archive/state/serial ]; then
13 next=$(cat archive/state/serial)
14 else
15 mkdir -p archive/state
16 next=1
17 fi
18 mkdir archive/"$next"
19 mv ca.cert certs crls index private state archive/"$next"/
20 expr "$next" + 1 >archive/state/serial.new
21 mv archive/state/serial.new archive/state/serial
22fi
23
24## Clear out the old CA completely.
25rm -rf certs index private tmp state
26rm -f ca.cert distorted.crl
27
28## Build a new one.
29mkdir -m750 private
30mkdir -m775 certs crls index index/byhash index/byserial state tmp
ab54a4bc 31chown $ca_owner:$ca_group certs crls index index/byhash index/byserial private state tmp
b294f6b5
MW
32touch state/db
33echo 01 >state/serial
34echo 01 >state/crlnumber
35
36## Set the CA subject name. It won't fit on one line, and there's no
37## good way of continuing it. Have fun parsing the sed.
0208298d 38subject=$(sed -n 's:^:/:;1h;2,$H;${x;s/\n//g;p;}' <etc/issuer)
b294f6b5
MW
39
40## Build the new CA key and certificate.
41umask 027
42openssl req -new -config openssl.conf -x509 -days 3650 \
43 -out ca.cert -keyout private/ca.key \
44 -subj "$subject"
ab54a4bc 45chown $ca_owner:$ca_group private/ca.key
b294f6b5 46chmod 644 ca.cert