Javacard的process()方法中计数器的奇怪行为

时间:2015-09-15 08:42:56

标签: javacard

我在Java Card小程序的static short方法中使用名为counter的{​​{1}}字段来计算此方法的数量!

嗯,该程序非常简单,看起来像这样:

process()

当我以常规方式安装此applet时,它可以正常工作:

常规安装:

package testPack;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;

public class Test extends Applet {

    public static short counter = 0x0000;

    public static void install(byte[] bArray, short bOffset, byte bLength) {
        new Test().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
    }

    public void process(APDU apdu) {
        if (selectingApplet()) {
            return;
        }
        counter = (short) (counter + 1);
        ISOException.throwIt(counter);

    }
}

定期安装,小程序输出:

GlobalPlatformPro:> gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)


GlobalPlatformPro:> gp -install d:\test.cap

GlobalPlatformPro:> gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,

AID: 010203040501020304 (|.........|)
     App SELECTABLE: (none)

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)

AID: 010203040501 (|......|)
     ExM LOADED: (none)
     010203040501020304 (|.........|)

但是当我将其安装为OpenSCTool:> OSC.exe -s 00A4040009010203040501020304 -s 00000000 Using reader with a card: ACS CCID USB Reader 0 Sending: 00 A4 04 00 09 01 02 03 04 05 01 02 03 04 Received (SW1=0x90, SW2=0x00) Sending: 00 00 00 00 Received (SW1=0x00, SW2=0x01) OpenSCTool:> OSC.exe -s 00A4040009010203040501020304 -s 00000000 -s 0000000 Using reader with a card: ACS CCID USB Reader 0 Sending: 00 A4 04 00 09 01 02 03 04 05 01 02 03 04 Received (SW1=0x90, SW2=0x00) Sending: 00 00 00 00 Received (SW1=0x00, SW2=0x02) Sending: 00 00 00 00 Received (SW1=0x00, SW2=0x03) 小程序时,计数器的工作方式不同:

安装为默认选择的小程序:

default selected

默认选中,小程序输出:

GlobalPlatformPro:> gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)


GlobalPlatformPro:> gp -install d:\test.cap -default

GlobalPlatformPro:> gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, CVM (PIN) managem

AID: 010203040501020304 (|.........|)
     App SELECTABLE: Default selected

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)

AID: 010203040501 (|......|)
     ExM LOADED: (none)
     010203040501020304 (|.........|)

如上所述,当我将applet安装为OpenSCTool:> OSC.exe -s 00A4040009010203040501020304 -s 00000000 Using reader with a card: ACS CCID USB Reader 0 Sending: 00 A4 04 00 09 01 02 03 04 05 01 02 03 04 Received (SW1=0x90, SW2=0x00) Sending: 00 00 00 00 Received (SW1=0x00, SW2=0x06) OpenSCTool:> OSC.exe -s 00A4040009010203040501020304 -s 00000000 -s 0000000 Using reader with a card: ACS CCID USB Reader 0 Sending: 00 A4 04 00 09 01 02 03 04 05 01 02 03 04 Received (SW1=0x90, SW2=0x00) Sending: 00 00 00 00 Received (SW1=0x00, SW2=0x0C) Sending: 00 00 00 00 Received (SW1=0x00, SW2=0x0D) 时,每个命令的计数器增加 6 (而不是增加1)!

背景上发生了什么?

更新1:

基于亲爱的@ Vojta的评论,我改变了程序,仅用Default Selected来增加APDU命令的counter值:

CLA = 0x80

这是输出(对于默认选择的情况):

public void process(APDU apdu) {
    if (selectingApplet()) {
        return;
    }

    byte[] buffer = apdu.getBuffer();

    if ((buffer[ISO7816.CLA_ISO7816] & 0x00FF) == 0x80 ) {
        counter = (short) (counter + 1);
    }

    ISOException.throwIt(counter);

}

0 个答案:

没有答案