Unable to load PKCS11 driver using IAIK PKCS11 Wrapper

jondinham picture jondinham · Jan 8, 2013 · Viewed 7.3k times · Source

I'm using the following:

  • Windows 7 64bit
  • JDK 7 64bit
  • JRE 7 64bit

The new funny JRE 7 64bit doesn't support Sun PKCS11 anymore (which is inside package 'sun.security.pkcs11'). And the big problem is that the end-users of the product by our company may have installed whatever version of JRE.

So I have to swap up the existing to code in 'Sun PKCS11' to 'IAIK PKCS11 Wrapper'. The wrapper by IAIK works simply this way:

(iaik-wrapper.jar)->(iaik-pkcs11-jni.dll)->(pki-token-driver.dll)

The PKI token driver dynamic link library is provided by the manufacturer of PKI USB token, it has the actual name of 'ca2-v34.dll'. The method to load this native driver is described in programmer's manual as below:

import iaik.pkcs.pkcs11.*;
...

Module pkcs11Driver;
try {
  pkcs11Driver = Module.getInstance("ca2-v34.dll"); //<--exception!
  pkcs11Driver.initialize(null);

  //test
  System.out.println(pkcs11Driver.getInfo());
}
catch (Exception ex) {
  System.out.println(ex);
}

The exception is raised at the line marked in the code above, with this detail: java.io.IOException: %1 is not a valid Win32 application. ca2-v34.dll

This exception surely means the IAIK library has found the .dll file, but it is not compatible somehow. I'm being stuck at this bottleneck.

Answer

jondinham picture jondinham · Jan 9, 2013

As noted by EJP in the comments right below the question, ca2-v34.dll is a 32bit dll. The sample usb token manager from the manufacturer is a 32bit-throughout software, so it can load this dll file on both Windows 32 and Windows 64.

The scenario of JRE is different:

  • In case the client computer has JRE 32bit installed, the Java application (.jar file) can run well because the process of JVM is a 32bit process.
  • The other case is that the client computer has JRE 64bit installed, the Java application can not run normally because JVM in this case is a 64bit process, it can load the Java application (.jar file) but fails to load the file 'ca2-v34.dll' due to a reason that this dll file is 32bit dll.