Page 1 of 1
change the javacard Historical Bytes
Posted: Tue Aug 25, 2015 2:17 am
by Tarantino
I am looking for a way to change the historical bytes of my javacard.
Is there any ways to do this?
It's very thankful for your help.
Re: change the javacard Historical Bytes
Posted: Wed Aug 26, 2015 8:53 am
by horse dream
Maybe you can use the below applet.
Code: Select all
public class HistoricalBytesChanger extends Applet {
public static byte[] state = { (byte) 0, (byte) 0 };
//change the Historical Bytes you want
public static byte[] HistByteArray = { (byte) 0x01, (byte) 0x02,
(byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,
(byte) 0x08, (byte) 0x09, (byte) 0x0a };
public static void install(byte[] bArray, short bOffset, byte bLength) {
new HistoricalBytesChanger().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
GPSystem.setATRHistBytes(HistByteArray, (short) 0, (byte) 10);
HistByteArray[0] = (byte) (HistByteArray[0] + 1);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
After you install it successfully into you card, set the card reset privilege to this applet.
Re: change the javacard Historical Bytes
Posted: Wed Aug 26, 2015 9:53 pm
by Bob2002
Another sample come from oracle community.
Code: Select all
/**
*
*/
package hands_on_setATRHistBytes;
import javacard.framework.*;
import visa.openplatform.OPSystem;
/**
* @author sonnyyu
*
*/
public class hands_on_setATRHistBytes_cls extends Applet {
private static final byte[] newATRHistory = {
(byte)'J', (byte)'C', (byte)'O', (byte)'P', (byte)'4', (byte)'1', (byte)'V', (byte)'2', (byte)'2', (byte)'1'
} ;
private static final byte[] newATRHistory1 = {
(byte)'J', (byte)'C', (byte)'O', (byte)'P', (byte)'4', (byte)'1', (byte)'V', (byte)'2', (byte)'2', (byte)'3'
} ;
public static void install(byte[] bArray, short bOffset, byte bLength) {
// GP-compliant JavaCard applet registration
new hands_on_setATRHistBytes_cls().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();
// good practice: If you don't know the CLA, say so:
if (buf[ISO7816.OFFSET_CLA] != 0) ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
if (GPSystem.setATRHistBytes(newATRHistory, (short)0, (byte)newATRHistory1.length))
{
return;
}
else
{
ISOException.throwIt(ISO7816.SW_WARNING_STATE_UNCHANGED);
}
case (byte) 0x01:
if (GPSystem.setATRHistBytes(newATRHistory1, (short)0, (byte)newATRHistory1.length))
{
return;
}
else
{
ISOException.throwIt(ISO7816.SW_WARNING_STATE_UNCHANGED);
}
default:
// good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}