File: oci-root-ca-gen

package info (click to toggle)
openstack-cluster-installer 43.0.18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,484 kB
  • sloc: php: 19,127; sh: 18,142; ruby: 75; makefile: 31; xml: 8
file content (174 lines) | stat: -rwxr-xr-x 5,753 bytes parent folder | download | duplicates (3)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/sh

set -e
#set -x

PKI_CONFIG_ROOT=/etc/openstack-cluster-installer/pki

# This script was made using the tutorial available at:
# http://pki-tutorial.readthedocs.io/en/latest/expert/index.html
# This script is made to run in non-interactive mode, with
# no password on the keyboard what so ever.
# It will create this:
#
# -----------        ------------        ----------------
# | ROOT CA |   =>   | OCI CA 2 |   =>   | Server certs |
# -----------        ------------        ----------------
#
#
# To change names and so on, simply edit config files in
# the /etc/openstack-cluster-installer/pki folder.
#
# By default we have:
#
# [ ca_dn ]
# countryName             = "CH"
# organizationName        = "OCI"
# organizationalUnitName  = "OCI Root CA org"
# commonName              = "OCI Root CA"
#
# for the root ca, and for OCI CA 2:
#
# [ ca_dn ]
# countryName             = "CH"
# organizationName        = "OCI"
# organizationalUnitName  = "OCI CA 2 CA org"
# commonName              = "OCI CA 2 Root CA"
#
# In production, you'd typically replace ROOT CA and OCI CA
# by real PKI infrastructure keys (ie: you'd only genreate keys
# for the Component CA).

print_header() {
    if [ -n "$(set | grep xtrace)" ]; then
      set +x
      local enable_xtrace='yes'
    fi
    echo "===================================================================================================="
    echo $1
    echo "===================================================================================================="
    if [ -n "${enable_xtrace}" ]; then
      set -x
    fi
}

cd ${PKI_CONFIG_ROOT}
#print_header "0. Delete everything"
#rm -rf ca crl certs

print_header "1.1 create directories"
for i in ca/root-ca/private ca/root-ca/db crl certs ; do
	mkdir -p ${PKI_CONFIG_ROOT}/${i}
done

print_header "1.2 create database"
cp /dev/null ${PKI_CONFIG_ROOT}/ca/root-ca/db/root-ca.db
cp /dev/null ${PKI_CONFIG_ROOT}/ca/root-ca/db/root-ca.db.attr
echo 01 > ${PKI_CONFIG_ROOT}/ca/root-ca/db/root-ca.crt.srl
echo 01 > ${PKI_CONFIG_ROOT}/ca/root-ca/db/root-ca.crl.srl

print_header "1.3 Create CA request"
if ! [ -e ${PKI_CONFIG_ROOT}/ca/root-ca/private/root-ca.key ] ; then
	openssl req -new \
	    -nodes \
	    -config ${PKI_CONFIG_ROOT}/root-ca.conf \
	    -out ${PKI_CONFIG_ROOT}/ca/root-ca.csr \
	    -keyout ${PKI_CONFIG_ROOT}/ca/root-ca/private/root-ca.key
fi

print_header "1.4 Create CA certificate (self signed)"
if ! [ -e ${PKI_CONFIG_ROOT}/ca/root-ca.crt ] ; then
	(echo "y"; echo "y") | \
	openssl ca -selfsign \
	    -config ${PKI_CONFIG_ROOT}/root-ca.conf \
	    -in ${PKI_CONFIG_ROOT}/ca/root-ca.csr \
	    -out ${PKI_CONFIG_ROOT}/ca/root-ca.crt \
	    -extensions root_ca_ext \
	    -days 3650  \
	    -enddate 20301231235959Z \
	    -notext
fi

print_header "1.5 Create initial CRL"
if ! [ -e ${PKI_CONFIG_ROOT}/crl/root-ca.crl ] ; then
	openssl ca -gencrl \
	    -config ${PKI_CONFIG_ROOT}/root-ca.conf \
	    -out ${PKI_CONFIG_ROOT}/crl/root-ca.crl
fi

print_header "2. Create OCI CA"
print_header "2.1 Create directories"
mkdir -p ${PKI_CONFIG_ROOT}/ca/oci-ca/private ${PKI_CONFIG_ROOT}/ca/oci-ca/db
chmod 700 ${PKI_CONFIG_ROOT}/ca/oci-ca/private

