0

In my Java Application, I used the keystore facility of Java in the client side. I support both Oracle and IBM Java environment. Basically the code looks like:

try {

        KeyStore ks = KeyStore.getInstance("JKS");

        MyResources gr = new MyResources(null);
        InputStream inpStream = gr.GetResourceAsStream(MYFILE);

        if (inpStream == null) {

        }

        ks.load(inpStream, MYPASSWORD);

        TrustManagerFactory Mytmf = null;

        try {
            Mytmf = TrustManagerFactory.getInstance("SUNX509");
        } catch (NoSuchAlgorithmException e) {
            Mytmf = TrustManagerFactory.getInstance("IbmX509");
        }

        Mytmf.init(ks);


    } catch (Exception e) {

    }

The program works fine in the IBM JRE 1.6 and earlier versions. In the version 1.7, The following exception is received in case of an connection attempt to the server and it fails at the end:

Exception in thread "myThread" java.lang.NoClassDefFoundError: sun/security/validator/KeyStores 09:06:46>>at sun.security.ssl.X509TrustManagerImpl.(X509TrustManagerImpl.java:80) 09:06:46>> at sun.security.ssl.TrustManagerFactoryImpl$SimpleFactory.getInstance(TrustManagerFactoryImpl.java:240) 09:06:46>> at sun.security.ssl.TrustManagerFactoryImpl.engineInit(TrustManagerFactoryImpl.java:79) 09:06:46>> at javax.net.ssl.TrustManagerFactory.init(TrustManagerFactory.java:19) 09:06:46>> at MyTrustMgr.getTrustManager(MyTrustMgr.java:34)

Do you have any idea what could be reason for this issue?

bugra
  • 181
  • 3
  • 8

1 Answers1

0

Whatever the cause, the code is wrong. If you use TrustManagerFactory.getDefaultAlgorithm() as the argument, instead of that try/catch block, the problem will disappear.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • In the documentation, the default algorithm seems to be "PKIX" for IBM and Oracle Java, how can I get the default algorthim as "X509"? – bugra May 28 '13 at 11:28
  • As far as I can see, PKIX is the *only* supported TrustManagerFactory algorithm. SunX509 is a *KeyManagerFactory* algorithm. – user207421 May 28 '13 at 12:18