hf mf nested: break bad loop if timeout (@uzlonewolf)

This commit is contained in:
iceman1001 2019-12-14 12:45:07 +01:00
commit bd70689de2
2 changed files with 12 additions and 3 deletions

View file

@ -32,6 +32,7 @@
#include "crc16.h" #include "crc16.h"
#include "dbprint.h" #include "dbprint.h"
#include "ticks.h" #include "ticks.h"
#include "usb_cdc.h" // usb_poll_validate_length
#ifndef HARDNESTED_AUTHENTICATION_TIMEOUT #ifndef HARDNESTED_AUTHENTICATION_TIMEOUT
# define HARDNESTED_AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation) # define HARDNESTED_AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation)
@ -918,7 +919,7 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
for (rtr = 0; rtr < 17; rtr++) { for (rtr = 0; rtr < 17; rtr++) {
// Test if the action was cancelled // Test if the action was cancelled
if (BUTTON_PRESS()) { if (BUTTON_PRESS() || usb_poll_validate_length()) {
isOK = -2; isOK = -2;
break; break;
} }
@ -998,6 +999,12 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
target_nt[i] = 0; target_nt[i] = 0;
while (target_nt[i] == 0) { // continue until we have an unambiguous nonce while (target_nt[i] == 0) { // continue until we have an unambiguous nonce
// Test if the action was cancelled
if (BUTTON_PRESS() || usb_poll_validate_length()) {
isOK = -2;
break;
}
// prepare next select. No need to power down the card. // prepare next select. No need to power down the card.
if (mifare_classic_halt(pcs, cuid)) { if (mifare_classic_halt(pcs, cuid)) {
if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Halt error"); if (DBGLEVEL >= DBG_INFO) Dbprintf("Nested: Halt error");

View file

@ -24,7 +24,6 @@
#include "mfkey.h" #include "mfkey.h"
#include "util_posix.h" // msclock #include "util_posix.h" // msclock
int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) {
uint32_t uid = 0; uint32_t uid = 0;
uint32_t nt = 0, nr = 0, ar = 0; uint32_t nt = 0, nr = 0, ar = 0;
@ -361,7 +360,10 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_HF_MIFARE_NESTED, (uint8_t *)&payload, sizeof(payload)); SendCommandNG(CMD_HF_MIFARE_NESTED, (uint8_t *)&payload, sizeof(payload));
if (!WaitForResponseTimeout(CMD_HF_MIFARE_NESTED, &resp, 1500)) return PM3_ETIMEOUT; if (!WaitForResponseTimeout(CMD_HF_MIFARE_NESTED, &resp, 2000)) {
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) if (resp.status != PM3_SUCCESS)
return PM3_ESOFT; return PM3_ESOFT;