legacy/firmware: make on-device input choice persistent

pull/712/head
exeabyss 5 years ago
parent c91c500c82
commit 9693c76a17

@ -78,6 +78,7 @@ static const uint32_t META_MAGIC_V10 = 0xFFFFFFFF;
#define KEY_NODE (15 | APP) // node
#define KEY_IMPORTED (16 | APP) // bool
#define KEY_U2F_ROOT (17 | APP | FLAG_PUBLIC_SHIFTED) // node
#define KEY_ON_DEVICE_INPUT (18 | APP | FLAG_PUBLIC_SHIFTED) // bool
#define KEY_DEBUG_LINK_PIN (255 | APP | FLAG_PUBLIC_SHIFTED) // string(10)
// The PIN value corresponding to an empty PIN.
@ -119,9 +120,6 @@ be added to the storage u2f_counter to get the real counter value.
* storage.u2f_counter + config_u2f_offset.
* This corresponds to the number of cleared bits in the U2FAREA.
*/
static secbool sessionUseOnDeviceTextInputCached = secfalse;
static secbool sessionUseOnDeviceTextInput;
static secbool sessionSeedCached, sessionSeedUsesPassphrase;
static uint8_t CONFIDENTIAL sessionSeed[64];
@ -410,7 +408,7 @@ void config_init(void) {
void session_clear(bool lock) {
sessionSeedCached = secfalse;
memzero(&sessionSeed, sizeof(sessionSeed));
if (!session_isUseOnDeviceTextInput()) {
if (!config_isUseOnDeviceTextInput()) {
sessionPassphraseCached = secfalse;
memzero(&sessionPassphrase, sizeof(sessionPassphrase));
}
@ -828,25 +826,22 @@ bool session_getState(const uint8_t *salt, uint8_t *state,
bool session_isUnlocked(void) { return sectrue == storage_is_unlocked(); }
bool session_isUseOnDeviceTextInputCached(void) {
return sectrue == sessionUseOnDeviceTextInputCached;
}
bool session_isUseOnDeviceTextInput(void) {
return sectrue == sessionUseOnDeviceTextInput;
}
void session_setUseOnDeviceTextInput(bool use) {
sessionUseOnDeviceTextInputCached = sectrue;
sessionUseOnDeviceTextInput = use ? sectrue : secfalse;
}
bool config_isInitialized(void) {
bool initialized = false;
config_get_bool(KEY_INITIALIZED, &initialized);
return initialized;
}
bool config_isUseOnDeviceTextInput(void) {
bool useOnDeviceTextInput;
secbool res = config_get_bool(KEY_ON_DEVICE_INPUT, &useOnDeviceTextInput);
return sectrue == res ? useOnDeviceTextInput : false;
}
void config_setUseOnDeviceTextInput(bool use) {
config_set_bool(KEY_ON_DEVICE_INPUT, use);
}
bool config_getImported(bool *imported) {
return sectrue == config_get_bool(KEY_IMPORTED, imported);
}

@ -109,10 +109,6 @@ bool config_getPassphraseProtection(bool *passphrase_protection);
bool config_getHomescreen(uint8_t *dest, uint16_t dest_size);
void config_setHomescreen(const uint8_t *data, uint32_t size);
bool session_isUseOnDeviceTextInputCached(void);
bool session_isUseOnDeviceTextInput(void);
void session_setUseOnDeviceTextInput(bool use);
void session_cachePassphrase(const char *passphrase);
bool session_isPassphraseCached(void);
bool session_getState(const uint8_t *salt, uint8_t *state,
@ -139,6 +135,9 @@ void config_setU2FCounter(uint32_t u2fcounter);
bool config_isInitialized(void);
bool config_isUseOnDeviceTextInput(void);
void config_setUseOnDeviceTextInput(bool use);
bool config_getImported(bool *imported);
void config_setImported(bool imported);

@ -119,26 +119,6 @@ void buttonWaitForIdle(void) {
}
}
void requestOnDeviceTextInput(void) {
layoutDialog(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
_("Do you like to use"), _("on-device text input?"), NULL, NULL,
NULL, NULL);
buttonUpdate();
for (;;) {
usbSleep(5);
buttonUpdate();
if (button.YesUp || button.NoUp) {
break;
}
}
layoutSwipe();
session_setUseOnDeviceTextInput(button.YesUp);
}
int findCharIndex(const char characters[], char needle, int numtotal,
int startindex, bool forward) {
if (startindex < 0 || startindex >= numtotal) {

@ -26,8 +26,6 @@
void buttonWaitForYesUp(void);
void requestOnDeviceTextInput(void);
bool inputText(char *text, int maxtextlen, const char characters[],
int numcharacters, char groupseparator, int width,
bool requiredone, bool allowempty);

@ -254,11 +254,7 @@ bool protectPin(bool use_cached) {
if (config_hasPin()) {
memzero(pin, sizeof(pin));
if (!session_isUseOnDeviceTextInputCached()) {
requestOnDeviceTextInput();
}
if (session_isUseOnDeviceTextInput()) {
if (config_isUseOnDeviceTextInput()) {
requestPinDevice("Please enter current PIN", "on the next screen.", NULL,
pin);
} else {
@ -285,12 +281,8 @@ bool protectChangePin(bool removal) {
static CONFIDENTIAL char new_pin[MAX_PIN_LEN + 1] = "";
static CONFIDENTIAL char pin[MAX_PIN_LEN + 1];
if (!session_isUseOnDeviceTextInputCached()) {
requestOnDeviceTextInput();
}
if (config_hasPin()) {
if (session_isUseOnDeviceTextInput()) {
if (config_isUseOnDeviceTextInput()) {
memzero(pin, sizeof(pin));
requestPinDevice("Please enter current PIN", "on the next screen.", NULL,
pin);
@ -320,7 +312,7 @@ bool protectChangePin(bool removal) {
}
if (!removal) {
if (session_isUseOnDeviceTextInput()) {
if (config_isUseOnDeviceTextInput()) {
memzero(pin, sizeof(pin));
requestPinDevice("Please enter new PIN", "on the next screen.", NULL,
pin);
@ -335,7 +327,7 @@ bool protectChangePin(bool removal) {
}
strlcpy(new_pin, pin, sizeof(new_pin));
if (session_isUseOnDeviceTextInput()) {
if (config_isUseOnDeviceTextInput()) {
memzero(pin, sizeof(pin));
requestPinDevice("Please re-enter new PIN", "on the next screen.", NULL,
pin);
@ -537,10 +529,7 @@ bool protectPassphrase(void) {
}
bool result;
if (!session_isUseOnDeviceTextInputCached()) {
requestOnDeviceTextInput();
}
if (session_isUseOnDeviceTextInput())
if (config_isUseOnDeviceTextInput())
result = protectPassphraseDevice();
else
result = protectPassphraseComputer();

@ -477,6 +477,26 @@ void next_word(void) {
recovery_request();
}
void requestOnDeviceTextInput(void) {
layoutDialog(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
_("Do you like to use"), _("on-device text input?"), NULL, NULL,
NULL, NULL);
buttonUpdate();
for (;;) {
usbSleep(5);
buttonUpdate();
if (button.YesUp || button.NoUp) {
break;
}
}
layoutSwipe();
config_setUseOnDeviceTextInput(button.YesUp);
}
bool confirmWord(const char *word, const char *desc, const char *input_invalid,
bool enable_edit, bool enable_done) {
char str[256];
@ -582,7 +602,7 @@ void recovery_init(uint32_t _word_count, bool passphrase_protection,
requestOnDeviceTextInput();
word_index = 0;
if (session_isUseOnDeviceTextInput()) {
if (config_isUseOnDeviceTextInput()) {
input_seed();
} else if ((type & RecoveryDeviceType_RecoveryDeviceType_Matrix) != 0) {
awaiting_word = 2;

Loading…
Cancel
Save