print_header "2.2 Create database"
if ! [ -e ${PKI_CONFIG_ROOT}/ca/oci-ca/db/oci-ca.db ] ; then
	cp /dev/null ${PKI_CONFIG_ROOT}/ca/oci-ca/db/oci-ca.db
fi
if ! [ -e ${PKI_CONFIG_ROOT}/ca/oci-ca/db/oci-ca.db.attr ] ; then
	cp /dev/null ${PKI_CONFIG_ROOT}/ca/oci-ca/db/oci-ca.db.attr
fi
if ! [ -e ${PKI_CONFIG_ROOT}/ca/oci-ca/db/oci-ca.crt.srl ] ; then
	echo 01 > ${PKI_CONFIG_ROOT}/ca/oci-ca/db/oci-ca.crt.srl
fi
if ! [ -e ${PKI_CONFIG_ROOT}/ca/oci-ca/db/oci-ca.crl.srl ] ; then
	echo 01 > ${PKI_CONFIG_ROOT}/ca/oci-ca/db/oci-ca.crl.srl
fi

print_header "2.3 Create CA request"
if ! [ -e ${PKI_CONFIG_ROOT}/ca/oci-ca/private/oci-ca.key ] ; then
	openssl req -new \
	    -nodes \
	    -config ${PKI_CONFIG_ROOT}/oci-ca.conf \
	    -out ${PKI_CONFIG_ROOT}/ca/oci-ca.csr \
	    -keyout ${PKI_CONFIG_ROOT}/ca/oci-ca/private/oci-ca.key
fi

print_header "2.4 Create CA certificate (sign with root CA)"
if ! [ -e ${PKI_CONFIG_ROOT}/ca/oci-ca.crt ] ; then
	(echo "y"; echo "y") | \
	openssl ca \
	    -config ${PKI_CONFIG_ROOT}/root-ca.conf \
	    -in ${PKI_CONFIG_ROOT}/ca/oci-ca.csr \
	    -out ${PKI_CONFIG_ROOT}/ca/oci-ca.crt \
	    -enddate 20301231235959Z \
	    -notext
fi

#print_header "2.5 Create initial CRL"
#openssl ca -gencrl \
#    -config ${PKI_CONFIG_ROOT}/oci-ca.conf \
#    -out ${PKI_CONFIG_ROOT}/crl/oci-ca.crl

print_header "2.6 Create PEM bundle"
cat ${PKI_CONFIG_ROOT}/ca/root-ca.crt ${PKI_CONFIG_ROOT}/ca/oci-ca.crt \
    >${PKI_CONFIG_ROOT}/ca/oci-ca-chain.pem

print_header "7. Publish Certificates"
print_header "7.1 Create DER certificate"
if ! [ -e ${PKI_CONFIG_ROOT}/ca/root-ca.cer ] ; then
	openssl x509 \
	    -in ${PKI_CONFIG_ROOT}/ca/root-ca.crt \
	    -out ${PKI_CONFIG_ROOT}/ca/root-ca.cer \
	    -outform der
fi

#print_header "7.2 Create DER CRL"
#openssl crl \
#    -in ${PKI_CONFIG_ROOT}/crl/oci-ca.crl \
#    -out ${PKI_CONFIG_ROOT}/crl/oci-ca.crl \
#    -outform der

#########################
print_header "Copying ca certs to be copied to slave nodes"

# When provisionning servers, all of the certs in this folder will end up in
# the slave nodes in /etc/ssl/certs. So we just push our 3 CA's certs there.
CLIENT_KEYS_FOLDER=/var/lib/oci/ssl
mkdir -p ${CLIENT_KEYS_FOLDER}/ca
cp ${PKI_CONFIG_ROOT}/ca/root-ca.crt ${CLIENT_KEYS_FOLDER}/ca/oci-pki-root-ca.pem
cp ${PKI_CONFIG_ROOT}/ca/oci-ca.crt ${CLIENT_KEYS_FOLDER}/ca/oci-pki-oci-ca.pem
cp ${PKI_CONFIG_ROOT}/ca/oci-ca-chain.pem ${CLIENT_KEYS_FOLDER}/ca/oci-pki-oci-ca-chain.pem
chown -R www-data:www-data ${CLIENT_KEYS_FOLDER}/ca
chgrp www-data /var/lib/oci
chgrp www-data /var/lib/oci/ssl