Smartcard 0x6f00转换Javacard可共享接口时出错
我尝试对两个不同的包使用SIO(可共享接口对象),以便将来更新小程序的业务逻辑。 我正在使用eclipse,我启动了两个不同的JavaCard应用程序,ClientSIOApplet和ServerSIOApplet。ClientSIOApplet中有一个名为appClient的包,ServerSIOApplet中有一个名为appServer的包。 此外,ClientApplet.java和ServerAppBankInterface.java是appClient和中的类 appServer中有ServerAppBankInterface.java和ServerApplet.java。您可以在下面看到源代码: appClient中的ClientApplet.javaSmartcard 0x6f00转换Javacard可共享接口时出错,smartcard,javacard,Smartcard,Javacard,我尝试对两个不同的包使用SIO(可共享接口对象),以便将来更新小程序的业务逻辑。 我正在使用eclipse,我启动了两个不同的JavaCard应用程序,ClientSIOApplet和ServerSIOApplet。ClientSIOApplet中有一个名为appClient的包,ServerSIOApplet中有一个名为appServer的包。 此外,ClientApplet.java和ServerAppBankInterface.java是appClient和中的类 appServer中有S
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);
}
}
}
package appClient;
import javacard.framework.Shareable;
public interface ServerAppBankInterface extends Shareable{
//public void saveMoneyInBank(short amount);
public short getSavedMoneyInBank();
}
appClient中的ServerAppBankInterface.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);
}
}
}
package appClient;
import javacard.framework.Shareable;
public interface ServerAppBankInterface extends Shareable{
//public void saveMoneyInBank(short amount);
public short getSavedMoneyInBank();
}
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;
}
}
package appServer;
import javacard.framework.Shareable;
public interface ServerAppBankInterface extends Shareable{
//public void saveMoneyInBank(short amount);
public short getSavedMoneyInBank();
}
appServer中的ServerAppBankInterface.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;
}
}
package appServer;
import javacard.framework.Shareable;
public interface ServerAppBankInterface extends Shareable{
//public void saveMoneyInBank(short amount);
public short getSavedMoneyInBank();
}
问题是:
我在铸造接口时遇到问题:
ServerAppBankInterface bankInterface = (ServerAppBankInterface) sio;
在ClientApplet.java中
如果我删除该行中的Try Catch,我将收到0x6F00错误,服务器小程序将提供该类型的可共享接口
appServer.ServerApplet <- appServer.ServerAppBankInterface <- javacard.framework.Shareable
appServer.ServerApplet以下是更新的代码
在我这边的JCIDE上运行良好
包应用服务器
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;
}
}
package appServer;
import javacard.framework.Shareable;
public interface ServerAppBankInterface extends Shareable{
//public void saveMoneyInBank(short amount);
public short getSavedMoneyInBank();
}
ServerAppel.java
包appServer;
导入javacard.framework.AID
导入javacard.framework.APDU
导入javacard.framework.Applet
导入javacard.framework.ISO7816
导入javacard.framework.ISOException
导入javacard.framework.Shareable
公共类ServerApplet扩展小程序实现ServerAppBankInterface
{
}
ServerAppBankInterface.java
包appServer
导入javacard.framework.Shareable
公共接口ServerAppBankInterface扩展了可共享{
//公共无效储蓄银行(短期金额);
公共短代码getSavedMoneyInBank();
}
包应用客户端
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);
}
}
}
package appClient;
import javacard.framework.Shareable;
public interface ServerAppBankInterface extends Shareable{
//public void saveMoneyInBank(short amount);
public short getSavedMoneyInBank();
}
1.客户端小程序
package appClient ;
import appServer.*;
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
{
ServerAppBankInterface sio;
byte[] serverAID = {(byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02,(byte)0xBB};
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 = (ServerAppBankInterface)JCSystem.getAppletShareableInterfaceObject(svrAid, (byte)0);
if(sio == null){
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
ServerAppBankInterface bankInterface = (ServerAppBankInterface) sio;
bankInterface.getSavedMoneyInBank();
break;
default:
// good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
你的意思是我应该在一个包中同时包含applet和一个项目?如果是,那么服务器小程序中的数据是否在删除客户端小程序后删除?也就是说,一个包中不同小程序的上下文是否不同?不,只有您的共享界面需要在appServer
包的范围内。我无法使用两个应用程序获得最佳结果。因此,我尝试了一个javacard应用程序和一个名为pkgSIO的包,其中包含两个名为APPClient和AppServer的小程序以及一个名为ServerAppBankInterface的接口,AppServer实现了它。现在我得到了我想要的结果。删除AppClient并在预装包中再次安装后,我可以访问以前保存的数据。非常感谢您的帮助。还有一个问题,如果我有两个应用程序,其中两个包的名称相同,那么我应该为applet AID和package AIDs定义什么?app1-->打包(AID=0102030405)-->AppletClient(AID=010203040501)app2-->打包(AID=010203040506)-->AppletServer(AID=0102030405001)