当前位置: 首页 > news >正文

网站建设百度文库网站建设情况

网站建设百度文库,网站建设情况,网站被电脑管家拦截做301跳转,日照机关建设网站文章目录 前言一、定义接口二、server端实现三、client端实现四、遇到的问题 前言 在进行开发时,可能会将业务放到不同的applet中,这时常常会需要进行数据的分享。 比如在一个applet中存储了密钥,而在另一个业务applet中需要进行签名时&…

文章目录

  • 前言
  • 一、定义接口
  • 二、server端实现
  • 三、client端实现
  • 四、遇到的问题


前言

在进行开发时,可能会将业务放到不同的applet中,这时常常会需要进行数据的分享。
比如在一个applet中存储了密钥,而在另一个业务applet中需要进行签名时,需要将数据传给第一个applet进行签名后,再返回签名后的数据。
这里介绍Java Card中的Shareable的数据分享的方式。

一、定义接口

import javacard.framework.Shareable;public interface DataShareable extends Shareable {public byte getDataInfo(byte[] buffer, short offset, short length);
}

需要继承Java Card的Shareable 类,定义好我们需要的接口,这里定义了getDataInfo方法,用于将数据写到buffer中以提供给client。

二、server端实现

public class DataInfoApplet extends Applet implements DataShareable{byte[] DataInfo;protected DataInfoApplet () {DataInfo = new byte[16];register();}public static void install(byte[] bArray, short bOffset, byte bLength) {new DataInfoApplet ();}@Overridepublic Shareable getShareableInterfaceObject(AID clientAID, byte parameter) {if (!clientAID.equals(sAIDClientApplet, (short) 0, (byte) sAIDClientApplet.length)) {return null;}return this;}@Overridepublic void process(APDU apdu) {}@Overridepublic byte getDataInfo(byte[] out, short offset, short length) {try {Util.arrayCopy(DataInfo, (short) 0, out, offset, length);return OK;} catch (ArrayIndexOutOfBoundsException e) {return NOT_OK;}}
}
  • server端需要实现DataShareable接口。
  • 需要实现getShareableInterfaceObject,该方法会在client端调用JCSystem.getShareableInterfaceObject时执行。在这里面可以进行clientAID的判断,以使得仅有特定的applet才能够调用shareable接口。

三、client端实现

注意:client和server是在不同的package中的。

public class ClientApplet extends Applet {DataShareable sio = null;protected ClientApplet () {register();}public static void install(byte[] bArray, short bOffset, byte bLength) {new ClientApplet ();}private boolean getSIO() {if (this.sio == null) {this.sio = (DataShareable)JCSystem.getAppletShareableInterfaceObject(JCSystem.lookupAID(DATAINFO_APPLET_AID_BYTES,(short)0, (byte)(DATAINFO_APPLET_AID_BYTES.length)),(byte)0);}if(this.sio != null) {return true;} else {return false;}}@Overridepublic void process(APDU apdu) {byte[] buffer = apdu.getBuffer();sio.getDataInfo(buffer , (short) 0, (short) 16);apdu.setOutgoing();apdu.setOutgoingLength((short) 16);apdu.sendBytesLong(buffer , (short) 0, (short) 16);return;}@Overridepublic boolean select() {return getSIO();}@Overridepublic void deselect() {sio = null;}
}
  • getSIO中通过JCSystem.getAppletShareableInterfaceObject来获得接口对象sio。
  • 使用sio来调用接口方法,并传入buffer参数。

四、遇到的问题

1、接口中创建对象失败

@Overridepublic byte getDataInfo(byte[] out, short offset, short length) {try {byte[] temp = JCSystem.makeTransientByteArray((short) 4, JCSystem.CLEAR_ON_DESELECT);Util.arrayCopy(DataInfo, (short) 0, out, offset, length);return OK;} catch (ArrayIndexOutOfBoundsException e) {return NOT_OK;}}

在server实现的接口方法中,添加了byte[] temp = JCSystem.makeTransientByteArray((short) 4, JCSystem.CLEAR_ON_DESELECT);则调用该接口时会报错。

