From 3b71827afdd046fac177951a01ad1c64d8548036 Mon Sep 17 00:00:00 2001 From: Vaibhav Sethia Date: Thu, 14 Nov 2024 13:39:43 +0530 Subject: [PATCH 1/7] fix(app): Pin display decryption --- .../inheritance_decrypt_data.c | 20 ++++++++++++------- src/constant_texts.h | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/inheritance_app/inheritance_decrypt_data.c b/apps/inheritance_app/inheritance_decrypt_data.c index 6cc7630c8..ca6e3eda3 100644 --- a/apps/inheritance_app/inheritance_decrypt_data.c +++ b/apps/inheritance_app/inheritance_decrypt_data.c @@ -80,6 +80,7 @@ #include "status_api.h" #include "ui_core_confirm.h" #include "ui_screens.h" +#include "ui_state_machine.h" #include "utils.h" #include "wallet.h" #include "wallet_list.h" @@ -355,7 +356,7 @@ STATIC bool inheritance_decryption_handle_initiate_query( result.decrypt.which_response = INHERITANCE_DECRYPT_DATA_WITH_PIN_RESPONSE_CONFIRMATION_TAG; inheritance_send_result(&result); - delay_scr_init(ui_text_processing, DELAY_TIME); + delay_scr_init(ui_text_processing, DELAY_SHORT); return true; } @@ -608,7 +609,7 @@ static bool decrypt_data(void) { } } while (0); - delay_scr_init(ui_text_processing, DELAY_TIME); + delay_scr_init(ui_text_processing, DELAY_SHORT); return status; } @@ -620,9 +621,14 @@ static bool show_data(void) { uint8_t tag = decryption_context->data[i].plain_data[0]; if (tag == INHERITANCE_ONLY_SHOW_ON_DEVICE) { - message_scr_init( - (const char *)&decryption_context->data[i] - .plain_data[3]); ///< sizeof (tag) + sizeof (length) = 3 + char msg[100] = {0}; + snprintf(msg, + sizeof(msg), + UI_TEXT_PIN, ///< TODO: Make this generic + &decryption_context->data[i].plain_data[3]); + message_scr_init(msg); ///< sizeof (tag) + sizeof (length) = 3 + // Do not care about the return value from confirmation screen + (void)get_state_on_confirm_scr(0, 0, 0); } else { uint16_t offset = 1; // Skip tag decryption_context->response_payload.decrypted_data[response_count] @@ -661,10 +667,10 @@ decryption_error_type_e inheritance_decrypt_data(inheritance_query_t *query) { if (inheritance_decryption_handle_initiate_query(query) && inheritance_get_encrypted_data(query) && decrypt_data() && show_data() && send_decrypted_data(query)) { - delay_scr_init(ui_text_inheritance_decryption_flow_success, DELAY_TIME); + delay_scr_init(ui_text_inheritance_decryption_flow_success, DELAY_SHORT); SET_ERROR_TYPE(DECRYPTION_OK); } else { - delay_scr_init(ui_text_inheritance_decryption_flow_failure, DELAY_TIME); + delay_scr_init(ui_text_inheritance_decryption_flow_failure, DELAY_SHORT); } decryption_handle_errors(); diff --git a/src/constant_texts.h b/src/constant_texts.h index 42ec2a51f..cb582947f 100644 --- a/src/constant_texts.h +++ b/src/constant_texts.h @@ -53,7 +53,7 @@ #define UI_TEXT_BLIND_SIGNING_WARNING \ LV_SYMBOL_WARNING " Blind Signing\nProceed at your own risk!" #define UI_TEXT_VERIFY_HD_PATH "Verify Derivation Path" -#define UI_TEXT_PIN "PIN" +#define UI_TEXT_PIN "PIN\n %s" #define UI_TEXT_VERIFY_DESTINATION_TAG "Verify Destination Tag\n%lu" // product hash From ac8280d79e3d4b183819ad2490b282645e273414 Mon Sep 17 00:00:00 2001 From: Vaibhav Sethia Date: Fri, 11 Oct 2024 17:56:39 +0530 Subject: [PATCH 2/7] fix: Add no wallet error beep sound --- .../inheritance_app/inheritance_auth_wallet.c | 11 ++++++++++ .../inheritance_decrypt_data.c | 16 +++++++++++++- .../inheritance_encrypt_data.c | 21 +++++++++++++++---- common/core/core_error.c | 10 +++------ common/core/core_error.h | 7 +++++++ src/card_operations/card_fetch_wallet_list.c | 1 + src/wallet/verify_pin_flow.c | 12 +++++------ 7 files changed, 60 insertions(+), 18 deletions(-) diff --git a/apps/inheritance_app/inheritance_auth_wallet.c b/apps/inheritance_app/inheritance_auth_wallet.c index bc1cff744..d9ba14df9 100644 --- a/apps/inheritance_app/inheritance_auth_wallet.c +++ b/apps/inheritance_app/inheritance_auth_wallet.c @@ -16,6 +16,7 @@ #include #include +#include #include "bip39.h" #include "card_fetch_data.h" @@ -460,6 +461,16 @@ auth_wallet_error_type_e inheritance_auth_wallet(inheritance_query_t *query) { auth_wallet_get_pairs() && auth_wallet_get_signature() && send_result()) { delay_scr_init(ui_text_inheritance_wallet_auth_success, DELAY_TIME); SET_ERROR_TYPE(AUTH_WALLET_OK); + } else { + // TODO: Add this in error handling + if (0 != strlen(error_screen.core_error_msg)) { + if (error_screen.ring_buzzer) { + buzzer_start(BUZZER_DURATION); + } + delay_scr_init(error_screen.core_error_msg, DELAY_TIME); + clear_core_error_screen(); + } + delay_scr_init(ui_text_inheritance_wallet_auth_fail, DELAY_TIME); } auth_wallet_handle_errors(); memzero(auth, sizeof(auth_wallet_config_t)); diff --git a/apps/inheritance_app/inheritance_decrypt_data.c b/apps/inheritance_app/inheritance_decrypt_data.c index 6cc7630c8..d5a93e818 100644 --- a/apps/inheritance_app/inheritance_decrypt_data.c +++ b/apps/inheritance_app/inheritance_decrypt_data.c @@ -66,6 +66,7 @@ #include "card_fetch_data.h" #include "card_operation_typedefs.h" #include "constant_texts.h" +#include "core_error.h" #include "core_session.h" #include "inheritance/core.pb.h" #include "inheritance/decrypt_data_with_pin.pb.h" @@ -608,7 +609,12 @@ static bool decrypt_data(void) { } } while (0); - delay_scr_init(ui_text_processing, DELAY_TIME); + if (status) { + delay_scr_init(ui_text_processing, DELAY_TIME); + } else { + inheritance_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG, + ERROR_DATA_FLOW_INVALID_REQUEST); + } return status; } @@ -664,6 +670,14 @@ decryption_error_type_e inheritance_decrypt_data(inheritance_query_t *query) { delay_scr_init(ui_text_inheritance_decryption_flow_success, DELAY_TIME); SET_ERROR_TYPE(DECRYPTION_OK); } else { + // TODO: Add this in error handling + if (0 != strlen(error_screen.core_error_msg)) { + if (error_screen.ring_buzzer) { + buzzer_start(BUZZER_DURATION); + } + delay_scr_init(error_screen.core_error_msg, DELAY_TIME); + clear_core_error_screen(); + } delay_scr_init(ui_text_inheritance_decryption_flow_failure, DELAY_TIME); } decryption_handle_errors(); diff --git a/apps/inheritance_app/inheritance_encrypt_data.c b/apps/inheritance_app/inheritance_encrypt_data.c index f34618144..d9cdcf295 100644 --- a/apps/inheritance_app/inheritance_encrypt_data.c +++ b/apps/inheritance_app/inheritance_encrypt_data.c @@ -60,10 +60,12 @@ *****************************************************************************/ #include +#include #include "bignum.h" #include "card_fetch_data.h" #include "constant_texts.h" +#include "core_error.h" #include "core_session.h" #include "inheritance/common.pb.h" #include "inheritance/core.pb.h" @@ -80,6 +82,7 @@ #include "ui_core_confirm.h" #include "ui_delay.h" #include "ui_input_text.h" +#include "ui_message.h" #include "utils.h" #include "verify_pin_flow.h" #include "wallet.h" @@ -654,24 +657,26 @@ static bool encrypt_data(void) { status = false; break; } - if (!encrypt_message_data()) { status = false; break; } - if (!serialize_packet()) { status = false; break; } - if (!encrypt_packet()) { status = false; break; } } while (0); - delay_scr_init(ui_text_processing, DELAY_TIME); + if (status) { + delay_scr_init(ui_text_processing, DELAY_TIME); + } else { + inheritance_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG, + ERROR_DATA_FLOW_INVALID_REQUEST); + } return status; } @@ -789,6 +794,14 @@ encryption_error_type_e inheritance_encrypt_data(inheritance_query_t *query) { delay_scr_init(ui_text_inheritance_encryption_flow_success, DELAY_TIME); SET_ERROR_TYPE(ENCRYPTION_OK); } else { + // TODO: Add this in error handling + if (0 != strlen(error_screen.core_error_msg)) { + if (error_screen.ring_buzzer) { + buzzer_start(BUZZER_DURATION); + } + delay_scr_init(error_screen.core_error_msg, DELAY_TIME); + clear_core_error_screen(); + } delay_scr_init(ui_text_inheritance_encryption_flow_failure, DELAY_TIME); } encryption_handle_errors(); diff --git a/common/core/core_error.c b/common/core/core_error.c index dab9f9414..54f9acdda 100644 --- a/common/core/core_error.c +++ b/common/core/core_error.c @@ -73,6 +73,7 @@ /***************************************************************************** * EXTERN VARIABLES *****************************************************************************/ +error_screen_t error_screen; /***************************************************************************** * PRIVATE MACROS AND DEFINES @@ -81,12 +82,6 @@ /***************************************************************************** * PRIVATE TYPEDEFS *****************************************************************************/ -typedef struct { - char core_error_msg[60]; /**< Buffer to store the error message that needs to - be displayed */ - bool ring_buzzer; /**< Configuration parameter to record if buzzer is required - while the error is being displayed */ -} error_screen_t; /***************************************************************************** * STATIC FUNCTION PROTOTYPES @@ -107,7 +102,6 @@ static void display_core_error(); /***************************************************************************** * STATIC VARIABLES *****************************************************************************/ -static error_screen_t error_screen = {0}; /***************************************************************************** * GLOBAL VARIABLES @@ -182,6 +176,8 @@ void handle_core_errors() { } display_core_error(); + // clear error_screen after display + clear_core_error_screen(); return; } diff --git a/common/core/core_error.h b/common/core/core_error.h index fe2dac325..00afbe959 100644 --- a/common/core/core_error.h +++ b/common/core/core_error.h @@ -21,10 +21,17 @@ /***************************************************************************** * TYPEDEFS *****************************************************************************/ +typedef struct { + char core_error_msg[60]; /**< Buffer to store the error message that needs to + be displayed */ + bool ring_buzzer; /**< Configuration parameter to record if buzzer is required + while the error is being displayed */ +} error_screen_t; /***************************************************************************** * EXPORTED VARIABLES *****************************************************************************/ +extern error_screen_t error_screen; /***************************************************************************** * GLOBAL FUNCTION PROTOTYPES diff --git a/src/card_operations/card_fetch_wallet_list.c b/src/card_operations/card_fetch_wallet_list.c index a2cb552fe..f51124937 100644 --- a/src/card_operations/card_fetch_wallet_list.c +++ b/src/card_operations/card_fetch_wallet_list.c @@ -239,6 +239,7 @@ bool card_fetch_wallet_name(const uint8_t *wallet_id, char *wallet_name) { } if (0 == strlen(wallet_name)) { + buzzer_start(BUZZER_DURATION); delay_scr_init(ui_text_wallet_doesnt_exists_on_this_card, DELAY_TIME); return false; } diff --git a/src/wallet/verify_pin_flow.c b/src/wallet/verify_pin_flow.c index 1eebb292b..34e97ed83 100644 --- a/src/wallet/verify_pin_flow.c +++ b/src/wallet/verify_pin_flow.c @@ -254,13 +254,13 @@ static bool get_verified_pin(const uint8_t *wallet_id, } if (COMPLETED == current_state) { + return true; } else if (reject_cb && EARLY_EXIT == current_state) { // Inform the host of any rejection reject_cb(ERROR_COMMON_ERROR_USER_REJECTION_TAG, ERROR_USER_REJECTION_CONFIRMATION); - return false; } - return true; + return false; } /***************************************************************************** @@ -272,15 +272,15 @@ bool verify_pin(const uint8_t *wallet_id, if ((NULL == wallet_id) || (NULL == pin_out)) { return false; } - + bool status = false; clear_wallet_data(); mnemonic_clear(); - if (!get_verified_pin(wallet_id, PIN_INPUT, pin_out, reject_cb)) { - return false; + if (get_verified_pin(wallet_id, PIN_INPUT, pin_out, reject_cb)) { + status = true; } mnemonic_clear(); clear_wallet_data(); - return true; + return status; } From 7124e4f3ec2dcc7640592fb862c50f6aeb5fa90e Mon Sep 17 00:00:00 2001 From: Vaibhav Sethia Date: Thu, 14 Nov 2024 15:41:35 +0530 Subject: [PATCH 3/7] chore: Rebase update --- apps/inheritance_app/inheritance_auth_wallet.c | 17 +++++++++-------- apps/inheritance_app/inheritance_decrypt_data.c | 4 +--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/inheritance_app/inheritance_auth_wallet.c b/apps/inheritance_app/inheritance_auth_wallet.c index d9ba14df9..07a775ad0 100644 --- a/apps/inheritance_app/inheritance_auth_wallet.c +++ b/apps/inheritance_app/inheritance_auth_wallet.c @@ -179,6 +179,15 @@ static void auth_wallet_handle_errors() { } LOG_ERROR("inheritance_auth_wallet error code:%d ", auth_wallet_error.type); + // Display any error msg if exists + if (0 != strlen(error_screen.core_error_msg)) { + if (error_screen.ring_buzzer) { + buzzer_start(BUZZER_DURATION); + } + delay_scr_init(error_screen.core_error_msg, DELAY_SHORT); + clear_core_error_screen(); + } + switch (type) { case AUTH_WALLET_USER_ABORT_ERROR: { // Error already sent to host, nothing to do here @@ -462,14 +471,6 @@ auth_wallet_error_type_e inheritance_auth_wallet(inheritance_query_t *query) { delay_scr_init(ui_text_inheritance_wallet_auth_success, DELAY_TIME); SET_ERROR_TYPE(AUTH_WALLET_OK); } else { - // TODO: Add this in error handling - if (0 != strlen(error_screen.core_error_msg)) { - if (error_screen.ring_buzzer) { - buzzer_start(BUZZER_DURATION); - } - delay_scr_init(error_screen.core_error_msg, DELAY_TIME); - clear_core_error_screen(); - } delay_scr_init(ui_text_inheritance_wallet_auth_fail, DELAY_TIME); } auth_wallet_handle_errors(); diff --git a/apps/inheritance_app/inheritance_decrypt_data.c b/apps/inheritance_app/inheritance_decrypt_data.c index d5a93e818..c3e46a880 100644 --- a/apps/inheritance_app/inheritance_decrypt_data.c +++ b/apps/inheritance_app/inheritance_decrypt_data.c @@ -609,11 +609,9 @@ static bool decrypt_data(void) { } } while (0); + // Display Processing only if proceeding with flow if (status) { delay_scr_init(ui_text_processing, DELAY_TIME); - } else { - inheritance_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG, - ERROR_DATA_FLOW_INVALID_REQUEST); } return status; } From 332e9dbf2ddcd51f1eff50a2dd79892519d1d8bf Mon Sep 17 00:00:00 2001 From: Vaibhav Sethia Date: Thu, 14 Nov 2024 16:03:33 +0530 Subject: [PATCH 4/7] chore: Refactor changes --- .../inheritance_encrypt_data.c | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/inheritance_app/inheritance_encrypt_data.c b/apps/inheritance_app/inheritance_encrypt_data.c index d9cdcf295..8a3a4cbdc 100644 --- a/apps/inheritance_app/inheritance_encrypt_data.c +++ b/apps/inheritance_app/inheritance_encrypt_data.c @@ -318,6 +318,16 @@ static void encryption_handle_errors() { LOG_ERROR("inheritance_encrypt_data Error Code:%d Flow Tag:%d ", encryption_error.type, encryption_error.flow); + + // Display any error msg if exists + if (0 != strlen(error_screen.core_error_msg)) { + if (error_screen.ring_buzzer) { + buzzer_start(BUZZER_DURATION); + } + delay_scr_init(error_screen.core_error_msg, DELAY_TIME); + clear_core_error_screen(); + } + encryption_error_type_e type = encryption_error.type; switch (type) { case ENCRYPTION_ERROR_DEFAULT: @@ -653,29 +663,31 @@ static bool encrypt_data(void) { status = false; break; } + if (!serialize_message_data()) { status = false; break; } + if (!encrypt_message_data()) { status = false; break; } + if (!serialize_packet()) { status = false; break; } + if (!encrypt_packet()) { status = false; break; } } while (0); + // Display Processing only if proceeding with flow if (status) { - delay_scr_init(ui_text_processing, DELAY_TIME); - } else { - inheritance_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG, - ERROR_DATA_FLOW_INVALID_REQUEST); + delay_scr_init(ui_text_processing, DELAY_SHORT); } return status; } @@ -794,14 +806,6 @@ encryption_error_type_e inheritance_encrypt_data(inheritance_query_t *query) { delay_scr_init(ui_text_inheritance_encryption_flow_success, DELAY_TIME); SET_ERROR_TYPE(ENCRYPTION_OK); } else { - // TODO: Add this in error handling - if (0 != strlen(error_screen.core_error_msg)) { - if (error_screen.ring_buzzer) { - buzzer_start(BUZZER_DURATION); - } - delay_scr_init(error_screen.core_error_msg, DELAY_TIME); - clear_core_error_screen(); - } delay_scr_init(ui_text_inheritance_encryption_flow_failure, DELAY_TIME); } encryption_handle_errors(); From 080a62c680be7ea103d53baa5ec11a1ff276dece Mon Sep 17 00:00:00 2001 From: Vaibhav Sethia Date: Thu, 14 Nov 2024 16:09:14 +0530 Subject: [PATCH 5/7] chore: Ci fix --- apps/inheritance_app/inheritance_decrypt_data.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/inheritance_app/inheritance_decrypt_data.c b/apps/inheritance_app/inheritance_decrypt_data.c index acc560515..3304a1e0d 100644 --- a/apps/inheritance_app/inheritance_decrypt_data.c +++ b/apps/inheritance_app/inheritance_decrypt_data.c @@ -604,13 +604,14 @@ static bool decrypt_data(void) { status = false; break; } + if (!decrypt_message_data()) { status = false; break; } } while (0); - + // Display Processing only if proceeding with flow if (status) { delay_scr_init(ui_text_processing, DELAY_SHORT); From 4782d295fc01592efd21ef659ac8a6a421c291f8 Mon Sep 17 00:00:00 2001 From: TejasvOnly Date: Thu, 14 Nov 2024 03:07:53 -0800 Subject: [PATCH 6/7] fix: Set proper flow status in ecnryption flow --- apps/inheritance_app/inheritance_encrypt_data.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/inheritance_app/inheritance_encrypt_data.c b/apps/inheritance_app/inheritance_encrypt_data.c index 8a3a4cbdc..4d6e28a3b 100644 --- a/apps/inheritance_app/inheritance_encrypt_data.c +++ b/apps/inheritance_app/inheritance_encrypt_data.c @@ -663,6 +663,7 @@ static bool encrypt_data(void) { status = false; break; } + set_app_flow_status(INHERITANCE_ENCRYPT_DATA_STATUS_PIN_ENTERED); if (!serialize_message_data()) { status = false; @@ -673,6 +674,7 @@ static bool encrypt_data(void) { status = false; break; } + set_app_flow_status(INHERITANCE_ENCRYPT_DATA_STATUS_MESSAGE_ENCRYPTED); if (!serialize_packet()) { status = false; From 80d541dc43e6ccc0b0292c6b46b9f8da9b409d14 Mon Sep 17 00:00:00 2001 From: TejasvOnly Date: Thu, 14 Nov 2024 03:09:22 -0800 Subject: [PATCH 7/7] fix: Typo in decryption flow logs --- apps/inheritance_app/inheritance_decrypt_data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/inheritance_app/inheritance_decrypt_data.c b/apps/inheritance_app/inheritance_decrypt_data.c index 3304a1e0d..b3f2a4613 100644 --- a/apps/inheritance_app/inheritance_decrypt_data.c +++ b/apps/inheritance_app/inheritance_decrypt_data.c @@ -260,7 +260,7 @@ static void decryption_handle_errors() { if (decryption_error.type == DECRYPTION_OK) { return; } - LOG_ERROR("inheritance_encrypt_data Error Code:%d Flow Tag:%d ", + LOG_ERROR("inheritance_decrypt_data Error Code:%d Flow Tag:%d ", decryption_error.type, decryption_error.flow); decryption_error_type_e type = decryption_error.type;