You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

javax.smartcardio package not working in Java 7 on OS X ML

Hi,


I have applet that uses javax.smartcardio package to comunicate with smart card! It works on all Windows, Linux and versions before Mac OS X Lion!

But in OS X ML the applet crashes. There is no 32 bit Java 7 to test with it. I don't know if the problem is PCSC library or this reported bug.

Since Java 7 is embeded in browser plugin if I remove it, my applets are not started at all, and I can not use Java 6.

What should I do?


At Thread 45 I see "libj2pcsc.dylib". Is this the pcsc library used by Java to connect to Smard Card readers?


The error mesage starts with :


Process: java [275]
Path: /usr/bin/java
Identifier: net.java.openjdk.cmd
Version: 1.0 (1.0)
Code Type: X86-64 (Native)
Parent Process: firefox [250]
User ID: 501

PlugIn Path: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/server/libjvm.dylib
PlugIn Identifier: libjvm.dylib
PlugIn Version: ??? (1)

Date/Time: 2013-02-22 14:42:21.668 +0200
OS Version: Mac OS X 10.8.2 (12C3103)
Report Version: 10

Interval Since Last Report: 578 sec
Crashes Since Last Report: 3
Per-App Interval Since Last Report: 81 sec
Per-App Crashes Since Last Report: 3
Anonymous UUID: 96EB679A-6347-0DC9-8DD0-92120850DE45

Crashed Thread: 45 Java: Thread-20

Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000

VM Regions Near 0:
-->
__TEXT 00000001075fd000-000000010760e000 [ 68K] r-x/rwx SM=COW /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java

Application Specific Information:
abort() called

Thread 0:: AppKit Thread Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff90f3d686 mach_msg_trap + 10
1 libsystem_kernel.dylib 0x00007fff90f3cc42 mach_msg + 70
2 com.apple.CoreFoundation 0x00007fff8e360803 __CFRunLoopServiceMachPort + 195
3 com.apple.CoreFoundation 0x00007fff8e365ee6 __CFRunLoopRun + 1078
4 com.apple.CoreFoundation 0x00007fff8e3656b2 CFRunLoopRunSpecific + 290
5 com.apple.HIToolbox 0x00007fff87dd10a4 RunCurrentEventLoopInMode + 209
6 com.apple.HIToolbox 0x00007fff87dd0e42 ReceiveNextEventCommon + 356
7 com.apple.HIToolbox 0x00007fff87dd0cd3 BlockUntilNextEventMatchingListInMode + 62
8 com.apple.AppKit 0x00007fff8eb94613 _DPSNextEvent + 685
9 com.apple.AppKit 0x00007fff8eb93ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
10 libosxapp.dylib 0x00000001657c1b56 -[NSApplicationAWT nextEventMatchingMask:untilDate:inMode:dequeue:] + 124
11 com.apple.AppKit 0x00007fff8eb8b283 -[NSApplication run] + 517
12 libosxapp.dylib 0x00000001657c19b9 +[NSApplicationAWT runAWTLoopWithApp:] + 156
13 liblwawt.dylib 0x000000016571b81a -[AWTStarter starter:] + 1591
14 com.apple.Foundation 0x00007fff89b57677 __NSThreadPerformPerform + 225
15 com.apple.CoreFoundation 0x00007fff8e343101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 com.apple.CoreFoundation 0x00007fff8e342a25 __CFRunLoopDoSources0 + 245
17 com.apple.CoreFoundation 0x00007fff8e365dc5 __CFRunLoopRun + 789
18 com.apple.CoreFoundation 0x00007fff8e3656b2 CFRunLoopRunSpecific + 290
19 java 0x000000010760442d CreateExecutionEnvironment + 871
20 java 0x00000001075febdc JLI_Launch + 1952
21 java 0x000000010760478a main + 101
22 java 0x00000001075fe434 start + 52
....

Thread 45 Crashed:: Java: Thread-20

0 libsystem_kernel.dylib 0x00007fff90f3f212 __pthread_kill + 10

1 libsystem_c.dylib 0x00007fff9092baf4 pthread_kill + 90

2 libsystem_c.dylib 0x00007fff9096fdce abort + 143

3 libjvm.dylib 0x0000000107adbc6f os::abort(bool) + 25

4 libjvm.dylib 0x0000000107bca42e VMError::report_and_die() + 2306

5 libjvm.dylib 0x0000000107add363 JVM_handle_bsd_signal + 1073

6 libsystem_c.dylib 0x00007fff909188ea _sigtramp + 26

7 libj2pcsc.dylib 0x0000000164a7066e pcsc_multi2jstring + 17

8 libj2pcsc.dylib 0x0000000164a707f9 Java_sun_security_smartcardio_PCSC_SCardListReaders + 114

9 ??? 0x00000001083b5f90 0 + 4433076112

10 ??? 0x00000001083aa333 0 + 4433027891

11 ??? 0x00000001083aa450 0 + 4433028176

12 ??? 0x00000001083aa450 0 + 4433028176

13 ??? 0x00000001083aa333 0 + 4433027891

