Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

0x6F00 casting Javacard Shareable Interface

JavaCard Applet Development Related Questions and Answers.
Romanzi
Posts: 18
Joined: Wed Dec 02, 2015 10:26 pm
Points :236
Contact:

0x6F00 casting Javacard Shareable Interface

Post by Romanzi » Thu Jan 14, 2016 2:54 am

I tried to use Shareable Interface Objects for two different packages. There is a package named appClient and one named appServer. ClientApplet.java and ServerAppBankInterface.java are classes in appClient and ServerAppBankInterface.java and ServerApplet.java are in appServer.

In ClientApplet.java, I have problem casting interface in line below. If I delete Try-Catch in that line I receive 0x6F00 error. Why this happened?

Code: Select all

ServerAppBankInterface bankInterface = (ServerAppBankInterface) sio;


Here are the source code below:

ServerApplet.java in appServer

Code: Select all

package appServer;

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


public class ServerApplet extends Applet implements ServerAppBankInterface{

    public ServerApplet(byte[] bArray, short bOffset, byte bLength){

        register(bArray, (short) (bOffset + 1), bArray[bOffset]);
    }

    public Shareable getShareableInterfaceObject(AID clientID, byte parameter){

        byte[] tempAID = {(byte)0x05, (byte)0x04, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01};

        if((clientID.equals(tempAID,
                (short)0,
                (byte)tempAID.length)) == false)
            return  null;
        else
            return this;
    }

    public boolean select()
    {
         return true;
    }

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

    public void process(APDU apdu) {

        byte[] buf = apdu.getBuffer();
        switch (buf[ISO7816.OFFSET_INS]) {
        case (byte) 0x00:
            break;
        default:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        }
    }

    public short getSavedMoneyInBank() {
        // TODO Auto-generated method stub
        return 0;
    }



}


ServerAppBankInterface.java in appServer

Code: Select all

package appServer;

import javacard.framework.Shareable;

public interface ServerAppBankInterface extends Shareable{
    public short getSavedMoneyInBank();
}


ClientApplet.java in appClient

Code: Select all

package appClient;

import javacard.framework.AID;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.JCSystem;
import javacard.framework.Shareable;
import javacard.framework.Util;

public class ClientApplet extends Applet {

    Shareable  sio;

    byte[] serverAID = {(byte)0x01, (byte)0x02, (byte)0x03, (byte)0x04, (byte)0x05, (byte)0x01};

    public ClientApplet() {
    }

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

    public void process(APDU apdu) {
        if (selectingApplet()) {
            return;
        }
        byte[] buf = apdu.getBuffer();     
        byte cla = buf[ISO7816.OFFSET_CLA];

        if (( cla != ISO7816.CLA_ISO7816) && (cla != (byte) 0x10))
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);

        switch (buf[ISO7816.OFFSET_INS]) {
        case (byte) 0x00:
             AID svrAid = JCSystem.lookupAID(serverAID,
                                     (short)0,
                                     (byte)serverAID.length);

            if(svrAid == null) {
                ISOException.throwIt((short)0x0010);
            }

            sio = JCSystem.getAppletShareableInterfaceObject(svrAid, (byte)0);

            if(sio == null){
                ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
            }

            try{
                ServerAppBankInterface bankInterface = (ServerAppBankInterface) sio;
            }catch(Exception ex){
                ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
            }


                        break;

        }
    }

}


ServerAppBankInterface.java in appClient

Code: Select all

package appClient;

import javacard.framework.Shareable;

public interface ServerAppBankInterface extends Shareable{
    public short getSavedMoneyInBank();
}

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: 0x6F00 casting Javacard Shareable Interface

Post by UNKNwYSHSA » Wed Jan 20, 2016 10:31 pm

I was tried it. But no exception found when i cast svrObj to ServerInterface without try ... catch ... statement.
Can you offer more details? Screen shoot of your APDU commands and responses?
sense and simplicity

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 49 guests

JavaCard OS : Disclaimer