Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check address #19

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ VARIANT_PARAM = COIN
VARIANT_VALUES = APTOS

# Enabling DEBUG flag will enable PRINTF and disable optimizations
#DEBUG = 1
DEBUG = 1
TEST_PUBLIC_KEY = 1
TESTING = 1

ENABLE_SWAP = 1

########################################
# Application custom permissions #
Expand Down
35 changes: 22 additions & 13 deletions src/handler/get_public_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,17 @@
#include "../ui/display.h"
#include "../helper/send_response.h"

int handler_get_public_key(buffer_t *cdata, bool display) {
explicit_bzero(&G_context, sizeof(G_context));
G_context.req_type = CONFIRM_ADDRESS;

int get_public_key(buffer_t *cdata) {
cx_ecfp_private_key_t private_key = {0};
cx_ecfp_public_key_t public_key = {0};

explicit_bzero(&G_context, sizeof(G_context));
if (!buffer_read_u8(cdata, &G_context.bip32_path_len) ||
!buffer_read_bip32_path(cdata, G_context.bip32_path, (size_t) G_context.bip32_path_len)) {
G_context.req_type = REQUEST_UNDEFINED;
return io_send_sw(SW_WRONG_DATA_LENGTH);
}

if (!validate_aptos_bip32_path(G_context.bip32_path, G_context.bip32_path_len)) {
G_context.req_type = REQUEST_UNDEFINED;
return io_send_sw(SW_GET_PUB_KEY_FAIL);
}

Expand All @@ -60,7 +56,8 @@ int handler_get_public_key(buffer_t *cdata, bool display) {
if (error != CX_OK) {
explicit_bzero(&private_key, sizeof(private_key));
PRINTF("crypto_derive_private_key error code: %x.\n", error);
G_context.req_type = REQUEST_UNDEFINED;
// reset private key
explicit_bzero(&private_key, sizeof(private_key));
return io_send_sw(SW_GET_PUB_KEY_FAIL);
}

Expand All @@ -70,19 +67,31 @@ int handler_get_public_key(buffer_t *cdata, bool display) {
if (error != CX_OK) {
explicit_bzero(&private_key, sizeof(private_key));
PRINTF("crypto_init_public_key error code: %x.\n", error);
G_context.req_type = REQUEST_UNDEFINED;
// reset private key
explicit_bzero(&private_key, sizeof(private_key));
return io_send_sw(SW_GET_PUB_KEY_FAIL);
}

// reset private key
explicit_bzero(&private_key, sizeof(private_key));
return 0;
}


int handler_get_public_key(buffer_t *cdata, bool display) {
G_context.req_type = CONFIRM_ADDRESS;

int result = get_public_key(cdata);

// All the work has been done, so set the context to undefined.
// NOTE: not sure if ui_display_address() should be taken into account for the G_context reset.
G_context.req_type = REQUEST_UNDEFINED;
if (result != 0) {
return io_send_sw(result);
}

if (display) {
int ui_status = ui_display_address();
G_context.req_type = REQUEST_UNDEFINED; // all the work is done, reset the context
return ui_status;
return ui_display_address();
}

G_context.req_type = REQUEST_UNDEFINED; // all the work is done, reset the context
return helper_send_response_pubkey();
}
2 changes: 2 additions & 0 deletions src/handler/get_public_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@
*
*/
int handler_get_public_key(buffer_t *cdata, bool display);

int get_public_key(buffer_t *cdata);
47 changes: 47 additions & 0 deletions src/swap/handle_check_address.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifdef HAVE_SWAP
#include <string.h>
#include "swap.h"
#include "../handler/get_public_key.h"
#include "os.h"

#define ADDRESS_LENGTH 32

/* Set params.result to 0 on error, 1 otherwise */
void swap_handle_check_address(check_address_parameters_t *params) {
PRINTF("Inside Aptos swap_handle_check_address\n");
params->result = 0;

// Checking that parameters are correct
if (params->address_parameters == NULL || params->address_parameters_length == 0) {
PRINTF("address_parameters is empty\n");
return;
}

PRINTF("address_parameters: %.*H\n", params->address_parameters_length, params->address_parameters);

if (params->address_to_check == NULL) {
PRINTF("address_to_check is empty\n");
return;
}

PRINTF("address_to_check: %s\n", params->address_to_check);
if (strlen(params->address_to_check) != ADDRESS_LENGTH) {
PRINTF("address_to_check length should be %d, not %d\n", ADDRESS_LENGTH, strlen(params->address_to_check));
return;
}

// Check that the address to check is in the list of addresses in the device
buffer_t cdata;
cdata.ptr = params->address_parameters;
cdata.size = params->address_parameters_length;
if (get_public_key(&cdata) != 0) {
PRINTF("get_public_key failed\n");
return;
}


PRINTF("addess_to_check matches within the addresses in the device\n");
params->result = 1;
}

#endif
14 changes: 14 additions & 0 deletions src/swap/handle_get_printable_amount.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifdef HAVE_SWAP

#include <string.h> // memset, explicit_bzero
#include "handle_swap_sign_transaction.h"
#include "swap.h"
#include "os.h"
#include "constants.h"

/* Set empty printable_amount on error, printable amount otherwise */
void swap_handle_get_printable_amount(get_printable_amount_parameters_t* params) {
PRINTF("TODO: swap_handle_get_printable_amount\n");
}

#endif
20 changes: 20 additions & 0 deletions src/swap/handle_swap_sign_transaction.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifdef HAVE_SWAP

#include "handle_swap_sign_transaction.h"
#include "display.h"
#include "swap.h"
#include "string.h"
#include "os_lib.h"
#include "constants.h"
#include "os_utils.h"
#include "globals.h"

bool swap_copy_transaction_parameters(create_transaction_parameters_t* params) {
PRINTF("TODO: swap_copy_transaction_parameters\n");

Check failure

Code scanning / CodeQL

Missing return statement Error

Function swap_copy_transaction_parameters should return a value of type bool but does not return a value here
}

void __attribute__((noreturn)) swap_finalize_exchange_sign_transaction(bool is_success) {
PRINTF("TODO: swap_finalize_exchange_sign_transaction\n");
}

#endif
Empty file.
Loading