blob: ea90c5c798336e2bb1ae36a6d4095de48e985899 [file] [log] [blame]
Aleksandra Maciaga13b7d052020-03-26 17:28:47 +01001all: step_1 step_2 step_3 step_4 step_5 step_6 step_7 step_8 step_9 step_10 step_11 step_12 step_13 step_14 step_15
2.PHONY: all
3#Clear certificates
4clear:
5 @echo "Clear certificates"
6 rm -f certServiceClient-keystore.jks certServiceServer-keystore.jks root.crt truststore.jks certServiceServer-keystore.p12
7 @echo "#####done#####"
8
9#Generate root private and public keys
10step_1:
11 @echo "Generate root private and public keys"
12 keytool -genkeypair -v -alias root -keyalg RSA -keysize 4096 -validity 3650 -keystore root-keystore.jks \
13 -dname "CN=root.com, OU=Root Org, O=Root Company, L=Wroclaw, ST=Dolny Slask, C=PL" -keypass secret \
14 -storepass secret -ext BasicConstraints:critical="ca:true"
15 @echo "#####done#####"
16
17#Export public key as certificate
18step_2:
19 @echo "(Export public key as certificate)"
20 keytool -exportcert -alias root -keystore root-keystore.jks -storepass secret -file root.crt -rfc
21 @echo "#####done#####"
22
23#Self-signed root (import root certificate into truststore)
24step_3:
25 @echo "(Self-signed root (import root certificate into truststore))"
26 keytool -importcert -alias root -keystore truststore.jks -file root.crt -storepass secret -noprompt
27 @echo "#####done#####"
28
29#Generate certService's client private and public keys
30step_4:
31 @echo "Generate certService's client private and public keys"
32 keytool -genkeypair -v -alias certServiceClient -keyalg RSA -keysize 2048 -validity 730 \
33 -keystore certServiceClient-keystore.jks -storetype JKS \
34 -dname "CN=certServiceClient.com,OU=certServiceClient company,O=certServiceClient org,L=Wroclaw,ST=Dolny Slask,C=PL" \
35 -keypass secret -storepass secret
36 @echo "####done####"
37
38#Generate certificate signing request for certService's client
39step_5:
40 @echo "Generate certificate signing request for certService's client"
41 keytool -certreq -keystore certServiceClient-keystore.jks -alias certServiceClient -storepass secret -file certServiceClient.csr
42 @echo "####done####"
43
44#Sign certService's client certificate by root CA
45step_6:
46 @echo "Sign certService's client certificate by root CA"
47 keytool -gencert -v -keystore root-keystore.jks -storepass secret -alias root -infile certServiceClient.csr \
48 -outfile certServiceClientByRoot.crt -rfc -ext bc=0 -ext ExtendedkeyUsage="serverAuth,clientAuth"
49 @echo "####done####"
50
51#Import root certificate into client
52step_7:
53 @echo "Import root certificate into intermediate"
54 cat root.crt >> certServiceClientByRoot.crt
55 @echo "####done####"
56
57#Import signed certificate into certService's client
58step_8:
59 @echo "Import signed certificate into certService's client"
60 keytool -importcert -file certServiceClientByRoot.crt -destkeystore certServiceClient-keystore.jks -alias certServiceClient -storepass secret -noprompt
61 @echo "####done####"
62
63#Generate certService private and public keys
64step_9:
65 @echo "Generate certService private and public keys"
Pawelb7a057e2020-08-07 14:53:48 +020066 keytool -genkeypair -v -alias oom-cert-service -keyalg RSA -keysize 2048 -validity 730 \
Aleksandra Maciaga13b7d052020-03-26 17:28:47 +010067 -keystore certServiceServer-keystore.jks -storetype JKS \
Pawelb7a057e2020-08-07 14:53:48 +020068 -dname "CN=oom-cert-service,OU=certServiceServer company,O=certServiceServer org,L=Wroclaw,ST=Dolny Slask,C=PL" \
Aleksandra Maciaga13b7d052020-03-26 17:28:47 +010069 -keypass secret -storepass secret -ext BasicConstraints:critical="ca:false"
70 @echo "####done####"
71
72#Generate certificate signing request for certService
73step_10:
74 @echo "Generate certificate signing request for certService"
Pawelb7a057e2020-08-07 14:53:48 +020075 keytool -certreq -keystore certServiceServer-keystore.jks -alias oom-cert-service -storepass secret -file certServiceServer.csr
Aleksandra Maciaga13b7d052020-03-26 17:28:47 +010076 @echo "####done####"
77
78#Sign certService certificate by root CA
79step_11:
80 @echo "Sign certService certificate by root CA"
81 keytool -gencert -v -keystore root-keystore.jks -storepass secret -alias root -infile certServiceServer.csr \
82 -outfile certServiceServerByRoot.crt -rfc -ext bc=0 -ext ExtendedkeyUsage="serverAuth,clientAuth" \
Pawelb7a057e2020-08-07 14:53:48 +020083 -ext SubjectAlternativeName:="DNS:oom-cert-service,DNS:localhost"
Aleksandra Maciaga13b7d052020-03-26 17:28:47 +010084 @echo "####done####"
85
86#Import root certificate into server
87step_12:
88 @echo "Import root certificate into intermediate(server)"
89 cat root.crt >> certServiceServerByRoot.crt
90 @echo "####done####"
91
92#Import signed certificate into certService
93step_13:
94 @echo "Import signed certificate into certService"
Pawelb7a057e2020-08-07 14:53:48 +020095 keytool -importcert -file certServiceServerByRoot.crt -destkeystore certServiceServer-keystore.jks -alias oom-cert-service \
Aleksandra Maciaga13b7d052020-03-26 17:28:47 +010096 -storepass secret -noprompt
97 @echo "####done####"
98
99#Convert certServiceServer-keystore(.jks) to PCKS12 format(.p12)
100step_14:
101 @echo "Convert certServiceServer-keystore(.jks) to PCKS12 format(.p12)"
102 keytool -importkeystore -srckeystore certServiceServer-keystore.jks -srcstorepass secret \
103 -destkeystore certServiceServer-keystore.p12 -deststoretype PKCS12 -deststorepass secret
104 @echo "#####done#####"
105
106#Clear unused certificates
107step_15:
108 @echo "Clear unused certificates"
109 rm -f certServiceClientByRoot.crt certServiceClient.csr root-keystore.jks certServiceServerByRoot.crt certServiceServer.csr
110 @echo "#####done#####"