JavaCard Applet开发风险建议

前言

由于EEPROM和Flash都有寿命限制,应用如果频繁的在同一区域进行擦写将会增加数据丢失的风险,本章节探讨如何设计应用来降低对应的风险。

F1 - Check where all your variables are stored and accordingly move them if there is a risk ofNVM stress (guaranteed 100,000 updates for E2PROM and FLASH technologies)

检查所有变量的存储,如果有NVM风险,则考虑移动它们
描述:
在Java Card中,对象都存在于EEPROM中:

1:基础类型(byte、short…)的全局变量
2:对象(通过new实现的)

只有以下存在于RAM中:

1:局部变量
2:方法的参数

F2 - Avoid writing in EEPROM upon STATUS event reception

注册了status事件的应用将会在每1或2分钟就被触发一次,因此一定要非常注意在此过程中对EEPROM的操作

F3 - Avoid writing in EEPROM upon file update events when the concerned file is a HIGH update activity file

有些文件是高频更新的,注意注册了FILE_UPDATE事件的应用在此过程中的操作,同F2

F4.1 - Avoid passing too many parameters in a function (4 or 5 max)

F4.2 - Avoid declaring too many local variables inside each method

F4.3 - Reduce the overall nesting level (ie a function calling a function). Latest Gemalto Javacards allow more than 20 nesting levels

F5 - ALL objects making up the application are created during installation

应用相关的 对象都在安装时创建,防止某些卡片不支持垃圾回收

F6 - If your application uses the Java Card transactions:

事务的关键部分应该尽可能小
begin和commit应该在同一个方法中完成
一个method开启了事务,那么该method的所有路径都要完成事务
事务临界区应由try-catch块保护

F7 - Insert a MORE TIME proactive command if your toolkit process is longer than 2s in order not to block the handset

如果Toolkit应用执行时间超过了2s,则插入MoreTime命令以防止手机阻塞

F8 - In reentrance, take into account that the OS resources are limited: proactive handlers,available RAM.Toolkit applications must be tested in reentreance, ie when a CAT context is already active

重入时要考虑OS的资源和主动式命令的句柄

javacard applet 开发实例 正常运行 带jar包 package mifare; import com.ibm.jz.JZSystem; import javacard.framework.APDU; import javacard.framework.Applet; import javacard.framework.ISO7816; import javacard.framework.ISOException; import javacard.framework.Util; public class AmbiqApplet extends Applet { byte[] mifarePassDefault={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] mifarePass8={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] mifarePass9={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] adminPass={(byte)0x40,(byte)0x41,(byte)0x42,(byte)0x43,(byte)0x44,(byte)0x45,(byte)0x46,(byte)0x47,(byte)0x48,(byte)0x49,(byte)0x4a,(byte)0x4b,(byte)0x4c,(byte)0x4d,(byte)0x4e,(byte)0x4f}; public static void install(byte[] bArray, short bOffset, byte bLength) { // GP-compliant JavaCard applet registration new AmbiqApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]); } public void process(APDU apdu) { short i; byte[] send=new byte[52]; byte[] send2=new byte[24]; // Good practice: Return 9000 on SELECT if (selectingApplet()) { return; } byte[] buf = apdu.getBuffer(); if(buf[ISO7816.OFFSET_CLA]==AmbiqConstant.CLS_AMBIQ) { switch (buf[ISO7816.OFFSET_INS]) { case AmbiqConstant.INS_GET_MIFARE: if(buf[ISO7816.OFFSET_P1]!=0 || buf[ISO7816.OFFSET_P2]!=0) { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); return; } /*Get Entire Mifare Ticket data * Returns back the content of the entire sector 8 (3 block 8.0, 8.1, 8.2) and the first 4 bytes of block 9.0; total 52bytes. Filed Length (in bytes) Data Comments CLA 1 0x80 Fixed class for the applet INS 1 0x20 Read entire data P1 1 0x00 Sector number P2 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值