T = 0 JavaCard的传输错误 [英] Transmission error for T=0 JavaCards

查看:99
本文介绍了T = 0 JavaCard的传输错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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:>

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卡怎么了?

解决方案

您的卡没有问题.实际上,三个"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规范对此非常清楚,并明确指出在case-1/case-3命令上调用setOutgoing*()可能会导致意外/错误的行为:

仅应在case 2或case 4命令上调用此方法,否则可能导致错误的行为.

因此,您应始终检查所用命令的大小写,并仅在适当时接收/响应数据(通常可以根据指令代码确定此条件,因为您知道每条指令的期望).

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

CLA INS P1 P2 P3 [DATA]

P3字段始终存在,而DATA字段仅对于情况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 =不存在

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

I have 4 different types of JavaCards. For a weird purpose, I wrote the following applet to return whole the APDU buffer on reception of each APDU command:

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);
    }

}

When I send APDU commands to my cards I have the following results:

NXP JCOP v2.4.2 r3 card - Working with 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:>

As you see above, my JCOP card responds me as I expected. But I have a problem with my T=0 cards:

Fudan FM1280 - Working with T=0 (Returns 9000 instead of the buffer!)

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 - Working with T=0 (I face with Transmission failed error)

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

Unknown card - Working with T=0 (I face with Transmission failed error)

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

What is wrong with T=0 cards?

解决方案

Nothing is wrong with your cards. Actually, the three "T=0" cards respond as "expected". It's rather the "T=1" card / JCOP that returns unexpected results.

You are sending the following APDUs:

  1. 00A404000B0102030405060708090101
  2. 00000000
  3. 00000000020101

The first and the third are case-3 APDUs (Lc and command DATA field present, Le field absent). The second APDU is a case-1 APDU (only command header, but no Lc, DATA and LE fields present). Hence, all three APDUs clearly indicate that no response data field should be returned. Consequently, you should never call setOutgoing*() methods for such commands. Note that the Java Card API specification is quite clear on this and clearly states that calling setOutgoing*() on case-1/case-3 commands may lead to unexpected/wrong behavior:

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

Thus, you should always check what command case you have and only receive/respond data when it is appropriate (you can typically determine this based on the instruction code, since you know what you would expect for each instruction).

Why the case-1 APDU works as you expect (i.e. returns a response data field) has to do with the format of T=0 TPDUs and the way that APDUs are mapped that format. A T=0 TPDU has the format

CLA INS P1 P2 P3 [DATA]

The P3 field is always present, while the DATA field is only present for case-3 APDUs. The following mapping between TPDU and APDU is applied:

  • Case-4 APDU: not directly supported by T=0 (the reader typically maps this into case-3 + a GET RESPONSE command)
  • Case-3 APDU: P3 = Lc, DATA = DATA
  • Case-2 APDU: P3 = Le, DATA = absent
  • Case-1 APDU: P3 = 0, DATA = absent

As you see, the P3 field is filled with zero for case-1 APDUs. This means that the card cannot distinguish between a case-2 APDU with Le = 0 and a case-1 APDU. As a result, with T=0, any case-1 APDU will be treatd as a case-2 APDU. Consequently, the setOutgoingAndSend() method will work for the case-1 APDU (00000000 in your case).

这篇关于T = 0 JavaCard的传输错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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