This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Security and the fly likes Null Pointer while loading the keystore Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Null Pointer while loading the keystore" Watch "Null Pointer while loading the keystore" New topic
Author

Null Pointer while loading the keystore

Mark Fraser
Greenhorn

Joined: Oct 15, 2010
Posts: 11
This shouldn't be this difficult. I'm getting a NullPointerException in the line where I try to load the keystore:

if (Security.getProvider("BC") == null)
{
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
}

KeyStore ks = KeyStore.getInstance("PKCS12", "BC");
ks.load(new FileInputStream(certificatePath), privateKeyPassword.toCharArray());

certificatePath is a PKCS12 encoded file with the public certificate and the private key.
privateKeyPassword is the password entered into OpenSSL while generating the PKCS12 file.

Can anyone suggest why I'm getting the exception?
Arshad Noor
Ranch Hand

Joined: Oct 06, 2011
Posts: 34
Post the exception. There are details in the exception which are not obvious from your posting.

Arshad Noor
StrongAuth, Inc.
Mark Fraser
Greenhorn

Joined: Oct 15, 2010
Posts: 11
Here's the exception:
Message: class java.lang.NullPointerException: cause:null, message:null, action:com.nutrasun.servlet.store.cart.ActionCartCalcShipping@1da87db
Stack Trace: com.patersonglobalfoods.servlet.BaseFrontController.processRequest(BaseFrontController.java:48)
com.patersonglobalfoods.servlet.BaseFrontController.doPost(BaseFrontController.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
com.patersonglobalfoods.filter.MaintenanceModeFilter.doFilter(MaintenanceModeFilter.java:63)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:393)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:200)
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:773)
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)
org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:895)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)

Mark Fraser
Greenhorn

Joined: Oct 15, 2010
Posts: 11
Here's the OpenSSL command I used to create the PKCS12 file:

openssl pkcs12 -export -in C:\ssl\nutrasunfoods_com.crt -inkey C:\ssl\PrivateKey.txt -out C:\ssl\bundle.p12
Mark Fraser
Greenhorn

Joined: Oct 15, 2010
Posts: 11
The problem was with the password I entered into OpenSSL. I suspect it has to do with my pasting it into the command prompt rather than typing it. Strange but true.
Arshad Noor
Ranch Hand

Joined: Oct 06, 2011
Posts: 34
Mark Fraser wrote:Here's the exception:
Message: class java.lang.NullPointerException: cause:null, message:null, action:com.nutrasun.servlet.store.cart.ActionCartCalcShipping@1da87db
Stack Trace: com.patersonglobalfoods.servlet.BaseFrontController.processRequest(BaseFrontController.java:48)
com.patersonglobalfoods.servlet.BaseFrontController.doPost(BaseFrontController.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


This exception is from your servlet to the browser. What is the exception in your web-container's logs? Tomcat or Glassfish or whatever you're using will have its own exception that might be different from what the servlet shows you. The ks.load() call is sandwiched between some try-catch clause, which must have thrown its own exception.

Arshad Noor
StrongAuth, Inc.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Null Pointer while loading the keystore