Skip to content

Set up SSL Keystore for Java Case API Application

MsaasAPI edited this page Sep 26, 2018 · 12 revisions
⏮API Prev API Next⏭

CONTENTS

PREREQUISITE

  • Locate the private key file (*.pfx) and its password on your local box. This private key should be created by your team, or even created by you as self-signed certificate on your local box.
  • Install Java JDK.

CREATE KEYSTORE

  1. Open the Command Prompt as administrator.

  2. Navigate to JRE bin folder. JRE folder shall be located inside Java folder along with JDK folder.

  3. Create a keystore with the following command.

    keytool -genkeypair -alias mydomain -keyalg RSA -keystore myFavKeyStoreName.jks
    

  4. Answer several questions (or left some blank). Type y or yes to confirm the information. If prompted for domain password, it may be left blank and simply press Return/Enter to proceed.

  1. Import private key certificate with the following command.

    keytool -importkeystore -srckeystore "yourPath\yourPrivateKey.pfx" -srcstoretype pkcs12 -destkeystore myFavKeyStoreName.jks -deststoretype JKS
    

  2. Supply both keystore (Enter destination keystore password) and private key (Enter source keystore password) passwords. Press Enter key and verify the result.

  3. Verify the Certificate info inside the keystore with the following command. Per Oracle, use the -list command to print the contents of the keystore entry identified by -alias to stdout. If -alias alias is not specified, then the contents of the entire keystore are printed.

    keytool -list -keystore myFavKeyStoreName.jks
    

📑Record the certificate alias for later reference in the code📑

  1. After supplying Keystore password, at least 2 certificates will appear. Ignore mydomain certificate.

  2. optional Alternatively, we can run the same command with verbose option. Per Oracle, the difference with/without -v is that, without verbose option, it prints the SHA-256 fingerprint of a certificate. With it, the certificate is printed in human-readable format, with additional information such as the owner, issuer, serial number, and any extensions.

    keytool -list -keystore myFavKeyStoreName.jks -v
    

📑Record the folder path to this keystore for later reference in the code📑

  1. Unless specifically specified otherwise, the newly-created keystore will be located in Java JRE bin folder.

  2. Now, you are ready to proceed to coding.

NEXT STEP

  1. Now you are ready to install and run the sample application.