Merge pull request #1806 from jmichelp/master

Fix prolematic return codes in mifare.
This commit is contained in:
Iceman 2022-11-04 15:04:20 +01:00 committed by GitHub
commit 1434e071f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View file

@ -115,14 +115,14 @@ static int GetHFMF14AUID(uint8_t *uid, int *uidlen) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
PrintAndLogEx(WARNING, "iso14443a card select failed"); PrintAndLogEx(WARNING, "iso14443a card select failed");
DropField(); DropField();
return 0; return PM3_ERFTRANS;
} }
iso14a_card_select_t card; iso14a_card_select_t card;
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t)); memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
memcpy(uid, card.uid, card.uidlen * sizeof(uint8_t)); memcpy(uid, card.uid, card.uidlen * sizeof(uint8_t));
*uidlen = card.uidlen; *uidlen = card.uidlen;
return 1; return PM3_SUCCESS;
} }
static char *GenerateFilename(const char *prefix, const char *suffix) { static char *GenerateFilename(const char *prefix, const char *suffix) {
@ -133,8 +133,8 @@ static char *GenerateFilename(const char *prefix, const char *suffix) {
int uidlen = 0; int uidlen = 0;
char *fptr = calloc(sizeof(char) * (strlen(prefix) + strlen(suffix)) + sizeof(uid) * 2 + 1, sizeof(uint8_t)); char *fptr = calloc(sizeof(char) * (strlen(prefix) + strlen(suffix)) + sizeof(uid) * 2 + 1, sizeof(uint8_t));
GetHFMF14AUID(uid, &uidlen); int res = GetHFMF14AUID(uid, &uidlen);
if (!uidlen) { if (res != PM3_SUCCESS || !uidlen) {
PrintAndLogEx(WARNING, "No tag found."); PrintAndLogEx(WARNING, "No tag found.");
free(fptr); free(fptr);
return NULL; return NULL;
@ -234,7 +234,7 @@ static bool mfc_value(const uint8_t *d, int32_t *val) {
if (val) { if (val) {
*val = a; *val = a;
} }
return (val_checks); return val_checks;
} }
static void mf_print_block(uint8_t blockno, uint8_t *d, bool verbose) { static void mf_print_block(uint8_t blockno, uint8_t *d, bool verbose) {
if (blockno == 0) { if (blockno == 0) {
@ -788,7 +788,7 @@ static int CmdHF14AMfDump(const char *Cmd) {
uint64_t select_status = resp.oldarg[0]; uint64_t select_status = resp.oldarg[0];
if (select_status == 0) { if (select_status == 0) {
PrintAndLogEx(WARNING, "iso14443a card select failed"); PrintAndLogEx(WARNING, "iso14443a card select failed");
return select_status; return PM3_SUCCESS;
} }
// store card info // store card info
@ -4907,7 +4907,7 @@ static int CmdHF14AMfCSave(const char *Cmd) {
uint64_t select_status = resp.oldarg[0]; uint64_t select_status = resp.oldarg[0];
if (select_status == 0) { if (select_status == 0) {
PrintAndLogEx(WARNING, "iso14443a card select failed"); PrintAndLogEx(WARNING, "iso14443a card select failed");
return select_status; return PM3_SUCCESS;
} }
// store card info // store card info
@ -5058,7 +5058,7 @@ static int CmdHF14AMfCView(const char *Cmd) {
if (select_status == 0) { if (select_status == 0) {
PrintAndLogEx(WARNING, "iso14443a card select failed"); PrintAndLogEx(WARNING, "iso14443a card select failed");
return select_status; return PM3_ERFTRANS;
} }
iso14a_card_select_t card; iso14a_card_select_t card;
@ -5826,7 +5826,7 @@ int CmdHFMFNDEFFormat(const char *Cmd) {
uint64_t select_status = resp.oldarg[0]; uint64_t select_status = resp.oldarg[0];
if (select_status == 0) { if (select_status == 0) {
PrintAndLogEx(WARNING, "iso14443a card select failed"); PrintAndLogEx(WARNING, "iso14443a card select failed");
return select_status; return PM3_SUCCESS;
} }
DropField(); DropField();
@ -6834,7 +6834,7 @@ static int CmdHF14AGen4View(const char *Cmd) {
if (select_status == 0) { if (select_status == 0) {
PrintAndLogEx(WARNING, "iso14443a card select failed"); PrintAndLogEx(WARNING, "iso14443a card select failed");
return select_status; return PM3_SUCCESS;
} }
iso14a_card_select_t card; iso14a_card_select_t card;

View file

@ -317,7 +317,7 @@ int MAD1DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose, bool *haveMA
int ibs = MADInfoByteDecode(sector, swapmad, 1, verbose); int ibs = MADInfoByteDecode(sector, swapmad, 1, verbose);
if (ibs) { if (ibs > 0) {
PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02x"), ibs); PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02x"), ibs);
} else { } else {
PrintAndLogEx(WARNING, "Card publisher " _RED_("not") " present " _YELLOW_("0x%02x"), ibs); PrintAndLogEx(WARNING, "Card publisher " _RED_("not") " present " _YELLOW_("0x%02x"), ibs);
@ -360,7 +360,7 @@ int MAD2DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose) {
} }
int ibs = MADInfoByteDecode(sector, swapmad, 2, verbose); int ibs = MADInfoByteDecode(sector, swapmad, 2, verbose);
if (ibs) { if (ibs > 0) {
PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02x"), ibs); PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02x"), ibs);
} else { } else {
PrintAndLogEx(WARNING, "Card publisher " _RED_("not") " present " _YELLOW_("0x%02x"), ibs); PrintAndLogEx(WARNING, "Card publisher " _RED_("not") " present " _YELLOW_("0x%02x"), ibs);

View file

@ -198,7 +198,7 @@ int MifareAuth4(mf4Session_t *mf4session, uint8_t *keyn, uint8_t *key, bool acti
if (res) { if (res) {
if (!silentMode) PrintAndLogEx(ERR, "Exchange raw error: %d", res); if (!silentMode) PrintAndLogEx(ERR, "Exchange raw error: %d", res);
if (dropFieldIfError) DropField(); if (dropFieldIfError) DropField();
return 2; return PM3_ERFTRANS;
} }
if (verbose) if (verbose)
@ -207,19 +207,19 @@ int MifareAuth4(mf4Session_t *mf4session, uint8_t *keyn, uint8_t *key, bool acti
if (datalen < 1) { if (datalen < 1) {
if (!silentMode) PrintAndLogEx(ERR, "Card response wrong length: %d", datalen); if (!silentMode) PrintAndLogEx(ERR, "Card response wrong length: %d", datalen);
if (dropFieldIfError) DropField(); if (dropFieldIfError) DropField();
return 3; return PM3_EWRONGANSWER;
} }
if (data[0] != 0x90) { if (data[0] != 0x90) {
if (!silentMode) PrintAndLogEx(ERR, "Card response error: %02x %s", data[0], mfpGetErrorDescription(data[0])); if (!silentMode) PrintAndLogEx(ERR, "Card response error: %02x %s", data[0], mfpGetErrorDescription(data[0]));
if (dropFieldIfError) DropField(); if (dropFieldIfError) DropField();
return 3; return PM3_EWRONGANSWER;
} }
if (datalen != 19) { // code 1b + 16b + crc 2b if (datalen != 19) { // code 1b + 16b + crc 2b
if (!silentMode) PrintAndLogEx(ERR, "Card response must be 19 bytes long instead of: %d", datalen); if (!silentMode) PrintAndLogEx(ERR, "Card response must be 19 bytes long instead of: %d", datalen);
if (dropFieldIfError) DropField(); if (dropFieldIfError) DropField();
return 3; return PM3_EWRONGANSWER;
} }
aes_decode(NULL, key, &data[1], RndB, 16); aes_decode(NULL, key, &data[1], RndB, 16);
@ -242,7 +242,7 @@ int MifareAuth4(mf4Session_t *mf4session, uint8_t *keyn, uint8_t *key, bool acti
if (res) { if (res) {
if (!silentMode) PrintAndLogEx(ERR, "Exchange raw error: %d", res); if (!silentMode) PrintAndLogEx(ERR, "Exchange raw error: %d", res);
if (dropFieldIfError) DropField(); if (dropFieldIfError) DropField();
return 4; return PM3_ERFTRANS;
} }
if (verbose) if (verbose)
@ -262,7 +262,7 @@ int MifareAuth4(mf4Session_t *mf4session, uint8_t *keyn, uint8_t *key, bool acti
PrintAndLogEx(ERR, "RndA card: %s", sprint_hex(&raw[4], 16)); PrintAndLogEx(ERR, "RndA card: %s", sprint_hex(&raw[4], 16));
} }
if (dropFieldIfError) DropField(); if (dropFieldIfError) DropField();
return 5; return PM3_EWRONGANSWER;
} }
if (verbose) { if (verbose) {
@ -319,7 +319,7 @@ int MifareAuth4(mf4Session_t *mf4session, uint8_t *keyn, uint8_t *key, bool acti
if (verbose) if (verbose)
PrintAndLogEx(INFO, "Authentication OK"); PrintAndLogEx(INFO, "Authentication OK");
return 0; return PM3_SUCCESS;
} }
static int intExchangeRAW14aPlus(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) { static int intExchangeRAW14aPlus(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) {