T=0 JavaCards 的传输错误
Transmission error for T=0 JavaCards
我有 4 种不同类型的 JavaCards。出于一个奇怪的目的,我编写了以下小程序 return 在接收到每个 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
(Returns 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" 卡片响应为 "expected"。而是 "T=1" 卡/JCOP returns 出乎意料的结果。
您正在发送以下 APDU:
00A404000B0102030405060708090101
00000000
00000000020101
第一个和第三个是 case-3 APDU(Lc 和命令 DATA 字段存在,Le 字段不存在)。第二个 APDU 是 case-1 APDU(只有命令头,但没有 Lc、DATA 和 LE 字段)。因此,所有三个 APDU 都清楚地表明不应返回任何响应数据字段。因此,您永远不应为此类命令调用 setOutgoing*()
方法。请注意,Java Card API 规范对此非常清楚,并明确指出在 case-1/case-3 命令上调用 setOutgoing*()
可能会导致 unexpected/wrong 行为:
This method should only be called on a case 2 or case 4 command, otherwise erroneous behavior may result.
因此,您应该始终检查您拥有的命令案例,并在适当时只检查 receive/respond 数据(您通常可以根据指令代码确定这一点,因为您知道每条指令的期望值).
为什么 case-1 APDU 像 你 期望的那样工作(即 returns 响应数据字段)与 T=0 TPDU 的格式和APDU 映射该格式的方式。 T=0 TPDU 的格式为
CLA INS P1 P2 P3 [DATA]
P3 字段始终存在,而 DATA 字段仅在 case-3 APDU 中存在。应用了 TPDU 和 APDU 之间的以下映射:
- Case-4 APDU:T=0 不直接支持(reader 通常将其映射到 case-3 + GET RESPONSE 命令)
- 案例 3 APDU:P3 = Lc,数据 = 数据
- 案例 2 APDU:P3 = Le,数据 = 不存在
- 案例 1 APDU:P3 = 0,数据 = 不存在
如您所见,对于 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
)。
我有 4 种不同类型的 JavaCards。出于一个奇怪的目的,我编写了以下小程序 return 在接收到每个 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
(Returns 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" 卡片响应为 "expected"。而是 "T=1" 卡/JCOP returns 出乎意料的结果。
您正在发送以下 APDU:
00A404000B0102030405060708090101
00000000
00000000020101
第一个和第三个是 case-3 APDU(Lc 和命令 DATA 字段存在,Le 字段不存在)。第二个 APDU 是 case-1 APDU(只有命令头,但没有 Lc、DATA 和 LE 字段)。因此,所有三个 APDU 都清楚地表明不应返回任何响应数据字段。因此,您永远不应为此类命令调用 setOutgoing*()
方法。请注意,Java Card API 规范对此非常清楚,并明确指出在 case-1/case-3 命令上调用 setOutgoing*()
可能会导致 unexpected/wrong 行为:
This method should only be called on a case 2 or case 4 command, otherwise erroneous behavior may result.
因此,您应该始终检查您拥有的命令案例,并在适当时只检查 receive/respond 数据(您通常可以根据指令代码确定这一点,因为您知道每条指令的期望值).
为什么 case-1 APDU 像 你 期望的那样工作(即 returns 响应数据字段)与 T=0 TPDU 的格式和APDU 映射该格式的方式。 T=0 TPDU 的格式为
CLA INS P1 P2 P3 [DATA]
P3 字段始终存在,而 DATA 字段仅在 case-3 APDU 中存在。应用了 TPDU 和 APDU 之间的以下映射:
- Case-4 APDU:T=0 不直接支持(reader 通常将其映射到 case-3 + GET RESPONSE 命令)
- 案例 3 APDU:P3 = Lc,数据 = 数据
- 案例 2 APDU:P3 = Le,数据 = 不存在
- 案例 1 APDU:P3 = 0,数据 = 不存在
如您所见,对于 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
)。