Commit graph

55 commits

Author SHA1 Message Date
Romain Tartiere
c7dc9f0ccc New API functions mifare_desfire_create_application_3k3des(), mifare_desfire_create_application_aes().
Update issue 37
Only ISO application creation as requested by Issue 57 is lacking now.
2011-03-25 13:00:24 +00:00
Romain Tartiere
22e9854995 Do not abort on crypto error.
Because in some circumstances the crypto is skipped regardless of the
communication settings by the Mifare DESFire (e.g. when reading a file which is
writable with any key), do not abort if the crypto fail, and make it possible
to the user to catch such an event to fix his code accordingly.

Only display crypto diagnostic if compiled with debug support.
2011-02-13 14:13:35 +00:00
Romain Tartiere
f418845fb4 Make mifare_desfire_authenticate() a bit more magic.
If the provided key is a 3K3DES key, authenticate in ISO mode.  If the key is
an AES one, authenticate in AES mode.  This sugar should help third party
applications to handle authentication in a more generic way.
2010-12-31 12:47:55 +00:00
Romain Tartiere
c2cc0ba53d Move away global variables. 2010-12-31 10:53:05 +00:00
Romain Tartiere
899ed3d7bb Fix create_file2().
ECOPYPASTETOOFAST | EBADLUCKITSVALID: The argument communication_settings is
not to be used to construct the parameters passed to the crypto functions
mifare_cryto_preprocess_data() & mifare_cryto_postprocess_data(), but only for
building the frame.
2010-12-29 22:18:30 +00:00
Romain Tartiere
8caa2da31e Fix write_data() return value when data is enciphered.
We only have to return the number of bytes of raw data which are sent.
2010-12-29 22:05:08 +00:00
Romain Tartiere
2750ed668c Fix usage of a potentially reallocated memory area. 2010-12-29 21:44:26 +00:00
Romain Tartiere
9a4b7b5882 New API function mifare_desfire_set_ats(). 2010-12-24 22:08:56 +00:00
Romain Tartiere
adbba0342b New API function mifare_desfire_set_default_key(). 2010-12-24 20:41:43 +00:00
Romain Tartiere
e587e26aeb Rename some internal functions.
A function with DES in its name that can perform AES crypto is somewhat
disturbing.
2010-12-24 14:10:44 +00:00
Romain Tartiere
01fff97d6c Add support for ISO authentication with 3DES keys. 2010-12-24 13:04:16 +00:00
Romain Tartiere
0d8a53308c Change the mifare_cbc_des() internal function prototype. 2010-12-24 11:41:15 +00:00
Romain Tartiere
dd5156a997 Reindent. 2010-12-18 13:32:05 +00:00
Romain Tartiere
b300ef5fcf Update the MifareDirection structure for consistency. 2010-12-18 03:11:05 +00:00
Romain Tartiere
ebd98b32e0 Switch from obscure 'int mac' argument to 'MifareCryptoOperation operation'. 2010-12-18 03:07:16 +00:00
Romain Tartiere
d098bf623f Add support for authentication using 3K3DES.
Please note that according to the NXP documentation of the Mifare DESFire EV1,
the mifare_desfire_authenticate_iso() function can be used using either 3DES or
3K3DES keys.  The former has not been tested yet and is likely not to work. To
word it differently, this is a 3K3DES crypto support, not a ISO authentication
support...
2010-12-18 02:28:27 +00:00
Romain Tartiere
373cb4f0ef Rewrite some tests using switch statements.
Add a note for the reason I do this in the HACKING file.
2010-12-18 02:07:56 +00:00
Romain Tartiere
48b161d67c Invalidate authentication when changing the currently used key. 2010-12-18 01:32:56 +00:00
Romain Tartiere
143042fb0b Remove weird code.
I should quit coding drunk... or maybe start to...
2010-12-18 01:09:30 +00:00
Romain Tartiere
a6e52db696 Workaround invalid write in read_data () (sic)
This has to be improved to some extend in the near future (hence the FIXME).
2010-12-18 01:05:35 +00:00
Romain Tartiere
5b55528008 Silent down the compiler.
The create_application() function has iso_ parameters for creating ISO
application but this mode is not available yet so the code is unused which
annoys the compiler when told to be somewhat strict.
2010-12-17 22:47:12 +00:00
Romain Tartiere
0a9a964c17 Fix a brunch of potentially reallocated memory areas. 2010-12-15 13:40:58 +00:00
Romain Tartiere
94bf8d83c6 Fix mifare_desfire_get_key_version() when authenticated with an AES key. 2010-12-15 13:34:15 +00:00
Romain Tartiere
3fd80a3eff Enable the mifare-desfire-ev1-configure-random-uid example. 2010-12-15 13:19:42 +00:00
Romain Tartiere
b91080ffc7 Fix mifare_desfire_free_mem(). 2010-12-15 12:51:22 +00:00
Romain Tartiere
42f9457d9f Add support for Mifare DESFire EV1 with AES encryption. 2010-12-15 12:43:31 +00:00
Audrey Diacre
1070d9bfde fix buffer overflow. 2010-12-13 10:56:27 +00:00
Audrey Diacre
5133491c2c replace deprecated bzero function by memset. 2010-12-10 17:10:12 +00:00
Romain Tartiere
0e2bc992bf Discard authentication information after deleting the currently selected application. 2010-12-10 14:30:28 +00:00
Romain Tartiere
e0a28547fd Reset session key in mifare_desfire_select_application().
For Mifare DESFire EV1 support, we need to know when the user has called
mifare_desfire_select_application() after being authenticated and before
authenticated again.
2010-11-23 01:15:27 +00:00
Romain Tartiere
a643e9149d Add an offset parameter to mifare_cryto_preprocess_data()
Some cryptographic operations are performed on the whole data frame and not
only the payload with Mifare DESFire EV1.  The solution for now is not perfect,
(one new macro wrapping another big macro) but makes the code a bit easier to
read, and with the MIFARE_DESFIRE macro rewriting as a function (at some point
in the future), the whole should be bearable :-)
2010-11-20 14:10:27 +00:00
Romain Tartiere
16ae154b42 Don't swap the status byte in the received data.
This have been done for consistency with other targets support, but
cryptographic operations with Mifare DESFire EV1 tags would require to swap
again this byte because MACing is performed on the following data (in this
order):
  - Plain data
  - Status
  - Padding
