3

我需要使用卡外字节码验证器验证 Java Card 程序(cap 文件)。我已经手动修改了 cap 文件中的信息,我想验证新的 cap 文件是否是好类型。

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

4

1 回答 1

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

验证CAP.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) {

        }
    }
}
于 2016-09-16T13:41:56.430 回答