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=1OpenSCTool:> OSC.exe -s 00A404000B0102030405060708090101 -s 00000000 -s 00000000020101Using reader with a card: CASTLES EZ100PU 0Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01Received (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 01Received (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 00000000020101Using reader with a card: CASTLES EZ100PU 0Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01Received (SW1=0x90, SW2=0x00)Sending: 00 00 00 00Received (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 01Received (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 00000000020101Using reader with a card: CASTLES EZ100PU 0Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01Received (SW1=0x90, SW2=0x00)Sending: 00 00 00 00Received (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 01APDU transmit failed: Transmit failedOpenSCTool:>Unknown card - Working with T=0(I face with Transmission failed error)OpenSCTool:> OSC.exe -s 00A404000B0102030405060708090101 -s 00000000 -s 00000000020101Using reader with a card: CASTLES EZ100PU 0Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01Received (SW1=0x90, SW2=0x00)Sending: 00 00 00 00Received (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 01APDU transmit failed: Transmit failedOpenSCTool:>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:00A404000B01020304050607080901010000000000000000020101The 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: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 formatCLA 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 = DATACase-2 APDU: P3 = Le, DATA = absentCase-1 APDU: P3 = 0, DATA = absentAs 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的传输错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-06 01:49