JSK KeyStore instantiation error

Posted on 2004-08-11
Last Modified: 2008-02-01
So here is my problem:

I try to create an SSLServerSocket using the function described below. It works perfectly under Windows (with NetBeans), but when I try to run it under Linux (it compiles, only doesn't run) I get
a with the message: "JKS".

So I guess it must be having difficulties with instantiating the JKS KeyStore object, but I've got no idea why.
The jsse.jar is in my classpath and the key file is in the right place and accessible (it fails before even accessing it).

public SSLServerSocket getServer() throws Exception {

      KeyStore ks = KeyStore.getInstance("JKS");   // This line fails !

      ks.load(new FileInputStream(keystore), keystorepass);
      KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
      kmf.init(ks, keypassword);
      SSLContext sslcontext = SSLContext.getInstance("SSLv3");
      sslcontext.init(kmf.getKeyManagers(), null, null);
      SSLServerSocketFactory ssf = sslcontext.getServerSocketFactory();
      SSLServerSocket serversocket = (SSLServerSocket) ssf.createServerSocket(2000);
      return serversocket;

Thanks for reading my problem and thinking about the solution!
Question by:jimnelson34
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
LVL 92

Expert Comment

ID: 11771416
Sounds like you don't have a JKS implementation available on your linux box.
LVL 35

Expert Comment

ID: 11771645
At first objects' suggestion seems right but can you post the exact error and the line it occurs?

Author Comment

ID: 11771676
objects: How can I install a JKS implementation on my Linux?
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

LVL 35

Expert Comment

ID: 11771789

Author Comment

ID: 11772122
girionis: The error ( occurs at the line marked in the above code.
I read the page you posted and it says that Sun JAVA has a built-in default implementation which implements a keystore as a file, so it should be working. Do I have to include any other .jar file in my classpath?
It's only a small test application for a bigger project so currently I'm only including "jsse.jar" in my classpath.

I also looked inside the jsse.jar file and the "javax/security" subdir contains no files, only 1 subdirectory named "cert" which contains 8 classes. Is it normal?
It might explain the missing implementation. If thats the problem, how can I fix it?

Meanwhile I checked my Windows version of JAVA and the situation inside "jsse.jar" is identical so its a lot more confusing to me now...
LVL 35

Expert Comment

ID: 11772303
You shouldn't need anything else, all classes you need are part of the jdk already. Can you post the *exact* error message?

Also what happens if you replace the failing line with the following:

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

Author Comment

ID: 11773270
KeyStore.getDefaultType() returns "jks" so its the same situation.
The getMessage() method of the throwed KeyStoreException returns just this: "JKS". Its not too informative.
LVL 35

Expert Comment

ID: 11773426
Are you using the same version of java on both windows and linux?

Author Comment

ID: 11773630
I use jdk 1.4.2 on both systems.
I'm putting the source code on my webserver so you may try running it:
Tell me if it runs please!
LVL 35

Accepted Solution

girionis earned 125 total points
ID: 11781084
It is working fine here on RedHat Linux 9.0 with jdk 1.4.1_05. I added a System.out.println() statement:

SSLServerSocket sslserver = getServer();
System.out.println("after getServer() is called...");

and I can see the message on the screen:

/home/panos/EE/JKS$ java Main
after getServer() is called...

which means that the call to the method getServer() is successfull.

Can you try to re-install your java? It could be a problem during installation.

Author Comment

ID: 11782963
I've installed a new Linux to my home computer and I was able to compile and run the code without difficulties. Girionis was right that the problem is with my JAVA installation, and because he was extreamly helpful and fast, I'm giving all points to him.
Thanks for your help!
LVL 35

Expert Comment

ID: 11782983

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question