Search code examples
javasmartcardjavacardpcsc

Getting 0x6A88 error after trying mutual authentication with java smartcardio


I been trying to do a mutual authentication on Java, this is what I'm doing:

First I ask for the challenge and got the random number.

TRX --> 0084000008
REC <-- 4E621D238C8B185F 9000 

Then I calculate everything, Key seed, enc, mac and send the mutual authorization command:

TRX --> 0082000028[seed enc mac ... bytes transformed]00
REC <-- 6A88

I always receive 0x6A88, and I found on internet that it means "Referenced data or reference data not found".

But the strange thing it's that my prois to implement code already working on C# to Java, we have test it along side, we get the same data with the keys, etc and I found that when I'm going to send the mutual auth (0x82) command I got the 0x6A88 error.

Here is some source code, I wanted to show that I have tried with and without beginExclusive() and endExclusive(), but didn't worked.

public CardTerminal getCardTerminal() throws Exception {
    CardTerminal ct = null;
    TerminalFactory terminalFactory = TerminalFactory.getDefault();        
    CardTerminals cardTerminals = terminalFactory.terminals();
    // Searches for first card terminal available on the PC
    if (cardTerminals.list().isEmpty() == false) {
        ct = cardTerminals.list().get(0);
    }
    return ct;
}

public void test() throws Exception {
    CardTerminal cardTerminal;
    Card card;
    MyManager instance;

    cardTerminal = getCardTerminal(); 
    instance = new DpiV2Manager();

    card = cardTerminal.connect("T=1");
    card = connect(cardTerminal);
    card.beginExclusive();
    CardChannel cardChannel = card.getBasicChannel();

    // Inside this method I do the get challange, mutual auth, etc
    instance.readGeneralData(cardChannel); 

    card.endExclusive();
    card.disconnect(true);
}

Does anyone had the same problem with Java doing mutual authentication?

Did someone found a solution?


Solution

  • My issue was that I was trying to do mutual authentication on a wrong applet. I just selected the correct applet id before the get challenge APDU, and finally got it.