change the javacard Historical Bytes
Moderator: UNKNwYSHSA
change the javacard Historical Bytes
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.
Is there any ways to do this?
It's very thankful for your help.
The greatest glory in living lies not in never falling, but in rising every time we fall.--Nelson Mandela
- horse dream
- Posts: 76
- Joined: Thu May 21, 2015 11:48 pm
- Points :138
- Contact:
Re: change the javacard Historical Bytes
Maybe you can use the below applet.
After you install it successfully into you card, set the card reset privilege to this 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
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);
}
}
}
Who is online
Users browsing this forum: No registered users and 16 guests