How to get SAK to Identify smart card type using JAVA?

前端 未结 3 751
深忆病人
深忆病人 2021-01-20 02:55

I am using Java Smart Card API to access. I have NXP Mifare desfire 4K , 1K , Ultra light smart cards with me & trying to find out its type programically in JAVA.

<
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 03:55

    I know this is an old blog but I have been working on this same issue and wanted to share my findings.

    In AN10833 it clearly states that the UID + SAK are returned from performing a select. Using the java smartcard io library I can perform a select like this:

    // Send pseudo APDU to retrieve the card serial number (UID)
    int cla = 0xFF;
    int ins = 0xCA;
    int p1 = 0x00;
    int p2 = 0x00;
    byte[] data = null;
    int dataOffset = 0x00;
    int dataLength = 0x00;
    int le = 0x00;
    
    CommandAPDU getDataApdu = new CommandAPDU(cla, ins, p1, p2, data, dataOffset, dataLength, le);
    ResponseAPDU r1 = channel.transmit(getDataApdu);
    

    However, I am only returned the UID. I found documentation on the PC/SC API that changing P1 = 0x01 will change the response to the historical bytes (which worked for me).

    (section 3.2.2.1.3 from here: http://pcscworkgroup.com/Download/Specifications/pcsc3_v2.01.09.pdf)

    Unfortunately, for the off-the-shelf readers I have access to I could not find the parameters to return the SAK. In a different reader's API document I found that if p2 = 0x01 the ATQA + UID + SAK is returned (this reader is propitiatory and I cannot share the doc).

    I believe if your reader supports it (or you are coding at a low enough level to control the reader itself) you can get/request the exact SAK. Otherwise you may need to use the ATS/ATR to determine the card type.

    Note, in Java here is the code to grab the ATS/ATR:

    // wait 10 seconds for a card
    CardTerminal terminal = terminal.waitForCardPresent(10000);
    
    Card card = terminal.connect("*");
    ATR atr = card.getATR();
    

    From there, the ATR can be processed as vikky mentioned above.

    I will respond with anything else I learn.

提交回复
热议问题