javajavacardsim-toolkit

Import javacard applet on cref


I have a problem linked with installing javacard applet on cref.

I take simple example from oracle javacard samples - HelloWorld and add thwo extra lines - import sim.toolkit.*; and private ToolkitRegistry reg;. Here is the code of applet

package helloworld;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;
import sim.toolkit.*;

public class Hello extends Applet {
    private byte[] echoBytes;
    private static final short LENGTH_ECHO_BYTES = 256;
    private ToolkitRegistry  reg;

    /**
     * Only this class's install method should create the applet object.
     */
    protected Hello() {
        echoBytes = new byte[LENGTH_ECHO_BYTES];
        register();
    }

    /**
     * Installs this applet.
     *
     * @param bArray
     *            the array containing installation parameters
     * @param bOffset
     *            the starting offset in bArray
     * @param bLength
     *            the length in bytes of the parameter data in bArray
     */
    public static void install(byte[] bArray, short bOffset, byte bLength) {
        new Hello();
    }

    /**
     * Processes an incoming APDU.
     *
     * @see APDU
     * @param apdu
     *            the incoming APDU
     * @exception ISOException
     *                with the response bytes per ISO 7816-4
     */

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

        // check SELECT APDU command
        if ((buffer[ISO7816.OFFSET_CLA] == 0) &&
                (buffer[ISO7816.OFFSET_INS] == (byte) (0xA4))) {
            return;
        }

        short bytesRead = apdu.setIncomingAndReceive();
        short echoOffset = (short) 0;

        while (bytesRead > 0) {
            Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, echoBytes, echoOffset, bytesRead);
            echoOffset += bytesRead;
            bytesRead = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
        }

        apdu.setOutgoing();
        apdu.setOutgoingLength((short) (echoOffset + 5));

        // echo header
        apdu.sendBytes((short) 0, (short) 5);
        // echo data
        apdu.sendBytesLong(echoBytes, (short) 0, echoOffset);
    }
}

Before adding these lines my applet installs on cref with no problems (SW1 SW2 90 00), but after these edits I got problems in installation - SW1 SW2 0x6438 which means Imported package not found.

What I have done wrong ? During compilation I used sim.toolkit jar file, during generation .cap file used export files from sim toolkit.


Solution

  • As far as I know the simulator bundled with Java Card Development Kit does not support SIM Toolkit functionality.

    You may want to use e.g. Gemalto Developer Suite.

    Good luck!