Process method does not receive full APDU command from host?

◇◆丶佛笑我妖孽 提交于 2019-12-19 09:53:52

问题


The host sends the following command to applet to select EF file

00 A4 02 00 02 40 01

The purpose is to select EF file with ID 40 01 (which is specified in the data field of the command).

But when I debug the process(APDU apdu) method, the APDU buffer only contains the 5 first bytes 00 A4 02 00 02. The data field is set to 00 00. So my applet cannot select the EF using EF ID.

Could you tell me what is wrong with my APDU command above?


回答1:


Depending on the card (or emulator), the APDU buffer may only contain the APDU header fields (CLA, INS, P1, P2, Lc). Even if some cards automatically fill the data part of the command APDU into the APDU buffer, you can't rely on that behavior.

Instead, you have to explicitly instruct the card (or emulator) to retrieve the data part by calling the setIncomingAndReceive() method on the APDU object. But note that this method must only be called for case 3 and case 4 APDUs (i.e. APDU commands that contain a command data part). If there is no command data field, you should not call this method (case 1 and case 2 APDUs).




回答2:


To get data in APDU buffer you need to call apdu.setIncomingAndReceive() and as in EMV specification AID for an applet is 5-16 bytes can't use less than 5 bytes.



来源:https://stackoverflow.com/questions/34149458/process-method-does-not-receive-full-apdu-command-from-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!