Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: eth hardcode key #103

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion rust/rust_c/src/interfaces/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::interfaces::ethereum::structs::{
use crate::interfaces::structs::{TransactionCheckResult, TransactionParseResult};
use crate::interfaces::types::{PtrBytes, PtrString, PtrT, PtrUR};
use crate::interfaces::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT};
use crate::interfaces::utils::recover_c_char;
use crate::interfaces::utils::{convert_c_char, recover_c_char};
use crate::interfaces::KEYSTONE;

mod abi;
Expand Down Expand Up @@ -63,6 +63,35 @@ pub extern "C" fn eth_check(
}
}

#[no_mangle]
pub extern "C" fn eth_get_root_path(ptr: PtrUR) -> PtrString
{
let eth_sign_request = extract_ptr_with_type!(ptr, EthSignRequest);
let derivation_path: third_party::ur_registry::crypto_key_path::CryptoKeyPath =
eth_sign_request.get_derivation_path();
if let Some(path) = derivation_path.get_path() {
if let Some(root_path) = parse_eth_root_path(path) {
return convert_c_char(root_path);
}
}
return convert_c_char("".to_string())
}

fn parse_eth_root_path(path: String) -> Option<String> {
let root_path = "44'/60'/";
match path.strip_prefix(root_path) {
Some(path) => {
if let Some(index) = path.find("/") {
let sub_path = &path[..index];
Some(format!("{}{}", root_path, sub_path))
} else {
None
}
}
None => None,
}
}

fn parse_eth_sub_path(path: String) -> Option<String> {
let root_path = "44'/60'/";
match path.strip_prefix(root_path) {
Expand Down
31 changes: 25 additions & 6 deletions src/ui/gui_chain/gui_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ const static EvmNetwork_t NETWORKS[] = {
#include "gui_constants.h"
extern const ABIItem_t ethereum_abi_map[];

static uint8_t GetEthPublickeyIndex(char* rootPath);

void GuiSetEthUrData(void *data, bool multi)
{
#ifndef COMPILE_SIMULATOR
Expand Down Expand Up @@ -324,13 +326,14 @@ void *GuiGetEthTypeData(void)
CHECK_FREE_PARSE_RESULT(g_parseResult);
uint8_t mfp[4];
void *data = g_isMulti ? ((URParseMultiResult *)g_urResult)->data : ((URParseResult *)g_urResult)->data;
char *ethStandardXpub = GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD);
char *rootPath = eth_get_root_path(data);
char *ethXpub = GetCurrentAccountPublicKey(GetEthPublickeyIndex(rootPath));
GetMasterFingerPrint(mfp);
TransactionCheckResult *result = NULL;
do {
result = eth_check(data, mfp, sizeof(mfp));
CHECK_CHAIN_BREAK(result);
PtrT_TransactionParseResult_DisplayETHTypedData parseResult = eth_parse_typed_data(data, ethStandardXpub);
PtrT_TransactionParseResult_DisplayETHTypedData parseResult = eth_parse_typed_data(data, ethXpub);
CHECK_CHAIN_BREAK(parseResult);
g_parseResult = (void *)parseResult;
} while (0);
Expand Down Expand Up @@ -395,13 +398,14 @@ void *GuiGetEthPersonalMessage(void)
CHECK_FREE_PARSE_RESULT(g_parseResult);
uint8_t mfp[4];
void *data = g_isMulti ? ((URParseMultiResult *)g_urResult)->data : ((URParseResult *)g_urResult)->data;
char *ethStandardXpub = GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD);
char *rootPath = eth_get_root_path(data);
char *ethXpub = GetCurrentAccountPublicKey(GetEthPublickeyIndex(rootPath));
GetMasterFingerPrint(mfp);
TransactionCheckResult *result = NULL;
do {
result = eth_check(data, mfp, sizeof(mfp));
CHECK_CHAIN_BREAK(result);
PtrT_TransactionParseResult_DisplayETHPersonalMessage parseResult = eth_parse_personal_message(data, ethStandardXpub);
PtrT_TransactionParseResult_DisplayETHPersonalMessage parseResult = eth_parse_personal_message(data, ethXpub);
CHECK_CHAIN_BREAK(parseResult);
g_parseResult = (void *)parseResult;
} while (0);
Expand Down Expand Up @@ -463,6 +467,20 @@ void GetMessageRaw(void *indata, void *param)
// sprintf((char *)indata, "%s%s", message->raw_message, "\n#F5C131 The data is not parseable. Please#\n#F5C131 refer to the software wallet interface#\n#F5C131 for viewing.#");
}

static uint8_t GetEthPublickeyIndex(char* rootPath)
{
if(strcmp(rootPath, "44'/60'/0'") == 0) return XPUB_TYPE_ETH_BIP44_STANDARD;
if(strcmp(rootPath, "44'/60'/1'") == 0) return XPUB_TYPE_ETH_LEDGER_LIVE_1;
if(strcmp(rootPath, "44'/60'/2'") == 0) return XPUB_TYPE_ETH_LEDGER_LIVE_2;
if(strcmp(rootPath, "44'/60'/3'") == 0) return XPUB_TYPE_ETH_LEDGER_LIVE_3;
if(strcmp(rootPath, "44'/60'/4'") == 0) return XPUB_TYPE_ETH_LEDGER_LIVE_4;
if(strcmp(rootPath, "44'/60'/5'") == 0) return XPUB_TYPE_ETH_LEDGER_LIVE_5;
if(strcmp(rootPath, "44'/60'/6'") == 0) return XPUB_TYPE_ETH_LEDGER_LIVE_6;
if(strcmp(rootPath, "44'/60'/7'") == 0) return XPUB_TYPE_ETH_LEDGER_LIVE_7;
if(strcmp(rootPath, "44'/60'/8'") == 0) return XPUB_TYPE_ETH_LEDGER_LIVE_8;
if(strcmp(rootPath, "44'/60'/9'") == 0) return XPUB_TYPE_ETH_LEDGER_LIVE_9;
}

// pase result
void *GuiGetEthData(void)
{
Expand All @@ -473,13 +491,14 @@ void *GuiGetEthData(void)
CHECK_FREE_PARSE_RESULT(g_parseResult);
uint8_t mfp[4];
void *data = g_isMulti ? ((URParseMultiResult *)g_urResult)->data : ((URParseResult *)g_urResult)->data;
char *ethStandardXpub = GetCurrentAccountPublicKey(XPUB_TYPE_ETH_BIP44_STANDARD);
char *rootPath = eth_get_root_path(data);
char *ethXpub = GetCurrentAccountPublicKey(GetEthPublickeyIndex(rootPath));
GetMasterFingerPrint(mfp);
TransactionCheckResult *result = NULL;
do {
result = eth_check(data, mfp, sizeof(mfp));
CHECK_CHAIN_BREAK(result);
PtrT_TransactionParseResult_DisplayETH parseResult = eth_parse(data, ethStandardXpub);
PtrT_TransactionParseResult_DisplayETH parseResult = eth_parse(data, ethXpub);
CHECK_CHAIN_BREAK(parseResult);
g_parseResult = (void *)parseResult;
g_fromEnsExist = GetEnsName((const char *)parseResult->data->overview->from, g_fromEthEnsName);
Expand Down
Loading