diff --git a/firmware/protect.c b/firmware/protect.c index 79819c6cf7..cf1dbddf77 100644 --- a/firmware/protect.c +++ b/firmware/protect.c @@ -145,24 +145,26 @@ bool protectPin(bool use_cached) if (!storage.has_pin || strlen(storage.pin) == 0 || (use_cached && session_isPinCached())) { return true; } - const char *pin; - uint32_t wait = storage_getPinFails(); - if (wait) { - if (wait > 2) { + uint32_t fails = storage_getPinFails(); + if (fails) { + if (fails > 2) { layoutDialogSwipe(DIALOG_ICON_INFO, NULL, NULL, NULL, "Wrong PIN entered", NULL, "Please wait ...", NULL, NULL, NULL); } - wait = (wait < 32) ? (1u << wait) : 0xFFFFFFFF; + uint32_t wait; + wait = (fails < 32) ? (1u << fails) : 0xFFFFFFFF; while (--wait > 0) { delay(10000000); } } storage_increasePinFails(); + bool increase_failed = (fails >= storage_getPinFails()); + const char *pin; pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, "Please enter current PIN:"); if (!pin) { fsm_sendFailure(FailureType_Failure_PinCancelled, "PIN Cancelled"); return false; } - if (storage_isPinCorrect(pin)) { + if (storage_isPinCorrect(pin) && !increase_failed) { session_cachePin(pin); storage_resetPinFails(); return true; diff --git a/firmware/storage.c b/firmware/storage.c index 1968f8bc53..f573ca6cb5 100644 --- a/firmware/storage.c +++ b/firmware/storage.c @@ -350,6 +350,7 @@ void storage_increasePinFails(void) uint32_t storage_getPinFails(void) { + storage_from_flash(STORAGE_VERSION); // reload from flash return storage.has_pin_failed_attempts ? storage.pin_failed_attempts : 0; }