Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame^] | 1 | all: 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 |
| 4 | clear: |
| 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 |
| 10 | step_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 |
| 18 | step_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) |
| 24 | step_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 |
| 30 | step_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 |
| 39 | step_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 |
| 45 | step_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 |
| 52 | step_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 |
| 58 | step_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 |
| 64 | step_9: |
| 65 | @echo "Generate certService private and public keys" |
| 66 | keytool -genkeypair -v -alias aaf-cert-service -keyalg RSA -keysize 2048 -validity 730 \ |
| 67 | -keystore certServiceServer-keystore.jks -storetype JKS \ |
| 68 | -dname "CN=aaf-cert-service,OU=certServiceServer company,O=certServiceServer org,L=Wroclaw,ST=Dolny Slask,C=PL" \ |
| 69 | -keypass secret -storepass secret -ext BasicConstraints:critical="ca:false" |
| 70 | @echo "####done####" |
| 71 | |
| 72 | #Generate certificate signing request for certService |
| 73 | step_10: |
| 74 | @echo "Generate certificate signing request for certService" |
| 75 | keytool -certreq -keystore certServiceServer-keystore.jks -alias aaf-cert-service -storepass secret -file certServiceServer.csr |
| 76 | @echo "####done####" |
| 77 | |
| 78 | #Sign certService certificate by root CA |
| 79 | step_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" \ |
| 83 | -ext SubjectAlternativeName:="DNS:aaf-cert-service,DNS:localhost" |
| 84 | @echo "####done####" |
| 85 | |
| 86 | #Import root certificate into server |
| 87 | step_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 |
| 93 | step_13: |
| 94 | @echo "Import signed certificate into certService" |
| 95 | keytool -importcert -file certServiceServerByRoot.crt -destkeystore certServiceServer-keystore.jks -alias aaf-cert-service \ |
| 96 | -storepass secret -noprompt |
| 97 | @echo "####done####" |
| 98 | |
| 99 | #Convert certServiceServer-keystore(.jks) to PCKS12 format(.p12) |
| 100 | step_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 |
| 107 | step_15: |
| 108 | @echo "Clear unused certificates" |
| 109 | rm -f certServiceClientByRoot.crt certServiceClient.csr root-keystore.jks certServiceServerByRoot.crt certServiceServer.csr |
| 110 | @echo "#####done#####" |