Java Card Export File Dependencies

Viewed 353

I wrote three applets in three separate packages

ServerApp in packageA

ClientApp in packageB

CharlieApp in packageC

My aim is to see if CharlieApp can access the grantCredit method through the ClientApp.

I am able to convert ServerApp and ClientApp into cap files and load into Java Card 2.2.0 and access the grantCredit method.

packageA also contains an interface extending Shareable by the name MSI. I am able to generate cap files for packageA and packageB, load them into the card and able to access the grantCredit method from ClientApp. But I am not able to include packageB.ClientApp in packageB.exp file due to which I am getting error while converting CharlieApp into cap file

When I try to convert the CharlieApp, the following error is shown

[cap] error: line 89: packageC.CharlieApp: class packageB.ClientApp not found in export file packageB.exp.

I have a hint that if you have applets in your CAP file, your exports will not contain public classes. But, I need a way to include the ClientApp in the packageB.exp.

The following is important code of Serverapp

package packageA;

import javacard.framework.*;

public class ServerApp extends Applet implements MSI{

    private static short miles;

    public ServerApp(){
        register();
        miles = (short) 0;
    } 

    public Shareable getShareableInterfaceObject(AID client, byte param){
        if(client.equals(ClientAID, (short)0, (byte) ClientAID.length) == false)
            return null;
        return this;
    }

    public void grantcredit(short amount){

        miles = (short)(miles + amount);
    }

}

The following is important part of ClientApp

package packageB;

import packageA.ServerApp;
import packageA.MSI;
import javacard.framework.*;

public class ClientApp extends Applet {

    public static MSI ServerObject;

    public void process(APDU apdu) throws ISOException {
    ...
        if (apduBuffer[ISO7816.OFFSET_CLA] == CLA_SIMPLEAPPLET) {
            switch (apduBuffer[ISO7816.OFFSET_INS] )
            {
                case INS_USERINPUT1: 
                    foo(apdu);
                    break;
                default :
                    ISOException.throwIt( ISO7816.SW_INS_NOT_SUPPORTED ) ;
                break ;

            }
        }
        else ISOException.throwIt( ISO7816.SW_CLA_NOT_SUPPORTED);
    }

    public void foo(APDU apdu){

        byte[]    apdubuf = apdu.getBuffer();
        ...

        AID aid = JCSystem.lookupAID(ServerAID, (short)0, (byte)ServerAID.length);

        ServerObject = (MSI) JCSystem.getAppletShareableInterfaceObject(aid, (byte) 0);

        ServerObject.grantcredit(amount);
        ...
        apdu.setOutgoing();
        ...
    }
}

And the CharlieApp

package packageC;

import packageA.MSI;
import packageB.ClientApp;
import javacard.framework.*;

public class CharlieApp extends Applet {

    private static MSI ServerObject;

    public void process(APDU apdu) throws ISOException {
    ...
        if (apduBuffer[ISO7816.OFFSET_CLA] == CLA_SIMPLEAPPLET) {
            switch (apduBuffer[ISO7816.OFFSET_INS] )
            {
                case INS_USERINPUT1: 
                    foo(apdu);
                    break;
                default :
                    ISOException.throwIt( ISO7816.SW_INS_NOT_SUPPORTED ) ;
                break ;
            }
        }
        else ISOException.throwIt( ISO7816.SW_CLA_NOT_SUPPORTED);
    }

    public void foo(APDU apdu){

        byte[]    apdubuf = apdu.getBuffer();

        ServerObject = ClientApp.ServerObject;

        ServerObject.grantcredit(amount);

        apdu.setOutgoing();
    }
}
0 Answers
Related