Commit graph

569 commits

Author SHA1 Message Date
broth-itk
682fbe69bd Cleanup: Replace DESFIRE_TRANSCEIVE by a function (#105)
The work for this commit was outlined by the third item from the TODO:

> ### The `DESFIRE_TRANSCEIVE` macro should be replaced by a function ###
>
> `DESFIRE_TRANSCEIVE` was originaly a macro to enclose a
> `nfc_initiator_transceive_bytes()` call with debug lines.  The
> functions has unexpectedly grown up and is now between 25 and 100
> lines of code (depending of my refactoring mood).  The main
> drawbacks are poor readability, redundant code in the binary,
> debuggers don't cope well with macros, and by design it sucks.

Thanks @broth-itk for submitting this change.
2019-11-05 11:42:53 -08:00
broth-itk
7f695cfbec Implementation of configurable timeout (#101)
Previously, no timeout or an arbitrary timeout (500ms) was used. This
usually works but causes some issues when operations take longer: for
example, during `mifare_desfire_format_picc`.

This changes increases the previous default timeout to two seconds and
adds a new function that allows setting custom timeouts.
2019-10-29 16:01:40 -07:00
Martin Dagarin
d13eca5d3c Added safety check len == 0 (#109) 2019-10-29 20:20:20 +00:00
Robert Quattlebaum
b83cbcbb09
Merge pull request #118 from darconeous/issue-91
Properly handle edge cases in AN10922 key diversification
2019-10-29 11:36:57 -07:00
Robert Quattlebaum
ec91014ebf Properly handle edge cases in AN10922 key diversification
This commit fixes issue #91.

[AN10922][] specifies the key diversification algorithms used by the
MIFARE SAM AV3. Support for these algorithms was added to
`libfreefare` via pull-request #79.

However, while every attempt was made to write a faithful
implementation, the implemented code did not properly handle cases
where the diversification data was less than or equal to the block
size of the cipher: 16 bytes for AES, and 8 bytes for DES. This
bug was identified in issue #91.

This commit addresses this problem while providing a way to revert to
the previous behavior in cases where it is necessary to maintain
previous deployments. This was accomplished by introducing a new
`flags` parameter to the `mifare_key_deriver_new_an10922` method.

Normally, `flags` should simply be set to `AN10922_FLAG_DEFAULT`.
However, if the previous behavior is required, it should be set to
`AN10922_FLAG_EMULATE_ISSUE_91`.

[AN10922][] does not include any test vectors that might have helped to
identify this problem earlier. However, [AN10957][] (pages 13-14) was
found to have a suitable example usage of [AN10922][] with an
appropriately short value for *M* that we are using as a test vector
to verify correct behavior.

Note that the issue being addressed here is not a security issue:
using the `AN10922_FLAG_EMULATE_ISSUE_91` should not be any less
secure than using `AN10922_FLAG_DEFAULT`.

[AN10922]: https://www.nxp.com/docs/en/application-note/AN10922.pdf
[AN10957]: https://www.nxp.com/docs/en/application-note/AN10957.pdf
2019-10-29 11:21:56 -07:00
broth-itk
262eacedca Added freefare_version() function (#104)
Added freefare_version() function
2019-06-30 18:22:26 -10:00
Romain Tartière
5459806659 Fix wrong buffer size
Fix build issue:

```
/tmp/libfreefare/libfreefare/ntag21x.c:718:5: error: array index 1 is past the end of the array
      (which contains 1 element) [-Werror,-Warray-bounds]
    cmd_step1[1] = 0x00;
    ^         ~
/tmp/libfreefare/libfreefare/ntag21x.c:715:5: note: array 'cmd_step1' declared here
    uint8_t cmd_step1[1];
    ^
1 error generated.
```
2019-01-25 15:25:06 -10:00
Romain Tartière
3d1e58b3dc Add missing switch case
Fix build issue:

```
/tmp/libfreefare/libfreefare/freefare.c:172:13: error: enumeration value 'NMT_BARCODE' not handled in switch
      [-Werror,-Wswitch]
    switch (tag->info.nm.nmt) {
            ^
1 error generated.
```
2019-01-25 15:24:13 -10:00
Romain Tartière
ba63f18d8e Add missing header
Fix build issue:

```
/tmp/libfreefare/libfreefare/felica.c:50:16: error: implicitly declaring library
      function 'malloc' with type 'void *(unsigned long)'
      [-Werror,-Wimplicit-function-declaration]
    if ((tag = malloc(sizeof(struct felica_tag)))) {
               ^
/tmp/libfreefare/libfreefare/felica.c:50:16: note: include the header <stdlib.h>
      or explicitly provide a declaration for 'malloc'
/tmp/libfreefare/libfreefare/felica.c:64:5: error: implicit declaration of
      function 'free' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
    free(tag);
    ^
2 errors generated.
```
2019-01-25 15:23:50 -10:00
Romain Tartière
26754f8042 Make CMake emit PACKAGE_VERSION in config.h
This is required for the upcomming freefare_version() function, and
mimics what is produced by the autotools.
2019-01-25 15:20:54 -10:00
Romain Tartière
4deb8c998a
Merge pull request #98 from manu0402/master
Introduce timeout on DESfire operations
2018-12-10 17:52:25 -10:00
Emmanuel Dreyfus
2d9ada743b Introduce timeout on DESfire operations
There are a few reasons why an NFC operation may timeout, including
the pn533 USB toggle bit bug. In that case it helps to report the
problem to calling process so that it can retry operation, instead
of hanging forever.

For instance, mifare_desfire_format_picc() may make the chip
unresponsive (see commit 91d3ff9cc4),
but if calling process gets ETIMEDOUT, it can select_application,
authenticate and format_picc again, with some success.
2018-12-11 03:47:03 +01:00
SloCompTech
c18f702840 Fix issues for NTAG21x tags
- Change default tag from NTAG_213 to NTAG_UNKNOWN so unknown tags can
  be detected.  ntag_get_info() MUST be called after connect;
- Fix reuse function which used to reset all tag info;
- Introduce ntag21x error reporting through freefare_error(3);
2018-03-09 23:19:30 +01:00
Philippe Teuwen
75f08d3a85
Merge pull request #79 from darconeous/an10922
Support for AN10922 key derivation
2018-01-19 02:00:02 +01:00
Robert Quattlebaum
9d88c18833 Support for AN10922 key derivation
This commit implements [AN10922][] key diversification, as described in issue #77.

[AN10922]: https://www.nxp.com/docs/en/application-note/AN10922.pdf
2018-01-08 22:08:37 -08:00
Romain Tartière
3d398dcd2f
Merge pull request #78 from darconeous/key-version-fix
Additional MifareDesfireKey fixes + tests
2018-01-08 18:31:22 +01:00
Robert Quattlebaum
67e7186d2b Additional MifareDesfireKey fixes + tests
In addition to adding tests for the bugs addressed via #70,
this commit also addresses a key corruption bug that would
occur on 3DES keys when `mifare_desfire_key_set_version()`
was called.
2018-01-08 09:23:07 -08:00
Andreas Oberritter
eea8b7b51e mifare_desfire_key: fix get/set_version for AES keys 2018-01-06 08:47:45 -08:00
Philippe Teuwen
2514cde675
Merge pull request #80 from darconeous/ultralightc-set-key
mifare-ultralight: Added mifare_ultralightc_set_key()
2018-01-06 17:36:49 +01:00
Robert Quattlebaum
58ced25978 mifare-ultralight: Added mifare_ultralightc_set_key()
This new method sets the authentication key on a MIFARE Ultralight C
card, and is analogous to `ntag21x_set_key()`.
2018-01-06 08:19:00 -08:00
Romain Tartière
2bda6a071f
Merge pull request #73 from lunixoid/master
Fixed possible memory leak
2017-10-31 09:31:18 +01:00
Roman Kalashnikov
5f9c23aaa9
Fixed possible memory leak 2017-10-31 00:44:55 +03:00
Romain Tartière
9d1d5f13a9
Merge pull request #72 from lunixoid/master
Fixed missprint
2017-10-30 08:43:07 +01:00
Roman Kalashnikov
f372c7500f
Fixed missprint 2017-10-29 23:20:33 +03:00
Romain Tartière
69bf99b33d Run make style to indent macros 2017-06-29 12:25:53 +02:00
Romain Tartière
c54e3d981c Ask astyle(1) to indent macros too 2017-06-29 12:23:03 +02:00
Romain Tartière
14b44b8076 Add Travis-CI badge 2017-06-29 09:55:48 +02:00
Romain Tartière
626f409676 Merge pull request #49 from nfc-tools/cleanup
No objection for a year, I guess anyone is fine with the `COPYING` file in the repository root directory and relying on git to determine who wrote what piece of code.
2017-06-29 09:41:03 +02:00
Romain Tartière
2a311c13ad Only include config.h if HAVE_CONFIG_H is defined 2017-06-29 09:29:15 +02:00
Romain Tartière
6c1f6283bd Deduplicate fixture headers. 2017-06-29 09:29:15 +02:00
Romain Tartière
94bf7059b4 Remove copyright comments.
The COPYRIGHT file is already here and is more complete, while the VCS
hold accurate information about contributors and conibution date.
2017-06-29 09:29:15 +02:00
Romain Tartière
32c6ed8f32 Align macros indentation with the rest of the code 2017-06-29 09:27:36 +02:00
Romain Tartière
5bd27a9d68 Merge pull request #66 from janschiefer/master
Convenience function for PICC master key settings, apply 'free_create_delete_files' in MDAPP_SETTINGS()
2017-06-29 09:22:58 +02:00
Dr. Jan Schiefer
091d60e227 1. Add convenience function for managing PICC master key settings. 2. Apply free_create_delete_files in MDAPP_SETTINGS(). 2017-06-29 01:06:33 +02:00
Romain Tartière
22929cd2cb Merge pull request #65 from salcatroppa/master
Update freefare_internal.h
2017-06-27 15:33:54 +02:00
Salvatore Catroppa
78322f486e Update freefare_internal.h 2017-06-27 15:14:51 +02:00
Romain Tartière
b49692848e Merge pull request #64 from nfc-tools/style
Use astyle(1) to make style consistent
2017-06-27 14:35:48 +02:00
Romain Tartière
73dc0529fa Run make style to fix style 2017-06-27 13:58:31 +02:00
Romain Tartière
187481bb4c Ignore new examples 2017-06-27 13:57:05 +02:00
Romain Tartière
9d016f7c3c Add make style target 2017-06-27 11:11:17 +02:00
Martin Dagarin
b2eca838c4 Added support for NTAG 21x tags (#53) 2017-06-27 10:50:50 +02:00
Romain Tartière
2be45f60e2 Merge pull request #63 from nfc-tools/travis-build
Test the build with Travis-CI
2017-06-27 08:10:39 +02:00
Romain Tartière
be3e581eff Build test then run them
We do not run the test suite at the `make check` stage here in order to
have a better output.
2017-06-26 13:17:37 +02:00
Romain Tartière
7536bbde06 Attempt to have a working cutter 2017-06-26 11:52:00 +02:00
Romain Tartière
33eaf7fcce Run the test suite using cutter
This is only available with the autotools build for now.
2017-06-26 11:43:17 +02:00
Romain Tartière
616df0af82 Do not use pkg-config(1) to search for libnfc
Since libnfc is not installed system-wide, pkg-config(1) can't find it.
Set LIBNFC_CFLAGS/LDFLAGS manually.
2017-06-26 11:30:36 +02:00
Romain Tartière
6ef62014d1 Imediatly stop on failure 2017-06-26 11:29:29 +02:00
Romain Tartière
d0f78c4880 Fix autotools build
CMake seems to find the libnfc includes and libraries, but not the
autotools.  Pass them to ./configure.
2017-06-26 11:21:28 +02:00
Romain Tartière
a884eb3dca Fix Travis-CI build
While here, refactor a bit so that a failing libnfc build does not
indicate a failure of the libfreefare build.
2017-06-26 11:15:12 +02:00
Romain Tartière
feb0f15f3e Test build using Travis-CI 2017-06-26 11:09:17 +02:00