Java Card客户端-服务器共享接口返回6F00
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java Card客户端-服务器共享接口返回6F00,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3842字,纯文字阅读大概需要6分钟。
内容图文
![Java Card客户端-服务器共享接口返回6F00](/upload/InfoBanner/zyjiaocheng/650/380b98ea4204474eb81896fae18759be.jpg)
我试图使用可共享接口,使用Eclipse 3.7 SDK在Java卡2.2.2中创建一个简单的客户端和服务器小程序.调用方法JCSystem.getAppletShareableInterfaceObject时,它将引发异常,因此返回SW设置为6F00.
这是客户端应用程序代码(Test_Client.java):
package client;
import server.Test_ServerInf;
import javacard.framework.AID;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.JCSystem;
public class Test_Client extends Applet {
protected static final byte INS1 = (byte)0xE2;
protected static final byte INS2 = (byte)0x21;
byte[] ServerAIDbyte={(byte)0x20,(byte)0x21,(byte)0x22,(byte)0x23,(byte)0x24,(byte)0x25,(byte)0x26,(byte)0x27,(byte)0x01};
AID ServerAID;
private Test_Client() {
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
new Test_Client().register();
}
public void process(APDU apdu) throws ISOException {
// TODO Auto-generated method stub
byte[] apduBuffer = apdu.getBuffer();
byte Ins=apduBuffer[ISO7816.OFFSET_INS];
short byteread = apdu.setIncomingAndReceive();
if (selectingApplet())
return;
switch (Ins){
case INS1:
Ins1_Handler(apdu);
return;
case INS2:
Ins2_Handler(apdu,apduBuffer);
return;
default:
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
}
}
private void Ins1_Handler(APDU apdu){
Test_ServerInf sio = null;
ServerAID=JCSystem.lookupAID(ServerAIDbyte,(short) 0,(byte) ServerAIDbyte.length);
if(ServerAID==null)
ISOException.throwIt( (short) 0x6A82);
////server request
try{
sio=(Test_ServerInf)(JCSystem.getAppletShareableInterfaceObject(ServerAID, (byte) 0));
}
catch(SecurityException e)
{
ISOException.throwIt((short)0x12);
}
catch(Exception e)
{
ISOException.throwIt((short)0x10);
}
if(sio==null)
ISOException.throwIt((short)0x6A00);
}
private void Ins2_Handler(APDU apdu,byte[] apduBuffer){
Test_ServerInf sio = null;
////connect to server
ServerAID=JCSystem.lookupAID(ServerAIDbyte,(short) 0,(byte) ServerAIDbyte.length);
if(ServerAID==null)
ISOException.throwIt( (short) 0x6A82);
////server request
try{
sio=(Test_ServerInf)(JCSystem.getAppletShareableInterfaceObject(ServerAID, (byte) 0));
}
catch(SecurityException e)
{
ISOException.throwIt((short)0x12);
}
catch(Exception e)
{
ISOException.throwIt((short)0x10);
}
if(sio==null)
ISOException.throwIt((short)0x6A00);
}
}
这是服务器小程序代码(Test_Server.java):
package server;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
import server.Test_ServerInf;
import javacard.framework.Shareable;
import javacard.framework.AID;
public class Test_Server extends Applet implements Test_ServerInf{
private Test_Server() {
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
new Test_Server().register();
}
public void process(APDU apdu) throws ISOException {
// TODO Auto-generated method stub
}
public Shareable getShareableInterfaceObject(AID clientAID, byte parameter) {
return this;
}
public short method1(){
return (short)0x01;
}
public short method2(){
return (short)0x02;
}
}
和可共享的接口文件(Test_ServerInf.java):
package server;
import javacard.framework.Shareable;
public interface Test_ServerInf extends Shareable {
public short method1();
public short method2();
}
解决方法:
您正在尝试在客户端applet类的成员字段中存储对可共享接口对象的引用:
sio = (Test_ServerInf)(JCSystem.getAppletShareableInterfaceObject(ServerAID, (byte) 0));
其中sio定义为applet类实例的私有成员:
public class Test_Client extends Applet {
private Test_ServerInf sio;
由于可共享接口对象由服务器小应用程序拥有(即由其他上下文拥有),因此将导致SecurityException.不允许将其他上下文拥有的对象存储在实例字段中.
请参阅《运行时环境规范》(Java卡平台,版本2.2.2)中的“访问类实例对象字段”(第6.2.8.3节):
Bytecodes:
getfield
,putfield
- […] if the object is owned by an applet in the currently active context, access is allowed.
- Otherwise, access is denied.
内容总结
以上是互联网集市为您收集整理的Java Card客户端-服务器共享接口返回6F00全部内容,希望文章能够帮你解决Java Card客户端-服务器共享接口返回6F00所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。