2010-11-20 02:22:37 +00:00
Romain Tartiere
f94c3c743f Rely on RAND_bytes() instead of DES_random_key() to generate random vectors. 2010-10-29 18:58:34 +00:00
Romain Tartiere
5b416ee508 Fix a regression introduced at r643. 2010-10-29 18:53:49 +00:00
Romain Tartiere
d9b2deebe2 Rework error reporting infrastructure. 2010-10-29 13:10:23 +00:00
Romain Tartiere
356219e21b Require the ivect to be provided to mifare_cbc_des().
- Store ivect in the struct mifare_desfire_tag;
- Reset it before and after authentication;
- Reset before each crypto operation (for now).
2010-10-29 12:22:47 +00:00
Romain Tartiere
13f03a60bb Change rol8() to rol() to work with buffers of any length. 2010-10-29 12:01:57 +00:00
Romain Tartiere
688d083f63 Fix build with recent libnfc API breakage. 2010-10-15 12:58:29 +00:00
Romain Tartiere
93011b4c07 Use the actual UID length to select a target.
Without it, the libfreefare cannot use 4-bytes-long random UIDs of Mifare
DESFire EV1.
2010-10-01 19:32:03 +00:00
Romain Tartiere
a77fa7ae4a Switch back to InDataExchange() for Mifare DESFire cards.
Wrapping all frames in ISO7816-4 ADPU workarounds the P3 (Lc) > 0xFA limitation
of the PN531.
2010-10-01 18:13:49 +00:00
Romain Tartiere
9a2a07ea53 Enhance error reporting.
Now that the libnfc has error handling, report errors triggered in the libnfc
and add support for errors triggered in libfreefare.
2010-09-28 19:01:28 +00:00
Romain Tartiere
91d3ff9cc4 Implement ISO14443-4 block numbers.
This feature was not used by the cards I initially used when coding the
, but is required for (at least some) Mifare DESFire EV1 to work.

IMPORTANT NOTE: The cards needing this block-number management to work out
break-down when mifare_desfire_format_picc() is performed on them.  The ATR
change from 0x7577810280 to 0x757781028f and further communication alway result
in a timeout.  At the time of committing, the reason is still unknown (bogus
cards, missed "Remarks" in the documentation, ...).  Other commands seems to
not expose additional problems.
2010-09-28 16:37:25 +00:00
Romain Tartiere
b6a4982102 Attempt to detect and use CoreFoundation's headers for endianness conversions on Mac OS X.
PR:		Issue 21
Submitted by:	MathewMcBride47
2010-09-04 11:06:14 +00:00
Romain Tartiere
7b9242e935 Reindent (2/2).
Align cases with switch statements.
Ça y est!  Le code est beau!
2010-09-03 18:04:12 +00:00
Romain Tartiere
af061a3c1a Reindent (1/2).
After trying to tweak gindent so that it does not mess-up my ASCII art, give
and read the help of Vim to setup 'cinoptions' according to my needs
(cino=t0(0).  This changeset reindent some bits that where not indented as they
should.  A future commit will reindent the switch/case according to my (bad)
taste now that I have setup cindent correctly on my system (cino=t0(0:0).
2010-09-03 18:01:02 +00:00
Romain Tartiere
036d2956f4 Update nfc_initiator_transceive_bytes() vs. nfc_initiator_transceive_dep_bytes().
nfc_initiator_transceive_dep_bytes() was removed, and
nfc_initiator_transceive_bytes() is now configured to behave like the one or
the other of the original functions.  For details, see:
http://code.google.com/p/libnfc/source/detail?r=592
2010-09-03 16:13:46 +00:00
Romain Tartiere
4abbb46515 Implement file settings caching.
For the regression test-suite test_mifare_desfire, it's a ~11% performance
boost, with 206 cache hits out of 488 calls to
mifare_desfire_get_file_settings().
2010-08-31 11:08:33 +00:00
Romain Tartiere
8171dd3960 Remove an irrelevant FIXME.
The check is already done by the PICC and we may not have access to the
required information to do the check from the library. Additionally, the
mifare_desfire_change_key() would require different keys to operate if we
detected an error, so no recovery of any kind is possible.
2010-08-31 10:20:24 +00:00
Romain Tartiere
878af0e22a Remove extra semi-columns at end of macro definitions. 2010-08-31 10:08:40 +00:00
Romain Tartiere
f7c4d99868 Enhance communication settings detection failures detection. 2010-08-31 10:06:55 +00:00