diff --git a/Makefile b/Makefile index e9d02a2..7cbf87f 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ APPNAME = "Kaspa" # Application version APPVERSION_M = 1 APPVERSION_N = 0 -APPVERSION_P = 0 +APPVERSION_P = 1 APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)" ifeq ($(TARGET_NAME),TARGET_NANOS) diff --git a/src/apdu/dispatcher.h b/src/apdu/dispatcher.h index 00873cc..de090c1 100644 --- a/src/apdu/dispatcher.h +++ b/src/apdu/dispatcher.h @@ -24,6 +24,7 @@ #pragma once #include "../types.h" +#include "parser.h" /** * Parameter 2 for last APDU to receive. diff --git a/src/apdu/parser.c b/src/apdu/parser.c deleted file mode 100644 index 6ac0a2e..0000000 --- a/src/apdu/parser.c +++ /dev/null @@ -1,46 +0,0 @@ -/***************************************************************************** - * MIT License - * - * Copyright (c) 2023 coderofstuff - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#include // size_t -#include // uint*_t -#include // bool - -#include "parser.h" -#include "../types.h" -#include "../offsets.h" - -bool apdu_parser(command_t *cmd, uint8_t *buf, size_t buf_len) { - // Check minimum length and Lc field of APDU command - if (buf_len < OFFSET_CDATA || buf_len - OFFSET_CDATA != buf[OFFSET_LC]) { - return false; - } - - cmd->cla = buf[OFFSET_CLA]; - cmd->ins = (command_e) buf[OFFSET_INS]; - cmd->p1 = buf[OFFSET_P1]; - cmd->p2 = buf[OFFSET_P2]; - cmd->lc = buf[OFFSET_LC]; - cmd->data = (buf[OFFSET_LC] > 0) ? buf + OFFSET_CDATA : NULL; - - return true; -} diff --git a/src/apdu/parser.h b/src/apdu/parser.h deleted file mode 100644 index 7bc39a3..0000000 --- a/src/apdu/parser.h +++ /dev/null @@ -1,45 +0,0 @@ -/***************************************************************************** - * MIT License - * - * Copyright (c) 2023 coderofstuff - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#pragma once - -#include // size_t -#include // uint*_t -#include // bool - -#include "../types.h" - -/** - * Parse APDU command from byte buffer. - * - * @param[out] cmd - * Structured APDU command (CLA, INS, P1, P2, Lc, Command data). - * @param[in] buf - * Byte buffer with raw APDU command. - * @param[in] buf_len - * Length of byte buffer. - * - * @return true if success, false otherwise. - * - */ -bool apdu_parser(command_t *cmd, uint8_t *buf, size_t buf_len); diff --git a/src/app_main.c b/src/app_main.c index 07fb70f..5a2f5b1 100644 --- a/src/app_main.c +++ b/src/app_main.c @@ -32,7 +32,7 @@ #include "io.h" #include "sw.h" #include "ui/menu.h" -#include "apdu/parser.h" +#include "parser.h" #include "apdu/dispatcher.h" global_ctx_t G_context; diff --git a/src/types.h b/src/types.h index 454b86e..f45ee13 100644 --- a/src/types.h +++ b/src/types.h @@ -44,18 +44,6 @@ typedef enum { SIGN_MESSAGE = 0x07 /// sign a personal message with BIP32 path } command_e; -/** - * Structure with fields of APDU command. - */ -typedef struct { - uint8_t cla; /// Instruction class - command_e ins; /// Instruction code - uint8_t p1; /// Instruction parameter 1 - uint8_t p2; /// Instruction parameter 2 - uint8_t lc; /// Length of command data - uint8_t *data; /// Command data -} command_t; - /** * Enumeration with parsing state. */ diff --git a/tests/snapshots/nanos/test_app_mainmenu/00001.png b/tests/snapshots/nanos/test_app_mainmenu/00001.png index dc3cd97..ca8e056 100644 Binary files a/tests/snapshots/nanos/test_app_mainmenu/00001.png and b/tests/snapshots/nanos/test_app_mainmenu/00001.png differ diff --git a/tests/snapshots/nanosp/test_app_mainmenu/00001.png b/tests/snapshots/nanosp/test_app_mainmenu/00001.png index 2b89efe..5df2afb 100644 Binary files a/tests/snapshots/nanosp/test_app_mainmenu/00001.png and b/tests/snapshots/nanosp/test_app_mainmenu/00001.png differ diff --git a/tests/snapshots/nanox/test_app_mainmenu/00001.png b/tests/snapshots/nanox/test_app_mainmenu/00001.png index 2b89efe..5df2afb 100644 Binary files a/tests/snapshots/nanox/test_app_mainmenu/00001.png and b/tests/snapshots/nanox/test_app_mainmenu/00001.png differ diff --git a/tests/snapshots/stax/test_app_mainmenu/00001.png b/tests/snapshots/stax/test_app_mainmenu/00001.png index 2d6324e..be8d96b 100644 Binary files a/tests/snapshots/stax/test_app_mainmenu/00001.png and b/tests/snapshots/stax/test_app_mainmenu/00001.png differ diff --git a/tests/test_name_version.py b/tests/test_name_version.py index d0ed305..2d73b0c 100644 --- a/tests/test_name_version.py +++ b/tests/test_name_version.py @@ -12,4 +12,4 @@ def test_get_app_and_version(backend, backend_name): app_name, version = unpack_get_app_and_version_response(response.data) assert app_name == "Kaspa" - assert version == "1.0.0" + assert version == "1.0.1" diff --git a/tests/test_version_cmd.py b/tests/test_version_cmd.py index f13232e..ec98c8a 100644 --- a/tests/test_version_cmd.py +++ b/tests/test_version_cmd.py @@ -4,7 +4,7 @@ # Taken from the Makefile, to update every time the Makefile version is bumped MAJOR = 1 MINOR = 0 -PATCH = 0 +PATCH = 1 # In this test we check the behavior of the device when asked to provide the app version def test_version(backend): diff --git a/unit-tests/CMakeLists.txt b/unit-tests/CMakeLists.txt index 10fade0..143df34 100644 --- a/unit-tests/CMakeLists.txt +++ b/unit-tests/CMakeLists.txt @@ -62,7 +62,7 @@ add_library(sighash SHARED ../src/sighash.c) add_library(personal_message SHARED ../src/personal_message.c) add_library(write SHARED /opt/ledger-secure-sdk/lib_standard_app/write.c) add_library(format_local SHARED ../src/common/format_local.c) -add_library(apdu_parser SHARED ../src/apdu/parser.c) +add_library(apdu_parser SHARED /opt/ledger-secure-sdk/lib_standard_app/parser.c) add_library(transaction_deserialize ../src/transaction/deserialize.c) add_library(transaction_serialize ../src/transaction/serialize.c) add_library(transaction_utils ../src/transaction/utils.c) diff --git a/unit-tests/test_apdu_parser.c b/unit-tests/test_apdu_parser.c index c0d3f4d..a5f70e6 100644 --- a/unit-tests/test_apdu_parser.c +++ b/unit-tests/test_apdu_parser.c @@ -31,7 +31,7 @@ #include #include "types.h" -#include "apdu/parser.h" +#include "parser.h" static void test_apdu_parser(void **state) { (void) state; @@ -42,10 +42,11 @@ static void test_apdu_parser(void **state) { command_t cmd; memset(&cmd, 0, sizeof(cmd)); - assert_false(apdu_parser(&cmd, apdu_bad_min_len, sizeof(apdu_bad_min_len))); + assert_true(apdu_parser(&cmd, apdu_bad_min_len, sizeof(apdu_bad_min_len))); + assert_int_equal(cmd.lc, 0); memset(&cmd, 0, sizeof(cmd)); - assert_false(apdu_parser(&cmd, apdu_bad_lc, sizeof(apdu_bad_min_len))); + assert_false(apdu_parser(&cmd, apdu_bad_lc, sizeof(apdu_bad_lc))); memset(&cmd, 0, sizeof(cmd)); assert_true(apdu_parser(&cmd, apdu, sizeof(apdu)));