JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html

How to change the card Historical Bytes?

Card Products

Moderator: horse dream

GraceGIRL
Posts: 15
Joined: Fri May 15, 2015 3:25 am
Points :30
Contact:

How to change the card Historical Bytes?

Post by GraceGIRL » Tue Dec 01, 2015 6:30 am

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?

Tarantino
Posts: 101
Joined: Wed Aug 19, 2015 1:56 am
Points :478
Contact:

Re: How to change the card Historical Bytes?

Post by Tarantino » Thu Dec 03, 2015 5:00 am

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

}
The greatest glory in living lies not in never falling, but in rising every time we fall.--Nelson Mandela

eclessiastes
Posts: 8
Joined: Tue Mar 29, 2016 8:52 am
Points :119
Contact:

Re: How to change the card Historical Bytes?

Post by eclessiastes » Fri Apr 28, 2017 8:23 am

The code is not changing the ATR. I tried different cards but none works.

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: How to change the card Historical Bytes?

Post by UNKNwYSHSA » Tue May 02, 2017 3:11 am

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.
sense and simplicity

eclessiastes
Posts: 8
Joined: Tue Mar 29, 2016 8:52 am
Points :119
Contact:

Re: How to change the card Historical Bytes?

Post by eclessiastes » Mon May 08, 2017 7:05 am

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 ?

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: How to change the card Historical Bytes?

Post by UNKNwYSHSA » Tue May 09, 2017 1:35 am

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.
sense and simplicity

andromeda92
Posts: 38
Joined: Tue Aug 18, 2020 6:08 pm
Points :320
Contact:

Re: How to change the card Historical Bytes?

Post by andromeda92 » Sun Sep 06, 2020 2:51 pm

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

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer