diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 2cd7f085..83180e7d 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -2670,7 +2670,7 @@ int CmdHF14AMfAuth4(const char *cmd) { return 1; } - return MifareAuth4(keyn, key, true, false, true); + return MifareAuth4(NULL, keyn, key, true, false, true); } static command_t CommandTable[] = diff --git a/client/cmdhfmfp.c b/client/cmdhfmfp.c index bcf4201f..a4c53f56 100644 --- a/client/cmdhfmfp.c +++ b/client/cmdhfmfp.c @@ -351,7 +351,7 @@ int CmdHFMFPAuth(const char *cmd) { CLIParserInit("hf mfp auth", "Executes AES authentication command in ISO14443-4", "Usage:\n\thf mfp auth 4000 000102030405060708090a0b0c0d0e0f -> executes authentication\n" - "\thf mfp auth 9003 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -> executes authentication\n"); + "\thf mfp auth 9003 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -v -> executes authentication and shows all the system data\n"); void* argtable[] = { arg_param_begin, @@ -377,10 +377,13 @@ int CmdHFMFPAuth(const char *cmd) { return 1; } - return MifareAuth4(keyn, key, true, false, verbose); + return MifareAuth4(NULL, keyn, key, true, false, verbose); } int CmdHFMFPRdbl(const char *cmd) { + //mf4Session session + //int res = MifareAuth4(&session, keyn, key, true, false, verbose); + //res = Read(); return 0; } diff --git a/client/mifare4.c b/client/mifare4.c index fc3fcf3d..3489c857 100644 --- a/client/mifare4.c +++ b/client/mifare4.c @@ -16,13 +16,15 @@ #include "ui.h" #include "polarssl/libpcrypto.h" -int MifareAuth4(uint8_t *keyn, uint8_t *key, bool activateField, bool leaveSignalON, bool verbose) { +int MifareAuth4(mf4Session *session, uint8_t *keyn, uint8_t *key, bool activateField, bool leaveSignalON, bool verbose) { uint8_t data[257] = {0}; int datalen = 0; uint8_t Rnd1[17] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00}; uint8_t Rnd2[17] = {0}; + if (session) + session->Authenticated = false; uint8_t cmd1[] = {0x70, keyn[1], keyn[0], 0x00}; int res = ExchangeRAW14a(cmd1, sizeof(cmd1), activateField, true, data, sizeof(data), &datalen); @@ -102,6 +104,13 @@ int MifareAuth4(uint8_t *keyn, uint8_t *key, bool activateField, bool leaveSigna if (verbose) PrintAndLog(""); + if (session) { + session->Authenticated = true; + session->KeyNum = keyn[1] + (keyn[0] << 8); + memmove(session->Rnd1, Rnd1, 16); + memmove(session->Rnd2, Rnd2, 16); + } + PrintAndLog("Authentication OK"); return 0; diff --git a/client/mifare4.h b/client/mifare4.h index 163bdead..70711847 100644 --- a/client/mifare4.h +++ b/client/mifare4.h @@ -15,7 +15,15 @@ #include #include -extern int MifareAuth4(uint8_t *keyn, uint8_t *key, bool activateField, bool leaveSignalON, bool verbose); +typedef struct { + bool Authenticated; + uint16_t KeyNum; + uint8_t Rnd1[16]; + uint8_t Rnd2[16]; + +}mf4Session; + +extern int MifareAuth4(mf4Session *session, uint8_t *keyn, uint8_t *key, bool activateField, bool leaveSignalON, bool verbose);