Tuesday, May 7, 2013

Extracting public and private keys from a Java Key Store

Step 1: Creating the “public-private” key-pair.   
keytool -genkey -alias client -validity 365 -keystore keystore.jks 

Step 2: Validate the “public-private” key pair.
keytool -list -v -keystore keystore.jks

Step 3: Extract the “public key” from the “public-private”
keytool -export -alias client -keystore keystore.jks -rfc -file public.cert

Step 4: Check the extracted public key (public.cert)
type public.cert

Step 5: Time to create the truststore using the public key, which was extracted.
keytool -import -alias client -file public.cert -keystore server.truststore
keytool -list -v -keystore server.truststore

Steps Private Keys Export : It is required to save the private key in the PKCS#12 format
and we can convert that to a text file using openssl:
Step 1: keytool -v -importkeystore -srckeystore keystore.jks -srcalias client -destkeystore myp12file.p12 -deststoretype PKCS12
Step 2: openssl pkcs12 -in myp12file.p12 -out private.pem

Other Keytool Commands:
- keytool -delete -alias client -keystore keystore.jks
- keytool -storepasswd -new new_storepass -keystore keystore.jks
- keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacerts
- Import New CA into Trusted Certs
keytool -import -trustcacerts -file /path/to/ca/ca.pem -alias CA_ALIAS -keystore $JAVA_HOME/jre/lib/security/cacerts

Frequently used OpenSSL Commands:
- http://shib.kuleuven.be/docs/ssl_commands.shtml
 

Wednesday, May 1, 2013

Maven Basic

Maven Phases
Although hardly a comprehensive list, these are the most common default life cycle phases executed.
-validate: validate the project is correct and all necessary information is available
-compile: compile the source code of the project
-test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
-package: take the compiled code and package it in its distributable format, such as a JAR.
-integration-test: process and deploy the package if necessary into an environment where integration tests can be run
-verify: run any checks to verify the package is valid and meets quality criteria
-install: install the package into the local repository, for use as a dependency in other projects locally
-deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
There are two other Maven life-cycles of note beyond the default list above. They are
-clean: cleans up artifacts created by prior builds
-site: generates site documentation for this project

An interesting thing to note is that phases and goals may be executed in sequence.

-mvn clean dependency:copy-dependencies package
This command will clean the project, copy dependencies, and package the project
(executing all phases up to package, of course).

Maven Quickstart

  • cls
  • mvn -version
  • mvn archetype:generate
    Try running the following commands in serial order:
  • mvn validate
  • mvn compile / mvn clean compile (-o offline mode)
  • mvn package / mvn jar:jar / mvn war:war  (To build jar/war package)
  • mvn test  (Skipping test use property -Dmaven.test.skip=true)
    Just execute the following command,
  • mvn install / mvn clean install (It will encapsulate much of the default build life-cycle)
    (including compiling, testing, packaging, and installing the artifact in the local repository)
  • mvn -o compile / mvn -o install / mvn -o test (To Work Offline -o)
  • mvn dependency:analyze (To check your project for both unnecessary dependencies)
  • mvn dependency:tree
  • mvn clean dependency:copy-dependencies package
  • mvn site
  • mvn eclipse:eclipse -Dwtpversion=2.0 (To support Eclipse ide)
  • mvn archetype:generate -Dfilter=org.apache:struts
  • mvn archetype:generate > list.txt
  • mvn -f  <other pom file>
  • mvn help:help / mvn javadoc:help / mvn eclipse:help / mvn tomcat:help....etc
    mvn help:describe -Dplugin=eclipse
- Create a Simple Java Project from Maven Template
  • mvn archetype:generate -DgroupId=com.jini -DartifactId=Hello -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
  • mvn eclipse:eclipse
  • mvn package
- Running Jar
  • java -cp target/Hello-1.0-SNAPSHOT.jar com.jini.App 
  • mvn exec:java
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.4</version>
      <configuration>
        <mainClass>org.dhappy.test.NeoTraverse</mainClass>
      </configuration>
    </plugin>
 - MAVEN_OPTS Environment Variable 
  • (UNIX) export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m" 
  • (Windows) set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=128m

Maven Tips and Tricks

-Download all your dependencies to target/dependencies:
mvn dependency:copy-dependencies
-But note, you probably only want the dependencies that you actually need at runtime:
mvn dependency:copy-dependencies -DincludeScope=runtime
-Check all of your dependencies to see if newer versions are available (versions plugin):
mvn versions:display-dependency-updates
-And do the same for your plugins:
mvn versions:display-plugin-updates
-Purge all the project’s dependencies and re-download (dependency plugin):
mvn dependency:purge-local-repository
-Build a package but skip running the tests:
mvn package -DskipTests
-If Maven caches a failure to find a dependency, but you’ve fixed it, add a -U to your command line.
In a multi-module project, you need to build from the root pom to find dependencies.
If you just want to build a specific module/project
(Note that I’m just specifying it using the artifactId and you need to include a colon in front):
mvn package -pl :artifactId
-Maven Installing Jar in Local Repo.
mvn install:install-file -Dfile=
mvn install:install-file -Dfile= -DpomFile=
mvn install:install-file -DgroupId=org.springframework.roo -DartifactId=org.springframework.roo.osgi.bundle -Dversion=1.2.4.RELEASE