mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
config: Set usbTiny whenever there is a possibility that protectPinUiCallback() may be called.
This commit is contained in:
parent
b457797c55
commit
b65f61650a
@ -297,6 +297,7 @@ static secbool config_upgrade_v10(void)
|
|||||||
if (config.has_pin) {
|
if (config.has_pin) {
|
||||||
storage_change_pin(PIN_EMPTY, pin_to_int(config.pin));
|
storage_change_pin(PIN_EMPTY, pin_to_int(config.pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
while (pin_wait != 0) {
|
while (pin_wait != 0) {
|
||||||
storage_pin_fails_increase();
|
storage_pin_fails_increase();
|
||||||
pin_wait >>= 1;
|
pin_wait >>= 1;
|
||||||
@ -354,6 +355,8 @@ static secbool config_upgrade_v10(void)
|
|||||||
|
|
||||||
void config_init(void)
|
void config_init(void)
|
||||||
{
|
{
|
||||||
|
char oldTiny = usbTiny(1);
|
||||||
|
|
||||||
config_upgrade_v10();
|
config_upgrade_v10();
|
||||||
|
|
||||||
storage_init(&protectPinUiCallback, HW_ENTROPY_DATA, HW_ENTROPY_LEN);
|
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));
|
storage_set(KEY_VERSION, &CONFIG_VERSION, sizeof(CONFIG_VERSION));
|
||||||
}
|
}
|
||||||
data2hex(config_uuid, sizeof(config_uuid), config_uuid_str);
|
data2hex(config_uuid, sizeof(config_uuid), config_uuid_str);
|
||||||
|
|
||||||
|
usbTiny(oldTiny);
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_clear(bool lock)
|
void session_clear(bool lock)
|
||||||
@ -719,9 +724,12 @@ bool config_containsMnemonic(const char *mnemonic)
|
|||||||
/* Check whether pin matches storage. The pin must be
|
/* Check whether pin matches storage. The pin must be
|
||||||
* a null-terminated string with at most 9 characters.
|
* 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)
|
bool config_hasPin(void)
|
||||||
@ -736,7 +744,9 @@ bool config_changePin(const char *old_pin, const char *new_pin)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char oldTiny = usbTiny(1);
|
||||||
secbool ret = storage_change_pin(pin_to_int(old_pin), new_pin_int);
|
secbool ret = storage_change_pin(pin_to_int(old_pin), new_pin_int);
|
||||||
|
usbTiny(oldTiny);
|
||||||
|
|
||||||
#if DEBUG_LINK
|
#if DEBUG_LINK
|
||||||
if (sectrue == ret) {
|
if (sectrue == ret) {
|
||||||
@ -907,10 +917,12 @@ void config_setAutoLockDelayMs(uint32_t auto_lock_delay_ms)
|
|||||||
|
|
||||||
void config_wipe(void)
|
void config_wipe(void)
|
||||||
{
|
{
|
||||||
|
char oldTiny = usbTiny(1);
|
||||||
storage_wipe();
|
storage_wipe();
|
||||||
if (storage_is_unlocked() != sectrue) {
|
if (storage_is_unlocked() != sectrue) {
|
||||||
storage_unlock(PIN_EMPTY);
|
storage_unlock(PIN_EMPTY);
|
||||||
}
|
}
|
||||||
|
usbTiny(oldTiny);
|
||||||
random_buffer((uint8_t *)config_uuid, sizeof(config_uuid));
|
random_buffer((uint8_t *)config_uuid, sizeof(config_uuid));
|
||||||
data2hex(config_uuid, sizeof(config_uuid), config_uuid_str);
|
data2hex(config_uuid, sizeof(config_uuid), config_uuid_str);
|
||||||
autoLockDelayMsCached = secfalse;
|
autoLockDelayMsCached = secfalse;
|
||||||
|
@ -120,9 +120,8 @@ bool config_dumpNode(HDNodeType *node);
|
|||||||
bool config_getPin(char *dest, uint16_t dest_size);
|
bool config_getPin(char *dest, uint16_t dest_size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool config_containsPin(const char *pin);
|
bool config_unlock(const char *pin);
|
||||||
bool config_hasPin(void);
|
bool config_hasPin(void);
|
||||||
void config_setPin(const char *pin);
|
|
||||||
bool config_changePin(const char *old_pin, const char *new_pin);
|
bool config_changePin(const char *old_pin, const char *new_pin);
|
||||||
bool session_isUnlocked(void);
|
bool session_isUnlocked(void);
|
||||||
|
|
||||||
|
@ -204,9 +204,7 @@ bool protectPin(bool use_cached)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usbTiny(1);
|
bool ret = config_unlock(pin);
|
||||||
bool ret = config_containsPin(pin);
|
|
||||||
usbTiny(0);
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
fsm_sendFailure(FailureType_Failure_PinInvalid, NULL);
|
fsm_sendFailure(FailureType_Failure_PinInvalid, NULL);
|
||||||
}
|
}
|
||||||
@ -229,7 +227,7 @@ bool protectChangePin(bool removal)
|
|||||||
// If removing, defer the check to config_changePin().
|
// If removing, defer the check to config_changePin().
|
||||||
if (!removal) {
|
if (!removal) {
|
||||||
usbTiny(1);
|
usbTiny(1);
|
||||||
bool ret = config_containsPin(pin);
|
bool ret = config_unlock(pin);
|
||||||
usbTiny(0);
|
usbTiny(0);
|
||||||
if (ret == false) {
|
if (ret == false) {
|
||||||
fsm_sendFailure(FailureType_Failure_PinInvalid, NULL);
|
fsm_sendFailure(FailureType_Failure_PinInvalid, NULL);
|
||||||
@ -265,9 +263,7 @@ bool protectChangePin(bool removal)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usbTiny(1);
|
|
||||||
bool ret = config_changePin(old_pin, new_pin);
|
bool ret = config_changePin(old_pin, new_pin);
|
||||||
usbTiny(0);
|
|
||||||
memzero(old_pin, sizeof(old_pin));
|
memzero(old_pin, sizeof(old_pin));
|
||||||
memzero(new_pin, sizeof(new_pin));
|
memzero(new_pin, sizeof(new_pin));
|
||||||
if (ret == false) {
|
if (ret == false) {
|
||||||
|
Loading…
Reference in New Issue
Block a user