forked from IBM/GameOn-Java-Microservices-on-Kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-keystore.sh
executable file
·148 lines (140 loc) · 3.9 KB
/
gen-keystore.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
#!/bin/bash
# Generate keystores in ./keystore for a given IP
if (( $# != 1))
then
echo "Usage: ./gen-keystore.sh <IP>"
exit 1
fi
IP=$1
if [ -z ${JAVA_HOME} ]
then
echo "JAVA_HOME is not set. Please set and re-run this script."
exit 1
fi
echo "Checking for keytool..."
keytool -help > /dev/null 2>&1
if [ $? != 0 ]
then
echo "Error: keytool is missing from the path, please correct this, then retry"
exit 1
fi
echo "Checking for openssl..."
openssl version > /dev/null 2>&1
if [ $? != 0 ]
then
echo "Error: openssl is missing from the path, please correct this, then retry"
exit 1
fi
echo "Generating key stores using ${IP}"
#create a ca cert we'll import into all our trust stores..
keytool -genkeypair \
-alias gameonca \
-keypass gameonca \
-storepass gameonca \
-keystore keystore/cakey.jks \
-keyalg RSA \
-keysize 2048 \
-dname "CN=GameOnLocalDevCA, OU=The Amazing GameOn Certificate Authority, O=The Ficticious GameOn Company, L=Earth, ST=Happy, C=CA" \
-ext KeyUsage="keyCertSign" \
-ext BasicConstraints:"critical=ca:true" \
-validity 9999
#export the ca cert so we can add it to the trust stores
keytool -exportcert \
-alias gameonca \
-keypass gameonca \
-storepass gameonca \
-keystore keystore/cakey.jks \
-file keystore/gameonca.crt \
-rfc
#create the keypair we plan to use for our ssl/jwt signing
keytool -genkeypair \
-alias gameonappkey \
-keypass testOnlyKeystore \
-storepass testOnlyKeystore \
-keystore keystore/key.jks \
-keyalg RSA \
-sigalg SHA1withRSA \
-dname "CN=${IP},OU=GameOn Application,O=The Ficticious GameOn Company,L=Earth,ST=Happy,C=CA" \
-validity 365
#create the signing request for the app key
keytool -certreq \
-alias gameonappkey \
-keypass testOnlyKeystore \
-storepass testOnlyKeystore \
-keystore keystore/key.jks \
-file keystore/appsignreq.csr
#sign the cert with the ca
keytool -gencert \
-alias gameonca \
-keypass gameonca \
-storepass gameonca \
-keystore keystore/cakey.jks \
-infile keystore/appsignreq.csr \
-outfile keystore/app.cer
#import the ca cert
keytool -importcert \
-alias gameonca \
-storepass testOnlyKeystore \
-keypass testOnlyKeystore \
-keystore keystore/key.jks \
-noprompt \
-file keystore/gameonca.crt
#import the signed cert
keytool -importcert \
-alias gameonappkey \
-storepass testOnlyKeystore \
-keypass testOnlyKeystore \
-keystore keystore/key.jks \
-noprompt \
-file keystore/app.cer
#change the alias of the signed cert
keytool -changealias \
-alias gameonappkey \
-destalias default \
-storepass testOnlyKeystore \
-keypass testOnlyKeystore \
-keystore keystore/key.jks
#export the signed cert in pem format for proxy to use
keytool -exportcert \
-alias default \
-storepass testOnlyKeystore \
-keypass testOnlyKeystore \
-keystore keystore/key.jks \
-file keystore/app.pem \
-rfc
#export the private key in pem format for proxy to use
keytool -importkeystore \
-srckeystore keystore/key.jks \
-destkeystore keystore/key.p12 \
-srcstoretype jks \
-deststoretype pkcs12 \
-srcstorepass testOnlyKeystore \
-deststorepass testOnlyKeystore \
-srckeypass testOnlyKeystore \
-destkeypass testOnlyKeystore \
-srcalias default
openssl pkcs12 \
-in keystore/key.p12 \
-out keystore/private.pem \
-nocerts \
-nodes \
-password pass:testOnlyKeystore
#concat the public and private key for haproxy
cat keystore/app.pem keystore/private.pem > keystore/proxy.pem
#add the cacert to the truststore
keytool -importcert \
-alias gameonca \
-storepass truststore \
-keypass truststore \
-keystore keystore/truststore.jks \
-noprompt \
-trustcacerts \
-file keystore/gameonca.crt
#add all jvm cacerts to the truststore.
keytool -importkeystore \
-srckeystore $JAVA_HOME/lib/security/cacerts \
-destkeystore keystore/truststore.jks \
-srcstorepass changeit \
-deststorepass truststore
#clean up the public cert..
rm -f keystore/public.crt