Skip to content

Commit

Permalink
Merge pull request #191 from Zondax/M2-maintenance
Browse files Browse the repository at this point in the history
M2 maintenance
  • Loading branch information
chcmedeiros committed Feb 13, 2023
2 parents f2d280b + c7f7d1d commit efc98fc
Show file tree
Hide file tree
Showing 388 changed files with 13,875 additions and 194,410 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "deps/ledger-zxlib"]
path = deps/ledger-zxlib
url = https://github.com/zondax/ledger-zxlib
[submodule "deps/picohash"]
path = deps/picohash
url = https://github.com/kazuho/picohash
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ file(GLOB_RECURSE TINYCBOR_SRC
file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/sha512/sha512.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/picohash/
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/consumer/parser_consumer.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/consumer/parser_impl_con.c
Expand Down Expand Up @@ -119,6 +120,7 @@ target_include_directories(app_lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/include
${CMAKE_CURRENT_SOURCE_DIR}/deps/tinycbor/src
${CMAKE_CURRENT_SOURCE_DIR}/deps/sha512
${CMAKE_CURRENT_SOURCE_DIR}/deps/picohash/
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/consumer
${CMAKE_CURRENT_SOURCE_DIR}/app/src/common
Expand Down Expand Up @@ -157,6 +159,7 @@ target_include_directories(unittests PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/deps/tinycbor/src
${CMAKE_CURRENT_SOURCE_DIR}/tests/utils
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/include
${CMAKE_CURRENT_SOURCE_DIR}/deps/picohash/
)

target_include_directories(unittests_val PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ $(error "$(error_message)")
endif

APP_LOAD_PARAMS = --delete $(COMMON_LOAD_PARAMS) --path ${APPPATH}

DEFINES += HAVE_PENDING_REVIEW_SCREEN
NANOS_STACK_SIZE := $(APP_STACK_SIZE)

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APPVERSION_M=2
APPVERSION_N=5
APPVERSION_P=1
APPVERSION_P=2
21 changes: 15 additions & 6 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "crypto.h"
#include "coin.h"
#include "app_main.h"
#include "app_mode.h"

#include "parser_txdef.h"
#include "parser_impl.h"
Expand Down Expand Up @@ -150,21 +151,26 @@ __Z_INLINE void handleSignSecp256k1(volatile uint32_t *flags, volatile uint32_t
}

CHECK_APP_CANARY()

const char *error_msg = tx_parse();
uint8_t parser_err;
const char *error_msg = tx_parse(&parser_err);
CHECK_APP_CANARY()

if (error_msg != NULL) {
int error_msg_length = strlen(error_msg);
MEMCPY(G_io_apdu_buffer, error_msg, error_msg_length);
*tx += (error_msg_length);
if (parser_err == parser_required_expert_mode) {
*flags |= IO_ASYNCH_REPLY;
view_custom_error_show("Signing Rejected","Expert Mode Required");
}
THROW(APDU_CODE_DATA_INVALID);
}

#if defined(APP_CONSUMER)
CHECK_APP_CANARY()
view_review_init(tx_getItem, tx_getNumItems, app_sign_secp256k1);
view_review_show(REVIEW_TXN);
*flags |= IO_ASYNCH_REPLY;
#endif
}

__Z_INLINE void handleSignEd25519(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
Expand All @@ -173,17 +179,20 @@ __Z_INLINE void handleSignEd25519(volatile uint32_t *flags, volatile uint32_t *t
}

CHECK_APP_CANARY()

const char *error_msg = tx_parse();
uint8_t parser_err;
const char *error_msg = tx_parse(&parser_err);
CHECK_APP_CANARY()

if (error_msg != NULL) {
int error_msg_length = strlen(error_msg);
MEMCPY(G_io_apdu_buffer, error_msg, error_msg_length);
*tx += (error_msg_length);
if (parser_err == parser_required_expert_mode) {
*flags |= IO_ASYNCH_REPLY;
view_custom_error_show("Signing Rejected","Expert Mode Required");
}
THROW(APDU_CODE_DATA_INVALID);
}

#if defined(APP_CONSUMER)
CHECK_APP_CANARY()
view_review_init(tx_getItem, tx_getNumItems, app_sign_ed25519);
Expand Down
5 changes: 5 additions & 0 deletions app/src/common/parser_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ typedef enum {
parser_invalid_handle_length,
parser_invalid_name_length,
parser_invalid_eth_mapping,
parser_required_id,
parser_required_code_id,
parser_required_pk,
parser_required_data,
parser_required_expert_mode
} parser_error_t;

typedef struct {
Expand Down
4 changes: 3 additions & 1 deletion app/src/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ uint8_t *tx_get_buffer() {
return buffering_get_buffer()->data;
}

const char *tx_parse() {
const char *tx_parse(uint8_t *parser_err) {
uint8_t err = parser_parse(
&ctx_parsed_tx,
tx_get_buffer(),
tx_get_buffer_length());

*parser_err = err;
if (err != parser_ok) {
*parser_err = err;
return parser_getErrorDescription(err);
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/consumer/coin_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ extern "C" {

#define ENTITY_METADATA_V 1

#define TOKENS_INDEX 3

#ifdef __cplusplus
}
#endif

0 comments on commit efc98fc

Please sign in to comment.