1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

feat(legacy): Show address confirmation in SignMessage.

This commit is contained in:
Andrew Kozlik 2021-11-06 11:07:36 +01:00 committed by Andrew Kozlik
parent 39a0901e99
commit 5e6e56ac4d
4 changed files with 53 additions and 37 deletions

View File

@ -0,0 +1 @@
Show address confirmation in SignMessage.

View File

@ -905,16 +905,6 @@ static void ethereum_message_hash(const uint8_t *message, size_t message_len,
void ethereum_message_sign(const EthereumSignMessage *msg, const HDNode *node, void ethereum_message_sign(const EthereumSignMessage *msg, const HDNode *node,
EthereumMessageSignature *resp) { EthereumMessageSignature *resp) {
uint8_t pubkeyhash[20] = {0};
if (!hdnode_get_ethereum_pubkeyhash(node, pubkeyhash)) {
return;
}
resp->address[0] = '0';
resp->address[1] = 'x';
ethereum_address_checksum(pubkeyhash, resp->address + 2, false, 0);
// ethereum_address_checksum adds trailing zero
uint8_t hash[32] = {0}; uint8_t hash[32] = {0};
ethereum_message_hash(msg->message.bytes, msg->message.size, hash); ethereum_message_hash(msg->message.bytes, msg->message.size, hash);

View File

@ -256,13 +256,6 @@ void fsm_msgSignMessage(const SignMessage *msg) {
CHECK_INITIALIZED CHECK_INITIALIZED
layoutSignMessage(msg->message.bytes, msg->message.size);
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
layoutHome();
return;
}
CHECK_PIN CHECK_PIN
const CoinInfo *coin = fsm_getCoin(msg->has_coin_name, msg->coin_name); const CoinInfo *coin = fsm_getCoin(msg->has_coin_name, msg->coin_name);
@ -271,24 +264,39 @@ void fsm_msgSignMessage(const SignMessage *msg) {
msg->address_n_count, NULL); msg->address_n_count, NULL);
if (!node) return; if (!node) return;
if (hdnode_fill_public_key(node) != 0) {
fsm_sendFailure(FailureType_Failure_ProcessError,
_("Failed to derive public key"));
layoutHome();
return;
}
if (!compute_address(coin, msg->script_type, node, false, NULL,
resp->address)) {
fsm_sendFailure(FailureType_Failure_ProcessError,
_("Error computing address"));
layoutHome();
return;
}
layoutVerifyAddress(coin, resp->address);
if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
layoutHome();
return;
}
layoutSignMessage(msg->message.bytes, msg->message.size);
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
layoutHome();
return;
}
layoutProgressSwipe(_("Signing"), 0); layoutProgressSwipe(_("Signing"), 0);
if (cryptoMessageSign(coin, node, msg->script_type, msg->no_script_type, if (cryptoMessageSign(coin, node, msg->script_type, msg->no_script_type,
msg->message.bytes, msg->message.size, msg->message.bytes, msg->message.size,
resp->signature.bytes) == 0) { resp->signature.bytes) == 0) {
if (hdnode_fill_public_key(node) != 0) {
fsm_sendFailure(FailureType_Failure_ProcessError,
_("Failed to derive public key"));
layoutHome();
return;
}
if (!compute_address(coin, msg->script_type, node, false, NULL,
resp->address)) {
fsm_sendFailure(FailureType_Failure_ProcessError,
_("Error computing address"));
layoutHome();
return;
}
resp->signature.size = 65; resp->signature.size = 65;
msg_write(MessageType_MessageType_MessageSignature, resp); msg_write(MessageType_MessageType_MessageSignature, resp);
} else { } else {

View File

@ -150,6 +150,29 @@ void fsm_msgEthereumSignMessage(const EthereumSignMessage *msg) {
CHECK_INITIALIZED CHECK_INITIALIZED
CHECK_PIN
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n,
msg->address_n_count, NULL);
if (!node) return;
uint8_t pubkeyhash[20] = {0};
if (!hdnode_get_ethereum_pubkeyhash(node, pubkeyhash)) {
return;
}
resp->address[0] = '0';
resp->address[1] = 'x';
ethereum_address_checksum(pubkeyhash, resp->address + 2, false, 0);
// ethereum_address_checksum adds trailing zero
layoutVerifyAddress(NULL, resp->address);
if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
layoutHome();
return;
}
layoutSignMessage(msg->message.bytes, msg->message.size); layoutSignMessage(msg->message.bytes, msg->message.size);
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
@ -157,12 +180,6 @@ void fsm_msgEthereumSignMessage(const EthereumSignMessage *msg) {
return; return;
} }
CHECK_PIN
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n,
msg->address_n_count, NULL);
if (!node) return;
ethereum_message_sign(msg, node, resp); ethereum_message_sign(msg, node, resp);
layoutHome(); layoutHome();
} }