Sharing object between different applet...
Posted: Mon Nov 14, 2016 5:20 am
Hello every one.
I am working on a project that should two applet can communicate to each other. one of them is client and one of them is server. now i am using shareable interface but i cannot succeed.
I wrote a sample by shareable interface. i created a sample for client and server. but when i want to get the shared object from server in client applet and cast it to shareable interface i get the error 6f00. in some website said, because i had created two shareable interface one for client and one for server it take back to me 6f00. it said i should use the server shareable interface and i should not create shareable interface on client too? my question is here, how i use server shareable interface? should i import server cap file to my project? (I think it's not possible for me) or anything else. can anyone suggest me a solution?
my server code is like this:
package nl.owlstead.javacard.sharedarray;
import javacard.framework.*;
public class Server extends Applet implements ISharedArray{
private static final byte PARAM_SHARED_ARRAY = 0;
//private final ISharedArray array;
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 Server().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public Server() {
}
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) {
return this;
}
public byte[] getSharedArray() {
return idinAID;
}
}
Sharable interface:
package nl.owlstead.javacard.sharedarray;
import javacard.framework.Shareable;
public interface ISharedArray extends Shareable{
public byte[] getSharedArray();
}
Client:
package nl.owlstead.javacard.sharedarray;
import javacard.framework.*;
public class Client extends Applet implements ISO7816 {
private static final byte SHARABLE_PARAM = 0;
byte[] serverAID = new byte[]{(byte)0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x01};
private AID masterAID = new AID(serverAID, (short) 0, (byte) serverAID.length);
Shareable sio;
byte[] shared;
public static void install(byte[] bArray, short bOffset, byte bLength) throws SystemException {
new Client().register(bArray, (short) (bOffset + 1),
bArray[bOffset]);
}
private Client() {
shared = new byte[20];
}
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) 0x04:
sendOut(apdu);
break;
default:
ISOException.throwIt(SW_INS_NOT_SUPPORTED);
}
}
public void sendOut(APDU apdu) {
sio = JCSystem.getAppletShareableInterfaceObject(masterAID, SHARABLE_PARAM);
// this part returns 6f00
ISharedArray array = (ISharedArray) sio;
apdu.setOutgoing();
apdu.setOutgoingLength((short) 2);
apdu.sendBytesLong(shared, (short) 0, (short) 2);
}
}
I have to mention that, the package name are same but package aid and applet aid are completely different between two applet. some body suggest to me in web to make the package name same, maybe it works.
I am working on a project that should two applet can communicate to each other. one of them is client and one of them is server. now i am using shareable interface but i cannot succeed.
I wrote a sample by shareable interface. i created a sample for client and server. but when i want to get the shared object from server in client applet and cast it to shareable interface i get the error 6f00. in some website said, because i had created two shareable interface one for client and one for server it take back to me 6f00. it said i should use the server shareable interface and i should not create shareable interface on client too? my question is here, how i use server shareable interface? should i import server cap file to my project? (I think it's not possible for me) or anything else. can anyone suggest me a solution?
my server code is like this:
package nl.owlstead.javacard.sharedarray;
import javacard.framework.*;
public class Server extends Applet implements ISharedArray{
private static final byte PARAM_SHARED_ARRAY = 0;
//private final ISharedArray array;
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 Server().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public Server() {
}
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) {
return this;
}
public byte[] getSharedArray() {
return idinAID;
}
}
Sharable interface:
package nl.owlstead.javacard.sharedarray;
import javacard.framework.Shareable;
public interface ISharedArray extends Shareable{
public byte[] getSharedArray();
}
Client:
package nl.owlstead.javacard.sharedarray;
import javacard.framework.*;
public class Client extends Applet implements ISO7816 {
private static final byte SHARABLE_PARAM = 0;
byte[] serverAID = new byte[]{(byte)0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x01};
private AID masterAID = new AID(serverAID, (short) 0, (byte) serverAID.length);
Shareable sio;
byte[] shared;
public static void install(byte[] bArray, short bOffset, byte bLength) throws SystemException {
new Client().register(bArray, (short) (bOffset + 1),
bArray[bOffset]);
}
private Client() {
shared = new byte[20];
}
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) 0x04:
sendOut(apdu);
break;
default:
ISOException.throwIt(SW_INS_NOT_SUPPORTED);
}
}
public void sendOut(APDU apdu) {
sio = JCSystem.getAppletShareableInterfaceObject(masterAID, SHARABLE_PARAM);
// this part returns 6f00
ISharedArray array = (ISharedArray) sio;
apdu.setOutgoing();
apdu.setOutgoingLength((short) 2);
apdu.sendBytesLong(shared, (short) 0, (short) 2);
}
}
I have to mention that, the package name are same but package aid and applet aid are completely different between two applet. some body suggest to me in web to make the package name same, maybe it works.