mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-16 08:06:05 +00:00
implement u2f_counter in LoadDevice, Recoverydevice and ResetDevice messages
This commit is contained in:
parent
4471c6e0e6
commit
71890e4edf
@ -384,7 +384,8 @@ void fsm_msgResetDevice(ResetDevice *msg)
|
||||
msg->has_passphrase_protection && msg->passphrase_protection,
|
||||
msg->has_pin_protection && msg->pin_protection,
|
||||
msg->has_language ? msg->language : 0,
|
||||
msg->has_label ? msg->label : 0
|
||||
msg->has_label ? msg->label : 0,
|
||||
msg->has_u2f_counter ? msg->u2f_counter : 0
|
||||
);
|
||||
}
|
||||
|
||||
@ -1055,7 +1056,8 @@ void fsm_msgRecoveryDevice(RecoveryDevice *msg)
|
||||
msg->has_pin_protection && msg->pin_protection,
|
||||
msg->has_language ? msg->language : 0,
|
||||
msg->has_label ? msg->label : 0,
|
||||
msg->has_enforce_wordlist ? msg->enforce_wordlist : false
|
||||
msg->has_enforce_wordlist ? msg->enforce_wordlist : false,
|
||||
msg->has_u2f_counter ? msg->u2f_counter : 0
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ const pb_field_t WipeDevice_fields[1] = {
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
const pb_field_t LoadDevice_fields[8] = {
|
||||
const pb_field_t LoadDevice_fields[9] = {
|
||||
PB_FIELD2( 1, STRING , OPTIONAL, STATIC , FIRST, LoadDevice, mnemonic, mnemonic, 0),
|
||||
PB_FIELD2( 2, MESSAGE , OPTIONAL, STATIC , OTHER, LoadDevice, node, mnemonic, &HDNodeType_fields),
|
||||
PB_FIELD2( 3, STRING , OPTIONAL, STATIC , OTHER, LoadDevice, pin, node, 0),
|
||||
@ -180,16 +180,18 @@ const pb_field_t LoadDevice_fields[8] = {
|
||||
PB_FIELD2( 5, STRING , OPTIONAL, STATIC , OTHER, LoadDevice, language, passphrase_protection, &LoadDevice_language_default),
|
||||
PB_FIELD2( 6, STRING , OPTIONAL, STATIC , OTHER, LoadDevice, label, language, 0),
|
||||
PB_FIELD2( 7, BOOL , OPTIONAL, STATIC , OTHER, LoadDevice, skip_checksum, label, 0),
|
||||
PB_FIELD2( 8, UINT32 , OPTIONAL, STATIC , OTHER, LoadDevice, u2f_counter, skip_checksum, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
const pb_field_t ResetDevice_fields[7] = {
|
||||
const pb_field_t ResetDevice_fields[8] = {
|
||||
PB_FIELD2( 1, BOOL , OPTIONAL, STATIC , FIRST, ResetDevice, display_random, display_random, 0),
|
||||
PB_FIELD2( 2, UINT32 , OPTIONAL, STATIC , OTHER, ResetDevice, strength, display_random, &ResetDevice_strength_default),
|
||||
PB_FIELD2( 3, BOOL , OPTIONAL, STATIC , OTHER, ResetDevice, passphrase_protection, strength, 0),
|
||||
PB_FIELD2( 4, BOOL , OPTIONAL, STATIC , OTHER, ResetDevice, pin_protection, passphrase_protection, 0),
|
||||
PB_FIELD2( 5, STRING , OPTIONAL, STATIC , OTHER, ResetDevice, language, pin_protection, &ResetDevice_language_default),
|
||||
PB_FIELD2( 6, STRING , OPTIONAL, STATIC , OTHER, ResetDevice, label, language, 0),
|
||||
PB_FIELD2( 7, UINT32 , OPTIONAL, STATIC , OTHER, ResetDevice, u2f_counter, label, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
@ -202,13 +204,14 @@ const pb_field_t EntropyAck_fields[2] = {
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
const pb_field_t RecoveryDevice_fields[7] = {
|
||||
const pb_field_t RecoveryDevice_fields[8] = {
|
||||
PB_FIELD2( 1, UINT32 , OPTIONAL, STATIC , FIRST, RecoveryDevice, word_count, word_count, 0),
|
||||
PB_FIELD2( 2, BOOL , OPTIONAL, STATIC , OTHER, RecoveryDevice, passphrase_protection, word_count, 0),
|
||||
PB_FIELD2( 3, BOOL , OPTIONAL, STATIC , OTHER, RecoveryDevice, pin_protection, passphrase_protection, 0),
|
||||
PB_FIELD2( 4, STRING , OPTIONAL, STATIC , OTHER, RecoveryDevice, language, pin_protection, &RecoveryDevice_language_default),
|
||||
PB_FIELD2( 5, STRING , OPTIONAL, STATIC , OTHER, RecoveryDevice, label, language, 0),
|
||||
PB_FIELD2( 6, BOOL , OPTIONAL, STATIC , OTHER, RecoveryDevice, enforce_wordlist, label, 0),
|
||||
PB_FIELD2( 7, UINT32 , OPTIONAL, STATIC , OTHER, RecoveryDevice, u2f_counter, enforce_wordlist, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
|
@ -617,6 +617,8 @@ typedef struct _LoadDevice {
|
||||
char label[33];
|
||||
bool has_skip_checksum;
|
||||
bool skip_checksum;
|
||||
bool has_u2f_counter;
|
||||
uint32_t u2f_counter;
|
||||
} LoadDevice;
|
||||
|
||||
typedef struct {
|
||||
@ -674,6 +676,8 @@ typedef struct _RecoveryDevice {
|
||||
char label[33];
|
||||
bool has_enforce_wordlist;
|
||||
bool enforce_wordlist;
|
||||
bool has_u2f_counter;
|
||||
uint32_t u2f_counter;
|
||||
} RecoveryDevice;
|
||||
|
||||
typedef struct _ResetDevice {
|
||||
@ -689,6 +693,8 @@ typedef struct _ResetDevice {
|
||||
char language[17];
|
||||
bool has_label;
|
||||
char label[33];
|
||||
bool has_u2f_counter;
|
||||
uint32_t u2f_counter;
|
||||
} ResetDevice;
|
||||
|
||||
typedef struct _SetU2FCounter {
|
||||
@ -863,11 +869,11 @@ extern const uint32_t SimpleSignTx_lock_time_default;
|
||||
#define Address_init_default {""}
|
||||
#define EthereumAddress_init_default {{0, {0}}}
|
||||
#define WipeDevice_init_default {0}
|
||||
#define LoadDevice_init_default {false, "", false, HDNodeType_init_default, false, "", false, 0, false, "english", false, "", false, 0}
|
||||
#define ResetDevice_init_default {false, 0, false, 256u, false, 0, false, 0, false, "english", false, ""}
|
||||
#define LoadDevice_init_default {false, "", false, HDNodeType_init_default, false, "", false, 0, false, "english", false, "", false, 0, false, 0}
|
||||
#define ResetDevice_init_default {false, 0, false, 256u, false, 0, false, 0, false, "english", false, "", false, 0}
|
||||
#define EntropyRequest_init_default {0}
|
||||
#define EntropyAck_init_default {false, {0, {0}}}
|
||||
#define RecoveryDevice_init_default {false, 0, false, 0, false, 0, false, "english", false, "", false, 0}
|
||||
#define RecoveryDevice_init_default {false, 0, false, 0, false, 0, false, "english", false, "", false, 0, false, 0}
|
||||
#define WordRequest_init_default {0}
|
||||
#define WordAck_init_default {""}
|
||||
#define SignMessage_init_default {0, {0, 0, 0, 0, 0, 0, 0, 0}, {0, {0}}, false, "Bitcoin"}
|
||||
@ -929,11 +935,11 @@ extern const uint32_t SimpleSignTx_lock_time_default;
|
||||
#define Address_init_zero {""}
|
||||
#define EthereumAddress_init_zero {{0, {0}}}
|
||||
#define WipeDevice_init_zero {0}
|
||||
#define LoadDevice_init_zero {false, "", false, HDNodeType_init_zero, false, "", false, 0, false, "", false, "", false, 0}
|
||||
#define ResetDevice_init_zero {false, 0, false, 0, false, 0, false, 0, false, "", false, ""}
|
||||
#define LoadDevice_init_zero {false, "", false, HDNodeType_init_zero, false, "", false, 0, false, "", false, "", false, 0, false, 0}
|
||||
#define ResetDevice_init_zero {false, 0, false, 0, false, 0, false, 0, false, "", false, "", false, 0}
|
||||
#define EntropyRequest_init_zero {0}
|
||||
#define EntropyAck_init_zero {false, {0, {0}}}
|
||||
#define RecoveryDevice_init_zero {false, 0, false, 0, false, 0, false, "", false, "", false, 0}
|
||||
#define RecoveryDevice_init_zero {false, 0, false, 0, false, 0, false, "", false, "", false, 0, false, 0}
|
||||
#define WordRequest_init_zero {0}
|
||||
#define WordAck_init_zero {""}
|
||||
#define SignMessage_init_zero {0, {0, 0, 0, 0, 0, 0, 0, 0}, {0, {0}}, false, ""}
|
||||
@ -1085,6 +1091,7 @@ extern const uint32_t SimpleSignTx_lock_time_default;
|
||||
#define LoadDevice_language_tag 5
|
||||
#define LoadDevice_label_tag 6
|
||||
#define LoadDevice_skip_checksum_tag 7
|
||||
#define LoadDevice_u2f_counter_tag 8
|
||||
#define MessageSignature_address_tag 1
|
||||
#define MessageSignature_signature_tag 2
|
||||
#define PassphraseAck_passphrase_tag 1
|
||||
@ -1102,12 +1109,14 @@ extern const uint32_t SimpleSignTx_lock_time_default;
|
||||
#define RecoveryDevice_language_tag 4
|
||||
#define RecoveryDevice_label_tag 5
|
||||
#define RecoveryDevice_enforce_wordlist_tag 6
|
||||
#define RecoveryDevice_u2f_counter_tag 7
|
||||
#define ResetDevice_display_random_tag 1
|
||||
#define ResetDevice_strength_tag 2
|
||||
#define ResetDevice_passphrase_protection_tag 3
|
||||
#define ResetDevice_pin_protection_tag 4
|
||||
#define ResetDevice_language_tag 5
|
||||
#define ResetDevice_label_tag 6
|
||||
#define ResetDevice_u2f_counter_tag 7
|
||||
#define SetU2FCounter_u2f_counter_tag 1
|
||||
#define SignIdentity_identity_tag 1
|
||||
#define SignIdentity_challenge_hidden_tag 2
|
||||
@ -1168,11 +1177,11 @@ extern const pb_field_t EthereumGetAddress_fields[3];
|
||||
extern const pb_field_t Address_fields[2];
|
||||
extern const pb_field_t EthereumAddress_fields[2];
|
||||
extern const pb_field_t WipeDevice_fields[1];
|
||||
extern const pb_field_t LoadDevice_fields[8];
|
||||
extern const pb_field_t ResetDevice_fields[7];
|
||||
extern const pb_field_t LoadDevice_fields[9];
|
||||
extern const pb_field_t ResetDevice_fields[8];
|
||||
extern const pb_field_t EntropyRequest_fields[1];
|
||||
extern const pb_field_t EntropyAck_fields[2];
|
||||
extern const pb_field_t RecoveryDevice_fields[7];
|
||||
extern const pb_field_t RecoveryDevice_fields[8];
|
||||
extern const pb_field_t WordRequest_fields[1];
|
||||
extern const pb_field_t WordAck_fields[2];
|
||||
extern const pb_field_t SignMessage_fields[4];
|
||||
@ -1236,11 +1245,11 @@ extern const pb_field_t DebugLinkFlashErase_fields[2];
|
||||
#define Address_size 43
|
||||
#define EthereumAddress_size 22
|
||||
#define WipeDevice_size 0
|
||||
#define LoadDevice_size (320 + HDNodeType_size)
|
||||
#define ResetDevice_size 66
|
||||
#define LoadDevice_size (326 + HDNodeType_size)
|
||||
#define ResetDevice_size 72
|
||||
#define EntropyRequest_size 0
|
||||
#define EntropyAck_size 131
|
||||
#define RecoveryDevice_size 66
|
||||
#define RecoveryDevice_size 72
|
||||
#define WordRequest_size 0
|
||||
#define WordAck_size 14
|
||||
#define SignMessage_size 1094
|
||||
|
@ -67,7 +67,7 @@ void next_word(void) {
|
||||
msg_write(MessageType_MessageType_WordRequest, &resp);
|
||||
}
|
||||
|
||||
void recovery_init(uint32_t _word_count, bool passphrase_protection, bool pin_protection, const char *language, const char *label, bool _enforce_wordlist)
|
||||
void recovery_init(uint32_t _word_count, bool passphrase_protection, bool pin_protection, const char *language, const char *label, bool _enforce_wordlist, uint32_t u2f_counter)
|
||||
{
|
||||
if (_word_count != 12 && _word_count != 18 && _word_count != 24) {
|
||||
fsm_sendFailure(FailureType_Failure_SyntaxError, "Invalid word count (has to be 12, 18 or 24 bits)");
|
||||
@ -88,6 +88,7 @@ void recovery_init(uint32_t _word_count, bool passphrase_protection, bool pin_pr
|
||||
storage.passphrase_protection = passphrase_protection;
|
||||
storage_setLanguage(language);
|
||||
storage_setLabel(label);
|
||||
storage_setU2FCounter(u2f_counter);
|
||||
|
||||
uint32_t i;
|
||||
for (i = 0; i < word_count; i++) {
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void recovery_init(uint32_t _word_count, bool passphrase_protection, bool pin_protection, const char *language, const char *label, bool _enforce_wordlist);
|
||||
void recovery_init(uint32_t _word_count, bool passphrase_protection, bool pin_protection, const char *language, const char *label, bool _enforce_wordlist, uint32_t u2f_counter);
|
||||
void recovery_word(const char *word);
|
||||
void recovery_abort(void);
|
||||
const char *recovery_get_fake_word(void);
|
||||
|
@ -33,7 +33,7 @@ static uint32_t strength;
|
||||
static uint8_t int_entropy[32];
|
||||
static bool awaiting_entropy = false;
|
||||
|
||||
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label)
|
||||
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label, uint32_t u2f_counter)
|
||||
{
|
||||
if (_strength != 128 && _strength != 192 && _strength != 256) {
|
||||
fsm_sendFailure(FailureType_Failure_SyntaxError, "Invalid strength (has to be 128, 192 or 256 bits)");
|
||||
@ -70,6 +70,7 @@ void reset_init(bool display_random, uint32_t _strength, bool passphrase_protect
|
||||
storage.passphrase_protection = passphrase_protection;
|
||||
storage_setLanguage(language);
|
||||
storage_setLabel(label);
|
||||
storage_setU2FCounter(u2f_counter);
|
||||
|
||||
EntropyRequest resp;
|
||||
memset(&resp, 0, sizeof(EntropyRequest));
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label);
|
||||
void reset_init(bool display_random, uint32_t _strength, bool passphrase_protection, bool pin_protection, const char *language, const char *label, uint32_t u2f_counter);
|
||||
void reset_entropy(const uint8_t *ext_entropy, uint32_t len);
|
||||
uint32_t reset_get_int_entropy(uint8_t *entropy);
|
||||
const char *reset_get_word(void);
|
||||
|
@ -290,6 +290,10 @@ void storage_loadDevice(LoadDevice *msg)
|
||||
if (msg->has_label) {
|
||||
storage_setLabel(msg->label);
|
||||
}
|
||||
|
||||
if (msg->has_u2f_counter) {
|
||||
storage_setU2FCounter(msg->u2f_counter);
|
||||
}
|
||||
}
|
||||
|
||||
void storage_setLabel(const char *label)
|
||||
|
2
vendor/trezor-common
vendored
2
vendor/trezor-common
vendored
@ -1 +1 @@
|
||||
Subproject commit 20c1d05f9de778e28726690c4969e6ce92296ce4
|
||||
Subproject commit 0b4b667ff1e7cc15e40e983f17eef03ec62921d1
|
Loading…
Reference in New Issue
Block a user