分析:

JCCRE中规定,对于CLEAR_ON_DESELECT类型的瞬态数据,只有当前活动的context是当前选择的applet的context时,才能够创建和使用。

这个案例中,对于两个不同package中的applet进行接口调用时,会进行context的切换,所以调用到getDataInfo接口时,当前活动的context已经切换为了server的context。但是接口是在client处理apdu请求时调用的,此时被选择的applet仍然是client。所以导致前面的条件无法满足,所以出现错误。
在这里插入图片描述
解决:
使用CLEAR_ON_RESET。

byte[] temp = JCSystem.makeTransientByteArray((short) 4, JCSystem.CLEAR_ON_RESET);

CLEAR_ON_RESET类型要求,当前活动的context是对象所有者的context,因此可以在这样的情况下满足条件

2、数据无法通过接口传输

 @Overridepublic void process(APDU apdu) {//byte[] buffer = apdu.getBuffer();byte[] data = JCSystem.makeTransientByteArray((short) 16, JCSystem.CLEAR_ON_RESET);sio.getDataInfo(data , (short) 0, (short) 16);apdu.setOutgoing();apdu.setOutgoingLength((short) 16);apdu.sendBytesLong(data , (short) 0, (short) 16);return;}

如果client中这样写,即使用makeTransientByteArray来创建瞬态数据data并作为参数传递,则调用时会出现数据的访问失败

分析:
在这里插入图片描述
从日志可以看出,是由于临时数据无法在不同的context之间进行访问。临时数据是收到防火墙保护的,这个data数据是属于client的context的,而调用接口后,活动的context切换为了server的context,那么在server中就无法访问这个data,进而无法向其中写入数据。

解决:
使用byte[] buffer = apdu.getBuffer();来进行数据的发送和接收。

 @Overridepublic void process(APDU apdu) {byte[] buffer = apdu.getBuffer();sio.getDataInfo(data , (short) 0, (short) 16);apdu.setOutgoing();apdu.setOutgoingLength((short) 16);apdu.sendBytesLong(data , (short) 0, (short) 16);return;}

apdu.getBuffer() 返回的是 APDU缓冲区,它是一个特殊的 全局缓冲区,在 Java Card 上被认为是跨防火墙允许的共享对象。

http://www.wangmingla.cn/news/99893.html

相关文章:

  • 淘宝京东拼多多购物券网站怎么做竞价托管信息
  • 安徽和住房建设厅网站seo网站培训优化怎么做
  • 制作网站软件手机优化的意思
  • 网站开发两端对齐底行左对齐新闻营销
  • iis wordpress关键词优化seo排名
  • wordpress安装双seo插件整站多关键词优化
  • wordpress robots.txt写法深圳优化公司统高粱seo
  • 做网站毕设答辩问题网站外链购买
  • 电商网站 服务器百度推荐现在为什么不能用了
  • 闵行网站制作设计公司宁波seo外包推广
  • 做建筑钢材的b2b网站有哪些游戏推广话术技巧
  • 网站模板 寻模板河南做网站的
  • 胶南网站建设哪家好seo顾问服务四川
  • 佛山怎么做网站深圳品牌seo
  • 惠民建设局网站是哪个百度开户资质
  • 柳城网站网络怎样做推广
  • wordpress postid随机自己搜20条优化措施
  • 帝国做视频网站百度指数官方版
  • 广东微信网站制作公司如何做免费网站推广
  • 企业门户网站建设公司如何让百度快速收录
  • 网站建设方案功能描述广州网站推广平台
  • 湖州建设局招投标网站网站推广哪家好
  • 网站结构物理百度大数据官网入口
  • 做网站的公司多吗怎么弄一个自己的网址
  • 怎样做私人网站网页制作代码
  • 网站服务器速度慢seo推广软件代理
  • wordpress 更换网址重庆seo教程搜索引擎优化
  • 网站开通微信支付收费广告免费推广网
  • 网上祭奠类网站怎么做企业推广是什么意思
  • 网站建设 事业单位 安全全网营销课程