bool protectPin(bool use_cached) { if (!storage.has_pin || storage.pin[0] == 0 || (use_cached && session_isPinCached())) { return true; } uint32_t *fails = storage_getPinFailsPtr(); uint32_t wait = ~*fails; protectCheckMaxTry(wait); usbTiny(1); while (wait > 0) { // convert wait to secstr string char secstrbuf[20]; strlcpy(secstrbuf, _("________0 seconds"), sizeof(secstrbuf)); char *secstr = secstrbuf + 9; uint32_t secs = wait; while (secs > 0 && secstr >= secstrbuf) { secstr--; *secstr = (secs % 10) + '0'; secs /= 10; } if (wait == 1) { secstrbuf[16] = 0; } layoutDialog(&bmp_icon_info, NULL, NULL, NULL, _("Wrong PIN entered"), NULL, _("Please wait"), secstr, _("to continue ..."), NULL); // wait one second usbSleep(1000); if (msg_tiny_id == MessageType_MessageType_Initialize) { protectAbortedByInitialize = true; msg_tiny_id = 0xFFFF; usbTiny(0); fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); return false; } wait--; } usbTiny(0); const char *pin; pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, _("Please enter current PIN:")); if (!pin) { fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); return false; } if (!storage_increasePinFails(fails)) { fsm_sendFailure(FailureType_Failure_PinInvalid, NULL); return false; } if (storage_containsPin(pin)) { session_cachePin(); storage_resetPinFails(fails); return true; } else { protectCheckMaxTry(~*fails); fsm_sendFailure(FailureType_Failure_PinInvalid, NULL); return false; } }
bool protectChangePin(void) { const char *pin; char pin1[17], pin2[17]; pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewFirst, "Please enter new PIN:"); if (!pin) { return false; } strlcpy(pin1, pin, sizeof(pin1)); pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewSecond, "Please re-enter new PIN:"); if (!pin) { return false; } strlcpy(pin2, pin, sizeof(pin2)); if (strcmp(pin1, pin2) == 0) { storage_setPin(pin1); return true; } else { return false; } }
void App::onBroadCast(Command &command) { Logger::Instance()->add("Connection request from " + ip); if (Authentication::Instance()->isAuthenticated(ip, pin)) { Logger::Instance()->add("Allowing to connect"); answerBroadCast(command); } else if (Settings::Instance()->usePin) { Logger::Instance()->add("Requesting Pin"); requestPin(command); } else { Logger::Instance()->add("Connection blocked"); refuseBroadCast(command); Server::Instance()->showNotification("Connection blocked", "A connection attempt from " + ip + " has been blocked."); } }