Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/coding_style_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ jobs:
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_lint.yml@v1
with:
source: './src'
extensions: 'h,c'
version: 11
5 changes: 3 additions & 2 deletions fuzzing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif()
project(FuzzTxParser
VERSION 1.0
DESCRIPTION "Fuzzing of transaction parser"
LANGUAGES CXX)
LANGUAGES C CXX)

# guard against bad build-type strings
if (NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -55,7 +55,8 @@ endif()

include(extra/TxParser.cmake)

add_executable(fuzz_tx_parser fuzz_tx_parser.cc)
add_executable(fuzz_tx_parser fuzz_tx_parser.c)
set_target_properties(fuzz_tx_parser PROPERTIES LINKER_LANGUAGE CXX)

target_compile_options(fuzz_tx_parser
PRIVATE ${COMPILATION_FLAGS}
Expand Down
6 changes: 2 additions & 4 deletions fuzzing/fuzz_tx_parser.cc → fuzzing/fuzz_tx_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
#include <string.h>
#include <sys/types.h>

extern "C" {
#include "bcs/init.h"
#include "buffer.h"
#include "format.h"
#include "transaction/deserialize.h"
#include "transaction/utils.h"
#include "transaction/types.h"
}

#define DEBUG 0

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
buffer_t buf = {.ptr = data, .size = size, .offset = 0};
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
buffer_t buf = {.ptr = (uint8_t *) data, .size = size, .offset = 0};
transaction_t tx;
parser_status_e status;
char sender[65] = {0};
Expand Down
38 changes: 21 additions & 17 deletions src/address.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
* limitations under the License.
*****************************************************************************/

#include <stdint.h> // uint*_t
#include <stddef.h> // size_t
#include "address.h"

#include <stdbool.h> // bool
#include <stddef.h> // size_t
#include <stdint.h> // uint*_t
#include <string.h> // memmove

#include "os.h"
#include "cx.h"

#include "address.h"

#include "os.h"
#include "transaction/types.h"

bool address_from_pubkey(const uint8_t public_key[static 32], uint8_t *out, size_t out_len) {
bool address_from_pubkey(const uint8_t public_key[static 32], uint8_t* out,
size_t out_len) {
const uint8_t signature_scheme_id = 0x00;
uint8_t address[32] = {0};

Expand All @@ -40,15 +40,15 @@ bool address_from_pubkey(const uint8_t public_key[static 32], uint8_t *out, size
if (error != CX_OK) {
return false;
}
error = cx_hash_update((cx_hash_t *) &sha3, public_key, 32);
error = cx_hash_update((cx_hash_t*)&sha3, public_key, 32);
if (error != CX_OK) {
return false;
}
error = cx_hash_update((cx_hash_t *) &sha3, &signature_scheme_id, 1);
error = cx_hash_update((cx_hash_t*)&sha3, &signature_scheme_id, 1);
if (error != CX_OK) {
return false;
}
error = cx_hash_final((cx_hash_t *) &sha3, address);
error = cx_hash_final((cx_hash_t*)&sha3, address);
if (error != CX_OK) {
return false;
}
Expand All @@ -58,18 +58,22 @@ bool address_from_pubkey(const uint8_t public_key[static 32], uint8_t *out, size
return true;
}

bool validate_aptos_bip32_path(const uint32_t *path, size_t path_len) {
bool validate_aptos_bip32_path(const uint32_t* path, size_t path_len) {
// m/purpose'/coin_type'/account'/change/address_index
// m/44' /637' /0' /0' /0'
const uint32_t aptos_prefix[2] = {0x8000002C, 0x8000027D};

// A 3-element HD path limit (`m/44'/637'/x'`) is enforced for:
// 1. BIP44 compliance, ensuring proper structure (`m/44'/637'` - purpose and coin type).
// 2. Operational flexibility, allowing basic account-level (`x'`) fund segregation.
// 3. A balance between security and usability, preventing the potential privacy and security
// risks associated with using an overly simple path (e.g., `m/44'/637'`), while not
// requiring the full 5-element path that may be unnecessary for users seeking
// straightforward wallet functionality.
// 1. BIP44 compliance, ensuring proper structure (`m/44'/637'` - purpose
// and coin type).
// 2. Operational flexibility, allowing basic account-level (`x'`) fund
// segregation.
// 3. A balance between security and usability, preventing the potential
// privacy and security
// risks associated with using an overly simple path (e.g.,
// `m/44'/637'`), while not requiring the full 5-element path that may
// be unnecessary for users seeking straightforward wallet
// functionality.
if (path_len < 3) {
return false;
}
Expand Down
26 changes: 14 additions & 12 deletions src/apdu/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
* limitations under the License.
*****************************************************************************/

#include <stdint.h>
#include <stdbool.h>
#include "dispatcher.h"

#include "buffer.h"
#include "io.h"
#include <stdbool.h>
#include <stdint.h>

#include "dispatcher.h"
#include "../constants.h"
#include "../globals.h"
#include "../types.h"
#include "../sw.h"
#include "../handler/get_version.h"
#include "../handler/get_app_name.h"
#include "../handler/get_public_key.h"
#include "../handler/get_version.h"
#include "../handler/sign_tx.h"
#include "../sw.h"
#include "../types.h"
#include "buffer.h"
#include "io.h"

int apdu_dispatcher(const command_t *cmd) {
int apdu_dispatcher(const command_t* cmd) {
PRINTF("Inside Aptos apdu_dispatcher\n");
if (cmd->cla != CLA) {
return io_send_sw(SW_CLA_NOT_SUPPORTED);
Expand Down Expand Up @@ -68,7 +68,7 @@ int apdu_dispatcher(const command_t *cmd) {
buf.size = cmd->lc;
buf.offset = 0;

return handler_get_public_key(&buf, (bool) cmd->p1);
return handler_get_public_key(&buf, (bool)cmd->p1);
case SIGN_TX:
PRINTF("SIGN_TX\n");
if ((cmd->p1 == P1_START && cmd->p2 != P2_MORE) || //
Expand All @@ -86,8 +86,10 @@ int apdu_dispatcher(const command_t *cmd) {
buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
PRINTF("Inside Aptos apdu_dispatcher: ready to call handler_sign_tx\n");
return handler_sign_tx(&buf, cmd->p1, (bool) (cmd->p2 & P2_MORE));
PRINTF(
"Inside Aptos apdu_dispatcher: ready to call "
"handler_sign_tx\n");
return handler_sign_tx(&buf, cmd->p1, (bool)(cmd->p2 & P2_MORE));
default:
return io_send_sw(SW_INS_NOT_SUPPORTED);
}
Expand Down
37 changes: 14 additions & 23 deletions src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
#include <stdint.h> // uint*_t
#include <string.h> // memset, explicit_bzero

#include "os.h"
#include "ux.h"

#include "types.h"
#include "apdu/dispatcher.h"
#include "globals.h"
#include "io.h"
#include "os.h"
#include "sw.h"
#include "types.h"
#include "ui/menu.h"
#include "apdu/dispatcher.h"
#include "ux.h"

#ifdef HAVE_SWAP
#include "swap.h"
Expand All @@ -41,7 +40,7 @@ void nvm_app_storage_init() {
storage.settings.show_full_message = 0x00;
storage.settings.allow_blind_signing = 0x00;
storage.initialized = 0x01;
nvm_write((void *) &N_storage, (void *) &storage, sizeof(app_storage_t));
nvm_write((void*)&N_storage, (void*)&storage, sizeof(app_storage_t));
}
}

Expand Down Expand Up @@ -80,35 +79,27 @@ void app_main() {

// Parse APDU command from G_io_apdu_buffer
if (!apdu_parser(&cmd, G_io_apdu_buffer, input_len)) {
PRINTF("=> /!\\ BAD LENGTH: %.*H\n", input_len, G_io_apdu_buffer);
PRINTF("=> /!\\ BAD LENGTH: %.*H\n", input_len,
G_io_apdu_buffer);
io_send_sw(SW_WRONG_DATA_LENGTH);
CLOSE_TRY;
continue;
}

PRINTF("=> CLA=%02X | INS=%02X | P1=%02X | P2=%02X | Lc=%02X | CData=%.*H\n",
cmd.cla,
cmd.ins,
cmd.p1,
cmd.p2,
cmd.lc,
cmd.lc,
cmd.data);
PRINTF(
"=> CLA=%02X | INS=%02X | P1=%02X | P2=%02X | Lc=%02X | "
"CData=%.*H\n",
cmd.cla, cmd.ins, cmd.p1, cmd.p2, cmd.lc, cmd.lc, cmd.data);

// Dispatch structured APDU command to handler
if (apdu_dispatcher(&cmd) < 0) {
CLOSE_TRY;
return;
}
}
CATCH(EXCEPTION_IO_RESET) {
THROW(EXCEPTION_IO_RESET);
}
CATCH_OTHER(e) {
io_send_sw(e);
}
FINALLY {
}
CATCH(EXCEPTION_IO_RESET) { THROW(EXCEPTION_IO_RESET); }
CATCH_OTHER(e) { io_send_sw(e); }
FINALLY {}
END_TRY;
}
}
Expand Down
Loading
Loading