Using j2pkcs11.dll with java 8 (64-bit) on windows 7 (64-bit) - pkcs#11

I trying to use the j2pkcs11.dll (packaged with jdk1.8.0 - 64bit) to access certificates stored on a smartcard but not unable to make it work.
--- sample code to add the SunPKCS11 provider dynamically ---
String pkcs11ConfigSettings = "name = " + "TestSmartCard" + "\n" + "library = " + "C:/jdk1.8.0_11/jre/bin/j2pkcs11.dll";
byte[] pkcs11ConfigBytes = pkcs11ConfigSettings.getBytes();
ByteArrayInputStream confStream = new ByteArrayInputStream(pkcs11ConfigBytes);
Provider p = new sun.security.pkcs11.SunPKCS11(confStream);
---- the exception I get ---
java.security.ProviderException: Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
at scpoc.SmartCard.main(SmartCard.java:28)
Caused by: java.io.IOException: The specified procedure could not be found.
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)
JEP 131 claims to have PKCS11 support in Java 8 (http://openjdk.java.net/jeps/131) but I have not been able to get it to work on windows 7 using the java8 64-bit. Note: I also tried the java 8 32-bit on windows 7 - but no luck either.
Has anyone had any success using the SunPKCS11 provider with java 8 (Windows 7)?

SunPKCS11 provider is present only in 32-bit Windows version of JRE up until JRE7. Since JRE8 it is present also in 64-bit Windows version of JRE. This is the information you see in JEP131.
If you need to use PKCS#11 API in 64-bit Windows version of JRE older than JRE8 then you will have to use one of alternative 3rd party implementations - such as IAIK-JCE.
I have also noticed in your code sample that you are trying to directly use "j2pkcs11.dll" as a PKCS#11 library which is wrong because it is just a JNI wrapper sitting between JRE and the library implementing PKCS#11 interface. Instead of loading "j2pkcs11.dll" you need to load PKCS#11 library provided by your smartcard or HSM vendor.

Related

Scenicview 8.7 cannot find JavaFX Application

Loading Scenicview.jar version 8.7 on Windows 10 (Version 10.0.16299.726) in Java 8 via cmd line:
"C:\Program Files\Java\jre1.8.0_181\bin\java.exe" -Dprism.verbose=true -Djavafx.verbose=true -jar "Scenicview.jar"
I get the following error in the cmd output:
Loaded C:\Program Files\Java\jre1.8.0_181\lib\ext\..\..\bin\jfxwebkit.dll from relative path
Startup done
Creating server
Server done
Exception in thread "org.scenicview.model.update.RemoteVMsUpdateStrategy" java.lang.UnsatisfiedLinkError: sun.tools.attach.WindowsAttachProvider.tempPath()Ljava/lang/String;
at sun.tools.attach.WindowsAttachProvider.tempPath(Native Method)
at sun.tools.attach.WindowsAttachProvider.isTempPathSecure(WindowsAttachProvider.java:91)
at sun.tools.attach.WindowsAttachProvider.listVirtualMachines(WindowsAttachProvider.java:75)
at com.sun.tools.attach.VirtualMachine.list(VirtualMachine.java:147)
at org.fxconnector.remote.RemoteConnectorImpl.getRunningJavaFXApplications(RemoteConnectorImpl.java:360)
at org.fxconnector.remote.RemoteConnectorImpl.connect(RemoteConnectorImpl.java:251)
at org.scenicview.model.update.RemoteVMsUpdateStrategy.getActiveApps(RemoteVMsUpdateStrategy.java:57)
at org.scenicview.model.update.RemoteVMsUpdateStrategy.work(RemoteVMsUpdateStrategy.java:77)
at org.fxconnector.helper.WorkerThread.run(WorkerThread.java:43)
Loading Prism common native library ...
Loaded C:\Program Files\Java\jre1.8.0_181\lib\ext\..\..\bin\prism_common.dll from relative path
succeeded.
The Scenicview application runs up but does not find a JavaFX application that is also running in Java8. The searching... icon just keeps spining.
Has anyone expericenced this?
I was using the JRE java.exe. If I use the JDK version it works without issue.
Duplicate of ScenicView Javafx java.lang.UnsatisfiedLinkError

Normalizer.DECOMP is not anymore in java 7

I have this in my code:
String name
StringnormString=Normalizer.normalize(name, Normalizer.DECOMP, 0);
this code is build in java 1.5 and I try to upgrade to java 1.7 but I cant find what the constant Normalizer.DECOMP means in java 1.7
Try this Normalizer.normalize(name, java.text.Normalizer.Form.NFD);
Normalizer api changed slightly in java 6,so its usage is a bit different now.

Running SimpleOpenNI and leJOS in same project

We have a project in which we want to control a Lego Mindstorms robot with the Microsoft Kinect sensor. We decided to use SimpleOpenNI with Processing to read the sensor and leJOS to control the robot for a simple reason: since both is in Java, we can specifiy a kind of RoboHandler and call its methods from the sensor reading class.
In order to achieve that, we downloaded the leJOS plugin for eclipse, created a new leJOS NXT project and put the processing and SimpleOpenNI libraries in the build path. Note that to use SimpleOpenNI, it is required an old processing version without Java.
Now the problem is, that when installing leJOS, it strictly requires a 32-bit Java JDK, so I had to download this and point to it at installation.
At this point, following build paths are in the project:
LeJOS NXT Runtime (which has among others java.awt classes)
core.jar (used to run Processing in eclipse)
SimpleOpenNI.jar
Having all this, and setting up a first Processing sketch like
import processing.core.*;
public class Test extends PApplet{
(....)
}
results in following error code:
Multiple markers at this line
- The type java.awt.event.MouseMotionListener cannot be resolved. It is indirectly referenced from
required .class files
- The type java.applet.Applet cannot be resolved. It is indirectly referenced from required .class files
- The type java.awt.event.MouseListener cannot be resolved. It is indirectly referenced from required .class files
- The hierarchy of the type FirstTry is inconsistent
- The type java.awt.event.FocusListener cannot be resolved. It is indirectly referenced from required .class files
- The type java.awt.event.KeyListener cannot be resolved. It is indirectly referenced from required .class files
When I downloaded the Processing without Java version, I wasn't able to choose from 32bit- or 64bit version. The SimpleOpenNI is installed as 64bit-version.
When adding the 64bit-JDK (eclipse workspace default) as workspace too, the error disappears, but when trying to run a sketch, following error gets printed in the console:
Invalid layout of java.lang.Thread at name
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:128), pid=9176, tid=8740
# fatal error: Invalid layout of preloaded class
#
# JRE version: 7.0_04-b22
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.0-b21 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Valentino\Desktop\workspaces\workspace_processing\RoboZeugs\bin\hs_err_pid9176.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#
So in my oppinion there is a problem with the JDK versions (32 and 64 bit), but there must be a way to handle this. Has anyone experience on this specific topic, maybe even with Kinect -> Mindstorms? Can anybody tell me what this error exactly means?
You're mixing classes that are designed to run with the JVM on the NXT brick (i.e. everything in classes.jar) with classes that are designed to run with a fully fledged JVM on the PC.
Don't do that. If you want to remote control an NXT, use pccomms.jar and everything else in lib/pc. But never add classes.jar or anything else in lib/nxt to the classpath when you're starting a Java program on your PC.
The error message about java.lang.Thread is probably due to the fact, that java.lang.Thread in classes.jar in by no means compatible with java.lang.Thread that comes with the JVM on your PC.

