mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 04:18:10 +00:00
feat(legacy): Implement pagination in SignMessage and VerifyMessage.
This commit is contained in:
parent
5e6e56ac4d
commit
c60305d8f0
1
legacy/firmware/.changelog.d/1586.added.2
Normal file
1
legacy/firmware/.changelog.d/1586.added.2
Normal file
@ -0,0 +1 @@
|
|||||||
|
Implement pagination in SignMessage and VerifyMessage.
|
@ -304,6 +304,49 @@ static bool fsm_layoutAddress(const char *address, const char *desc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool fsm_layoutPaginated(const char *description, const uint8_t *msg,
|
||||||
|
uint32_t len, bool is_ascii) {
|
||||||
|
const char **str = NULL;
|
||||||
|
const uint32_t row_len = is_ascii ? 13 : 8;
|
||||||
|
do {
|
||||||
|
const uint32_t show_len = MIN(len, row_len * 4);
|
||||||
|
if (is_ascii) {
|
||||||
|
str = split_message(msg, show_len, row_len);
|
||||||
|
} else {
|
||||||
|
str = split_message_hex(msg, show_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg += show_len;
|
||||||
|
len -= show_len;
|
||||||
|
|
||||||
|
const char *label = len > 0 ? _("Next") : _("Confirm");
|
||||||
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), label, description,
|
||||||
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
||||||
|
|
||||||
|
if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} while (len > 0);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fsm_layoutSignMessage(const uint8_t *msg, uint32_t len) {
|
||||||
|
if (is_valid_ascii(msg, len)) {
|
||||||
|
return fsm_layoutPaginated(_("Sign message?"), msg, len, true);
|
||||||
|
} else {
|
||||||
|
return fsm_layoutPaginated(_("Sign binary message?"), msg, len, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fsm_layoutVerifyMessage(const uint8_t *msg, uint32_t len) {
|
||||||
|
if (is_valid_ascii(msg, len)) {
|
||||||
|
return fsm_layoutPaginated(_("Verified message?"), msg, len, true);
|
||||||
|
} else {
|
||||||
|
return fsm_layoutPaginated(_("Verified binary message?"), msg, len, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void fsm_msgRebootToBootloader(void) {
|
void fsm_msgRebootToBootloader(void) {
|
||||||
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
|
||||||
_("Do you want to"), _("restart device in"),
|
_("Do you want to"), _("restart device in"),
|
||||||
|
@ -135,4 +135,7 @@ void fsm_msgStellarBumpSequenceOp(const StellarBumpSequenceOp *msg);
|
|||||||
|
|
||||||
void fsm_msgRebootToBootloader(void);
|
void fsm_msgRebootToBootloader(void);
|
||||||
|
|
||||||
|
bool fsm_layoutSignMessage(const uint8_t *msg, uint32_t len);
|
||||||
|
bool fsm_layoutVerifyMessage(const uint8_t *msg, uint32_t len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -286,8 +286,7 @@ void fsm_msgSignMessage(const SignMessage *msg) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutSignMessage(msg->message.bytes, msg->message.size);
|
if (!fsm_layoutSignMessage(msg->message.bytes, msg->message.size)) {
|
||||||
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
|
|
||||||
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||||
layoutHome();
|
layoutHome();
|
||||||
return;
|
return;
|
||||||
@ -319,12 +318,13 @@ void fsm_msgVerifyMessage(const VerifyMessage *msg) {
|
|||||||
layoutHome();
|
layoutHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
layoutVerifyMessage(msg->message.bytes, msg->message.size);
|
|
||||||
if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) {
|
if (!fsm_layoutVerifyMessage(msg->message.bytes, msg->message.size)) {
|
||||||
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||||
layoutHome();
|
layoutHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fsm_sendSuccess(_("Message verified"));
|
fsm_sendSuccess(_("Message verified"));
|
||||||
} else {
|
} else {
|
||||||
fsm_sendFailure(FailureType_Failure_DataError, _("Invalid signature"));
|
fsm_sendFailure(FailureType_Failure_DataError, _("Invalid signature"));
|
||||||
|
@ -173,8 +173,7 @@ void fsm_msgEthereumSignMessage(const EthereumSignMessage *msg) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutSignMessage(msg->message.bytes, msg->message.size);
|
if (!fsm_layoutSignMessage(msg->message.bytes, msg->message.size)) {
|
||||||
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
|
|
||||||
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||||
layoutHome();
|
layoutHome();
|
||||||
return;
|
return;
|
||||||
@ -202,12 +201,13 @@ void fsm_msgEthereumVerifyMessage(const EthereumVerifyMessage *msg) {
|
|||||||
layoutHome();
|
layoutHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
layoutVerifyMessage(msg->message.bytes, msg->message.size);
|
|
||||||
if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) {
|
if (!fsm_layoutVerifyMessage(msg->message.bytes, msg->message.size)) {
|
||||||
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||||
layoutHome();
|
layoutHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fsm_sendSuccess(_("Message verified"));
|
fsm_sendSuccess(_("Message verified"));
|
||||||
|
|
||||||
layoutHome();
|
layoutHome();
|
||||||
|
@ -445,7 +445,7 @@ void layoutConfirmOmni(const uint8_t *data, uint32_t size) {
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_valid_ascii(const uint8_t *data, uint32_t size) {
|
bool is_valid_ascii(const uint8_t *data, uint32_t size) {
|
||||||
for (uint32_t i = 0; i < size; i++) {
|
for (uint32_t i = 0; i < size; i++) {
|
||||||
if (data[i] < ' ' || data[i] > '~') {
|
if (data[i] < ' ' || data[i] > '~') {
|
||||||
return false;
|
return false;
|
||||||
@ -603,36 +603,6 @@ void layoutConfirmNondefaultLockTime(uint32_t lock_time,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void layoutSignMessage(const uint8_t *msg, uint32_t len) {
|
|
||||||
const char **str = NULL;
|
|
||||||
if (!is_valid_ascii(msg, len)) {
|
|
||||||
str = split_message_hex(msg, len);
|
|
||||||
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
||||||
_("Sign binary message?"), str[0], str[1], str[2], str[3],
|
|
||||||
NULL, NULL);
|
|
||||||
} else {
|
|
||||||
str = split_message(msg, len, 20);
|
|
||||||
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
||||||
_("Sign message?"), str[0], str[1], str[2], str[3], NULL,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void layoutVerifyMessage(const uint8_t *msg, uint32_t len) {
|
|
||||||
const char **str = NULL;
|
|
||||||
if (!is_valid_ascii(msg, len)) {
|
|
||||||
str = split_message_hex(msg, len);
|
|
||||||
layoutDialogSwipe(&bmp_icon_info, _("Cancel"), _("Confirm"),
|
|
||||||
_("Verified binary message"), str[0], str[1], str[2],
|
|
||||||
str[3], NULL, NULL);
|
|
||||||
} else {
|
|
||||||
str = split_message(msg, len, 20);
|
|
||||||
layoutDialogSwipe(&bmp_icon_info, _("Cancel"), _("Confirm"),
|
|
||||||
_("Verified message"), str[0], str[1], str[2], str[3],
|
|
||||||
NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void layoutVerifyAddress(const CoinInfo *coin, const char *address) {
|
void layoutVerifyAddress(const CoinInfo *coin, const char *address) {
|
||||||
render_address_dialog(coin, address, _("Confirm address?"),
|
render_address_dialog(coin, address, _("Confirm address?"),
|
||||||
_("Message signed by:"), 0);
|
_("Message signed by:"), 0);
|
||||||
|
@ -65,9 +65,7 @@ void layoutFeeOverThreshold(const CoinInfo *coin, AmountUnit amount_unit,
|
|||||||
void layoutChangeCountOverThreshold(uint32_t change_count);
|
void layoutChangeCountOverThreshold(uint32_t change_count);
|
||||||
void layoutConfirmNondefaultLockTime(uint32_t lock_time,
|
void layoutConfirmNondefaultLockTime(uint32_t lock_time,
|
||||||
bool lock_time_disabled);
|
bool lock_time_disabled);
|
||||||
void layoutSignMessage(const uint8_t *msg, uint32_t len);
|
|
||||||
void layoutVerifyAddress(const CoinInfo *coin, const char *address);
|
void layoutVerifyAddress(const CoinInfo *coin, const char *address);
|
||||||
void layoutVerifyMessage(const uint8_t *msg, uint32_t len);
|
|
||||||
void layoutCipherKeyValue(bool encrypt, const char *key);
|
void layoutCipherKeyValue(bool encrypt, const char *key);
|
||||||
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing);
|
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing);
|
||||||
void layoutDecryptMessage(const uint8_t *msg, uint32_t len,
|
void layoutDecryptMessage(const uint8_t *msg, uint32_t len,
|
||||||
@ -110,4 +108,6 @@ void layoutConfirmSafetyChecks(SafetyCheckLevel safety_checks_level);
|
|||||||
const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen);
|
const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen);
|
||||||
const char **split_message_hex(const uint8_t *msg, uint32_t len);
|
const char **split_message_hex(const uint8_t *msg, uint32_t len);
|
||||||
|
|
||||||
|
bool is_valid_ascii(const uint8_t *data, uint32_t size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user