I wrote three applets in three separate packages
ServerApp in packageA
ClientApp in package B
CharlieApp in package
My goal is to see if CharlieApp can access the grantCredit method through ClientApp.
I can convert ServerApp and ClientApp to files with an inscription and upload them to the Java card 2.2.0 and access the grantCredit method.
packageA also contains an interface that extends Sharing using the MSI name . I can create cap files for packageA and packageB, upload them to the card and access the grantCredit method from ClientApp. But I can not turn packageB.ClientApp file packageB.exp , because I get an error when converting a file CharlieApp cap
When I try to convert CharlieApp, the following error is displayed
[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 export will not contain public classes. But I need to include ClientApp in packageB.exp.
Below is the important Serverapp code
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 an 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 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();
}
}