jimnelson34
asked on
JSK KeyStore instantiation error
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.KeyStoreExce ption 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.getInsta nce("SunX5 09");
kmf.init(ks, keypassword);
SSLContext sslcontext = SSLContext.getInstance("SS Lv3");
sslcontext.init(kmf.getKey Managers() , null, null);
SSLServerSocketFactory ssf = sslcontext.getServerSocket Factory();
SSLServerSocket serversocket = (SSLServerSocket) ssf.createServerSocket(200 0);
return serversocket;
}
Thanks for reading my problem and thinking about the solution!
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.KeyStoreExce
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"
ks.load(new FileInputStream(keystore),
KeyManagerFactory kmf = KeyManagerFactory.getInsta
kmf.init(ks, keypassword);
SSLContext sslcontext = SSLContext.getInstance("SS
sslcontext.init(kmf.getKey
SSLServerSocketFactory ssf = sslcontext.getServerSocket
SSLServerSocket serversocket = (SSLServerSocket) ssf.createServerSocket(200
return serversocket;
}
Thanks for reading my problem and thinking about the solution!
Sounds like you don't have a JKS implementation available on your linux box.
At first objects' suggestion seems right but can you post the exact error and the line it occurs?
ASKER
objects: How can I install a JKS implementation on my Linux?
ASKER
girionis: The error (java.security.KeyStoreExc eption) 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...
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...
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(KeySt ore.getDef aultType() );
Also what happens if you replace the failing line with the following:
KeyStore ks = KeyStore.getInstance(KeySt
ASKER
KeyStore.getDefaultType() returns "jks" so its the same situation.
The getMessage() method of the throwed KeyStoreException returns just this: "JKS". Its not too informative.
The getMessage() method of the throwed KeyStoreException returns just this: "JKS". Its not too informative.
Are you using the same version of java on both windows and linux?
ASKER
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
Thanks for your help!
:)