-
Notifications
You must be signed in to change notification settings - Fork 85
/
gen_client_node_cert.sh
executable file
·54 lines (45 loc) · 1.35 KB
/
gen_client_node_cert.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
#!/bin/bash
set -e
CLIENT_NAME=$1
KS_PASS=$2
CA_PASS=$3
rm -f $CLIENT_NAME-keystore.jks
rm -f $CLIENT_NAME.csr
rm -f $CLIENT_NAME-signed.pem
echo Generating keystore and certificate for node $CLIENT_NAME
keytool -genkey \
-alias $CLIENT_NAME \
-keystore $CLIENT_NAME-keystore.jks \
-keyalg RSA \
-keysize 2048 \
-validity 712 \
-keypass $KS_PASS \
-storepass $KS_PASS \
-dname "CN=$CLIENT_NAME, OU=client, O=client, L=Test, C=DE"
echo Generating certificate signing request for node $CLIENT_NAME
keytool -certreq \
-alias $CLIENT_NAME \
-keystore $CLIENT_NAME-keystore.jks \
-file $CLIENT_NAME.csr \
-keyalg rsa \
-keypass $KS_PASS \
-storepass $KS_PASS \
-dname "CN=$CLIENT_NAME, OU=client, O=client, L=Test, C=DE"
echo Sign certificate request with CA
openssl ca \
-in $CLIENT_NAME.csr \
-notext \
-out $CLIENT_NAME-signed.pem \
-config etc/signing-ca.conf \
-extensions v3_req \
-batch \
-passin pass:$CA_PASS \
-extensions server_ext
echo "Import back to keystore (including CA chain)"
cat ca/chain-ca.pem $CLIENT_NAME-signed.pem | keytool \
-importcert \
-keystore $CLIENT_NAME-keystore.jks \
-storepass $KS_PASS \
-noprompt \
-alias $CLIENT_NAME
echo All done for $CLIENT_NAME