GithubHelp home page GithubHelp logo

Comments (4)

pollev avatar pollev commented on July 30, 2024 1

Hi,

I encountered the same error.
I don't know why this happens but I do know what happens and how you can circumvent it:

Have a look at the following code (and ignore the printf statements I jammed in there for debugging):
file: src/mfoc.c

// Try A key, auth() + read()
      memcpy(mp.mpa.abtKey, t.sectors[i].KeyA, sizeof(t.sectors[i].KeyA));
      int res;
      fprintf(stdout, "Trying key A\n");
      if ((res = nfc_initiator_mifare_cmd(r.pdi, MC_AUTH_A, block, &mp)) < 0) {
        fprintf(stdout, "authfail\n");
        if (res != NFC_EMFCAUTHFAIL) {
          nfc_perror(r.pdi, "nfc_initiator_mifare_cmd");
          goto error;
        }
        mf_configure(r.pdi);
        mf_anticollision(t, r);
      } else { // and Read
        fprintf(stdout, "and read\n");
        if ((res = nfc_initiator_mifare_cmd(r.pdi, MC_READ, block, &mp)) >= 0) {
          fprintf(stdout, "read A ok\n");
          fprintf(stdout, "Block %02d, type %c, key %012llx :", block, 'A', bytes_to_num(t.sectors[i].KeyA, 6));
          print_hex(mp.mpd.abtData, 16);
          mf_configure(r.pdi);
          mf_select_tag(r.pdi, &(t.nt));
          failure = false;
        } else {
          fprintf(stdout, "read A failed with err %d\n", res);
          // Error, now try read() with B key
          if (res != NFC_ERFTRANS) {
            nfc_perror(r.pdi, "nfc_initiator_mifare_cmd");
            //goto error;  <------ COMMENT THIS LINE <------------
          }
          mf_configure(r.pdi);
          mf_anticollision(t, r);
          memcpy(mp.mpa.abtKey, t.sectors[i].KeyB, sizeof(t.sectors[i].KeyB));
          fprintf(stdout, "Trying key B\n");

Basically it first attempts to authenticate with KEY A. which succeeds, it then tries to read with KEY A. Which fails with an AUTH error.

For some odd reason it does not fail with an auth error in the first check. Which trips up the application because it does not expect an auth error after that point.

Because of this it does not try with KEY B, which would have worked.

The solution that worked for me was to simply comment out the goto error;, recompile, and everything worked perfectly.

Hope this helps someone else

from mfoc.

priv avatar priv commented on July 30, 2024

It's no odd because KEY A has no read right.
ACs bits are 4b 44 bb, so it behaves correctly. KEYA can auth but will not read the block 12/13.

from mfoc.

pollev avatar pollev commented on July 30, 2024

Regardless. It makes no sense that the tool just errors out and quits instead of trying the second key, which would just work... This fixes that.

from mfoc.

OLivecode7 avatar OLivecode7 commented on July 30, 2024

Hi,

I encountered the same error. I don't know why this happens but I do know what happens and how you can circumvent it:

Have a look at the following code (and ignore the printf statements I jammed in there for debugging): file: src/mfoc.c

// Try A key, auth() + read()
      memcpy(mp.mpa.abtKey, t.sectors[i].KeyA, sizeof(t.sectors[i].KeyA));
      int res;
      fprintf(stdout, "Trying key A\n");
      if ((res = nfc_initiator_mifare_cmd(r.pdi, MC_AUTH_A, block, &mp)) < 0) {
        fprintf(stdout, "authfail\n");
        if (res != NFC_EMFCAUTHFAIL) {
          nfc_perror(r.pdi, "nfc_initiator_mifare_cmd");
          goto error;
        }
        mf_configure(r.pdi);
        mf_anticollision(t, r);
      } else { // and Read
        fprintf(stdout, "and read\n");
        if ((res = nfc_initiator_mifare_cmd(r.pdi, MC_READ, block, &mp)) >= 0) {
          fprintf(stdout, "read A ok\n");
          fprintf(stdout, "Block %02d, type %c, key %012llx :", block, 'A', bytes_to_num(t.sectors[i].KeyA, 6));
          print_hex(mp.mpd.abtData, 16);
          mf_configure(r.pdi);
          mf_select_tag(r.pdi, &(t.nt));
          failure = false;
        } else {
          fprintf(stdout, "read A failed with err %d\n", res);
          // Error, now try read() with B key
          if (res != NFC_ERFTRANS) {
            nfc_perror(r.pdi, "nfc_initiator_mifare_cmd");
            //goto error;  <------ COMMENT THIS LINE <------------
          }
          mf_configure(r.pdi);
          mf_anticollision(t, r);
          memcpy(mp.mpa.abtKey, t.sectors[i].KeyB, sizeof(t.sectors[i].KeyB));
          fprintf(stdout, "Trying key B\n");

Basically it first attempts to authenticate with KEY A. which succeeds, it then tries to read with KEY A. Which fails with an AUTH error.

For some odd reason it does not fail with an auth error in the first check. Which trips up the application because it does not expect an auth error after that point.

Because of this it does not try with KEY B, which would have worked.

The solution that worked for me was to simply comment out the goto error;, recompile, and everything worked perfectly.

Hope this helps someone else

I confirm this works on my practical case

Big Thanks
@pollev pollev

from mfoc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.