0
votes

I'm trying to authenticate any sector of a MIFARE classic card. I'm using a twinlinx mymax sticker (which makes almost any bluetooth device NFC enabled). It sends commands to a connected NFC tag. I've already made a connection and sent and recieved data with a Ultralight C tag, but so far I had no success on accessing a Mifare Classic. Here is my authentication code:

    private boolean authenticate(int sector, byte[] key, boolean keyA) {

    byte[] cmd = new byte[12];

    // First byte is the command
    if (keyA) {
        cmd[0] = 0x60; // phHal_eMifareAuthentA
    } else {
        cmd[0] = 0x61; // phHal_eMifareAuthentB
    }

    // Second byte is block address
    cmd[1] = (byte) 0x03;

    // Next 6 bytes are the key
    System.arraycopy(key, 0, cmd, 2, 6);

    // Next 4 bytes is the UID
    System.arraycopy(Answer, 3, cmd, 8,4);

    byte[] test = null;

    //this makes a connection to the NFC tag (and this works)
    TR.ConnectToExternalCard(AUTH, (byte)0x00);

    //checking if the tag is still connected
    if (TR.isCardPresent() == true){

    //sending command to authenticate
    test = TR.SendCommandPropAndWaitResponse(cmd, (byte) 0x00);
    }

    try {
        if (test != null) {

            return true;
        }
    } 

I'm using standard MIFARE Classic keys, the tags are fresh from the factory. The complete command (in bytes) which is sent to the tag is:

[0x60, 0x3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0xf4, 0xa9, 0xfb]

Any Ideas? The tag seems to be non-responsive... tried accessing other Classic tags but also had no success. Thanks!

1

1 Answers

0
votes

It is hard to say what you are doing wrong using an SDK that is not publicly available. However, the API looks familiar enough, so I will give it a try anyway. I can think of a number of things you may try (in decreasing order of likeliness):

  1. The UID bytes may be in the wrong order, so try reversing them.
  2. Perhaps Answer does not only contain the UID, but other bytes, too (e.g. SAK), and you are copying the wrong bytes from it.
  3. The MIFARE Classic tags you have may have a 7-byte UID and you are not using the correct 4 bytes from that.
  4. May be TR.SendCommandPropAndWaitResponse() is the wrong method to use. Perhaps there is a dedicated method for MIFARE Classic.
  5. The MyMax sticker may not support MIFARE Classic. I don't see explicit confirmation on their website that they do. However, indications are that their solution is based on NXP hardware, which always supports MIFARE Classic.