How to edit build properties of a Java Library

There seem to be some similar questions, but nothing quite specific enough, I hope this is OK.
I am wondering how to edit the build properties of the Jamod MODBUS library so as to use the RxTx API instead of the deprecated javax.comm. The Library page says this is supported:
You will need an implementation of the Java Communications API extension (javax.comm) installed to be able to run serial modbus applications.
Note that there is also support for building with the gnu.io prefix (RXTX), via the boolean build property build.serial.gnu (true will cause the build process to replace the javax.comm prefix with gnu.io in the sources used for builds).
More info here: http://jamod.sourceforge.net/development/project_build.html
I am unsure how to access this file, or the technique for doing so. Do I need to create it or edit and existing one? I have look for build.xml in the project, but no luck, and have googled many times. Any help very much appreciated.
Just open the proyect source (you can download it from rxtx) with an IDE (for example Netbeans) then replace every appearance of javax.comm by gnu.io, from rxtx, add RXTXcomm.jar library to project, and if you are using windows then copy and rxtxSerial.dll for example to C:\windows\system32.
It will work. Good Luck
The " Modbus Jamod Project - Original " folder contains the original project is available at
Web http://jamod.sourceforge.net/ . This project has a significant dependence :
[1 ] javax.comm : comm : jar :3.0 -u1
Description : The Java Communications 3.0 API is a Java extension That Facilitates develop developing platform -independent communications applications for technologies : such as Smart Cards , embedded systems, and point -of -sale devices , financial services devices , fax , modems, display terminals , and robotic equipment .
This API is not available from Oracle repositories .
That's why you have to open the " Jamod -1.2 -SNAPSHOT - sources.jar " project and recompile using other libraries for serial communication. This project is now ready to " Modbus Jamod Project with CXR " to 64 Bits.
METHOD OF SOLUTION OF DEPENDENCE
-------------------------------------------
To recompile the Jamod (Modbus Jamod Project - Original) project, you must open the project with Netbeans clear the javax.comm library , and replaced with the rxtx library. CXR This library can be selected which are in the " CXR - Serial comms Java " folder , ie :
[1 ] MFZ - rxtx -2.2- 20081207 -linux- i386
[2 ] MFZ - rxtx -2.2- 20081207 -x86_64 -linux
[3 ] MFZ - rxtx -2.2- 20081207 -win- ia64
[4 ] MFZ - rxtx -2.2- x64 -win- 20081207
[5 ] MFZ - rxtx -2.2- x86 -win- 20081207
We must take into account the following when choosing :
Windows
-------
Select a binary build - x64 or x86 (based on Which version of
the JVM you are installing to)
NOTE : You MUST match your architecture . You can not install the i386
version on a 64 - bit version of the JDK and vice - versa.
For a JDK installation:
Copy RXTXcomm.jar ---> <JAVA_HOME> \ jre \ lib \ ext
Copy rxtxSerial.dll ---> <JAVA_HOME> \ jre \ bin
Copy rxtxParallel.dll ---> <JAVA_HOME> \ jre \ bin
Linux
-----
Select a binary build - x86_64 or i386 (based on Which version of
the JVM you are installing to)
NOTE : You MUST match your architecture . You can not install the i386
version on a 64 - bit version of the JDK and vice - versa.
For a JDK installation on i386 architecture =
Copy RXTXcomm.jar ---> <JAVA_HOME> / jre / lib / ext
Copy librxtxSerial.so ---> <JAVA_HOME> / jre/lib/i386 /
Copy librxtxParallel.so ---> <JAVA_HOME> / jre/lib/i386 /
NOTE : For a JDK installation on architecture = x86_64 , just change the
i386 to x86_64 above.
-------------------------------------------------- -----------------------------------------------
After this replace the javax.comm library , the Jamod (Modbus Jamod Project - Original) project is recompiled , and the generated Jar Crossover is added.
When the Crossover project contains the library Jamod repaired , it will have to also add the RXTX library to Crossover.
Done.
-------------------------------------------------- -----------------------------------------------
There is a copy of a build.xml file if you download the source ZIP of version 1.2rc1 at http://sourceforge.net/projects/jamod/files/jamod/1.2/jamod-1.2rc1-src.zip/download
If you unzip, you will find build.xml and build-snap.xml, as well as the build.properties file, which lets you specify the build.serial.gnu.
You then just need to install ant and run it in the directory to initiate the build.
Edit: I also didn't have Apache Forrest installed, which appears to be using for generating the docs, so I needed to comment out all references to Forrest in the build.xml as well.

unmanaged dll code

I am having a C# (.NET 3.5, VS2005 Professional) application that uses unmanaged 32bit library written in C/C++. API that I use is like this:
void * Initialize(int x);
voic GetData(void *);
And this works when I run it on Windows XP 32bit, but on Windows XP64bit it throws exception:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at Aktuelizator.CommonLibrary.InitializeRingBuffer(Int32 dim)
at Aktuelizator.AktuelizatorWService.AktuelizatorWS..ctor()
These unmanaged DLL's work under 64bit XP when called from 32bit unmanages application writetn in C/C++.
Does anyone have any idea?
Your build configuration Platform is set to 'Any CPU', that means on a 64 bit OS it runs as 64 bit and you can't load the dll. Set it instead to x86, this will force it to run as 32 bit regardless of OS and your dll will load fine.
It sounds like your DLL is only compiled to 32 bit, but you try to call it from both a 32 bit and 64 bit process. The former will work, of course. The later, however, won't. 32 bit DLLs can only be used in 32 bit processes. Try compiling the DLL to a 64 bit target and let the C# app use that one.
Check all parameters that are defined as Int32, that should in fact be IntPtr.