Skip to content

Commit 3b05d74

Browse files
authored
Merge pull request #1515 from KeystoneHQ/fix/slip39_error_input
slip39 error scenario causes the import to fail
2 parents 3be05c5 + af63d22 commit 3b05d74

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

src/ui/gui_model/gui_model.c

-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,6 @@ static int32_t Slip39CreateGenerate(Slip39Data_t *slip39, bool isDiceRoll)
624624
} else {
625625
GenerateEntropy(entropy, entropyLen, SecretCacheGetNewPassword());
626626
}
627-
PrintArray("entropy", entropy, entropyLen);
628627
SecretCacheSetEntropy(entropy, entropyLen);
629628
GetSlip39MnemonicsWords(entropy, ems, slip39->wordCnt, slip39->memberCnt, slip39->threShold, wordsList, &id, &ie);
630629
SecretCacheSetEms(ems, entropyLen);

src/ui/gui_widgets/gui_create_share_widgets.c

+34-31
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ typedef struct {
6464
static ShareBackupWidget_t g_shareBackupTile;
6565
static ShareBackupWidget_t g_shareConfirmTile;
6666

67-
static uint8_t g_phraseCnt = 20;
67+
static uint8_t g_selectCnt = 20;
6868
static uint8_t g_pressedBtn[SLIP39_MNEMONIC_WORDS_MAX + 1];
6969
static uint8_t g_pressedBtnFlag[SLIP39_MNEMONIC_WORDS_MAX + 1];
7070
static uint8_t g_currId = 0;
7171
static char g_randomBuff[BUFFER_SIZE_512];
7272
static lv_obj_t *g_noticeWindow = NULL;
7373
static uint8_t g_entropyMethod;
7474
static PageWidget_t *g_pageWidget;
75-
static void SelectPhraseCntHandler(lv_event_t *e);
75+
static void SelectParseCntHandler(lv_event_t *e);
7676
static void SelectCheckBoxHandler(lv_event_t* e);
7777

7878
static void ShareUpdateTileHandler(lv_event_t *e)
@@ -97,7 +97,7 @@ static void ContinueStopCreateHandler(lv_event_t *e)
9797

9898
static void ResetBtnTest(void)
9999
{
100-
for (int i = 0; i < g_phraseCnt; i++) {
100+
for (int i = 0; i < g_selectCnt; i++) {
101101
g_pressedBtn[i] = 0;
102102
g_pressedBtnFlag[i] = 0;
103103
}
@@ -113,12 +113,16 @@ static void ResetBtnHandler(lv_event_t * e)
113113

114114
void GuiCreateShareUpdateMnemonic(void *signalParam, uint16_t paramLen)
115115
{
116-
g_shareBackupTile.keyBoard->wordCnt = g_phraseCnt;
116+
g_shareBackupTile.keyBoard->wordCnt = g_selectCnt;
117117
GuiUpdateMnemonicKeyBoard(g_shareBackupTile.keyBoard, SecretCacheGetSlip39Mnemonic(g_createShareTileView.currentSlice), false);
118-
g_shareConfirmTile.keyBoard->wordCnt = g_phraseCnt;
119-
ArrayRandom(SecretCacheGetSlip39Mnemonic(g_createShareTileView.currentSlice), g_randomBuff, g_phraseCnt);
118+
g_shareConfirmTile.keyBoard->wordCnt = g_selectCnt;
119+
ArrayRandom(SecretCacheGetSlip39Mnemonic(g_createShareTileView.currentSlice), g_randomBuff, g_selectCnt);
120120
GuiUpdateMnemonicKeyBoard(g_shareConfirmTile.keyBoard, g_randomBuff, true);
121121
GuiStopCircleAroundAnimation();
122+
if (g_pageWidget != NULL) {
123+
SetRightBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_WORD_SELECT, g_selectCnt == 20 ? "20" : "33");
124+
SetRightBtnCb(g_pageWidget->navBarWidget, SelectParseCntHandler, NULL);
125+
}
122126
}
123127

124128
static void StopCreateViewHandler(lv_event_t *e)
@@ -301,13 +305,13 @@ static void MnemonicConfirmHandler(lv_event_t * e)
301305
g_currId++;
302306
}
303307

304-
if (g_currId == g_phraseCnt) {
305-
char *confirmMnemonic = SRAM_MALLOC(10 * g_phraseCnt + 1);
308+
if (g_currId == g_selectCnt) {
309+
char *confirmMnemonic = SRAM_MALLOC(10 * g_selectCnt + 1);
306310
confirmMnemonic[0] = 0;
307-
for (i = 0; i < g_phraseCnt; i++) {
311+
for (i = 0; i < g_selectCnt; i++) {
308312
j = (g_pressedBtn[i] - 1) + (g_pressedBtn[i] - 1) / 3;
309313
strcat(confirmMnemonic, strchr(g_shareConfirmTile.keyBoard->mnemonicWord[j], '\n') + 1);
310-
if (i < g_phraseCnt - 1) {
314+
if (i < g_selectCnt - 1) {
311315
strcat(confirmMnemonic, " ");
312316
}
313317
}
@@ -319,7 +323,7 @@ static void MnemonicConfirmHandler(lv_event_t * e)
319323
} else {
320324
g_noticeWindow = GuiCreateErrorCodeWindow(ERR_KEYSTORE_MNEMONIC_NOT_MATCH_WALLET, &g_noticeWindow, NULL);
321325
}
322-
memset_s(confirmMnemonic, 10 * g_phraseCnt + 1, 0, 10 * g_phraseCnt + 1);
326+
memset_s(confirmMnemonic, 10 * g_selectCnt + 1, 0, 10 * g_selectCnt + 1);
323327
SRAM_FREE(confirmMnemonic);
324328
}
325329
}
@@ -339,7 +343,7 @@ static void GuiShareBackupWidget(lv_obj_t *parent)
339343
lv_obj_refr_size(label);
340344
height -= lv_obj_get_self_height(label);
341345

342-
g_shareBackupTile.keyBoard = GuiCreateMnemonicKeyBoard(parent, NULL, g_phraseCnt == 20 ? KEY_STONE_MNEMONIC_20 : KEY_STONE_MNEMONIC_33, NULL);
346+
g_shareBackupTile.keyBoard = GuiCreateMnemonicKeyBoard(parent, NULL, g_selectCnt == 20 ? KEY_STONE_MNEMONIC_20 : KEY_STONE_MNEMONIC_33, NULL);
343347
lv_obj_align_to(g_shareBackupTile.keyBoard->cont, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 36);
344348
lv_obj_set_size(g_shareBackupTile.keyBoard->cont, 408, height);
345349

@@ -364,7 +368,7 @@ static void GuiShareConfirmWidget(lv_obj_t *parent)
364368

365369
g_shareConfirmTile.noticeLabel = label;
366370

367-
g_shareConfirmTile.keyBoard = GuiCreateMnemonicKeyBoard(parent, MnemonicConfirmHandler, g_phraseCnt == 20 ? KEY_STONE_MNEMONIC_20 : KEY_STONE_MNEMONIC_33, NULL);
371+
g_shareConfirmTile.keyBoard = GuiCreateMnemonicKeyBoard(parent, MnemonicConfirmHandler, g_selectCnt == 20 ? KEY_STONE_MNEMONIC_20 : KEY_STONE_MNEMONIC_33, NULL);
368372
lv_obj_align_to(g_shareConfirmTile.keyBoard->cont, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 36);
369373
}
370374

@@ -420,7 +424,7 @@ int8_t GuiCreateShareNextSlice(void)
420424
GuiUpdateMnemonicKeyBoard(g_shareBackupTile.keyBoard, SecretCacheGetSlip39Mnemonic(g_createShareTileView.currentSlice), false);
421425
SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, NULL);
422426
lv_obj_set_tile_id(g_createShareTileView.tileView, g_createShareTileView.currentTile, 0, LV_ANIM_OFF);
423-
ArrayRandom(SecretCacheGetSlip39Mnemonic(g_createShareTileView.currentSlice), g_randomBuff, g_phraseCnt);
427+
ArrayRandom(SecretCacheGetSlip39Mnemonic(g_createShareTileView.currentSlice), g_randomBuff, g_selectCnt);
424428
GuiUpdateMnemonicKeyBoard(g_shareConfirmTile.keyBoard, g_randomBuff, true);
425429
return SUCCESS_CODE;
426430
}
@@ -430,7 +434,7 @@ int8_t GuiCreateShareNextTile(void)
430434
Slip39Data_t slip39 = {
431435
.threShold = g_selectSliceTile.memberThreshold,
432436
.memberCnt = g_selectSliceTile.memberCnt,
433-
.wordCnt = g_phraseCnt,
437+
.wordCnt = g_selectCnt,
434438
};
435439
switch (g_createShareTileView.currentTile) {
436440
case CREATE_SHARE_SELECT_SLICE:
@@ -446,8 +450,8 @@ int8_t GuiCreateShareNextTile(void)
446450
case CREATE_SHARE_CUSTODIAN:
447451
lv_obj_clear_flag(g_shareBackupTile.nextCont, LV_OBJ_FLAG_HIDDEN);
448452
if (g_createShareTileView.currentSlice == 0) {
449-
SetRightBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_WORD_SELECT, g_phraseCnt == 20 ? "20" : "33");
450-
SetRightBtnCb(g_pageWidget->navBarWidget, SelectPhraseCntHandler, NULL);
453+
SetRightBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_WORD_SELECT, g_selectCnt == 20 ? "20" : "33");
454+
SetRightBtnCb(g_pageWidget->navBarWidget, SelectParseCntHandler, NULL);
451455
}
452456
break;
453457
case CREATE_SHARE_BACKUPFROM:
@@ -458,7 +462,7 @@ int8_t GuiCreateShareNextTile(void)
458462
case CREATE_SHARE_CONFIRM:
459463
SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_LEFT_BUTTON_BUTT, NULL, NULL);
460464
SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_RIGHT_BUTTON_BUTT, NULL, NULL);
461-
GuiModelSlip39WriteSe(g_phraseCnt);
465+
GuiModelSlip39WriteSe(g_selectCnt);
462466
break;
463467
}
464468
g_createShareTileView.currentTile++;
@@ -492,7 +496,7 @@ void GuiCreateShareDeInit(void)
492496
g_pressedBtnFlag[i] = 0;
493497
}
494498
g_currId = 0;
495-
g_phraseCnt = 20;
499+
g_selectCnt = 20;
496500
g_selectSliceTile.memberCnt = SLIP39_DEFAULT_MEMBER_COUNT;
497501
g_selectSliceTile.memberThreshold = SLIP39_DEFAULT_MEMBER_THRESHOLD;
498502
memset_s(g_randomBuff, 512, 0, 512);
@@ -514,8 +518,8 @@ void GuiCreateShareRefresh(void)
514518
SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_RETURN, CloseCurrentViewHandler, NULL);
515519
} else if (g_createShareTileView.currentTile == CREATE_SHARE_BACKUPFROM) {
516520
SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_CLOSE, StopCreateViewHandler, NULL);
517-
SetRightBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_WORD_SELECT, g_phraseCnt == 20 ? "20" : "33");
518-
SetRightBtnCb(g_pageWidget->navBarWidget, SelectPhraseCntHandler, NULL);
521+
SetRightBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_WORD_SELECT, g_selectCnt == 20 ? "20" : "33");
522+
SetRightBtnCb(g_pageWidget->navBarWidget, SelectParseCntHandler, NULL);
519523
} else if (g_createShareTileView.currentTile == CREATE_SHARE_CONFIRM) {
520524
SetNavBarLeftBtn(g_pageWidget->navBarWidget, NVS_BAR_CLOSE, StopCreateViewHandler, NULL);
521525
SetNavBarRightBtn(g_pageWidget->navBarWidget, NVS_BAR_WORD_RESET, ResetBtnHandler, NULL);
@@ -525,7 +529,7 @@ void GuiCreateShareRefresh(void)
525529
SetNavBarMidBtn(g_pageWidget->navBarWidget, NVS_MID_BUTTON_BUTT, NULL, NULL);
526530
}
527531

528-
static void SelectPhraseCntHandler(lv_event_t *e)
532+
static void SelectParseCntHandler(lv_event_t *e)
529533
{
530534
static uint32_t currentIndex = 0;
531535
lv_obj_t *checkBox = NULL;
@@ -537,7 +541,7 @@ static void SelectPhraseCntHandler(lv_event_t *e)
537541
lv_obj_t *button = GuiCreateImgButton(g_noticeWindow, &imgClose, 36, CloseHintBoxHandler, &g_noticeWindow);
538542
lv_obj_align(button, LV_ALIGN_DEFAULT, 407, 550);
539543

540-
if (g_phraseCnt == 33) {
544+
if (g_selectCnt == 33) {
541545
checkBox = GuiCreateSingleCheckBox(g_noticeWindow, _("wallet_phrase_20words"));
542546
lv_obj_align(checkBox, LV_ALIGN_DEFAULT, 30, 630);
543547
checkBox = GuiCreateSingleCheckBox(g_noticeWindow, _("wallet_phrase_33words"));
@@ -576,10 +580,9 @@ static void SelectCheckBoxHandler(lv_event_t* e)
576580
const char *currText = lv_checkbox_get_text(actCb);
577581
if (!strcmp(currText, _("wallet_phrase_20words"))) {
578582
SetRightBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_WORD_SELECT, "20");
579-
SetRightBtnCb(g_pageWidget->navBarWidget, SelectPhraseCntHandler, NULL);
580-
if (g_phraseCnt != 20) {
581-
g_phraseCnt = 20;
582-
slip39.wordCnt = g_phraseCnt;
583+
if (g_selectCnt != 20) {
584+
g_selectCnt = 20;
585+
slip39.wordCnt = g_selectCnt;
583586
if (g_entropyMethod == 0) {
584587
GuiModelSlip39UpdateMnemonic(slip39);
585588
} else {
@@ -588,17 +591,17 @@ static void SelectCheckBoxHandler(lv_event_t* e)
588591
}
589592
} else if (!strcmp(currText, _("wallet_phrase_33words"))) {
590593
SetRightBtnLabel(g_pageWidget->navBarWidget, NVS_BAR_WORD_SELECT, "33");
591-
SetRightBtnCb(g_pageWidget->navBarWidget, SelectPhraseCntHandler, NULL);
592-
if (g_phraseCnt != 33) {
593-
g_phraseCnt = 33;
594-
slip39.wordCnt = g_phraseCnt;
594+
if (g_selectCnt != 33) {
595+
g_selectCnt = 33;
596+
slip39.wordCnt = g_selectCnt;
595597
if (g_entropyMethod == 0) {
596598
GuiModelSlip39UpdateMnemonic(slip39);
597599
} else {
598600
GuiModelSlip39UpdateMnemonicWithDiceRolls(slip39);
599601
}
600602
}
601603
}
604+
lv_obj_clear_flag(g_pageWidget->navBarWidget->rightBtn, LV_OBJ_FLAG_CLICKABLE);
602605
lv_obj_scroll_to_y(g_shareBackupTile.keyBoard->cont, 0, LV_ANIM_ON);
603606
GUI_DEL_OBJ(g_noticeWindow)
604607
}

0 commit comments

Comments
 (0)