Skip to content

Commit

Permalink
fix fuzzing findings
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Dec 17, 2024
1 parent a8ad11f commit 1130130
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/shared_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "nbgl_types.h"
#endif

extern void app_exit();
extern void app_exit(void);
extern void common_app_init(void);

#define SELECTOR_LENGTH 4
Expand Down
25 changes: 21 additions & 4 deletions src_features/provideDynamicNetwork/network_dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ static uint16_t parse_icon_buffer(void) {
uint8_t digest[CX_SHA256_SIZE];
const uint8_t *data = g_network_icon[g_current_slot].bitmap;
const uint16_t field_len = g_icon_payload.received_size;
cx_err_t error = CX_INTERNAL_ERROR;

// Check the icon header
sw = check_icon_header(data, field_len, &img_len);
Expand All @@ -298,7 +299,7 @@ static uint16_t parse_icon_buffer(void) {
CHECK_FIELD_OVERFLOW("NETWORK_ICON", g_network_icon[g_current_slot].bitmap);

// Check icon hash
cx_sha256_hash(data, field_len, digest);
CX_CHECK(cx_sha256_hash(data, field_len, digest));
if (memcmp(digest, g_network_icon[g_current_slot].hash, CX_SHA256_SIZE) != 0) {
PRINTF("NETWORK_ICON hash mismatch!\n");
return APDU_RESPONSE_INVALID_DATA;
Expand All @@ -313,7 +314,9 @@ static uint16_t parse_icon_buffer(void) {
DYNAMIC_NETWORK_INFO[g_current_slot].icon.isFile = true;
COPY_FIELD(DYNAMIC_NETWORK_INFO[g_current_slot].icon.bitmap);
print_icon_info();
return APDU_RESPONSE_OK;
error = APDU_RESPONSE_OK;
end:
return error;
}

/**
Expand Down Expand Up @@ -376,6 +379,12 @@ static uint16_t handle_next_icon_chunk(const uint8_t *data, uint8_t length) {
*/
static uint16_t handle_icon_chunks(uint8_t p1, const uint8_t *data, uint8_t length) {
uint16_t sw = APDU_RESPONSE_UNKNOWN;
uint8_t hash[CX_SHA256_SIZE] = {0};

if (memcmp(g_network_icon[g_current_slot].hash, hash, CX_SHA256_SIZE) == 0) {
PRINTF("Error: Icon hash not set!\n");
return APDU_RESPONSE_INVALID_DATA;
}

// Check the received chunk index
if (p1 == P1_FIRST_CHUNK) {
Expand Down Expand Up @@ -432,16 +441,24 @@ static bool verify_signature(s_sig_ctx *sig_ctx) {
CX_CHECK(
cx_hash_no_throw((cx_hash_t *) &sig_ctx->hash_ctx, CX_LAST, NULL, 0, hash, INT256_LENGTH));

#ifdef HAVE_LEDGER_PKI
CX_CHECK(check_signature_with_pubkey("Dynamic Network",
hash,
sizeof(hash),
LEDGER_SIGNATURE_PUBLIC_KEY,
sizeof(LEDGER_SIGNATURE_PUBLIC_KEY),
#ifdef HAVE_LEDGER_PKI
CERTIFICATE_PUBLIC_KEY_USAGE_COIN_META,
#endif
(uint8_t *) (sig_ctx->sig),
sig_ctx->sig_size));
#else
CX_CHECK(check_signature_with_pubkey("Dynamic Network",
hash,
sizeof(hash),
LEDGER_SIGNATURE_PUBLIC_KEY,
sizeof(LEDGER_SIGNATURE_PUBLIC_KEY),
(uint8_t *) (sig_ctx->sig),
sig_ctx->sig_size));
#endif

ret_code = true;
end:
Expand Down

0 comments on commit 1130130

Please sign in to comment.