14 ??? 0x00000001083aa158 0 + 4433027416

15 ??? 0x00000001083aa450 0 + 4433028176

16 ??? 0x00000001083aa333 0 + 4433027891

17 ??? 0x00000001083aa333 0 + 4433027891

18 ??? 0x00000001083aa806 0 + 4433029126

19 ??? 0x00000001083a44f7 0 + 4433003767

20 libjvm.dylib 0x00000001079af52f JavaCalls::call_helper(JavaValue*, methodHandle*, JavaCallArguments*, Thread*) + 557

21 libjvm.dylib 0x00000001079afa0c JavaCalls::call_virtual(JavaValue*, KlassHandle, Symbol*, Symbol*, JavaCallArguments*, Thread*) + 256

22 libjvm.dylib 0x00000001079afb46 JavaCalls::call_virtual(JavaValue*, Handle, KlassHandle, Symbol*, Symbol*, Thread*) + 74

23 libjvm.dylib 0x00000001079e64c0 thread_entry(JavaThread*, Thread*) + 169

24 libjvm.dylib 0x0000000107b9f294 JavaThread::thread_main_inner() + 134

25 libjvm.dylib 0x0000000107ba077a JavaThread::run() + 440

26 libjvm.dylib 0x0000000107adc191 java_start(Thread*) + 173

27 libsystem_c.dylib 0x00007fff9092a742 _pthread_start + 327

28 libsystem_c.dylib 0x00007fff90917181 thread_start + 13

Thank you

Best Regards

Valentin Ivanov

MacBook Air, OS X Mountain Lion (10.8.2)

Posted on Mar 6, 2013 1:42 AM

Reply
9 replies

Mar 11, 2013 3:00 PM in response to V@lentino

Hi. Yes, it is the same as the bug you linked.


Solution: replace libj2pcsc.dylib[1] with a fixed library. You can download the one I made here[3], if you trust some random person on the Internet.


Details: I filed a more descriptive bug two months ago but Oracle never acknowledged it. The bug is that Oracle's 64-bit PCSC native library[1] is broken. They included a header file that typedef's DWORD to a 64-bit value, when the PCSC OS X library actually gives you a 32-bit value. The fix is to replace winscard.h[2] with a header that simply #include <PCSC/wincard.h>, #include <PCSC/wintypes.h> and then run the openjdkathome compile. Then replace your JDK7 copy of the library with the fixed one.


Yonathan Randolph

www.github.com/yonran


[1]: /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/libj2pc sc.dylib

[2]: OpenJDK: jdk/src/solaris/native/sun/security/smartcardio/MUSCLE/winscard.h

[3]: http://dl.dropbox.com/u/17967820/libj2pcsc.dylib

Mar 14, 2013 3:31 AM in response to yonran

Hi Yonathan Randolph,


I have tried your fixed library but nothing happens at all. The problem still remains.

By the way in Mac OS X ML we have no path as /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/libj2pc sc.dylib. We have libj2pcsc.dylib in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin 1/Contents/Home/lib, since Java 7 is embeded in browser plugin for OS X ML. We have no installed jDK at all. This is client pc.

I would like to ask you for link to the bug you have posted to Oracle.


Thank you

Best Regards, Valentin Ivanov

Mar 14, 2013 4:04 AM in response to V@lentino

Since Java 7 is embeded in browser plugin if I remove it, my applets are not started at all


I cannot address your question, but you should be aware that using Java in the browser is extremely dangerous at this time, and shows no signs of ever becoming safe. See:


Java is vulnerable… Again?!


and:


http://java-0day.com


You should really start finding ways to replace Java in your web browser with other things.

Oct 10, 2013 7:33 AM in response to V@lentino

I can confirm the issue here (Mountain Lion, 10.8.5). A very simple program (attached below) that just enumerates terminals and checks if a card is present will crash:


  • If Apple JDK6 is used in 64-bit mode (without supplying the -d32 argument)
  • If Oracle JDK7 is used (can not switch to 64-bit, uses)


It will work if:


  • If Apple JDK6 is forced into 32-bit mode using -d32
  • If Oracle JDK7 version of libj2pcsc.dylib is replaced with a patched version


javax.smartcardio on Mac OS X is in a truly sad state. :-(

Can anyone suggest alternatives for Smartcard communication on Mac OS X fat clients?





package com.example.smartcardio;


import javax.smartcardio.CardTerminal;

import javax.smartcardio.CardTerminals;

import javax.smartcardio.TerminalFactory;


public class TestWaitForChanges {

public static void main(String[] args) throws Exception {

CardTerminals terminals = TerminalFactory.getDefault().terminals();

while (true) {

for (CardTerminal terminal : terminals.list()) {

System.out.println("Checking terminal: " + terminal.getName());

System.out.println("Card present: " + (terminal.isCardPresent() ? "YES" : "NO"));

}



System.out.println("Waiting for changes...");

terminals.waitForChange();

}

}

}

javax.smartcardio package not working in Java 7 on OS X ML

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.