Solved

JSK KeyStore instantiation error

Posted on 2004-08-11
12
732 Views
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 java.security.KeyStoreException 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!
0
Comment
Question by:jimnelson34
  • 6
  • 5
12 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
Sounds like you don't have a JKS implementation available on your linux box.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
At first objects' suggestion seems right but can you post the exact error and the line it occurs?
0
 

Author Comment

by:jimnelson34
Comment Utility
objects: How can I install a JKS implementation on my Linux?
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
0
 

Author Comment

by:jimnelson34
Comment Utility
girionis: The error (java.security.KeyStoreException) 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...
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
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());
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

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

Expert Comment

by:girionis
Comment Utility
Are you using the same version of java on both windows and linux?
0
 

Author Comment

by:jimnelson34
Comment Utility
I use jdk 1.4.2 on both systems.
I'm putting the source code on my webserver so you may try running it: http://www.wedgesystems.hu/nstest/
Tell me if it runs please!
0
 
LVL 35

Accepted Solution

by:
girionis earned 125 total points
Comment Utility
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.
0
 

Author Comment

by:jimnelson34
Comment Utility
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!
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
:)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now