DESFire EV1 – invalidResponse: No Such Key

Forum / MIFARE SDK / DESFire EV1 – invalidResponse: No Such Key

  • 4. June 2015 at 9:03
    Hi,
    I'm using the Advanced SDK and I'm trying to authenticate a DESFire EV1 card, with bad results.

    I've created my key like this but replacing the bytes with my key for example '0xE9' etc
    public static final byte[] MY_CARD_KEY = { (byte) 0x00, (byte) 0x00,
    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };


    Then I've set my key in this way:
    ks.formatKeyEntry(0, IKeyConstants.KeyType.KEYSTORE_KEY_TYPE_2K3DES);
    ks.setKey(0, (byte) 0, IKeyConstants.KeyType.KEYSTORE_KEY_TYPE_2K3DES, MY_CARD_KEY);


    And in the end into the desfire method I've put
    desFire.connectL4();
    desFire.authenticate(DESFire.AuthType.Native, 0, (byte) 0, 1, (byte) 0, null);
    desFire.closeL4();


    But I always catch into an exception: invalidResponse: No Such Key

    What's going wrong?
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 10:30
    Could you try changing authenticate parameter to this:

    desFire.authenticate(DESFire.AuthType.Native, 0, (byte) 0, 0, (byte) 0, null);


    I have changed your 1 to 0.
    Let me know if this changes someting.

    Best,
    David
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 10:34
    I don't know why, but if I make this change i catch into "android.nfc.TagLostException: Tag was lost." exception.
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 10:37
    Hm. Not expected that one.
    Are you quickly removing the card ?

    If not, are you using anywhere in your card (after authentication)
    format()
    method?

    Also, could you put something into LogCat, right after
    authenticate()
    method ?
    Like:
    Log.d("TAG", "Checking if auth succesfull");


    Because it could be the reason, that you are calling
    close()
    method immidieatly after authenticate, and that's why it could say Tag lost, because you "closed" the connection. You could try removing that line also to see what happens.

    Best,
    David
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 10:44
    No, I'm not. I've tried lots of times (always without removing the card) and it gives me the same error.

    I'm not using
    format()
    method and I can't see the logcat message of successfully authentication.

    So, I've also tried so remove the
    close()
    method but it didn't change anything, because the problem is before.
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 10:47
    Another suggestion:

    Try to do something with the DESFire, for example: create an Application on it, ignoring this Exception.
    But I don't know still at which line of code you get this exception so it's hard to predict something specific.

    Best,
    David
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 10:56
    I've tried something like this
    @Override
    public void onDESFireCardDetected(DESFire desFire) {
    super.onDESFireCardDetected(desFire);
    try {
    try {
    desFire.connectL4();
    } catch (IOException e) {
    e.printStackTrace();
    Log.d("TAG", "Problem with connection");
    }
    try {
    desFire.authenticate(DESFire.AuthType.Native, 0, (byte) 0, 0, (byte) 0, null);
    } catch (IOException e) {
    e.printStackTrace();
    Log.d("TAG", "Problem with authentication");
    }
    Log.d("TAG", "Checking if auth succesfull");

    byte[] UID = desFire.getCardUID();
    String rfid = com.nxp.nfclib.utils.Utilities.dumpBytes(UID);

    desFire.closeL4();

    Toast.makeText(context, "DESFire UID: " + rfid, Toast.LENGTH_SHORT).show();

    } catch (DESFireException e) {
    e.printStackTrace();
    Toast.makeText(context, "Authentication failed.", Toast.LENGTH_SHORT).show();
    } catch (SmartCardException e) {
    e.printStackTrace();
    } catch (GeneralSecurityException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }


    And it gives me "Problem with authentication"
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 10:58
    Is it possible to see your entire source code for MainActivity ?
    You could also copy / paste it in Pastebin page.

    Best,
    David
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 11:06
    I will do it in a couple of minutes, but if it can be useful, I've just tried to use the sample app edited with my key and it gives me the same error with the "0"
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 11:09
    Yes, that is why I want to see your source code.
    Because I always used only 6 byte Key with DESFire authentication and it worked in my case. I also used KEY_TYPE_MIFARE.

    But when you have the code copied and I can take a look, something might come to my mind.

    Best,
    David
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 11:17
    http://pastebin.com/a9XhJE5k
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 11:31
    could you change just for the test your KEY to

    0xFF and only 6 bytes long ?

    Because I cannot see from the code why it wouldn't work, all seems fine with me. You say that card gets detected, that means lib is initialized correctly. It also even connects to the card. But the error occurs during authentication, and what does authentication need:

    AUTH TYPE
    KEY NO
    KEY VERSION
    cardKeyNo,
    divOption
    divInput

    And all the parameters you have in. Maybe also to try (if 0xFF 6 byte long won't work), to use AUTH TYPE ISO ?

    David
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 11:56
    Always the same error. Too weird. Could it be the phone? I'm using a Samsung S4 with Android Lollipop
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 12:04
    I have also Samsung S4, for which it is often that we get TagLost exception,but not with authentication stuff, this works for me.
    Is your device rooted? Mine is not. But again, not sure if that would affect such stuff. I have still KitKat on it though if that would matter.
    + 0  |  - 0

    Re: DESFire EV1 – invalidResponse: No Such Key

    4. June 2015 at 12:08
    No, mine is not rooted, too. This error is so strange because happens always with "0", independently from others parameters.
    + 0  |  - 0
Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.