smartcard - T=0 JavaCard 的传输错误

标签 smartcard javacard apdu globalplatform

我有 4 种不同类型的 JavaCard。出于一个奇怪的目的,我编写了以下小程序,以在接收到每个 APDU 命令时返回整个 APDU 缓冲区:

package bufferReturner;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;

public class BufferReturner extends Applet {

    private BufferReturner() {
    }

    public static void install(byte bArray[], short bOffset, byte bLength)
            throws ISOException {
        new BufferReturner().register();

    }

    public void process(APDU arg0) throws ISOException {
        arg0.setOutgoingAndSend((short)0, (short)256);
    }

}

当我向我的卡发送 APDU 命令时,我得到以下结果:

NXP JCOP v2.4.2 r3 卡 - 使用 T=1

OpenSCTool:> OSC.exe -s 00A404000B0102030405060708090101 -s 00000000 -s 00000000020101
Using reader with a card: CASTLES EZ100PU 0
Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01
Received (SW1=0x90, SW2=0x00):
00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

Sending: 00 00 00 00 02 01 01
Received (SW1=0x90, SW2=0x00):
00 00 00 00 02 01 01 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

OpenSCTool:>

正如您在上面看到的,我的 JCOP 卡按照我的预期做出了回应。但我的 T=0 卡有问题:

复旦FM1280 - 使用T=0 (返回 9000 而不是缓冲区!)

OpenSCTool:> OSC.exe -s 00A404000B0102030405060708090101 -s 00000000 -s 00000000020101
Using reader with a card: CASTLES EZ100PU 0
Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01
Received (SW1=0x90, SW2=0x00)
Sending: 00 00 00 00
Received (SW1=0x90, SW2=0x00):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Sending: 00 00 00 00 02 01 01
Received (SW1=0x90, SW2=0x00)

OpenSCTool:>

金雅拓 Top dl v2 - 使用 T=0 (我遇到传输失败错误)

OpenSCTool:> OSC.exe -s 00A404000B0102030405060708090101 -s 00000000 -s 00000000020101
Using reader with a card: CASTLES EZ100PU 0
Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01
Received (SW1=0x90, SW2=0x00)
Sending: 00 00 00 00
Received (SW1=0x90, SW2=0x00):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Sending: 00 00 00 00 02 01 01
APDU transmit failed: Transmit failed

OpenSCTool:>

未知卡 - 使用 T=0 (我遇到传输失败错误)

OpenSCTool:> OSC.exe -s 00A404000B0102030405060708090101 -s 00000000 -s 00000000020101
Using reader with a card: CASTLES EZ100PU 0
Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01
Received (SW1=0x90, SW2=0x00)
Sending: 00 00 00 00
Received (SW1=0x90, SW2=0x00):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Sending: 00 00 00 00 02 01 01
APDU transmit failed: Transmit failed

OpenSCTool:>

T=0 卡有什么问题?

最佳答案

你的卡没有任何问题。实际上,三张“T=0”卡的响应是“预期的”。相反,“T=1”卡/JCOP 返回了意想不到的结果。

您正在发送以下 APDU:

  1. 00A404000B0102030405060708090101
  2. 00000000
  3. 00000000020101

第一个和第三个是情况 3 APDU(存在 Lc 和命令数据字段,不存在 Le 字段)。第二个 APDU 是 case-1 APDU(仅命令头,但不存在 Lc、DATA 和 LE 字段)。因此,所有三个 APDU 都清楚地表明不应返回任何响应数据字段。因此,您永远不应该为此类命令调用 setOutgoing*() 方法。请注意,Java Card API 规范对此非常明确,并明确指出在 case-1/case-3 命令上调用 setOutgoing*() 可能会导致意外/错误的行为:

This method should only be called on a case 2 or case 4 command, otherwise erroneous behavior may result.

因此,您应该始终检查您拥有的命令情况,并且仅在适当时接收/响应数据(您通常可以根据指令代码确定这一点,因为您知道每条指令的期望)。

为什么 case-1 APDU 按的预期工作(即返回响应数据字段)与 T=0 TPDU 的格式以及 APDU 映射该格式的方式有关。 T=0 TPDU 的格式为

CLA INS P1 P2 P3 [DATA]

P3 字段始终存在,而 DATA 字段仅在 case-3 APDU 中存在。 TPDU 和 APDU 之间应用以下映射:

  • 案例 4 APDU:T=0 不直接支持(读者通常将其映射到案例 3 + GET RESPONSE 命令)
  • 案例 3 APDU:P3 = Lc,DATA = DATA
  • 案例 2 APDU:P3 = Le,DATA = 不存在
  • 案例 1 APDU:P3 = 0,DATA = 不存在

如您所见,对于 case-1 APDU,P3 字段填充为零。这意味着卡无法区分 Le = 0 的 case-2 APDU 和 case-1 APDU。因此,当 T=0 时,任何 case-1 APDU 将被视为 case-2 APDU。因此,setOutgoingAndSend() 方法将适用于 case-1 APDU(在您的情况下为 00000000)。

关于smartcard - T=0 JavaCard 的传输错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34986522/

相关文章:

java - 我可以在非 Java 智能卡上上传我的 Java 卡小程序吗?

java - 如何使用java在智能卡上安装applet

java - 是否可以在卡不存在时发送伪 APDU 命令?

security - 锁定/解锁智能卡和安全隐患

javascript - 通过网络浏览器访问智能卡读卡器?

c - 无法编译读取智能卡的 C 应用程序

java - 如何使用 "install"方法将 "process"方法参数发送到读卡器?

rsa - 如何从我的 RSA Sign 获得正确的结果?

apdu - 建议 EMV 卡需要回应吗?

smartcard - 我应该使用哪个APDU命令来取消当前正在执行的读取记录?