封面文件的字节码离卡验证器

时间:2012-04-22 10:51:55

标签: bytecode-manipulation javacard

我需要使用卡外字节码验证程序验证Java Card程序(上限文件)。 我手动修改了cap文件中的信息,我想验证新的cap文件是否输入正确。

我尝试使用com.sun.javacard.scriptgen.CAP.verifyCAP()方法。我发送有效和无效的上限文件,但结果总是等于0。

1 个答案:

答案 0 :(得分:1)

我从不发布解决方案。那天终于到了;)

下载JavaCard SDK。它包含验证程序的编译版本。例如,java_card_kit-2_2_1。

我的档案:

./
./java_card_kit-2_2_1/
./java2CAP.sh
./ValidApplet/
./ValidApplet/ValidApp.java
./verifyCAP.sh

java2CAP.sh:

#!/bin/bash
export JC_HOME=./java_card_kit-2_2_1
export CLASSPATH=$JC_HOME/lib/apduio.jar:$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/lib/:$JC_HOME/samples/classes:$CLASSPATH
PACKAGE=ValidApplet
CLASS=ValidApp
APPLET=$CLASS.java
PACKAGE_AID=0x46:0x56:0x55:0x4c:0x4e:0x54:0x45:0x53:0x54:0x53
APPLET_AID=0x46:0x56:0x55:0x4c:0x4e:0x54:0x45:0x53:0x54:0x53:0x41:0x70:0x70
javac -g -source 1.3 -target 1.1  $PACKAGE/$APPLET
java com.sun.javacard.converter.Converter -nobanner -out CAP -exportpath $JC_HOME/api_export_files -applet $APPLET_AID $CLASS $PACKAGE $PACKAGE_AID 1.0 -i

verifyCAP.sh:

#!/bin/bash
export JC_HOME=./java_card_kit-2_2_1
export CLASSPATH=$JC_HOME/lib/apduio.jar:$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/lib/:$JC_HOME/samples/classes:$CLASSPATH

export CAPP_PATH=./ValidApplet/javacard
export CAPP_NAME=ValidApplet.cap

java -classpath $JC_HOME/lib/offcardverifier.jar com.sun.javacard.offcardverifier.Verifier $JC_HOME/api_export_files/javacard/framework/javacard/framework.exp $JC_HOME/api_export_files/java/lang/javacard/lang.exp $JC_HOME/api_export_files/javacard/security/javacard/security.exp $CAPP_PATH/$CAPP_NAME

./ ValidApplet / ValidApp.java:

package ValidApplet;

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

public class ValidApp extends Applet //implements PIN
{
    final static byte TEST_CLA = (byte)0x77;

    public static class TestClassStatic {};

    protected ValidApp()
    {
        register();
    }

    public static void install(byte[] bArray, short bOffset, byte bLength)
    {
        new ValidApp();
    }

    public void process(APDU apdu)
    {
        byte buffer[] = apdu.getBuffer();

        try {
            if (buffer[ISO7816.OFFSET_CLA] == TEST_CLA) {
                test((byte)4, (short)2);
            } else {
                ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
            }
        } catch (ISOException e) {

        }
    }
}