diff --git a/firmware/fsm.c b/firmware/fsm.c index d86134ca8..89c36e799 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -441,21 +441,32 @@ void fsm_msgClearSession(ClearSession *msg) void fsm_msgApplySettings(ApplySettings *msg) { - if (msg->has_label && msg->has_language) { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change label to", msg->label, "and language to", msg->language, "?"); - } else if (msg->has_label) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change label to", msg->label, "?", NULL, NULL); - } else + if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); + layoutHome(); + return; + } + } if (msg->has_language) { layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change language to", msg->language, "?", NULL, NULL); - } else { - fsm_sendFailure(FailureType_Failure_SyntaxError, "No setting provided"); - return; + if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); + layoutHome(); + return; + } } - if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); - layoutHome(); + if (msg->has_use_passphrase) { + layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", msg->use_passphrase ? "enable passphrase" : "disable passphrase", "protection?", NULL, NULL, NULL); + if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { + fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); + layoutHome(); + return; + } + } + if (!msg->has_label && !msg->has_language && !msg->has_use_passphrase) { + fsm_sendFailure(FailureType_Failure_SyntaxError, "No setting provided"); return; } if (!protectPin(true)) { @@ -468,6 +479,9 @@ void fsm_msgApplySettings(ApplySettings *msg) if (msg->has_language) { storage_setLanguage(msg->language); } + if (msg->has_use_passphrase) { + storage_setPassphraseProtection(msg->use_passphrase); + } storage_commit(); fsm_sendSuccess("Settings applied"); layoutHome(); diff --git a/firmware/protob/messages.pb.c b/firmware/protob/messages.pb.c index 892abd02b..9dacf83b3 100644 --- a/firmware/protob/messages.pb.c +++ b/firmware/protob/messages.pb.c @@ -46,9 +46,10 @@ const pb_field_t ClearSession_fields[1] = { PB_LAST_FIELD }; -const pb_field_t ApplySettings_fields[3] = { +const pb_field_t ApplySettings_fields[4] = { PB_FIELD( 1, STRING , OPTIONAL, STATIC , FIRST, ApplySettings, language, language, 0), PB_FIELD( 2, STRING , OPTIONAL, STATIC , OTHER, ApplySettings, label, language, 0), + PB_FIELD( 3, BOOL , OPTIONAL, STATIC , OTHER, ApplySettings, use_passphrase, label, 0), PB_LAST_FIELD }; diff --git a/firmware/protob/messages.pb.h b/firmware/protob/messages.pb.h index c9ad776c8..75892f9f9 100644 --- a/firmware/protob/messages.pb.h +++ b/firmware/protob/messages.pb.h @@ -123,6 +123,8 @@ typedef struct _ApplySettings { char language[17]; bool has_label; char label[33]; + bool has_use_passphrase; + bool use_passphrase; } ApplySettings; typedef struct _ButtonRequest { @@ -520,7 +522,7 @@ extern const char SimpleSignTx_coin_name_default[17]; #define Initialize_init_default {0} #define Features_init_default {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, 0, false, 0, false, "", false, "", 0, {CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0} #define ClearSession_init_default {0} -#define ApplySettings_init_default {false, "", false, ""} +#define ApplySettings_init_default {false, "", false, "", false, 0} #define ChangePin_init_default {false, 0} #define Ping_init_default {false, "", false, 0, false, 0, false, 0} #define Success_init_default {false, ""} @@ -571,7 +573,7 @@ extern const char SimpleSignTx_coin_name_default[17]; #define Initialize_init_zero {0} #define Features_init_zero {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, 0, false, 0, false, "", false, "", 0, {CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0} #define ClearSession_init_zero {0} -#define ApplySettings_init_zero {false, "", false, ""} +#define ApplySettings_init_zero {false, "", false, "", false, 0} #define ChangePin_init_zero {false, 0} #define Ping_init_zero {false, "", false, 0, false, 0, false, 0} #define Success_init_zero {false, ""} @@ -624,6 +626,7 @@ extern const char SimpleSignTx_coin_name_default[17]; #define Address_address_tag 1 #define ApplySettings_language_tag 1 #define ApplySettings_label_tag 2 +#define ApplySettings_use_passphrase_tag 3 #define ButtonRequest_code_tag 1 #define ButtonRequest_data_tag 2 #define ChangePin_remove_tag 1 @@ -746,7 +749,7 @@ extern const char SimpleSignTx_coin_name_default[17]; extern const pb_field_t Initialize_fields[1]; extern const pb_field_t Features_fields[16]; extern const pb_field_t ClearSession_fields[1]; -extern const pb_field_t ApplySettings_fields[3]; +extern const pb_field_t ApplySettings_fields[4]; extern const pb_field_t ChangePin_fields[2]; extern const pb_field_t Ping_fields[5]; extern const pb_field_t Success_fields[2]; @@ -799,7 +802,7 @@ extern const pb_field_t DebugLinkLog_fields[4]; #define Initialize_size 0 #define Features_size (230 + 5*CoinType_size) #define ClearSession_size 0 -#define ApplySettings_size 54 +#define ApplySettings_size 56 #define ChangePin_size 2 #define Ping_size 265 #define Success_size 259 diff --git a/firmware/storage.c b/firmware/storage.c index 752474121..99f21558b 100644 --- a/firmware/storage.c +++ b/firmware/storage.c @@ -205,6 +205,15 @@ void storage_setLanguage(const char *lang) } } +void storage_setPassphraseProtection(bool passphrase_protection) +{ + sessionRootNodeCached = false; + sessionPassphraseCached = false; + + storage.has_passphrase_protection = true; + storage.passphrase_protection = passphrase_protection; +} + void get_root_node_callback(uint32_t iter, uint32_t total) { static uint8_t i; diff --git a/firmware/storage.h b/firmware/storage.h index f68ab78fd..58021b8f2 100644 --- a/firmware/storage.h +++ b/firmware/storage.h @@ -41,6 +41,8 @@ void storage_setLabel(const char *label); const char *storage_getLanguage(void); void storage_setLanguage(const char *lang); +void storage_setPassphraseProtection(bool passphrase_protection); + void session_cachePassphrase(const char *passphrase); bool session_isPassphraseCached(void); diff --git a/trezor-common b/trezor-common index 437eff319..40b3cb414 160000 --- a/trezor-common +++ b/trezor-common @@ -1 +1 @@ -Subproject commit 437eff319f0673aae9f3416bd771d52dcc983e37 +Subproject commit 40b3cb414864f970d627651f8be0669be95c5efc