Skip to content

Instantly share code, notes, and snippets.

@rajithacharith
Created May 28, 2022 02:34
Show Gist options
  • Save rajithacharith/edd6cdbe6ef8e2958d77fe1083c5c262 to your computer and use it in GitHub Desktop.
Save rajithacharith/edd6cdbe6ef8e2958d77fe1083c5c262 to your computer and use it in GitHub Desktop.
This gist will contain the commands to generate private keys and certificates for the CarParkServer and CarParkClient which was used for the securing gRPC api blog
echo "----------------------------------------------------------------------------------"
echo "| Generating private keys and certs for CarParkServer and CarParkClient |"
echo "----------------------------------------------------------------------------------"
# Check the availability of openssl.
readonly KEYTOOL=$(which keytool)
if [[ ! ${KEYTOOL} ]]
then
echo "keytool is not installed. Exiting !"
exit 1
fi
# Use keytool to generate keystores and truststores.
echo "Generating keystore for carparkserver.........."
${KEYTOOL} -genkey -alias carparkserver -keyalg RSA -keysize 2048 \
-storetype PKCS12 \
-keystore carparkserver-keystore.jks \
-dname "CN=localhost" \
-storepass 111111 \
-keypass 111111
echo "Exporting carparkserver certificate........."
${KEYTOOL} -export -alias carparkserver \
-keystore carparkserver-keystore.jks \
-file carparkserver.crt \
-rfc -storepass 111111
echo "Generating a dummy truststore for carparkserver........."
${KEYTOOL} -genkey -alias carparkserver -keyalg RSA -keysize 2048 \
-storetype PKCS12 \
-keystore carparkserver-truststore.jks \
-dname "CN=localhost" \
-storepass 111111 \
-keypass 111111
echo "Generating keystore for carparkclient........."
${KEYTOOL} -genkey -alias carparkclient -keyalg RSA -keysize 2048 \
-storetype PKCS12 \
-keystore carparkclient-keystore.jks \
-dname "CN=localhost" \
-storepass 111111 \
-keypass 111111
echo "Exporting carparkclient certificate........."
${KEYTOOL} -export -alias carparkclient \
-keystore carparkclient-keystore.jks \
-file carparkclient.crt \
-rfc -storepass 111111
echo "Generating a dummy truststore for carparkclient........."
${KEYTOOL} -genkey -alias carparkclient -keyalg RSA -keysize 2048 \
-storetype PKCS12 \
-keystore carparkclient-truststore.jks \
-dname "CN=localhost" \
-storepass 111111 \
-keypass 111111
echo "Importing carparkclient cert to carparkserver truststore........."
${KEYTOOL} -delete -alias carparkserver \
-keystore carparkserver-truststore.jks \
-storepass 111111
${KEYTOOL} -import -alias carparkclient -file carparkclient.crt \
-keystore carparkserver-truststore.jks \
-storepass 111111 \
-noprompt
echo "Importing carparkserver cert to carparkclient truststore........."
${KEYTOOL} -delete -alias carparkclient \
-keystore carparkclient-truststore.jks \
-storepass 111111
${KEYTOOL} -import -alias carparkserver -file carparkserver.crt \
-keystore carparkclient-truststore.jks \
-storepass 111111 \
-noprompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment