Page 1 of 1

How to change the card Historical Bytes?

Posted: Tue Dec 01, 2015 6:30 am
by GraceGIRL
I know that changing Historical bytes is limited to Pre-Personalization step. But I found a method named setATRHistBytes in the GlobalPlatform APIs today.
This is description.
setATRHistBytes

public static boolean setATRHistBytes (byte[] buffer, short bOffset, byte bLength)

This method sets the historical bytes contained in the ATR (Answer To Reset). The sequence of bytes will be set
on a subsequent power-up or reset. Only the “default selected” Application may invoke this method. The Card
Manager locates the AID of the selected Application in the GlobalPlatform Registry and determines if the
Application has the required privilege.

Parameters:
buffer – byte[] Array containing the ATR historical bytes.
bOffset – short Offset within the buffer where ATR historical bytes begin.
bLength – byte Length of the ATR historical bytes in the buffer.

Returns:
TRUE if ATR bytes set, FALSE otherwise.


How can I use this method to change the card historical bytes? Can somebody give me any demo code?

Re: How to change the card Historical Bytes?

Posted: Thu Dec 03, 2015 5:00 am
by Tarantino
Maybe this can help you.

Code: Select all

public class HistoricalBytesChanger extends Applet {
    public static byte[] state = { (byte) 0, (byte) 0 };
    public static byte[] HistByteArray = { (byte) 0x01, (byte) 0x02,
            (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,
            (byte) 0x08, (byte) 0x09, (byte) 0x0a };// assign 0102030405060708090A to Historical Bytes

    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);
        }
    }

}

Re: How to change the card Historical Bytes?

Posted: Fri Apr 28, 2017 8:23 am
by eclessiastes
The code is not changing the ATR. I tried different cards but none works.

Re: How to change the card Historical Bytes?

Posted: Tue May 02, 2017 3:11 am
by UNKNwYSHSA
eclessiastes wrote:The code is not changing the ATR. I tried different cards but none works.


Please check the return value of the method GPSystem.setATRHistBytes(). If it returns false, the HistoryBytes is not set.
And make sure that the privilege of current applet has privilege "Card Reset". If not, this method will be fail.

Re: How to change the card Historical Bytes?

Posted: Mon May 08, 2017 7:05 am
by eclessiastes
GPSystem.setATRHistBytes() returns true and ATR is changed but the first 6 bytes of the atr are the same. Is there any way to change whole atr ?

Re: How to change the card Historical Bytes?

Posted: Tue May 09, 2017 1:35 am
by UNKNwYSHSA
eclessiastes wrote:GPSystem.setATRHistBytes() returns true and ATR is changed but the first 6 bytes of the atr are the same. Is there any way to change whole atr ?

The ATR can not be changed in the applet.
If you want to change the ATR value not only the history bytes, ask your card provider about how to do that.

Re: How to change the card Historical Bytes?

Posted: Sun Sep 06, 2020 2:51 pm
by andromeda92
How do i do for changing applet privilege to Card Reset ?

EDIT:
Selecting default when install applet, the privilege is card reset.

11.1.2 Privilege config (Card SPecification) Global Platform v2.3