config: Set usbTiny whenever there is a possibility that protectPinUiCallback() may be called.

pull/25/head
Andrew Kozlik 5 years ago
parent b457797c55
commit b65f61650a

@ -297,6 +297,7 @@ static secbool config_upgrade_v10(void)
if (config.has_pin) {
storage_change_pin(PIN_EMPTY, pin_to_int(config.pin));
}
while (pin_wait != 0) {
storage_pin_fails_increase();
pin_wait >>= 1;
@ -354,6 +355,8 @@ static secbool config_upgrade_v10(void)
void config_init(void)
{
char oldTiny = usbTiny(1);
config_upgrade_v10();
storage_init(&protectPinUiCallback, HW_ENTROPY_DATA, HW_ENTROPY_LEN);
@ -372,6 +375,8 @@ void config_init(void)
storage_set(KEY_VERSION, &CONFIG_VERSION, sizeof(CONFIG_VERSION));
}
data2hex(config_uuid, sizeof(config_uuid), config_uuid_str);
usbTiny(oldTiny);
}
void session_clear(bool lock)
@ -719,9 +724,12 @@ bool config_containsMnemonic(const char *mnemonic)
/* Check whether pin matches storage. The pin must be
* a null-terminated string with at most 9 characters.
*/
bool config_containsPin(const char *pin)
bool config_unlock(const char *pin)
{
return sectrue == storage_unlock(pin_to_int(pin));
char oldTiny = usbTiny(1);
secbool ret = storage_unlock(pin_to_int(pin));
usbTiny(oldTiny);
return sectrue == ret;
}
bool config_hasPin(void)
@ -736,7 +744,9 @@ bool config_changePin(const char *old_pin, const char *new_pin)
return false;
}
char oldTiny = usbTiny(1);
secbool ret = storage_change_pin(pin_to_int(old_pin), new_pin_int);
usbTiny(oldTiny);
#if DEBUG_LINK
if (sectrue == ret) {
@ -907,10 +917,12 @@ void config_setAutoLockDelayMs(uint32_t auto_lock_delay_ms)
void config_wipe(void)
{
char oldTiny = usbTiny(1);
storage_wipe();
if (storage_is_unlocked() != sectrue) {
storage_unlock(PIN_EMPTY);
}
usbTiny(oldTiny);
random_buffer((uint8_t *)config_uuid, sizeof(config_uuid));
data2hex(config_uuid, sizeof(config_uuid), config_uuid_str);
autoLockDelayMsCached = secfalse;

@ -120,9 +120,8 @@ bool config_dumpNode(HDNodeType *node);
bool config_getPin(char *dest, uint16_t dest_size);
#endif
bool config_containsPin(const char *pin);
bool config_unlock(const char *pin);
bool config_hasPin(void);
void config_setPin(const char *pin);
bool config_changePin(const char *old_pin, const char *new_pin);
bool session_isUnlocked(void);

@ -204,9 +204,7 @@ bool protectPin(bool use_cached)
}
}
usbTiny(1);
bool ret = config_containsPin(pin);
usbTiny(0);
bool ret = config_unlock(pin);
if (!ret) {
fsm_sendFailure(FailureType_Failure_PinInvalid, NULL);
}
@ -229,7 +227,7 @@ bool protectChangePin(bool removal)
// If removing, defer the check to config_changePin().
if (!removal) {
usbTiny(1);
bool ret = config_containsPin(pin);
bool ret = config_unlock(pin);
usbTiny(0);
if (ret == false) {
fsm_sendFailure(FailureType_Failure_PinInvalid, NULL);
@ -265,9 +263,7 @@ bool protectChangePin(bool removal)
}
}
usbTiny(1);
bool ret = config_changePin(old_pin, new_pin);
usbTiny(0);
memzero(old_pin, sizeof(old_pin));
memzero(new_pin, sizeof(new_pin));
if (ret == false) {

Loading…
Cancel
Save