diff --git a/.github/workflows/codeql-workflow.yml b/.github/workflows/codeql-workflow.yml index 54e0d881..4627cd1b 100644 --- a/.github/workflows/codeql-workflow.yml +++ b/.github/workflows/codeql-workflow.yml @@ -13,6 +13,7 @@ on: paths-ignore: - '.github/workflows/*.yml' - 'tests/*' + - 'build/*' jobs: ledger_app_analyse: diff --git a/CHANGELOG.md b/CHANGELOG.md index a2970e88..d6a9fea8 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change log +## [1.5.4] - 2023-11-30 +### Added +- Added mandatory Ledger embedded application manifest file + +### Changed +- Combined BIP39 wordlist and SSKR wordlist unit tests + +### Fixed +- + ## [1.5.3] - 2023-11-18 ### Added - Added unit tests for BIP39 diff --git a/Makefile b/Makefile index 20d87984..8a393338 100755 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ all: default APPNAME = "Seed Tool" APPVERSION_M = 1 APPVERSION_N = 5 -APPVERSION_P = 3 +APPVERSION_P = 4 APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)" APP_LOAD_PARAMS = --appFlags 0x10 $(COMMON_LOAD_PARAMS) --curve secp256k1 --path "" diff --git a/ledger_app.toml b/ledger_app.toml new file mode 100644 index 00000000..2b7b03a5 --- /dev/null +++ b/ledger_app.toml @@ -0,0 +1,8 @@ +[app] +build_directory = "./" +sdk = "C" +devices = ["nanos", "nanox", "nanos+", "stax"] + +[tests] +unit_directory = "./tests/unit" +pytest_directory = "./tests/functional" diff --git a/src/nano/nanos_enter_phrase.c b/src/nano/nanos_enter_phrase.c index f3fb0afc..04bea5fb 100644 --- a/src/nano/nanos_enter_phrase.c +++ b/src/nano/nanos_enter_phrase.c @@ -281,15 +281,12 @@ const bagl_element_t* screen_onboarding_restore_word_keyboard_callback(unsigned // update the slider's possible words // account for the extra clear word, and clear any previous word items (go back // in the onboarding process) - if (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_BIP39) { - bolos_ux_hslider3_init(G_bolos_ux_context.onboarding_words_checked + - MIN(G_bolos_ux_context.onboarding_step + 1, - RESTORE_BIP39_WORD_MAX_BACKWARD_STEPS)); - } else if (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_SSKR) { - bolos_ux_hslider3_init(G_bolos_ux_context.onboarding_words_checked + - MIN(G_bolos_ux_context.onboarding_step + 1, - RESTORE_SSKR_WORD_MAX_BACKWARD_STEPS)); - } + bolos_ux_hslider3_init( + G_bolos_ux_context.onboarding_words_checked + + MIN(G_bolos_ux_context.onboarding_step + 1, + (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_BIP39) + ? RESTORE_BIP39_WORD_MAX_BACKWARD_STEPS + : RESTORE_SSKR_WORD_MAX_BACKWARD_STEPS)); screen_onboarding_restore_word_display_word_selection(); } return NULL; diff --git a/src/nano/ux_nano_sskr.c b/src/nano/ux_nano_sskr.c index 89d441ea..1d647390 100644 --- a/src/nano/ux_nano_sskr.c +++ b/src/nano/ux_nano_sskr.c @@ -37,12 +37,11 @@ bool get_next_data(bool share_step) { G_bolos_ux_context.sskr_share_index += share_step ? 1 : -1; return true; } - if (G_bolos_ux_context.sskr_share_index < 1) { - G_bolos_ux_context.sskr_share_index = 1; - } - if (G_bolos_ux_context.sskr_share_index > G_bolos_ux_context.sskr_share_count) { - G_bolos_ux_context.sskr_share_index = G_bolos_ux_context.sskr_share_count; - } + G_bolos_ux_context.sskr_share_index = + (G_bolos_ux_context.sskr_share_index < 1) ? 1 + : (G_bolos_ux_context.sskr_share_index > G_bolos_ux_context.sskr_share_count) + ? G_bolos_ux_context.sskr_share_count + : G_bolos_ux_context.sskr_share_index; return false; } diff --git a/tests/functional/requirements.txt b/tests/functional/requirements.txt index 34079170..6f0b25c5 100755 --- a/tests/functional/requirements.txt +++ b/tests/functional/requirements.txt @@ -1 +1 @@ -ragger[tests,speculos]>=1.7.0 +ragger[tests,speculos]>=1.13.0 diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index a770a75a..4608c308 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -6,7 +6,7 @@ endif() # project information project(unit_tests - VERSION 1.5.3 + VERSION 1.5.4 DESCRIPTION "Unit tests for app-seed-tool Ledger Application" LANGUAGES C) @@ -79,14 +79,10 @@ add_executable(test_roundtrip ./tests/roundtrip.c ../../src/ux_common/onboarding target_include_directories(test_roundtrip PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ux_common) target_link_libraries(test_roundtrip PUBLIC cmocka gcov testutils sskr shamir) -add_executable(test_bip39_words ./tests/bip39_words.c ../../src/ux_common/onboarding_seed_rom_variables.c ../../src/ux_common/onboarding_seed_bip39.c) -target_include_directories(test_bip39_words PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ux_common) -target_link_libraries(test_bip39_words PUBLIC cmocka gcov testutils) +add_executable(test_words ./tests/words.c ../../src/ux_common/onboarding_seed_rom_variables.c ../../src/ux_common/onboarding_seed_bip39.c ../../src/ux_common/onboarding_seed_sskr.c) +target_include_directories(test_words PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ux_common) +target_link_libraries(test_words PUBLIC cmocka gcov testutils sskr shamir) -add_executable(test_sskr_words ./tests/sskr_words.c ../../src/ux_common/onboarding_seed_rom_variables.c ../../src/ux_common/onboarding_seed_sskr.c ../../src/ux_common/onboarding_seed_bip39.c) -target_include_directories(test_sskr_words PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ux_common) -target_link_libraries(test_sskr_words PUBLIC cmocka gcov testutils sskr shamir) - -foreach(target test_shamir test_sskr test_bip39 test_roundtrip test_bip39_words test_sskr_words) +foreach(target test_shamir test_sskr test_bip39 test_roundtrip test_words) add_test(NAME ${target} COMMAND ${target}) endforeach() diff --git a/tests/unit/tests/sskr_words.c b/tests/unit/tests/sskr_words.c deleted file mode 100644 index 5d2e0260..00000000 --- a/tests/unit/tests/sskr_words.c +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "testutils.h" -#include "common_sskr.h" - -static void test_sskr_words(void **state) { - unsigned char next_letters[27] = {0}; - size_t return_num = 0; - unsigned char prefix[] = "ab"; - unsigned char buffer[5] = {0}; - - return_num = bolos_ux_sskr_get_word_idx_starting_with((const unsigned char *) prefix, 2); - assert_int_equal(return_num, 0); - - return_num = bolos_ux_sskr_idx_strcpy(return_num, buffer); - assert_int_equal(return_num, 4); - assert_string_equal(buffer, "able"); - - return_num = bolos_ux_sskr_get_word_count_starting_with((const unsigned char *) prefix, 2); - assert_int_equal(return_num, 1); - - return_num = bolos_ux_sskr_get_word_next_letters_starting_with((const unsigned char *) prefix, 2, next_letters); - assert_int_equal(return_num, 1); - assert_string_equal(next_letters, "l"); - - prefix[0] = 'z'; - memset(next_letters,0,sizeof(next_letters)); - - return_num = bolos_ux_sskr_get_word_idx_starting_with((const unsigned char *) prefix, 1); - assert_int_equal(return_num, 250); - - return_num = bolos_ux_sskr_idx_strcpy(return_num, buffer); - assert_int_equal(return_num, 4); - assert_string_equal(buffer, "zaps"); - - return_num = bolos_ux_sskr_get_word_count_starting_with((const unsigned char *) prefix, 1); - assert_int_equal(return_num, 6); - - return_num = bolos_ux_sskr_get_word_next_letters_starting_with((const unsigned char *) prefix, 1, next_letters); - assert_int_equal(return_num, 4); - assert_string_equal(next_letters, "aeio"); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_sskr_words) - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/tests/unit/tests/bip39_words.c b/tests/unit/tests/words.c similarity index 51% rename from tests/unit/tests/bip39_words.c rename to tests/unit/tests/words.c index 42e4dc2e..b245fcff 100644 --- a/tests/unit/tests/bip39_words.c +++ b/tests/unit/tests/words.c @@ -7,8 +7,9 @@ #include "testutils.h" #include "common_bip39.h" +#include "common_sskr.h" -static void test_bip39_words(void **state) { +static void test_words_bip39(void **state) { unsigned char next_letters[27] = {0}; size_t return_num = 0; unsigned char prefix[] = "ab"; @@ -46,9 +47,48 @@ static void test_bip39_words(void **state) { assert_string_equal(next_letters, "eo"); } +static void test_words_sskr(void **state) { + unsigned char next_letters[27] = {0}; + size_t return_num = 0; + unsigned char prefix[] = "ab"; + unsigned char buffer[5] = {0}; + + return_num = bolos_ux_sskr_get_word_idx_starting_with((const unsigned char *) prefix, 2); + assert_int_equal(return_num, 0); + + return_num = bolos_ux_sskr_idx_strcpy(return_num, buffer); + assert_int_equal(return_num, 4); + assert_string_equal(buffer, "able"); + + return_num = bolos_ux_sskr_get_word_count_starting_with((const unsigned char *) prefix, 2); + assert_int_equal(return_num, 1); + + return_num = bolos_ux_sskr_get_word_next_letters_starting_with((const unsigned char *) prefix, 2, next_letters); + assert_int_equal(return_num, 1); + assert_string_equal(next_letters, "l"); + + prefix[0] = 'z'; + memset(next_letters,0,sizeof(next_letters)); + + return_num = bolos_ux_sskr_get_word_idx_starting_with((const unsigned char *) prefix, 1); + assert_int_equal(return_num, 250); + + return_num = bolos_ux_sskr_idx_strcpy(return_num, buffer); + assert_int_equal(return_num, 4); + assert_string_equal(buffer, "zaps"); + + return_num = bolos_ux_sskr_get_word_count_starting_with((const unsigned char *) prefix, 1); + assert_int_equal(return_num, 6); + + return_num = bolos_ux_sskr_get_word_next_letters_starting_with((const unsigned char *) prefix, 1, next_letters); + assert_int_equal(return_num, 4); + assert_string_equal(next_letters, "aeio"); +} + int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(test_bip39_words) + cmocka_unit_test(test_words_bip39), + cmocka_unit_test(test_words_sskr) }; return cmocka_run_group_tests(tests, NULL, NULL); }