0x6F00 casting Javacard Shareable Interface
Posted: 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?
Here are the source code below:
ServerApplet.java in appServer
ServerAppBankInterface.java in appServer
ClientApplet.java in appClient
ServerAppBankInterface.java in appClient
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();
}