Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null Pointer while loading the keystore

 
Mark Fraser
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the exception. There are details in the exception which are not obvious from your posting.

Arshad Noor
StrongAuth, Inc.
 
Mark Fraser
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic