Skip to content

Commit

Permalink
fix(legacy): fix OK-19956 & OK-19958 & OK-19969 & OK-19329 (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyxyx authored May 17, 2023
1 parent d9cabcb commit 7d3e0d4
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 189 deletions.
6 changes: 0 additions & 6 deletions legacy/firmware/ada.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,6 @@ bool txHashBuilder_addToken(const CardanoToken *msg) {
return false;
}

layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, NULL,
_("Token Amount:"), amount, NULL, NULL, NULL);
if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
return false;
}
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, NULL,
_("Token Amount:"), amount, NULL, NULL, NULL);
if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) {
Expand Down
2 changes: 1 addition & 1 deletion legacy/firmware/aptos.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void aptos_sign_tx(const AptosSignTx *msg, const HDNode *node,
char address[67] = {0};
aptos_get_address_from_public_key(node->public_key + 1, address);

if (!layoutBlindSign(address)) {
if (!layoutBlindSign("Aptos", address)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled,
"Signing cancelled by user");
layoutHome();
Expand Down
9 changes: 2 additions & 7 deletions legacy/firmware/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1738,13 +1738,8 @@ uint32_t config_getPinFails(void) {
}

bool config_getCoinSwitch(CoinSwitch loc) {
uint32_t coin_switch = 0;
if (sectrue == config_get_uint32(KEY_COIN_FUNCTION_SWITCH, &coin_switch)) {
if (coin_switch & loc) {
return true;
}
}
return false;
(void)loc;
return true;
}

void config_setCoinSwitch(CoinSwitch loc, bool flag) {
Expand Down
2 changes: 1 addition & 1 deletion legacy/firmware/kaspa.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void kaspa_sign_sighash(HDNode *node, const uint8_t *raw_message,
}
// show display
if (show_confirm_signing(address, sizeof(address))) {
if (!layoutBlindSign(address)) {
if (!layoutBlindSign("Kaspa", address)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled,
"Signing cancelled by user");
kaspa_signing_abort();
Expand Down
34 changes: 23 additions & 11 deletions legacy/firmware/layout2.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,9 @@ void layoutHome(void) {
#if ONEKEY_MINI
static bool first_boot = true;
if (!config_isInitialized() && first_boot) {
if (config_hasPin()) {
config_wipe();
}
first_boot = false;
layout_language_set(KEY_UP);
} else
Expand Down Expand Up @@ -3584,8 +3587,8 @@ void layoutConfirmHash(const BITMAP *icon, const char *description,
oledDrawString(20, 4 * 9, str[3], FONT_FIXED);
oledHLine(OLED_HEIGHT - 13);

layoutButtonNo(_("Cancel"), &bmp_btn_cancel);
layoutButtonYes(_("Confirm"), &bmp_btn_confirm);
layoutButtonNoAdapter(_("Cancel"), &bmp_btn_cancel);
layoutButtonYesAdapter(_("Confirm"), &bmp_btn_confirm);
oledRefresh();
}

Expand Down Expand Up @@ -3617,12 +3620,13 @@ void layoutScroollbarButtonYesAdapter(const char *btnYes, const BITMAP *icon) {
OLED_HEIGHT - (font->pixel + 2), OLED_WIDTH - 4, OLED_HEIGHT);
}

bool layoutBlindSign(char *address) {
bool layoutBlindSign(const char *chain_name, char *address) {
const struct font_desc *font = find_cur_font();
bool result = false;
int index = 0;
int y = 0;
uint8_t key = KEY_NULL;
const char **tx_msg = format_tx_message(chain_name);
const char **str =
split_message((const uint8_t *)address, strlen(address), 17);
int lines = (strlen(address) / 17) + 1;
Expand All @@ -3634,6 +3638,20 @@ bool layoutBlindSign(char *address) {
resp.code = ButtonRequestType_ButtonRequest_SignTx;
msg_write(MessageType_MessageType_ButtonRequest, &resp);

if (0 == ui_language) {
layoutDialogSwipe(&bmp_icon_warning, _("Abort"), _("Continue"), NULL,
_("Unable to decode data"), _("from this transaction. "),
NULL, _("Sign at your own risk."), NULL, NULL);
} else {
layoutDialogSwipe(&bmp_icon_warning, _("Abort"), _("Continue"), NULL,
"无法解析交易数据.", "可能存在风险, 请谨慎甄别.", NULL,
NULL, NULL, NULL);
}
key = protectWaitKey(0, 1);
if (key != KEY_CONFIRM) {
return false;
}

refresh_menu:
layoutSwipe();
oledClear();
Expand Down Expand Up @@ -3679,16 +3697,10 @@ bool layoutBlindSign(char *address) {
case 2:
oledDrawBitmap((OLED_WIDTH - bmp_btn_down.width) / 2, 0, &bmp_btn_up);
y += bmp_btn_up.height + 3;

oledDrawStringAdapter(0, y, _("CONFIRM SIGNING:"), FONT_STANDARD);
y += font->pixel + 5;
oledDrawStringAdapter(0, y, _("Transaction data cannot be decoded"),
FONT_STANDARD);
if (0 == ui_language) {
y += 2 * font->pixel + 3;
} else {
y += font->pixel + 1;
}
oledDrawStringAdapter(0, y, _("Sign at you own risk"), FONT_STANDARD);
oledDrawStringAdapter(0, y, tx_msg[1], FONT_STANDARD);

// scrollbar
for (int i = 0; i < OLED_HEIGHT; i += 3) {
Expand Down
2 changes: 1 addition & 1 deletion legacy/firmware/layout2.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ static inline void layoutSwipe(void) {
}
#endif

bool layoutBlindSign(char *address);
bool layoutBlindSign(const char *chain_name, char *address);
const char *address_n_str(const uint32_t *address_n, size_t address_n_count,
bool address_is_account);

Expand Down
159 changes: 1 addition & 158 deletions legacy/firmware/menu_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

extern uint8_t ui_language;
bool exitBlindSignByInitialize;
static struct menu settings_menu, main_menu, security_set_menu, blind_sign_menu;
static struct menu settings_menu, main_menu, security_set_menu;

void menu_recovery_device(int index) {
(void)index;
Expand Down Expand Up @@ -387,120 +387,6 @@ void menu_showMnemonic(int index) {
}
}

void menu_set_eth_eip(int index) {
char desc[64] = {0};

bool state = index ? false : true;
if (config_hasPin()) {
if (!protectPinOnDevice(false, true)) {
return;
}
}

config_setCoinSwitch(COIN_SWITCH_ETH_EIP712, state);

strcat(desc, _("ETH advance signing turn"));
strcat(desc, state ? _(" On") : _(" Off"));
layoutDialogSwipeCenterAdapter(&bmp_icon_ok, NULL, NULL, &bmp_btn_confirm,
_("Done"), NULL, NULL, NULL, NULL, desc, NULL,
NULL);
protectWaitKey(0, 1);
layoutHome();
}

void menu_set_sol_blind_sign(int index) {
char desc[64] = {0};

bool state = index ? false : true;
if (config_hasPin()) {
if (!protectPinOnDevice(false, true)) {
return;
}
}

config_setCoinSwitch(COIN_SWITCH_SOLANA, state);

strcat(desc, _("SOL advance signing turn"));
strcat(desc, state ? _(" On") : _(" Off"));
layoutDialogSwipeCenterAdapter(&bmp_icon_ok, NULL, NULL, &bmp_btn_confirm,
_("Done"), NULL, NULL, NULL, NULL, desc, NULL,
NULL);
protectWaitKey(0, 1);
layoutHome();
}

void menu_blind_sign(int index) {
(void)index;

uint8_t key = KEY_NULL;

step1:
#if ONEKEY_MINI
layoutDialogSwipeCenterAdapterEx(
NULL, &bmp_button_back, _("BACK"), &bmp_button_forward, _("NEXT"), NULL,
true, NULL, NULL, NULL, NULL,
_("After enabling\"Blind \nSigning\",your device \nwill support signing "
"\n"
"for messages and \ntransactions, but it \ncan't decode the metadata."),
NULL, NULL, NULL, NULL, NULL, NULL, NULL);

key = protectWaitKey(0, 1);
if (key != KEY_CONFIRM) {
return;
}

layoutDialogSwipeCenterAdapterEx(
NULL, &bmp_button_back, _("BACK"), &bmp_button_forward, _("NEXT"), NULL,
true, NULL, NULL, NULL, NULL,
_("Visiting Help Center \nand search \"Blind \nSigning\" to learn \n"
"more\n \nhelp.onekey.so"),
NULL, NULL, NULL, NULL, NULL, NULL, NULL);
#else
layoutDialogAdapter_ex(NULL, &bmp_btn_back, _("Back"), &bmp_btn_forward,
_("Next"), NULL,
_("After enabling \n\"Blind Signing\",your device "
" will support signing for messages and "
"transactions, but it can't decode the metadata."),
NULL, NULL, NULL, NULL, NULL);

key = protectWaitKey(0, 1);
if (key != KEY_CONFIRM) {
return;
}

layoutDialogAdapter_ex(
NULL, &bmp_btn_back, _("Back"), &bmp_btn_forward, _("Next"), NULL, NULL,
_("Visiting Help Center and search \"Blind Signing\" to "
"learn more\n help.onekey.so"),
NULL, NULL, NULL, NULL);
#endif

key = protectWaitKey(0, 1);
if (key == KEY_CANCEL) {
goto step1;
} else if (key != KEY_CONFIRM) {
return;
}

menu_init(&blind_sign_menu);
menu_display(&blind_sign_menu);

while (1) {
key = blindsignWaitKey();
if (exitBlindSignByInitialize) {
return;
}
if (key == KEY_CANCEL) {
menu_init(&security_set_menu);
return;
}
menu_run(key, 0);
if (layoutLast == layoutHome) {
return;
}
}
}

void menu_set_passphrase(int index) {
(void)index;

Expand Down Expand Up @@ -725,7 +611,6 @@ static struct menu check_word_menu = {

static struct menu_item security_set_menu_items[] = {
{"Change PIN", NULL, true, menu_changePin, NULL, false},
{"Blind Signing", NULL, true, menu_blind_sign, NULL, false},
{"Recovery Phrase verify", NULL, true, menu_check_all_words, NULL, false},
{"Passphrase", NULL, false, .sub_menu = &passphrase_set_menu,
menu_para_passphrase, true},
Expand Down Expand Up @@ -789,48 +674,6 @@ static struct menu main_uninitilized_menu = {
.button_type = BTN_TYPE_NEXT,
};

static struct menu_item eth_eip_set_menu_items[] = {
{"On", NULL, true, menu_set_eth_eip, NULL, false},
{"Off", NULL, true, menu_set_eth_eip, NULL, false}};

static struct menu eth_eip_switch_menu = {
.start = 0,
.current = 0,
.counts = COUNT_OF(eth_eip_set_menu_items),
.title = NULL,
.items = eth_eip_set_menu_items,
.previous = &blind_sign_menu,
};

static struct menu_item sol_set_menu_items[] = {
{"On", NULL, true, menu_set_sol_blind_sign, NULL, false},
{"Off", NULL, true, menu_set_sol_blind_sign, NULL, false}};

static struct menu sol_switch_menu = {
.start = 0,
.current = 0,
.counts = COUNT_OF(sol_set_menu_items),
.title = NULL,
.items = sol_set_menu_items,
.previous = &blind_sign_menu,
};

static struct menu_item blind_sign_menu_items[] = {
{"Advance ETH Sign", NULL, false, .sub_menu = &eth_eip_switch_menu,
menu_para_eth_eip_switch, false},
{"Advance SOL Sign", NULL, false, .sub_menu = &sol_switch_menu,
menu_para_sol_switch, false}};

static struct menu blind_sign_menu = {
.start = 0,
.current = 0,
.counts = COUNT_OF(blind_sign_menu_items),
.title = NULL,
.items = blind_sign_menu_items,
.previous = NULL,
.button_type = BTN_TYPE_NEXT,
};

void menu_language_init(void) {
uint8_t key = KEY_NULL;
int index = 0;
Expand Down
2 changes: 1 addition & 1 deletion legacy/firmware/near.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ bool near_sign_tx(const NearSignTx *msg, const HDNode *node,
return false;
}
} else {
if (!layoutBlindSign(address)) {
if (!layoutBlindSign("Near", address)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing cancelled");
layoutHome();
return false;
Expand Down
2 changes: 1 addition & 1 deletion legacy/firmware/polkadot.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bool polkadot_sign_tx(const PolkadotSignTx *msg, const HDNode *node,
memcpy(polkadot_network, msg->network, strlen(msg->network) + 1);
parser_error_t ret = polkadot_tx_parse(msg->raw_tx.bytes, msg->raw_tx.size);
if (ret == parser_unexpected_callIndex) {
if (!layoutBlindSign(signer)) {
if (!layoutBlindSign(polkadot_network, signer)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing cancelled");
layoutHome();
return false;
Expand Down
2 changes: 1 addition & 1 deletion legacy/firmware/starcoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool starcoin_sign_tx(const StarcoinSignTx *msg, const HDNode *node,
address[1] = 'x';
starcoin_get_address_from_public_key(node->public_key + 1, address + 2);

if (!layoutBlindSign(address)) {
if (!layoutBlindSign("Starcoin", address)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing cancelled");
layoutHome();
return false;
Expand Down
2 changes: 1 addition & 1 deletion legacy/firmware/sui.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void sui_sign_tx(const SuiSignTx *msg, const HDNode *node, SuiSignedTx *resp) {
blake2b_Update(&ctx, msg->raw_tx.bytes, msg->raw_tx.size);
blake2b_Final(&ctx, digest, 32);

if (!layoutBlindSign(address)) {
if (!layoutBlindSign("Sui", address)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled,
"Signing cancelled by user");
layoutHome();
Expand Down

0 comments on commit 7d3e0d4

Please sign in to comment.