Friday, July 20, 2012

Create a keystore for SSL using maven

Normally you would buy a trusted certificate however, the poor man's way is to create one your self.

Put this in a pom.xml and run it with mvn install.


<project>
<modelVersion>1.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build><plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>generate-resources</phase>
<id>clean</id>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<phase>generate-resources</phase>
<id>genkey</id>
<goals>
<goal>genkey</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>example.keystore</keystore>
<dname>cn=localhost</dname>
<keypass>broadleaf</keypass>
<storepass>broadleaf</storepass>
<alias>broadleaf</alias>
<keyalg>RSA</keyalg>
</configuration>
</plugin>
</plugins>
</build>
</project>


SSL on tomcat

To turn on SSL port in tomcat is a simple process. You will need to modify the configuration file context.xml to allow the port to be open.


  1. Create the keyStore file to be used for ssl.  Click here to  create one using maven. 
  2.  In your tomcathomedir/conf/server.xml, add the following:


    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"                keystoreFile="/tmp/example.keystore"
               keystorePass="somePassword"               clientAuth="false" sslProtocol="TLS" />

That's it.....
Now hit the url  in your browser , https://localhost:8443 and it should ask your for security exception.