Search code examples
classjavacardapdu

(Javacard) Class Error Test of APDU Command 'Select File'


there

I don't understand why the Error 'Class is Not Supported' does not occur.

Firstly, my source code and APDU commands are as follows

< Source Code >

package SelectFileTest;
import javacard.framework.*;

public class SelectFileTest extends Applet{
    public static void install(byte[] bArray, short bOffset, byte bLength) {
        new SelectFileTest(bArray, bOffset, bLength);
    }   
    private SelectFileTest(byte bArray[], short bOffset, byte bLength){     
        register();
    }

    public void process(APDU apdu){
        byte buf[] = apdu.getBuffer();
        if (buf[1]==(byte)0xA4) {       
            if((buf[0]&0xff)!=0x00)                         // Class Check (Question)
                ISOException.throwIt((short)0xfff5);

            if(selectingApplet()) 
                {   }
            else
                ISOException.throwIt((short)0xffff);        // 6881
        }
        return ;
    }
}

< APDU Command >

[Card-1C] <== 00 A4 04 00 07 A0000000031234
[Card-1R] ==> 9000
[Card-2C] <== 00 A4 00 00 02 F801
[Card-2R] ==> FFFF                              // Expected
[Card-3C] <== 01 A4 00 00 02 F801
[Card-3R] ==> 6881                              // (Question) Expect the SW 'FFF5'
[Card-4C] <== 08 A4 00 00 02 F801
[Card-4R] ==> FFF5                              // Expected

By the command 3 and 4, the card must output the SW 'FFF5' because of the line 'Class Check'in source code. But, it outputs 6881(3R) (maybe by JCRE) at CLA=01~07.

I know that once the applet is selected, the JCRE forwards all subsequent APDUs commands to the selected applet. Therefore, I think the 3rd response(3R) is also 'FFF5' like 4R. I don't understand and couldn't find my mistakes in my code.

I hope your valuable comments. Thanks in advance.


Solution

  • In the CLA byte the logical channel is indicated in the lower bits. You are selecting a logical channel which the platform then tries to send to the correct applet. It will however not find any open channel except the basic one (with ID = 0). So the platform will handle the error instead of the Applet. This happens before the Applet receives the APDU; the Applet will not be notified.

    Note that this can also happen for the INS: MANAGE CHANNEL. I probably don't have to explain that SELECT by AID is also initially handled by the runtime environment.

    More information about logical channels and how they might be utilized can be found in the ISO/IEC 7816-4.