I have a question about javacard sharable object. I want to read a shared array from server in client base on following link: [JavaCard: How can an applet's instance call a method in another instance's context?
I have a client and a server applet, when i call the function
theSharedArray = (SharedArray) JCSystem.getAppletShareableInterfaceObject(masterAID, SHARABLE_PARAM);
in client it returns 6f00. client applet is:
public class Client extends Applet implements ISO7816 {
private static final byte SHARABLE_PARAM = 0;
public interface SharedArray extends Shareable {
public byte[] getSharedArray();
}
public static class SharedArrayImpl implements SharedArray {
private byte[] sharedArray;
public SharedArrayImpl(final byte[] arrayToShare) {
this.sharedArray = arrayToShare;
}
public byte[] getSharedArray() {
return sharedArray;
}
}
byte[] idinAID = new byte[]{(byte)0xA0, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00, 0x10, 0x00};
private AID masterAID = new AID(idinAID, (short) 0, (byte) idinAID.length);
public static void install(byte[] bArray, short bOffset, byte bLength) throws SystemException {
new Client().register(bArray, (short) (bOffset + 1),
bArray[bOffset]);
}
private Client() {
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
byte[] buf = apdu.getBuffer();
byte cla = buf[OFFSET_CLA];
byte ins = buf[OFFSET_INS];
switch (ins) {
case (byte) 0x03:
sendOut(apdu);
break;
default:
ISOException.throwIt(SW_INS_NOT_SUPPORTED);
}
}
public void sendOut(APDU apdu)
{
final SharedArray theSharedArray;
theSharedArray = (SharedArray) JCSystem.getAppletShareableInterfaceObject(masterAID, SHARABLE_PARAM);
byte[] sa = theSharedArray.getSharedArray();
apdu.setOutgoing();
apdu.setOutgoingLength((short) 10);
apdu.sendBytesLong(sa, (short) 0, (short) 10);
}
}
and the server applet is:
public class SharingApplet extends Applet {
public interface SharedArray extends Shareable {
public byte[] getSharedArray();
}
public static class SharedArrayImpl implements SharedArray {
private byte[] sharedArray;
public SharedArrayImpl(final byte[] arrayToShare) {
this.sharedArray = arrayToShare;
}
public byte[] getSharedArray() {
return sharedArray;
}
}
private static final byte PARAM_SHARED_ARRAY = 0;
private final SharedArray sharedArray;
byte[] idinAID = new byte[]{(byte)0xA0, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00, 0x10, 0x00};
private AID masterAID = new AID(idinAID, (short) 0, (byte) idinAID.length);
public static void install(byte[] bArray, short bOffset, byte bLength) {
new SharingApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public SharingApplet() {
sharedArray = new SharedArrayImpl(idinAID);
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x03:
{
apdu.setOutgoing();
apdu.setOutgoingLength((short) 9);
apdu.sendBytesLong(idinAID, (short) 0, (short) 9);
break;
}
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
public Shareable getShareableInterfaceObject(AID clientAID, byte parameter) {
if (sharedArray == null || parameter != PARAM_SHARED_ARRAY) {
return null;
}
return sharedArray;
}
}
I will be gratefull if anyone can help me. Thanks