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