-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcreate-pki.sh
executable file
·124 lines (97 loc) · 2.4 KB
/
create-pki.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
set -x
set -e
CONFIG_DIR="${1:-.}"
# check prerequisites
if [ ! -f "${CONFIG_DIR}/root-ca.conf" ] ; then
echo "error: missing ${CONFIG_DIR}/root-ca.conf"
exit 1
fi
if [ ! -f "${CONFIG_DIR}/signing-ca.conf" ] ; then
echo "error: missing ${CONFIG_DIR}/signing-ca.conf"
exit 1
fi
if [ ! -f "${CONFIG_DIR}/alice.conf" ] ; then
echo "error: missing ${CONFIG_DIR}/alice.conf"
exit 1
fi
which openssl
if [ "0" -ne "$?" ] ; then
echo "error: openssl needed"
exit 1
fi
# clean up (previously generated files)
rm -rf self-signed
rm -rf ca
rm -rf crl
rm -rf certs
rm -f keyring.pem
# create self signed certificate (and key)
mkdir self-signed
openssl req -x509 \
-newkey rsa:4096 \
-keyout self-signed/key.pem \
-out self-signed/cert.pem \
-days 365 \
-nodes \
-batch
# create Root CA
mkdir -p ca/root-ca/private
mkdir -p ca/root-ca/db
mkdir -p crl
mkdir -p certs
chmod 700 ca/root-ca/private
cp /dev/null ca/root-ca/db/root-ca.db
cp /dev/null ca/root-ca/db/root-ca.db.attr
echo 01 > ca/root-ca/db/root-ca.crt.srl
echo 01 > ca/root-ca/db/root-ca.crl.srl
openssl req -new \
-nodes \
-config ${CONFIG_DIR}/root-ca.conf \
-out ca/root-ca.csr \
-keyout ca/root-ca/private/root-ca.key
openssl ca -selfsign \
-config ${CONFIG_DIR}/root-ca.conf \
-in ca/root-ca.csr \
-out ca/root-ca.crt \
-extensions root_ca_ext \
-batch
# create signing CA
mkdir -p ca/signing-ca/private
mkdir -p ca/signing-ca/db
mkdir -p crl
mkdir -p certs
chmod 700 ca/signing-ca/private
cp /dev/null ca/signing-ca/db/signing-ca.db
cp /dev/null ca/signing-ca/db/signing-ca.db.attr
echo 01 > ca/signing-ca/db/signing-ca.crt.srl
echo 01 > ca/signing-ca/db/signing-ca.crl.srl
openssl req -new \
-nodes \
-config ${CONFIG_DIR}/signing-ca.conf \
-out ca/signing-ca.csr \
-keyout ca/signing-ca/private/signing-ca.key \
-batch
openssl ca \
-config ${CONFIG_DIR}/root-ca.conf \
-in ca/signing-ca.csr \
-out ca/signing-ca.crt \
-extensions signing_ca_ext \
-batch
# create certificate and key for Alice
openssl req -new \
-nodes \
-config ${CONFIG_DIR}/alice.conf \
-out certs/alice.csr \
-keyout certs/alice.key \
-batch
openssl ca \
-config ${CONFIG_DIR}/signing-ca.conf \
-in certs/alice.csr \
-out certs/alice.crt \
-extensions email_ext \
-batch
# create key ring
cat ca/root-ca.crt \
ca/signing-ca.crt \
> keyring.pem