1

I used the XADES4j project to sign electronic invoices using JavaSE-1.8 (jre1.8.0_121) 32-bit version + Windows32Bits + eclipse (32-bit Luna) + Gemalto token and it worked well. Now I'm using the Windows64 bit system, I have not changed anything: I installed the JavaSE-1.8 (jre1.8.0_121) 32-bit version, the same version of eclipse (32-bit) and the token Gemalto (gclib. 64bit dll). when running the signature from eclipse I encountered runtime errors at the pkcs11 security provider installation level :

0 [main] DEBUG org.apache.xml.security.Init  - Registering default 
algorithms
------------------------------------------------------------
...
profileCore.getInstance
SignerBES.class
profileCore.getInstance
SignerBES.class
Provider 0: SUN
Provider 1: SunRsaSign
Provider 2: SunEC
Provider 3: SunJSSE
Provider 4: SunJCE
Provider 5: SunJGSS
Provider 6: SunSASL
Provider 7: XMLDSig
Provider 8: SunPCSC
Provider 9: SunMSCAPI
INTALL PROVIDER .....

Exception in thread "AWT-EventQueue-0" java.security.ProviderException: 
Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
at xades4j.providers.impl.PKCS11KeyStoreKeyingDataProvider.createPkcs11Provider(PKCS11KeyStoreKeyingDataProvider.java:327)
at xades4j.providers.impl.PKCS11KeyStoreKeyingDataProvider.access$1(PKCS11KeyStoreKeyingDataProvider.java:322)
at xades4j.providers.impl.PKCS11KeyStoreKeyingDataProvider$1.getBuilder(PKCS11KeyStoreKeyingDataProvider.java:180)
at xades4j.providers.impl.KeyStoreKeyingDataProvider.ensureInitialized(KeyStoreKeyingDataProvider.java:277)
at xades4j.providers.impl.KeyStoreKeyingDataProvider.getSigningCertificateChain(KeyStoreKeyingDataProvider.java:423)
at xades4j.production.SignerBES.sign(SignerBES.java:183)
at xades4j.production.SignerBES.sign(SignerBES.java:145)
at FENETRE.PSD_SIGNATURE1(FENETRE.java:706)
at FENETRE.actionPerformed(FENETRE.java:983)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.io.IOException: %1 is not a valid Win32 application.
C:\Program Files\Gemalto\Classic Client\BIN\gclib.dl
at sun.security.pkcs11.wrapper.PKCS11.connect(Native Method)
at sun.security.pkcs11.wrapper.PKCS11.<init>(PKCS11.java:138)
at sun.security.pkcs11.wrapper.PKCS11.getInstance(PKCS11.java:151)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:313)
... 46 more

How to solve this problem ?

Sabri Mbarek
  • 31
  • 1
  • 12
  • have you tried eclipse and java for x64 then? – Dmitry Senkovich Jan 31 '18 at 08:28
  • also in this line `C:\Program Files\Gemalto\Classic Client\BIN\gclib.dl` I see `dl` only, maybe some troubles with the extension? Windows tends to honor extensions – Dmitry Senkovich Jan 31 '18 at 08:29
  • When using eclipse and java for x64. Several errors appear in my java code, and I have no time to check them. But for the display of .dl and not .dll: I noticed this, but in my code I passed the variable with the name 'gclib.dll' and not 'gclib.dl' !!!! – Sabri Mbarek Jan 31 '18 at 08:41
  • are you really passing a path on C drive? that seems strange do me, looks like it is some default path. maybe your parameter gets ignored? – Dmitry Senkovich Jan 31 '18 at 08:43
  • Java variable "C:\\Program Files\\Gemalto\\Classic Client\\BIN\\gclib.dll" and the file exists under "C:\Program Files (x86)\Gemalto\Classic Client\ BIN\gclib.dll " – Sabri Mbarek Jan 31 '18 at 08:58
  • You have to install the 32-bit Gemalto library (PKCS11 dll). – beat Jan 31 '18 at 12:34
  • Seems like you already have the 32-bit dll if it is in "Program Files (x86)" but the path you are passing has no "x86" in it. Try to use the path "C:\Program Files (x86)\Gemalto\Classic Client\ BIN\gclib.dll" in Java / your pkcs11 config file.. – beat Jan 31 '18 at 13:52
  • Thank you very much for your help. I installed the Gemalto token in a different location and it worked well. Note: Even if added (x86) to the old location, errors are also displayed. I think the parentheses are unacceptable by java. – Sabri Mbarek Jan 31 '18 at 15:06

2 Answers2

1

Install the Gemalto driver in another location that does not contain special characters

0

The error "is not a valid Win32 application" may occur if the PKCS11 module depends on other libraries and fails to load them. Adding the path of the dependencies to the PATH environment variable should fix this (typically, the directory of the PKCS11 library itself).

Emmanuel Bourg
  • 9,601
  • 3
  • 48
  • 76