mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-04 13:38:28 +00:00
firmware: refactor fsm_getDerivedNode to include fingerprint
This commit is contained in:
parent
d5e49556c5
commit
2a4a298d58
@ -194,9 +194,12 @@ static const CoinInfo *fsm_getCoin(bool has_name, const char *name)
|
|||||||
return coin;
|
return coin;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HDNode *fsm_getDerivedNode(const char *curve, const uint32_t *address_n, size_t address_n_count)
|
static HDNode *fsm_getDerivedNode(const char *curve, const uint32_t *address_n, size_t address_n_count, uint32_t *fingerprint)
|
||||||
{
|
{
|
||||||
static CONFIDENTIAL HDNode node;
|
static CONFIDENTIAL HDNode node;
|
||||||
|
if (fingerprint) {
|
||||||
|
*fingerprint = 0;
|
||||||
|
}
|
||||||
if (!storage_getRootNode(&node, curve, true)) {
|
if (!storage_getRootNode(&node, curve, true)) {
|
||||||
fsm_sendFailure(FailureType_Failure_NotInitialized, _("Device not initialized or passphrase request cancelled or unsupported curve"));
|
fsm_sendFailure(FailureType_Failure_NotInitialized, _("Device not initialized or passphrase request cancelled or unsupported curve"));
|
||||||
layoutHome();
|
layoutHome();
|
||||||
@ -205,7 +208,7 @@ static HDNode *fsm_getDerivedNode(const char *curve, const uint32_t *address_n,
|
|||||||
if (!address_n || address_n_count == 0) {
|
if (!address_n || address_n_count == 0) {
|
||||||
return &node;
|
return &node;
|
||||||
}
|
}
|
||||||
if (hdnode_private_ckd_cached(&node, address_n, address_n_count, NULL) == 0) {
|
if (hdnode_private_ckd_cached(&node, address_n, address_n_count, fingerprint) == 0) {
|
||||||
fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to derive private key"));
|
fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to derive private key"));
|
||||||
layoutHome();
|
layoutHome();
|
||||||
return 0;
|
return 0;
|
||||||
@ -439,19 +442,8 @@ void fsm_msgGetPublicKey(GetPublicKey *msg)
|
|||||||
curve = msg->ecdsa_curve_name;
|
curve = msg->ecdsa_curve_name;
|
||||||
}
|
}
|
||||||
uint32_t fingerprint;
|
uint32_t fingerprint;
|
||||||
HDNode *node;
|
HDNode *node = node = fsm_getDerivedNode(curve, msg->address_n, msg->address_n_count, &fingerprint);
|
||||||
if (msg->address_n_count == 0) {
|
|
||||||
/* get master node */
|
|
||||||
fingerprint = 0;
|
|
||||||
node = fsm_getDerivedNode(curve, msg->address_n, 0);
|
|
||||||
} else {
|
|
||||||
/* get parent node */
|
|
||||||
node = fsm_getDerivedNode(curve, msg->address_n, msg->address_n_count - 1);
|
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
fingerprint = hdnode_fingerprint(node);
|
|
||||||
/* get child */
|
|
||||||
hdnode_private_ckd(node, msg->address_n[msg->address_n_count - 1]);
|
|
||||||
}
|
|
||||||
hdnode_fill_public_key(node);
|
hdnode_fill_public_key(node);
|
||||||
|
|
||||||
if (msg->has_show_display && msg->show_display) {
|
if (msg->has_show_display && msg->show_display) {
|
||||||
@ -545,7 +537,7 @@ void fsm_msgSignTx(SignTx *msg)
|
|||||||
|
|
||||||
const CoinInfo *coin = fsm_getCoin(msg->has_coin_name, msg->coin_name);
|
const CoinInfo *coin = fsm_getCoin(msg->has_coin_name, msg->coin_name);
|
||||||
if (!coin) return;
|
if (!coin) return;
|
||||||
const HDNode *node = fsm_getDerivedNode(coin->curve_name, 0, 0);
|
const HDNode *node = fsm_getDerivedNode(coin->curve_name, NULL, 0, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
signing_init(msg->inputs_count, msg->outputs_count, coin, node, msg->version, msg->lock_time);
|
signing_init(msg->inputs_count, msg->outputs_count, coin, node, msg->version, msg->lock_time);
|
||||||
@ -573,7 +565,7 @@ void fsm_msgEthereumSignTx(EthereumSignTx *msg)
|
|||||||
|
|
||||||
CHECK_PIN
|
CHECK_PIN
|
||||||
|
|
||||||
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
ethereum_signing_init(msg, node);
|
ethereum_signing_init(msg, node);
|
||||||
@ -594,7 +586,7 @@ void fsm_msgCipherKeyValue(CipherKeyValue *msg)
|
|||||||
|
|
||||||
CHECK_PIN
|
CHECK_PIN
|
||||||
|
|
||||||
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
bool encrypt = msg->has_encrypt && msg->encrypt;
|
bool encrypt = msg->has_encrypt && msg->encrypt;
|
||||||
@ -789,7 +781,7 @@ void fsm_msgGetAddress(GetAddress *msg)
|
|||||||
|
|
||||||
const CoinInfo *coin = fsm_getCoin(msg->has_coin_name, msg->coin_name);
|
const CoinInfo *coin = fsm_getCoin(msg->has_coin_name, msg->coin_name);
|
||||||
if (!coin) return;
|
if (!coin) return;
|
||||||
HDNode *node = fsm_getDerivedNode(coin->curve_name, msg->address_n, msg->address_n_count);
|
HDNode *node = fsm_getDerivedNode(coin->curve_name, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
hdnode_fill_public_key(node);
|
hdnode_fill_public_key(node);
|
||||||
|
|
||||||
@ -844,7 +836,7 @@ void fsm_msgEthereumGetAddress(EthereumGetAddress *msg)
|
|||||||
|
|
||||||
CHECK_PIN
|
CHECK_PIN
|
||||||
|
|
||||||
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
resp->address.size = 20;
|
resp->address.size = 20;
|
||||||
@ -883,7 +875,7 @@ void fsm_msgEthereumSignMessage(EthereumSignMessage *msg)
|
|||||||
|
|
||||||
CHECK_PIN
|
CHECK_PIN
|
||||||
|
|
||||||
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
ethereum_message_sign(msg, node, resp);
|
ethereum_message_sign(msg, node, resp);
|
||||||
@ -945,7 +937,7 @@ void fsm_msgSignMessage(SignMessage *msg)
|
|||||||
|
|
||||||
const CoinInfo *coin = fsm_getCoin(msg->has_coin_name, msg->coin_name);
|
const CoinInfo *coin = fsm_getCoin(msg->has_coin_name, msg->coin_name);
|
||||||
if (!coin) return;
|
if (!coin) return;
|
||||||
HDNode *node = fsm_getDerivedNode(coin->curve_name, msg->address_n, msg->address_n_count);
|
HDNode *node = fsm_getDerivedNode(coin->curve_name, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
layoutProgressSwipe(_("Signing"), 0);
|
layoutProgressSwipe(_("Signing"), 0);
|
||||||
@ -1027,7 +1019,7 @@ void fsm_msgSignIdentity(SignIdentity *msg)
|
|||||||
if (msg->has_ecdsa_curve_name) {
|
if (msg->has_ecdsa_curve_name) {
|
||||||
curve = msg->ecdsa_curve_name;
|
curve = msg->ecdsa_curve_name;
|
||||||
}
|
}
|
||||||
HDNode *node = fsm_getDerivedNode(curve, address_n, 5);
|
HDNode *node = fsm_getDerivedNode(curve, address_n, 5, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
bool sign_ssh = msg->identity.has_proto && (strcmp(msg->identity.proto, "ssh") == 0);
|
bool sign_ssh = msg->identity.has_proto && (strcmp(msg->identity.proto, "ssh") == 0);
|
||||||
@ -1104,7 +1096,7 @@ void fsm_msgGetECDHSessionKey(GetECDHSessionKey *msg)
|
|||||||
curve = msg->ecdsa_curve_name;
|
curve = msg->ecdsa_curve_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const HDNode *node = fsm_getDerivedNode(curve, address_n, 5);
|
const HDNode *node = fsm_getDerivedNode(curve, address_n, 5, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
int result_size = 0;
|
int result_size = 0;
|
||||||
@ -1140,7 +1132,7 @@ void fsm_msgEncryptMessage(EncryptMessage *msg)
|
|||||||
|
|
||||||
CHECK_PIN
|
CHECK_PIN
|
||||||
|
|
||||||
node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
hdnode_get_address_raw(node, coin->address_type, address_raw);
|
hdnode_get_address_raw(node, coin->address_type, address_raw);
|
||||||
}
|
}
|
||||||
@ -1177,7 +1169,7 @@ void fsm_msgDecryptMessage(DecryptMessage *msg)
|
|||||||
|
|
||||||
CHECK_PIN
|
CHECK_PIN
|
||||||
|
|
||||||
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
layoutProgressSwipe(_("Decrypting"), 0);
|
layoutProgressSwipe(_("Decrypting"), 0);
|
||||||
@ -1266,7 +1258,7 @@ void fsm_msgNEMGetAddress(NEMGetAddress *msg)
|
|||||||
|
|
||||||
RESP_INIT(NEMAddress);
|
RESP_INIT(NEMAddress);
|
||||||
|
|
||||||
HDNode *node = fsm_getDerivedNode(ED25519_KECCAK_NAME, msg->address_n, msg->address_n_count);
|
HDNode *node = fsm_getDerivedNode(ED25519_KECCAK_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
if (!hdnode_get_nem_address(node, msg->network, resp->address))
|
if (!hdnode_get_nem_address(node, msg->network, resp->address))
|
||||||
@ -1339,7 +1331,7 @@ void fsm_msgNEMSignTx(NEMSignTx *msg) {
|
|||||||
|
|
||||||
RESP_INIT(NEMSignedTx);
|
RESP_INIT(NEMSignedTx);
|
||||||
|
|
||||||
HDNode *node = fsm_getDerivedNode(ED25519_KECCAK_NAME, msg->transaction.address_n, msg->transaction.address_n_count);
|
HDNode *node = fsm_getDerivedNode(ED25519_KECCAK_NAME, msg->transaction.address_n, msg->transaction.address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
hdnode_fill_public_key(node);
|
hdnode_fill_public_key(node);
|
||||||
@ -1503,7 +1495,7 @@ void fsm_msgNEMDecryptMessage(NEMDecryptMessage *msg)
|
|||||||
|
|
||||||
CHECK_PIN
|
CHECK_PIN
|
||||||
|
|
||||||
HDNode *node = fsm_getDerivedNode(ED25519_KECCAK_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(ED25519_KECCAK_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
const uint8_t *salt = msg->payload.bytes;
|
const uint8_t *salt = msg->payload.bytes;
|
||||||
@ -1557,7 +1549,7 @@ void fsm_msgCosiCommit(CosiCommit *msg)
|
|||||||
|
|
||||||
CHECK_PIN
|
CHECK_PIN
|
||||||
|
|
||||||
HDNode *node = fsm_getDerivedNode(ED25519_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(ED25519_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
uint8_t nonce[32];
|
uint8_t nonce[32];
|
||||||
@ -1597,7 +1589,7 @@ void fsm_msgCosiSign(CosiSign *msg)
|
|||||||
|
|
||||||
CHECK_PIN
|
CHECK_PIN
|
||||||
|
|
||||||
HDNode *node = fsm_getDerivedNode(ED25519_NAME, msg->address_n, msg->address_n_count);
|
const HDNode *node = fsm_getDerivedNode(ED25519_NAME, msg->address_n, msg->address_n_count, NULL);
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
uint8_t nonce[32];
|
uint8_t nonce[32];
|
||||||
|
@ -511,11 +511,16 @@ void layoutAddress(const char *address, const char *desc, bool qrcode, bool igno
|
|||||||
|
|
||||||
void layoutPublicKey(const uint8_t *pubkey)
|
void layoutPublicKey(const uint8_t *pubkey)
|
||||||
{
|
{
|
||||||
char hex[32*2+1], desc[16];
|
char hex[32 * 2 + 1], desc[16];
|
||||||
strlcpy(desc, "Public Key: 00", sizeof(desc));
|
strlcpy(desc, "Public Key: 00", sizeof(desc));
|
||||||
|
if (pubkey[0] == 1) {
|
||||||
|
/* ed25519 public key */
|
||||||
|
// pass - leave 00
|
||||||
|
} else {
|
||||||
data2hex(pubkey, 1, desc + 12);
|
data2hex(pubkey, 1, desc + 12);
|
||||||
|
}
|
||||||
data2hex(pubkey + 1, 32, hex);
|
data2hex(pubkey + 1, 32, hex);
|
||||||
const char **str = split_message((const uint8_t *)hex, 32*2, 16);
|
const char **str = split_message((const uint8_t *)hex, 32 * 2, 16);
|
||||||
layoutDialogSwipe(&bmp_icon_question, NULL, _("Continue"), NULL,
|
layoutDialogSwipe(&bmp_icon_question, NULL, _("Continue"), NULL,
|
||||||
desc, str[0], str[1], str[2], str[3], NULL);
|
desc, str[0], str[1], str[2], str[3], NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user