问题
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