From 16af7f13535cb2806811b17741fb85b56e8251aa Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 3 Oct 2019 15:41:45 +0200 Subject: [PATCH] common: add {needs,no}_backup flags to LoadDevice, make it debug only --- common/protob/messages-management.proto | 23 +++++++++++---------- core/src/apps/management/load_device.py | 5 ++++- core/src/trezor/messages/LoadDevice.py | 6 ++++++ legacy/firmware/config.c | 12 ++++++++++- legacy/firmware/fsm.h | 2 ++ legacy/firmware/fsm_msg_common.h | 4 ++++ python/src/trezorlib/messages/LoadDevice.py | 6 ++++++ 7 files changed, 45 insertions(+), 13 deletions(-) diff --git a/common/protob/messages-management.proto b/common/protob/messages-management.proto index be595c8534..24dd382759 100644 --- a/common/protob/messages-management.proto +++ b/common/protob/messages-management.proto @@ -223,6 +223,8 @@ message LoadDevice { optional string label = 6; // device label optional bool skip_checksum = 7; // do not test mnemonic for valid BIP-39 checksum optional uint32 u2f_counter = 8; // U2F counter + optional bool needs_backup = 9; // set "needs backup" flag + optional bool no_backup = 10; // indicate that no backup is going to be made } /** @@ -232,17 +234,16 @@ message LoadDevice { * @next Failure */ message ResetDevice { - optional bool display_random = 1; // display entropy generated by the device before asking for additional entropy - optional uint32 strength = 2 [default=256]; // strength of seed in bits - optional bool passphrase_protection = 3; // enable master node encryption using passphrase - optional bool pin_protection = 4; // enable PIN protection - optional string language = 5 [default='english']; // device language - optional string label = 6; // device label - optional uint32 u2f_counter = 7; // U2F counter - optional bool skip_backup = 8; // postpone seed backup to BackupDevice workflow - optional bool no_backup = 9; // indicate that no backup is going to be made - // type of the mnemonic backup - optional BackupType backup_type = 10 [default=Bip39]; + optional bool display_random = 1; // display entropy generated by the device before asking for additional entropy + optional uint32 strength = 2 [default=256]; // strength of seed in bits + optional bool passphrase_protection = 3; // enable master node encryption using passphrase + optional bool pin_protection = 4; // enable PIN protection + optional string language = 5 [default='english']; // device language + optional string label = 6; // device label + optional uint32 u2f_counter = 7; // U2F counter + optional bool skip_backup = 8; // postpone seed backup to BackupDevice workflow + optional bool no_backup = 9; // indicate that no backup is going to be made + optional BackupType backup_type = 10 [default=Bip39]; // type of the mnemonic backup } /** diff --git a/core/src/apps/management/load_device.py b/core/src/apps/management/load_device.py index 9ee0f256ce..c9b9fc27a9 100644 --- a/core/src/apps/management/load_device.py +++ b/core/src/apps/management/load_device.py @@ -37,7 +37,10 @@ async def load_device(ctx, msg): storage.device.set_slip39_iteration_exponent(iteration_exponent) storage.device.store_mnemonic_secret( - secret, backup_type, needs_backup=True, no_backup=False + secret, + backup_type, + needs_backup=msg.needs_backup is True, + no_backup=msg.no_backup is True, ) storage.device.load_settings( use_passphrase=msg.passphrase_protection, label=msg.label diff --git a/core/src/trezor/messages/LoadDevice.py b/core/src/trezor/messages/LoadDevice.py index 56029e7f86..db9a43200d 100644 --- a/core/src/trezor/messages/LoadDevice.py +++ b/core/src/trezor/messages/LoadDevice.py @@ -25,6 +25,8 @@ class LoadDevice(p.MessageType): label: str = None, skip_checksum: bool = None, u2f_counter: int = None, + needs_backup: bool = None, + no_backup: bool = None, ) -> None: self.mnemonics = mnemonics if mnemonics is not None else [] self.node = node @@ -34,6 +36,8 @@ class LoadDevice(p.MessageType): self.label = label self.skip_checksum = skip_checksum self.u2f_counter = u2f_counter + self.needs_backup = needs_backup + self.no_backup = no_backup @classmethod def get_fields(cls) -> Dict: @@ -46,4 +50,6 @@ class LoadDevice(p.MessageType): 6: ('label', p.UnicodeType, 0), 7: ('skip_checksum', p.BoolType, 0), 8: ('u2f_counter', p.UVarintType, 0), + 9: ('needs_backup', p.BoolType, 0), + 10: ('no_backup', p.BoolType, 0), } diff --git a/legacy/firmware/config.c b/legacy/firmware/config.c index a5fe21c7b2..3db52ea3ed 100644 --- a/legacy/firmware/config.c +++ b/legacy/firmware/config.c @@ -460,6 +460,7 @@ static void config_setNode(const HDNodeType *node) { } #if DEBUG_LINK + bool config_dumpNode(HDNodeType *node) { memzero(node, sizeof(HDNodeType)); @@ -488,7 +489,6 @@ bool config_dumpNode(HDNodeType *node) { memzero(&storageNode, sizeof(storageNode)); return true; } -#endif void config_loadDevice(const LoadDevice *msg) { session_clear(false); @@ -517,8 +517,18 @@ void config_loadDevice(const LoadDevice *msg) { if (msg->has_u2f_counter) { config_setU2FCounter(msg->u2f_counter); } + + if (msg->has_needs_backup) { + config_setNeedsBackup(msg->needs_backup); + } + + if (msg->has_no_backup && msg->no_backup) { + config_setNoBackup(); + } } +#endif + void config_setLabel(const char *label) { if (label == NULL || label[0] == '\0') { storage_delete(KEY_LABEL); diff --git a/legacy/firmware/fsm.h b/legacy/firmware/fsm.h index 7e78edb63c..d66e1699e7 100644 --- a/legacy/firmware/fsm.h +++ b/legacy/firmware/fsm.h @@ -54,7 +54,9 @@ void fsm_msgPing(const Ping *msg); void fsm_msgChangePin(const ChangePin *msg); void fsm_msgWipeDevice(const WipeDevice *msg); void fsm_msgGetEntropy(const GetEntropy *msg); +#if DEBUG_LINK void fsm_msgLoadDevice(const LoadDevice *msg); +#endif void fsm_msgResetDevice(const ResetDevice *msg); void fsm_msgEntropyAck(const EntropyAck *msg); void fsm_msgBackupDevice(const BackupDevice *msg); diff --git a/legacy/firmware/fsm_msg_common.h b/legacy/firmware/fsm_msg_common.h index 8c477e1b8e..ebe0116eb1 100644 --- a/legacy/firmware/fsm_msg_common.h +++ b/legacy/firmware/fsm_msg_common.h @@ -216,6 +216,8 @@ void fsm_msgGetEntropy(const GetEntropy *msg) { layoutHome(); } +#if DEBUG_LINK + void fsm_msgLoadDevice(const LoadDevice *msg) { CHECK_PIN @@ -245,6 +247,8 @@ void fsm_msgLoadDevice(const LoadDevice *msg) { layoutHome(); } +#endif + void fsm_msgResetDevice(const ResetDevice *msg) { CHECK_PIN diff --git a/python/src/trezorlib/messages/LoadDevice.py b/python/src/trezorlib/messages/LoadDevice.py index 23966bda44..680f2be724 100644 --- a/python/src/trezorlib/messages/LoadDevice.py +++ b/python/src/trezorlib/messages/LoadDevice.py @@ -25,6 +25,8 @@ class LoadDevice(p.MessageType): label: str = None, skip_checksum: bool = None, u2f_counter: int = None, + needs_backup: bool = None, + no_backup: bool = None, ) -> None: self.mnemonics = mnemonics if mnemonics is not None else [] self.node = node @@ -34,6 +36,8 @@ class LoadDevice(p.MessageType): self.label = label self.skip_checksum = skip_checksum self.u2f_counter = u2f_counter + self.needs_backup = needs_backup + self.no_backup = no_backup @classmethod def get_fields(cls) -> Dict: @@ -46,4 +50,6 @@ class LoadDevice(p.MessageType): 6: ('label', p.UnicodeType, 0), 7: ('skip_checksum', p.BoolType, 0), 8: ('u2f_counter', p.UVarintType, 0), + 9: ('needs_backup', p.BoolType, 0), + 10: ('no_backup', p.BoolType, 0), }