Help with authentication on DESFireEV1 card

Forum / MIFARE SDK / Help with authentication on DESFireEV1 card

  • 5. January 2017 at 11:44

    I'm having some trouble authenticating against a DESFireEV1 card to read password protected file.

    The customer I work for has supplied me with a DESFireEV1 card where they expect me to read the content of a file in a certain application. I don't have access to the full master key of the card, but only the specific key for that specific file in that specific application.

    I have created an android app based on the code provided in the sample app for TapLinX and the code to authenticate and read looks like this.

    The key used was provided in the format of a hex string like this.


    And based on that I created a byte array like this.

    public static final byte[] KEY_AES128 =
    (byte) 0x00, (byte) 0x11, (byte) 0x22, (byte) 0x33,
    (byte) 0x44, (byte) 0x55, (byte) 0x66, (byte) 0x77,
    (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB,
    (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF

    Does that look correct?

    When I run it I get a InvalidResponseLengthException: Authentication Error like this.

    D/NfcDemo: onNewIntent
    D/NfcDemo: DESFireEV1 found
    D/NfcDemo: Existing Application Ids : [1, 2, 3, 4, 5, 6, 7, 8]
    D/NfcDemo: AID 000006 selected
    D/NfcDemo: Authentication status: Not Authenticated
    W/System.err: com.nxp.nfclib.exceptions.InvalidResponseLengthException: Authentication Error
    W/System.err: at com.nxp.nfclib.desfire.If.ˎ(:4223)
    W/System.err: at com.nxp.nfclib.desfire.If.ˏ(:1031)
    W/System.err: at com.nxp.nfclib.desfire.If.ॱ(:572)
    W/System.err: at com.nxp.nfclib.desfire.If.authenticate(:602)

    One bit I find confusing is that according to the info I got from the customer each file in that application is encrypted with a different key, but the authentication is only done against the application. I can't find any authenticate or readData method that allows me to authenticate directly against a file, so wondering if that is that even possible?
    + 0  |  - 0

    Re: Help with authentication on DESFireEV1 card

    6. January 2017 at 8:06
    You have to select the application. Than you must do an authorisation with the right key of the application that is defined for the file als read or read/write key.
    When this authorisation is working you can ReadData from the file or WriteData to the file.

    If your authorisation getting wrong like here, you have to start new with selection the application. To any command after the error is getting refused.
    + 0  |  - 0

    Re: Help with authentication on DESFireEV1 card

    9. January 2017 at 10:11
    Thanks for the reply Christian.

    As can be seen in the initial post I used this method for selecting the application.

    _objDESFireEV1.selectApplication( 6 );

    Then I did an authentication using the following method.

    _objDESFireEV1.authenticate( 0, IDESFireEV1.AuthType.AES, KeyType.AES128, keyData);

    Is that not enough or the correct way to do this?

    Error message I get is thrown when trying to authenticate with the code above.

    Data is stored something like this.

    Application	File	Key
    X A 112233AA112233AA112233AA
    X B 445566BB445566BB445566BB
    X C 778899CC778899CC778899CC

    Is it possible to authenticate with different keys for the same application in order to access the different files stored there?
    + 0  |  - 0

    Re: Help with authentication on DESFireEV1 card

    10. January 2017 at 17:41
    Hi Mats and Christian,

    First of all: you should use TapLinx version 1.1. In version 1.0, we had a numerous issues and it is possible, that you run into a bug.

    Which key you use for the authentication depends on the setting of the target file. If the file permission for reading is 0x05, you have to use key #5 for the authentication. If another files uses reading permission 0x06, you have to authenticate with key #6 before. You have a maximum of 14 keys per application which you can use.

    You will find an example at the end of the post:

    The TapLinx Team
    + 0  |  - 0
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.