从Linux 64位访问javax.smartcardio [英] Accessing javax.smartcardio from Linux 64 bits

查看:169
本文介绍了从Linux 64位访问javax.smartcardio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有以下代码的javax.smartcardio API加载智能卡终端:

I'm trying to load the smartcard terminals using the javax.smartcardio API with the following code:

public CardTerminal getReadyCardTerminal() throws CardException {

    TerminalFactory factory = TerminalFactory.getDefault();
    CardTerminals terminals = factory.terminals();
    List<CardTerminal> list = terminals.list(State.CARD_PRESENT);

    while (list.isEmpty()) {
        terminals.waitForChange(1000);
        list = terminals.list(State.CARD_PRESENT);
    }
    CardTerminal cardTerminal = list.get(0);
    return cardTerminal;
}

...我总是得到以下例外:

... and I always get the following exception:

java.lang.IllegalStateException: no terminals
at javax.smartcardio.TerminalFactory$NoneCardTerminals.waitForChange(TerminalFactory.java:145)

在Windows Vista / 7上,一切正常,但我无法在Linux上运行。我正在使用Ubuntu 12.04 64位。

On Windows Vista/7 everything works fine, but I can't get it to work on Linux. I'm using Ubuntu 12.04 64 bits.

我使用以下命令安装了pcscd服务:

I installed the pcscd service using the following command:

sudo apt-get install libccid pcscd libpcsclite-dev libpcsclite1
sudo service pcscd start

并且pcsc_scan命令打印出:

And the pcsc_scan command prints this:

PC/SC device scanner
V 1.4.18 (c) 2001-2011, Ludovic Rousseau <ludovic.rousseau@free.fr>
Compiled with PC/SC lite version: 1.7.4
Using reader plug'n play mechanism
Scanning present readers...
0: OMNIKEY CardMan 3x21 00 00

Tue Sep 11 15:44:49 2012
Reader 0: OMNIKEY CardMan 3x21 00 00
  Card state: Card inserted, 
  ATR: <some hexa codes>
  ...

所以一切看起来都不错,但智能卡只是不起作用。我正在尝试使用Oracle和OpenJDK 1.7.0_05,32和64位。

So everything looks ok, but the smartcardio just doesn't work. I'm trying with both Oracle and OpenJDK 1.7.0_05, 32 and 64 bits.

使用OpenJDK可以运行代码(但不能使用Oracle JDK,不知道真的是为什么)在Ubuntu 32位环境下。所以我认为从Java到PC / SC库的64位桥是一个问题。

The code runs ok with OpenJDK (but not with Oracle JDK, don't know really why) on a Ubuntu 32 bits environment. So I think it is a problem with the 64 bits bridge from Java to the PC/SC library.

有什么想法吗?

谢谢。

推荐答案

我想我找到了一个解决方法,因为我遇到了类似的问题。在来自ubuntu的bug报告中,它表示javax。 smartcardio库在错误的目录中搜索PC / SC库。

I think I found a workaround for this as I just had a similar problem. In a bugreport from ubuntu it says that the javax.smartcardio library searches for the PC/SC library in the wrong directory.

通过在我的机器上指定PC / SC库的路径,就像bugreport提到的那样,我得到了它的工作。

By specifying the path to the PC/SC library on my machine, like the bugreport mentions, I got it working.

bug报告中的路径对我来说是错误的,我在64位fedora上,其中pc / sc库安装在/usr/lib64/libpcsclite.so.1

The paths in the bugreport are wrong for me, I'm on 64 bit fedora, where the pc/sc library are installed at /usr/lib64/libpcsclite.so.1

因此我的解决方法是指定java的库路径,如下所示:

So the workaround for me is to specify the library path to java like this:

java -Dsun.security.smartcardio.library=/usr/lib64/libpcsclite.so.1

取决于您的Linux发行版, libpcsclite.so.1 的位置实际上可能不同,它也可能位于 /lib/x86_64-linux-gnu/libpcsclite.so。 1 (即Kubuntu 15.04)。
在这种情况下,请这样称呼:

Depending on your Linux distribution, the location of libpcsclite.so.1 actually might differ, it could also be at /lib/x86_64-linux-gnu/libpcsclite.so.1 (i.e. Kubuntu 15.04). In that case, call it like this:

java -Dsun.security.smartcardio.library=/lib/x86_64-linux-gnu/libpcsclite.so.1

这篇关于从Linux 64位访问javax.smartcardio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