-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for MIFARE DESFire #31
Comments
I second this. MIFARE DESFire is a must. |
Me to for MIFARE DESFire EV1 and MIFARE DESFire EV2 versions On 13 October 2016 at 16:04, Ing. Radomír Polách [email protected]
|
I agree - however DESFire has a very complex protocol (three different modes of communication to start with, many functions, ...) -> we will likely start with a subset (in the WISSEC paper, it was mainly just authentication). If anyone wants to further contribute here pls contact us (or do it and send us a pull request for the complete DESFire emulation :) ) |
Thanks David! If I can have the authentication code, I think I can hard code the file system of a target card. Please do see if you can include the DESFire authentication in the code. |
FYI, this is what's lying around the 'nets: |
Oh well. I'll get things rolling in my fork. |
By the way, any suggestions for a good (= compliant, stable, documented APIs) reader for these cards? Will have to test with something, right? AFAIK, proxmark3 does not support DESFire cards, and that's the only one "reader" I have. |
libfreefare has DESFire support, so it works with any libnfc-compliant reader. The libfreefare code could also be useful as a reference how the reader side works. |
Since everyone is really looking forward to having support for DESFire in Chameleon, I think it is OK to ask for some help. :-) Could anyone who has the actual cards do a few captures of PDU traffic between cards and readers, for reference? Selecting the card, authenticating, selecting an app, reading a file... that kind of stuff. Including the 14443-4 headers please. Bonus points for full captures of 14443-4 and 7816 exchanges! Thanks! FWIW, I think I have implemented ISO 14443-4 layer and stuff below it, so I'm working on implementing DESFire commands now. Not sure at which point it will be ready for testing, but I am confident we'll have something before mid-November. |
Maybe the captures here help: http://adamsblog.aperturelabs.com/2013/02/atmel-sam7xc-crypto-co-processor-key.html Otherwise give us a few days and we'll get/find something. |
@dev-zzo thanks for your effort on the DESFire stuff. If you still need captures of DESFire card communication, I could contribute. |
@david-oswald Thanks for the link, I will go through it ASAP! @martinbeier Would be awesome if you could play with them cards and share PDU traces. As for the command set, I am currently at the basic DESFire level; I believe EV1 and EV2 are supersets but I don't have docs to back that. |
@dev-zzo I can confirm your assumption, DESFire EV1 and EV2 are fully backward compatible |
And we have the first contact, ladies and gentlemen. https://gist.github.com/dev-zzo/77e1365d40b0a70f8d33e988412afcb3 Now to find a reader that would issue actual commands. :) |
Quite impressive! Like to see the way you implemented it in your Code. |
@skuep The code is public at https://github.com/dev-zzo/ChameleonMini/tree/desfire |
That looks great 😄. |
@Maxhy I will give LibLogicalAccess a close look this weekend. :-) |
This is very impressive, we really like your work and look forward to any progress you make! |
The current implementation will be able to support emulation of EV0 cards completely, and EV1 cards to some extent. Currently, I don't have insight into how key material is managed for EV1/EV2 cards, specifically the nuances of setting the key type... but I will find out eventually. >:-) For EV0, the remaining parts are the actual FS interactions (values/record files, read/write operations, transactions). Authentication, key material management, and application management should be ready for testing; if anyone is willing to test and debug this please do so. |
Can't compile version in your repo, I am getting:
|
@dev-zzo It looks like you have your old Makefile fix for compiling under Windows, which breaks up compiling under linux. |
@geo-rg @exander77 I have rebased my branch to master's HEAD, it should be OK now. |
I think it's best if you create issues in my fork for any problems you might discover. :-) |
I don't see issue section on your repository, do you have it enabled? But it compiles fine now. I will try DESFIRE emulation and will report back. |
I am looking at ATS values, the emulation gives me 7500810200, normal Desfire cards gives me 7577810280, same as here: http://nfc-tools.org/index.php?title=ISO14443A |
@exander77: second byte is the "speed" byte and as the current emulation only supports the slowest speed, @dev-zzo prefers to indicate to the reader to not try higher speeds. Last byte changes too as it's a checksum. |
I just tested emulation on some doors, I had success with some doors, but not with all, maybe related to the speed? |
@exander77 From what I know, the 2nd byte in ATS reports which comm speeds the card supports, as correctly noted by @doegox ; as Chameleon right now doesn't support anything faster than the basic 106k/s, that's what is hardcoded in my emulation. If the reader tries to use higher speed then it won't work anyway, so there is no big point in reporting faster speeds. The last byte reportedly is unused and can be set to anything, but I will set ti to 80 to better mimic the original hardware. |
@exander77 please capture the exchange for the ones that didn't work; you can use proxmark3 for that. |
For those trying things and seeing bugs: use the built-in logging facility to save traffic for future analysis. Before presenting the card, use |
Alright, we're battling with auth code now... I am not exactly sure what the problem is, though. If I understand the D40 algorithm correctly, then on the first step, the card sends E(RndB) without using CBC at all (the IV is not updated). On step 2, the reader sends E(RndA|RndB') using CBC with zero IV -- and this is the only mention of CBC in the whole chapter on auth in the doc. On step 3, the card sends E(RndA'), again without using CBC. This does align with the example here: https://ridrix.wordpress.com/2009/09/19/mifare-desfire-communication-example/ -- if you do each step manually data agrees well (assuming the key of all zeros). The problem is, libfreefare doesn't agree with this flow: https://github.com/nfc-tools/libfreefare/blob/master/libfreefare/mifare_desfire.c#L366 seems to use CBC all the way through the three steps. I have come up with a method to test whether at least parts of crypto work as expected... We can easily figure out what RndB is since we know the key the card uses and can decipher the value from the data being sent over the wire. We can also figure out RndB' from what the reader sends; since CBC is used in send mode, we can use the first block E(RndA) as the IV and get the plaintext for 2nd block easily as well. So we can verify RndB being handled correctly at all times if we know the key; additionally, this does not depend on whether CBC is used throughout or only on step 2. This seems to work on the data in Ridrix's blog page but not on e.g. Adam's blog and not in tests with a reader we have. Why? No idea whatsoever. Any insights from you guys? |
All steps are with CBC, ridrix told it in a comment |
Also beware when testing 3DES with a null key, it has the nasty property that ENC(data)==DEC(data). |
@doegox Thanks for the response. Do you know more about "older and newer" cards? How old/how new? Is this DESFire EV0 vs EV1 or is this within the same major version? |
I have made a test script using pycrypto: https://gist.github.com/dev-zzo/87e0947f3ca0bb6d6baf78dd4d0ecb9c
|
afaik libfreefare is working fine, so better to take it as a model ;) I was not correct about older & newer cards, it's not about cards but commands. |
@doegox I am currently trying to get the "legacy" mode supported properly, as it is the only one supported by EV0 cards. ISO and AES auth modes are supported from EV1 onwards AFAICT. |
I'll just leave this here... |
A quick test with my own key tracing a DF EV1
This matches the behavior of ridrix data. |
@doegox Then it seems like libfreefare has an issue handling the legacy authentication method? |
Just to let everyone here know, EV0 "legacy" authentication has been verified to work fine. My big thanks to @shombre for help with testing it! |
Hello @dev-zzo I wanted to reproduce your https://gist.github.com/dev-zzo/77e1365d40b0a70f8d33e988412afcb3/revisions proxmark3 read. Is this still working with your Latest commit b73bba3? |
I tried it with another reader with the pn532_uart it is responding but it fails to respond on the samsung galaxy s4. The s4 should be able to read the uid but the tag is not found. Using the same UID on the MF_CLASSIC_1K_7B config, android reports the UID correctly. |
Hi, is it possible right now to "emulate" a desfire ev1 card (only the part related to the UID) ? Simply answering when asked for the (U)ID (with ATQA 0x0344 and SAK 0X20) ? R |
I would very much like to see Chameleon supporting emulation of DESFire cards. I reckon this was already implemented according to the WISSEC paper, but is not shred with general public. Any plans on putting it on github?
The text was updated successfully, but these errors were encountered: