BzH*_*BzH 5 smartcard javacard
我尝试对两个不同的包使用 SIO(可共享接口对象),以便将来更新我的小程序的业务逻辑。我正在使用 eclipse,并启动两个不同的 JavaCard 应用程序:ClientSIOApplet 和 ServerSIOApplet。ClientSIOApplet 中有一个名为 appClient 的包,ServerSIOApplet 中有一个名为 appServer 的包。另外,ClientApplet.java 和 ServerAppBankInterface.java 是 appClient 中的类,而 ServerAppBankInterface.java 和 ServerApplet.java 是 appServer 中的类。您可以看到下面的源代码:
appClient 中的 ClientApplet.java
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() {
// TODO Auto-generated constructor stub
}
public static void install(byte[] bArray, short bOffset, byte bLength) {
// GP-compliant JavaCard applet registration
new ClientApplet().register(bArray, (short) (bOffset + 1),
bArray[bOffset]);
}
public void process(APDU apdu) {
// Good practice: Return 9000 on SELECT
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) {
// Cannot find the serverAID AID
ISOException.throwIt((short)0x0010);
}
/*sio = JCSystem.getAppletShareableInterfaceObject(svrAid, (byte)0);
if (sio == null) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
if (! (sio instanceof SharedArray))
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
SharedArray theSharedArray = (SharedArray) sio;
final byte[] sa = theSharedArray.getSharedArray();*/
//ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);
sio = JCSystem.getAppletShareableInterfaceObject(svrAid, (byte)0);
if(sio == null){
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
/*if (! (sio instanceof ServerAppBankInterface))
ISOException.throwIt(ISO7816.SW_FILE_INVALID);*/
try{
ServerAppBankInterface bankInterface = (ServerAppBankInterface) sio;
}catch(Exception ex){
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
}
break;
//default:
// good practice: If you don't know the INStruction, say so:
//ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
Run Code Online (Sandbox Code Playgroud)
appClient 中的 ServerAppBankInterface.java
package appClient;
import javacard.framework.Shareable;
public interface ServerAppBankInterface extends Shareable{
//public void saveMoneyInBank(short amount);
public short getSavedMoneyInBank();
}
Run Code Online (Sandbox Code Playgroud)
appServer 中的 ServerApplet.java
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]);
/*final byte[] sa = new byte[] { 'm' };
sharedArray = new SharedArrayImpl(sa);*/
}
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;
//return sharedArray;
//return serverAppBankObject;
//return (ServerAppBankInterface) this;
//return (Shareable) this;
}
public boolean select()
{
return true;
}
public static void install(byte[] bArray, short bOffset, byte bLength) {
// GP-compliant JavaCard applet registration
new ServerApplet(bArray, bOffset, bLength);
}
public void process(APDU apdu) {
// Good practice: Return 9000 on SELECT
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
break;
default:
// good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
public short getSavedMoneyInBank() {
// TODO Auto-generated method stub
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
appServer 中的 ServerAppBankInterface.java
package appServer;
import javacard.framework.Shareable;
public interface ServerAppBankInterface extends Shareable{
//public void saveMoneyInBank(short amount);
public short getSavedMoneyInBank();
}
Run Code Online (Sandbox Code Playgroud)
问题是:
我在投射界面时遇到问题:
ServerAppBankInterface bankInterface = (ServerAppBankInterface) sio;
Run Code Online (Sandbox Code Playgroud)
在ClientApplet.java中
如果我删除该行中的 Try-Catch,我会收到 0x6F00 错误,
服务器小程序提供以下类型的可共享接口
appServer.ServerApplet <- appServer.ServerAppBankInterface <- javacard.framework.Shareable
Run Code Online (Sandbox Code Playgroud)
但是当您在客户端小程序中收到此可共享接口对象时,您正尝试将其转换为
appClient.ServerAppBankInterface <- javacard.framework.Shareable
Run Code Online (Sandbox Code Playgroud)
虽然接口appServer.ServerAppBankInterface和appClient.ServerAppBankInterface具有相似的名称并公开具有相同名称的方法,但这两个接口既不相同也不相互继承。因此你不能在它们之间进行转换。
因此,您尝试将接收到的可共享对象实例转换为不相关的类型。因此,强制转换失败并引发(未处理的)异常。
为了解决这个问题,您需要将客户端小程序中接收到的可共享对象转换为appServer.ServerAppBankInterface.
| 归档时间: |
|
| 查看次数: |
1371 次 |
| 最近记录: |