1 (edited by luke.marlin 2014-12-07 15:58:38)

Topic: [Solved] Changing keys with libfreefare

Hi there,

I am currently trying to do a simple change of master PICC key on a Mifare Desfire EV1 tag using the last version of libfreefare built from source.

Here is the code I use :

...

uint8_t oldKeyData[16] = {0,0,0,0,
                          0,0,0,0,
                          0,0,0,0,
                          0,0,0,0};
uint8_t newKeyData[16] = {1,1,1,1,
                          1,1,1,1,
                          1,1,1,1,
                          1,1,1,1};

MifareDESFireKey old_master_key = mifare_desfire_3des_key_new (oldKeyData); 
MifareDESFireKey new_master_key= mifare_desfire_3des_key_new (newKeyData); 

mifare_desfire_connect(tag); //Returns OPERATION_OK
mifare_desfire_authenticate(tag,0, old_master_key); //Returns OPERATION_OK

mifare_desfire_change_key(tag, 0, new_master_key, old_master_key); //Returns -1

If this can be of any help, here is the debug output :

debug    libnfc.chip.pn53x    InDataExchange
debug    libnfc.chip.pn53x    No timeout
debug    libnfc.bus.uart    TX: 00 00 ff 22 de d4 40 01 90 c4 00 00 19 00 9e a8 19 3b de 48 15 74 65 54 17 9c 14 28 29 dc 83 dd 45 3c 2b 1a a5 d9 00 e4 00
debug    libnfc.bus.uart    RX: 00 00 ff 00 ff 00
debug    libnfc.chip.pn53x    PN53x ACKed
debug    libnfc.bus.uart    RX: 00 00 ff 05 fb
debug    libnfc.bus.uart    RX: d5 41
debug    libnfc.bus.uart    RX: 00 91 1e
debug    libnfc.bus.uart    RX: 3b 00

Any ideas on what is going on ? Or what I should check ?

PS: I have the same output when I try to change the key settings..

Re: [Solved] Changing keys with libfreefare

I found some time to resolve my issue by myself.
In fact I was just being fooled by the mifare_desfire_authenticate's return value. I was authenticating with a 3DES key instead of the default DES key. Although authenticate returns OPERATION_OK, I was using the wrong key and encryption method.

Re: [Solved] Changing keys with libfreefare

Hi,

I'm sorry but I don't understand.
Could you put your new code?

I have the same error...

Tx

4 (edited by luke.marlin 2015-03-04 09:35:46)

Re: [Solved] Changing keys with libfreefare

Hi pykoon,

I can't give you any code right now but I'll try to give you an example tonight.
I can however try to re-explain my problem.

I was using a clean tag, which have a DES key by default, which has the value 0000 0000. I was trying to authenticate with a 3DES key with value 0000 0000 0000 0000, and the mifare_desfire_authenticate method was returning me OPERATION_OK, but subsequent operation were throwing errors. It is fairly obvious that my authentication was wrong : I'm not using the right algorithm. When I switched to a DES key, the code above (modified accordingly) worked flawlessly.

Is it any clearer ?

Re: [Solved] Changing keys with libfreefare

Hi Luke and thank you for your response.
Now, it's clearer and I undestood the problem.``

Tx.