diff --git a/client/src/cmdhf.c b/client/src/cmdhf.c index 8a7afeb2a..83b551e33 100644 --- a/client/src/cmdhf.c +++ b/client/src/cmdhf.c @@ -91,11 +91,13 @@ int CmdHFSearch(const char *Cmd) { PROMPT_CLEARLINE; PrintAndLogEx(INPLACE, " Searching for ISO14443-A tag..."); if (IfPm3Iso14443a()) { - if (infoHF14A(false, false, false) > 0) { + int sel_state = infoHF14A(false, false, false); + if (sel_state > 0) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO 14443-A tag") " found\n"); res = PM3_SUCCESS; - infoHF14A4Applications(verbose); + if (sel_state == 1) + infoHF14A4Applications(verbose); } } diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index b221869d7..b471ed9fd 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -1027,7 +1027,7 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea // 3 byte here - 1b framing header, 2b crc16 if (APDUInFramingEnable && - ((g_frame_len && (datainlen > g_frame_len - 3)) || (datainlen > PM3_CMD_DATA_SIZE - 3))) { + ((g_frame_len && (datainlen > g_frame_len - 3)) || (datainlen > PM3_CMD_DATA_SIZE - 3))) { int clen = 0; @@ -1807,6 +1807,8 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { memcpy(card.ats, resp.data.asBytes, resp.oldarg[0]); card.ats_len = resp.oldarg[0]; // note: ats_len includes CRC Bytes + if (card.ats_len > 3) + select_status = 1; } if (card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes @@ -2097,6 +2099,8 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { if ((card.sak & 0x20) == 0x20) { PrintAndLogEx(INFO, "--> SAK incorrectly claims that card supports RATS <--"); } + if (select_status == 1) + select_status = 2; } int isMagic = 0; @@ -2169,7 +2173,7 @@ int infoHF14A4Applications(bool verbose) { int res = Iso7816Select(CC_CONTACTLESS, ActivateField, true, (uint8_t *)hintAIDList[i].aid, hintAIDList[i].aid_length, result, sizeof(result), &resultlen, &sw); ActivateField = false; if (res) - continue; + break; if (sw == 0x9000 || sw == 0x6283 || sw == 0x6285) { if (!found) { diff --git a/client/src/cmdhfcipurse.c b/client/src/cmdhfcipurse.c index 427340ca4..882bc797b 100644 --- a/client/src/cmdhfcipurse.c +++ b/client/src/cmdhfcipurse.c @@ -126,7 +126,7 @@ static int CmdHFCipurseAuth(const char *Cmd) { CLIParserFree(ctx); return PM3_EINVARG; } - + uint8_t key[] = {0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73}; if (hdatalen) memcpy(key, hdata, CIPURSE_AES_KEY_LENGTH); @@ -150,10 +150,10 @@ static int CmdHFCipurseAuth(const char *Cmd) { CipurseCGetKVV(key, kvv); if (verbose) { PrintAndLogEx(INFO, "Key id" _YELLOW_("%d") " key " _YELLOW_("%s") " KVV " _YELLOW_("%s") - , keyId - , sprint_hex(key, CIPURSE_AES_KEY_LENGTH) - , sprint_hex_inrow(kvv, CIPURSE_KVV_LENGTH) - ); + , keyId + , sprint_hex(key, CIPURSE_AES_KEY_LENGTH) + , sprint_hex_inrow(kvv, CIPURSE_KVV_LENGTH) + ); } bool bres = CIPURSEChannelAuthenticate(keyId, key, verbose); @@ -413,11 +413,11 @@ static int CmdHFCipurseWriteFile(const char *Cmd) { if (verbose) { PrintAndLogEx(INFO, "File id " _YELLOW_("%x") " offset " _YELLOW_("%zu") " key id " _YELLOW_("%d") " key " _YELLOW_("%s") - , fileId - , offset - , keyId - , sprint_hex(key, CIPURSE_AES_KEY_LENGTH) - ); + , fileId + , offset + , keyId + , sprint_hex(key, CIPURSE_AES_KEY_LENGTH) + ); PrintAndLogEx(INFO, "data[%d]: %s", hdatalen, sprint_hex(hdata, hdatalen)); } @@ -529,10 +529,10 @@ static int CmdHFCipurseReadFileAttr(const char *Cmd) { if (verbose) { PrintAndLogEx(INFO, "File id " _YELLOW_("%x") " key id " _YELLOW_("%d") " key " _YELLOW_("%s") - , fileId - , keyId - , sprint_hex(key, CIPURSE_AES_KEY_LENGTH) - ); + , fileId + , keyId + , sprint_hex(key, CIPURSE_AES_KEY_LENGTH) + ); } if (noAuth == false) { @@ -651,10 +651,10 @@ static int CmdHFCipurseDeleteFile(const char *Cmd) { if (verbose) { PrintAndLogEx(INFO, "File id " _YELLOW_("%x") " key id " _YELLOW_("%d") " key " _YELLOW_("%s") - , fileId - , keyId - , sprint_hex(key, CIPURSE_AES_KEY_LENGTH) - ); + , fileId + , keyId + , sprint_hex(key, CIPURSE_AES_KEY_LENGTH) + ); } bool bres = CIPURSEChannelAuthenticate(keyId, key, verbose); diff --git a/client/src/iso7816/iso7816core.c b/client/src/iso7816/iso7816core.c index 3907d7744..4168036a4 100644 --- a/client/src/iso7816/iso7816core.c +++ b/client/src/iso7816/iso7816core.c @@ -38,10 +38,10 @@ void SetISODEPState(isodep_state_t state) { isodep_state = state; if (APDULogging) { PrintAndLogEx(SUCCESS, "Setting ISODEP -> %s%s%s" - , isodep_state == ISODEP_INACTIVE ? "inactive" : "" - , isodep_state == ISODEP_NFCA ? _GREEN_("NFC-A") : "" - , isodep_state == ISODEP_NFCB ? _GREEN_("NFC-B") : "" - ); + , isodep_state == ISODEP_INACTIVE ? "inactive" : "" + , isodep_state == ISODEP_NFCA ? _GREEN_("NFC-A") : "" + , isodep_state == ISODEP_NFCB ? _GREEN_("NFC-B") : "" + ); } } @@ -79,7 +79,7 @@ int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool activate_field, bool l *result_len = 0; if (sw) { - *sw = 0; + *sw = 0; } if (activate_field) { @@ -177,30 +177,30 @@ int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool activate_field, bool l int Iso7816Exchange(Iso7816CommandChannel channel, bool leave_field_on, sAPDU apdu, uint8_t *result, size_t max_result_len, size_t *result_len, uint16_t *sw) { return Iso7816ExchangeEx(channel - , false - , leave_field_on - , apdu - , false - , 0 - , result - , max_result_len - , result_len - , sw - ); + , false + , leave_field_on + , apdu + , false + , 0 + , result + , max_result_len + , result_len + , sw + ); } int Iso7816Select(Iso7816CommandChannel channel, bool activate_field, bool leave_field_on, uint8_t *aid, size_t aid_len, uint8_t *result, size_t max_result_len, size_t *result_len, uint16_t *sw) { return Iso7816ExchangeEx(channel - , activate_field - , leave_field_on - , (sAPDU) {0x00, 0xa4, 0x04, 0x00, aid_len, aid} - , (channel == CC_CONTACTLESS) - , 0 - , result - , max_result_len - , result_len - , sw - ); + , activate_field + , leave_field_on + , (sAPDU) {0x00, 0xa4, 0x04, 0x00, aid_len, aid} + , (channel == CC_CONTACTLESS) + , 0 + , result + , max_result_len + , result_len + , sw + ); } diff --git a/client/src/iso7816/iso7816core.h b/client/src/iso7816/iso7816core.h index beb5e3e90..003db1256 100644 --- a/client/src/iso7816/iso7816core.h +++ b/client/src/iso7816/iso7816core.h @@ -40,13 +40,13 @@ int Iso7816Connect(Iso7816CommandChannel channel); // exchange int Iso7816Exchange(Iso7816CommandChannel channel, bool leave_field_on, sAPDU apdu, uint8_t *result, size_t max_result_len, - size_t *result_len, uint16_t *sw); + size_t *result_len, uint16_t *sw); int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool activate_field, bool leave_field_on, sAPDU apdu, bool include_le, - uint16_t le, uint8_t *result, size_t max_result_len, size_t *result_len, uint16_t *sw); + uint16_t le, uint8_t *result, size_t max_result_len, size_t *result_len, uint16_t *sw); // search application int Iso7816Select(Iso7816CommandChannel channel, bool activate_field, bool leave_field_on, uint8_t *aid, size_t aid_len, - uint8_t *result, size_t max_result_len, size_t *result_len, uint16_t *sw); + uint8_t *result, size_t max_result_len, size_t *result_len, uint16_t *sw); #endif