-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path1-create-certificates.sh
executable file
·284 lines (241 loc) · 9.61 KB
/
1-create-certificates.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/bin/bash
set -euo pipefail
BASEDIR=$(dirname "$0")
#######################################################
# GENERATE ROOT CA CERTIFICATES for Backend Service 1 #
#######################################################
# Generate the root CA private key
openssl genrsa -out $BASEDIR/certs/rootCA-service-1.key 2048
# Create and self sign the root CA public key
openssl req -x509 -new -nodes \
-key $BASEDIR/certs/rootCA-service-1.key \
-sha256 \
-days 365 \
-subj "/C=US/ST=Washington/L=Seattle/O=Root CA Inc./OU=CA" \
-out $BASEDIR/certs/rootCA-service-1.crt
#######################################################
# GENERATE ROOT CA CERTIFICATES for Backend Service 2 #
#######################################################
# Generate the root CA private key
openssl genrsa -out $BASEDIR/certs/rootCA-service-2.key 2048
# Create and self sign the root CA public key
openssl req -x509 -new -nodes \
-key $BASEDIR/certs/rootCA-service-2.key \
-sha256 \
-days 365 \
-subj "/C=US/ST=Ohio/L=Columbus/O=Root CA Inc./OU=CA" \
-out $BASEDIR/certs/rootCA-service-2.crt
###########################################
# GENERATE BACKEND SERVICE 1 CERTIFICATES #
###########################################
# Create the backend service 1 private key
openssl genrsa -out $BASEDIR/certs/backend_service_1.key 2048
# Create the backend service 1 signing request
openssl req -new -sha256 \
-key $BASEDIR/certs/backend_service_1.key \
-subj "/C=US/ST=Washington/L=Seattle/O=The Cloud Company/OU=Backend Service 1/CN=backend-service-1.com" \
-out $BASEDIR/certs/backend_service_1.csr
# Create the backend service 1 sign public key, by signing the backend service 1 signing request with the root CA private and public key
openssl x509 -req \
-in $BASEDIR/certs/backend_service_1.csr \
-days 365 -sha256 \
-CA $BASEDIR/certs/rootCA-service-1.crt \
-CAkey $BASEDIR/certs/rootCA-service-1.key \
-CAserial $BASEDIR/certs/rootCA-service-1.srl \
-CAcreateserial \
-out $BASEDIR/certs/backend_service_1.crt
###########################################
# GENERATE BACKEND SERVICE 2 CERTIFICATES #
###########################################
# Create the backend service 2 private key
openssl genrsa -out $BASEDIR/certs/backend_service_2.key 2048
# Create the backend service 2 signing request
openssl req -new -sha256 \
-key $BASEDIR/certs/backend_service_2.key \
-subj "/C=US/ST=Ohio/L=Columbus/O=The Cloud Company/OU=Backend Service 2/CN=backend-service-2.com" \
-out $BASEDIR/certs/backend_service_2.csr
# Create the backend service 2 sign public key, by signing the backend service 2 signing request with the root CA private and public key
openssl x509 -req \
-in $BASEDIR/certs/backend_service_2.csr \
-days 365 -sha256 \
-CA $BASEDIR/certs/rootCA-service-2.crt \
-CAkey $BASEDIR/certs/rootCA-service-2.key \
-CAserial $BASEDIR/certs/rootCA-service-2.srl \
-CAcreateserial \
-out $BASEDIR/certs/backend_service_2.crt
################################
# GENERATE LAMBDA CERTIFICATES #
################################
# Generate the lambda truststore and import the rootCA-service-1 public key
keytool -importcert \
-keystore $BASEDIR/certs/client_truststore.jks \
-storetype JKS \
-file $BASEDIR/certs/rootCA-service-1.crt \
-keypass secret \
-storepass secret \
-alias rootCA-service-1 \
-noprompt
keytool -importcert \
-keystore $BASEDIR/certs/client_truststore.jks \
-storetype JKS \
-file $BASEDIR/certs/rootCA-service-2.crt \
-keypass secret \
-storepass secret \
-alias rootCA-service-2 \
-noprompt
# Import the signed backend service 1 public key into the lambda truststore
keytool -importcert \
-keystore $BASEDIR/certs/client_truststore.jks \
-alias backend_service_1 \
-file $BASEDIR/certs/backend_service_1.crt \
-keypass secret \
-storepass secret \
-noprompt
# Import the signed backend service 2 public key into the lambda truststore
keytool -importcert \
-keystore $BASEDIR/certs/client_truststore.jks \
-alias backend_service_2 \
-file $BASEDIR/certs/backend_service_2.crt \
-keypass secret \
-storepass secret \
-noprompt
# verify the lambda truststore
#keytool -list \
# -keystore $BASEDIR/certs/client_truststore.jks \
# -storepass secret \
# -v
# Generate the lambda keystore for backend service 1 which contains the rootCA-service-1 certificate
keytool -genkeypair \
-keyalg RSA \
-sigalg SHA256withRSA \
-alias lambda \
-keystore $BASEDIR/certs/client_keystore_1.jks \
-storepass secret \
-keypass secret \
-validity 365 \
-keysize 2048 \
-dname "CN=Lambda for Backend Service 1, OU=S-Team, O=The Cloud Company, L=Seattle, S=Washington, C=US"
# Create a signing request for the client keystore backend service 1
keytool -certreq \
-keystore $BASEDIR/certs/client_keystore_1.jks \
-sigalg SHA256withRSA \
-alias lambda \
-file $BASEDIR/certs/client_1.csr \
-keypass secret \
-storepass secret
# Check the certificate request
#openssl req -text -noout \
# -in $BASEDIR/certs/client_1.csr \
# -verify
# Sign the signing request with the root CA keys
openssl x509 -req \
-CA $BASEDIR/certs/rootCA-service-1.crt \
-CAkey $BASEDIR/certs/rootCA-service-1.key \
-in $BASEDIR/certs/client_1.csr \
-out $BASEDIR/certs/client_1.crt \
-sha256 \
-days 365 \
-CAcreateserial \
-CAserial $BASEDIR/certs/client_1.srl \
# Check the public key
#openssl x509 -noout -text \
# -in client_1.crt
# Import the rootCA-service-1 public key to the client keystore for backend service 1
keytool -importcert \
-keystore $BASEDIR/certs/client_keystore_1.jks \
-storetype JKS \
-file $BASEDIR/certs/rootCA-service-1.crt \
-keypass secret \
-storepass secret \
-alias rootCA-service-1 \
-noprompt
# Import the signed client public key into the lambda keystore for backend service 1
keytool -importcert \
-keystore $BASEDIR/certs/client_keystore_1.jks \
-alias lambda \
-file $BASEDIR/certs/client_1.crt \
-keypass secret \
-storepass secret \
-trustcacerts \
-noprompt
# verify the client keystore for backend service 1
#keytool -list \
# -keystore $BASEDIR/certs/client_keystore_1.jks \
# -storepass secret \
# -v
# Generate the lambda keystore for backend service 2 which contains the rootCA-service-2 certificate
keytool -genkeypair \
-keyalg RSA \
-sigalg SHA256withRSA \
-alias lambda \
-keystore $BASEDIR/certs/client_keystore_2.jks \
-storepass secret \
-keypass secret \
-validity 365 \
-keysize 2048 \
-dname "CN=Lambda for Backend Service 2, OU=S-Team, O=The Cloud Company, L=Columbus, S=Ohio, C=US"
# Create s signing request for the client keystore backend service 2
keytool -certreq \
-keystore $BASEDIR/certs/client_keystore_2.jks \
-sigalg SHA256withRSA \
-alias lambda \
-file $BASEDIR/certs/client_2.csr \
-keypass secret \
-storepass secret
# Check the certificate request
#openssl req -text -noout \
# -in $BASEDIR/certs/client_2.csr \
# -verify
# Sign the signing request with the root CA keys
openssl x509 -req \
-CA $BASEDIR/certs/rootCA-service-2.crt \
-CAkey $BASEDIR/certs/rootCA-service-2.key \
-in $BASEDIR/certs/client_2.csr \
-out $BASEDIR/certs/client_2.crt \
-sha256 \
-days 365 \
-CAcreateserial \
-CAserial $BASEDIR/certs/client_2.srl \
# Check the public key
#openssl x509 -noout -text \
# -in client_2.crt
# Import the rootCA-service-2 public key to the client keystore for backend service 2
keytool -importcert \
-keystore $BASEDIR/certs/client_keystore_2.jks \
-storetype JKS \
-file $BASEDIR/certs/rootCA-service-2.crt \
-keypass secret \
-storepass secret \
-alias rootCA-service-2 \
-noprompt
# Import the signed client public key into the lambda keystore for backend service 2
keytool -importcert \
-keystore $BASEDIR/certs/client_keystore_2.jks \
-alias lambda \
-file $BASEDIR/certs/client_2.crt \
-keypass secret \
-storepass secret \
-trustcacerts \
-noprompt
# verify the client keystore for backend service 2
#keytool -list \
# -keystore $BASEDIR/certs/client_keystore_2.jks \
# -storepass secret \
# -v
# Copy the backend_service_1.crt, backend_service_1.key and rootCA-service-1.crt into the backend service 1 module
cp $BASEDIR/certs/backend_service_1.crt $BASEDIR/../software/backend-service-1/conf.d/certs/
cp $BASEDIR/certs/backend_service_1.key $BASEDIR/../software/backend-service-1/conf.d/certs/
cp $BASEDIR/certs/rootCA-service-1.crt $BASEDIR/../software/backend-service-1/conf.d/certs/
# Copy the backend_service_2.crt, backend_service_2.key and rootCA-service-2.crt into the backend service 2 module
cp $BASEDIR/certs/backend_service_2.crt $BASEDIR/../software/backend-service-2/conf.d/certs/
cp $BASEDIR/certs/backend_service_2.key $BASEDIR/../software/backend-service-2/conf.d/certs/
cp $BASEDIR/certs/rootCA-service-2.crt $BASEDIR/../software/backend-service-2/conf.d/certs/
# Copy the client_keystore_1.jks and client_truststore.jks into the lambda-only module
cp $BASEDIR/certs/client_keystore_1.jks $BASEDIR/../software/1-lambda-only/src/main/resources/
cp $BASEDIR/certs/client_truststore.jks $BASEDIR/../software/1-lambda-only/src/main/resources/
# Copy the client_keystore_1.jks and client_truststore.jks into the lambda-layer-service-1-cert module
cp $BASEDIR/certs/client_keystore_1.jks $BASEDIR/../software/lambda-layer-service-1-cert/src/main/resources/
cp $BASEDIR/certs/client_truststore.jks $BASEDIR/../software/lambda-layer-service-1-cert/src/main/resources/
# Copy the client_keystore_2.jks and client_truststore.jks into the lambda-layer-service-2-cert module
cp $BASEDIR/certs/client_keystore_2.jks $BASEDIR/../software/lambda-layer-service-2-cert/src/main/resources/
cp $BASEDIR/certs/client_truststore.jks $BASEDIR/../software/lambda-layer-service-2-cert/src/main/resources/