2

我有 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 卡有问题:

Fudan 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:>

Gemalto 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 卡有什么问题?

4

1 回答 1

4

你的卡没什么问题。实际上,三张“T=0”牌的反应是“预期的”。而是返回意外结果的“T=1”卡/JCOP。

您正在发送以下 APDU:

  1. 00A404000B0102030405060708090101
  2. 00000000
  3. 00000000020101

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

此方法只能在 case 2 或 case 4 命令上调用,否则可能会导致错误行为。

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

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

CLA INS P1 P2 P3 [DATA]

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

  • Case-4 APDU:T=0 不直接支持(阅读器通常将其映射到 case-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在您的情况下)。

于 2016-01-25T08:02:08.167 回答