I'm using j2se1.4-b3, though I don't believe that's the problem.  When I 
get an org.mozilla.jss.CryptoManager instance and then try to get a 
java.security.cert.CertificateFactory, I get the following:
/************************************************************/
$java CertFactoryTest f
java.security.cert.CertificateException: X.509 not found
         at 
java.security.cert.CertificateFactory.getInstance(CertificateFactory.java:194)
         at CertFactoryTest.initCertFactory(CertFactoryTest.java:8)
         at CertFactoryTest.main(CertFactoryTest.java:34)
Caused by: java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:42)
         at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:28)
         at java.lang.reflect.Method.invoke(Method.java:327)
         at 
java.security.cert.CertificateFactory.getInstance(CertificateFactory.java:180)
         ... 2 more
Caused by: java.security.NoSuchAlgorithmException: X.509 
CertificateFactory not available
         at java.security.Security.getEngineClassName(Security.java:573)
         at java.security.Security.getEngineClassName(Security.java:584)
         at java.security.Security.getImpl(Security.java:1033)
         ... 7 more
/************************************************************/

However, when I reverse the order of the creation, I don't seem to have 
a conflict.  I have not tested to verify that all the functionality of 
these successfully created classes is available.  I have only 
established that no exceptions are thrown when they are created.  The 
code below demonstrates the situation.  Running CertFactoryTest with no 
arguments creates the CertificateFactory before the CryptoManager.  By 
giving an argument on the commandline the call order is reversed.

The obvious question is: What is going on here?

/* CertFactoryTest.java */
public class CertFactoryTest {

   public CertFactoryTest() {
   } // constructor

   public void initCertFactory() {
     try {
       java.security.cert.CertificateFactory cf
         = java.security.cert.CertificateFactory.getInstance("X.509");
     } catch (Exception e) {
       e.printStackTrace();
     } // catch
   } // initCertFactory

   public void initCryptoMan() {
     org.mozilla.jss.CryptoManager.InitializationValues vals
       = new org.mozilla.jss.CryptoManager.InitializationValues("ns-keys");
     try {
       org.mozilla.jss.CryptoManager.initialize(vals);
       org.mozilla.jss.CryptoManager cryptoMan
         = org.mozilla.jss.CryptoManager.getInstance();
     } catch(Exception e) {
       e.printStackTrace();
     } // catch
   } // initCryptoMan

   public static void main(String[] args) {
     CertFactoryTest cft = new CertFactoryTest();
     if (args.length == 0 ) {
       cft.initCertFactory();
       cft.initCryptoMan();
     } else {
       cft.initCryptoMan();
       cft.initCertFactory();
     } // else
   } // main

} // certFactoryTest


Reply via email to