【问题标题】:PCSC does not return anything on linux, the card reader is connectedPCSC 在 linux 上不返回任何内容,读卡器已连接
【发布时间】:2013-04-12 08:59:25
【问题描述】:

我正在尝试这个,用 PCSC 框架读取卡。但它根本不返回任何东西。

import java.util.List;
import javax.smartcardio.*;

public class Blog {
 public static void main(String[] args) {
  try {
   // Display the list of terminals
   TerminalFactory factory = TerminalFactory.getDefault();
   List<CardTerminal> terminals = factory.terminals().list();
   System.out.println("Terminals: " + terminals);

   // Use the first terminal
   CardTerminal terminal = terminals.get(0);

   // Connect wit hthe card
   Card card = terminal.connect("*");
   System.out.println("card: " + card);
   CardChannel channel = card.getBasicChannel();

   // Send Select Applet command
   byte[] aid = {(byte)0xA0, 0x00, 0x00, 0x00, 0x62, 0x03, 0x01, 0x0C, 0x06, 0x01};
   ResponseAPDU answer = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x04, 0x00, aid));
   System.out.println("answer: " + answer.toString());

   // Send test command
   answer = channel.transmit(new CommandAPDU(0x00, 0x00, 0x00, 0x00));
   System.out.println("answer: " + answer.toString());
   byte r[] = answer.getData();
   for (int i=0; i<r.length; i++)
    System.out.print((char)r[i]);
   System.out.println();

   // Disconnect the card
   card.disconnect(false);
  } catch(Exception e) {
   System.out.println("Ouch: " + e.toString());
  }
 }
}

输出:

run-single:
Terminals: []
Ouch: java.lang.IndexOutOfBoundsException: Index: 0
BUILD SUCCESSFUL (total time: 4 seconds)

通过使用其他工具,它可以工作,但无法弄清楚为什么 Java 代码没有显示?

root@sun-M14xR2:/var/tmp# ps -e | grep pcsc
16399 ?        00:00:00 pcscd
root@sun-M14xR2:/var/tmp# service pcscd status
 * pcscd is running
root@sun-M14xR2:/var/tmp# service pcscd restart
 * Restarting PCSC Lite resource manager pcscd                                                                                                                   [ OK ] 
root@sun-M14xR2:/var/tmp# lsusb
Bus 003 Device 032: ID 076b:3021 OmniKey AG CardMan 3121
root@sun-M14xR2:/var/tmp# opensc-tool -l
# Detected readers (pcsc)
Nr.  Card  Features  Name
0    No              Generic CCID Reader 00 00

root@sun-M14xR2:/var/tmp# pcsc_scan 
PC/SC device scanner
V 1.4.20 (c) 2001-2011, Ludovic Rousseau <ludovic.rousseau@free.fr>
Compiled with PC/SC lite version: 1.8.3
Using reader plug'n play mechanism
Scanning present readers...
0: Generic CCID Reader 00 00

Fri Apr 19 05:30:22 2013
Reader 0: Generic CCID Reader 00 00
  Card state: Card removed, 

Fri Apr 19 05:30:59 2013
Reader 0: Generic CCID Reader 00 00
  Card state: Card inserted, Unresponsive card, 

Fri Apr 19 05:31:04 2013
Reader 0: Generic CCID Reader 00 00
  Card state: Card removed, 


Fri Apr 19 05:33:31 2013
Reader 0: Generic CCID Reader 00 00
  Card state: Card inserted, 
  ATR: 3B 98 13 40 0A A5 03 01 01 01 AD 13 11

ATR: 3B 98 13 40 0A A5 03 01 01 01 AD 13 11
+ TS = 3B --> Direct Convention
+ T0 = 98, Y(1): 1001, K: 8 (historical bytes)
  TA(1) = 13 --> Fi=372, Di=4, 93 cycles/ETU
    43010 bits/s at 4 MHz, fMax for Fi = 5 MHz => 53763 bits/s
  TD(1) = 40 --> Y(i+1) = 0100, Protocol T = 0 
-----
  TC(2) = 0A --> Work waiting time: 960 x 10 x (Fi/F)
+ Historical bytes: A5 03 01 01 01 AD 13 11
  Category indicator byte: A5 (proprietary format)

Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
3B 98 13 40 0A A5 03 01 01 01 AD 13 11
    Belgium Electronic ID card

【问题讨论】:

    标签: java linux pcsc


    【解决方案1】:

    我在这里找到了另一种解决方法

    Accessing javax.smartcardio from Linux 64 bits

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

    因此,使用以下设置运行我的应用程序对我有用

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

    【讨论】:

    • 这个解决方案对我有用,但在我的机器(Ubuntu 18.08)中,文件不同:-Dsun.security.smartcardio.library=/usr/lib/x86_64-linux-gnu/libpcsclite.so。 1
    【解决方案2】:

    这是因为 Linux 中的驱动程序问题。请为此硬件安装正确的驱动程序:https://www.hidglobal.com/drivers/14919

    然后我在终端中至少得到了代码反馈。

    【讨论】:

    • 我已经为 ACR122U 安装了驱动程序,现在 libpcsclite.so 文件的程序参数路径是有效的,但仍然没有在 java 代码中获取终端。我在哪里得到了积极的pcsc_scan 结果,显示卡详细信息和状态
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 2021-05-10
    • 2016-02-23
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    • 2021-06-18
    相关资源
    最近更新 更多