Friday, August 26, 2011

Self Signed SSL certificate creation sing keytool!

First, we will generate a keystore that has a key pair (public and private key) along with a self-signed certificate.
1) keytool -genkey -alias SecureServer -keyalg RSA -keystore ServerKeystore

Next, we will examine the contents of the generated Server Keystore, which is accomplished by the following command.
2) keytool -list -v  -keystore ServerKeystore

The next step is to create a self-signed certificate and this is accomplished by executing the following commands.
3) keytool -export -alias SecureServer -keystore ServerKeystore -rfc -file Server.cer



Just to see what the certificate looks like, we'll print to the console with the following:
4) cat Server.cer

import this certificate into a truststore, which then can be used by the client.
5) keytool -import -alias SecureServer -file Server.cer -keystore ClientTruststore

To verify the contents of the truststore that we created, we issue the following command
6) keytool -list -v  -keystore ClientTruststore


    * Setting Keystore - Programmatically:
      System.setProperty("javax.net.ssl.keyStore", "./resources/Server_Keystore"); System.setProperty("javax.net.ssl.keyStorePassword", "password");
    * Setting Keystore - Command Line:
      java -Djavax.net.ssl.keyStore=./resources/Server_Keystore -Djavax.net.ssl.keyStorePassword=password com.article.jn.securermi.CreditCardAuthServer
    * Setting Truststore - Programmatically:
      System.setProperty("javax.net.ssl.trustStore", "./resources/Client_Truststore");
    * Setting Truststore - Command Line:
      java -Djavax.net.ssl.trustStore= ./resources/Client_Truststore

No comments:

Post a Comment