Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeutin-ledger committed Aug 4, 2023
1 parent 10f2973 commit 315c65b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ all: default
############

DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_BAGL HAVE_SPRINTF HAVE_SNPRINTF_FORMAT_U
DEFINES += HAVE_BAGL HAVE_SPRINTF
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=4 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P)

Expand Down
3 changes: 2 additions & 1 deletion src/apdu_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ uint16_t apdu_parser(uint8_t *apdu, size_t apdu_length, command_t *command) {
if (!is_last_data_chunk) {
// Reply a blank success to indicate that we await the followup part
// Do NOT update any kind of internal state machine, we have not validated what we have received
PRINTF("Split APDU successfully initiated, size %d\n", G_received_apdu.data_length);
return SUCCESS;
} else {
PRINTF("Split APDU successfully recreated, size %d\n", G_received_apdu.data_length);
// The APDU is valid and complete, signal caller that it can proceed
command->ins = G_received_apdu.instruction;
command->rate = G_received_apdu.rate;
Expand All @@ -245,6 +245,7 @@ uint16_t apdu_parser(uint8_t *apdu, size_t apdu_length, command_t *command) {
command->data.bytes = apdu + OFFSET_CDATA;
} else {
// Split has taken place, data is in the split buffer
PRINTF("Split APDU successfully recreated, size %d\n", G_received_apdu.data_length);
command->data.bytes = G_swap_ctx.raw_transaction;
}
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ uint8_t G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];
swap_app_context_t G_swap_ctx;

void app_main(void) {
PRINTF("app_main\n");
int input_length = 0;
command_t cmd;

Expand Down
6 changes: 3 additions & 3 deletions test/python/apps/exchange_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def perform_test_swap_refuse_double_sign(self):
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, self.valid_destination_memo_1)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, self.valid_destination_memo_1)
assert e.value.status == Errors.INVALID_INSTRUCTION or e.value.status == Errors.WRONG_P2
assert e.value.status != 0x9000

# Test swap with a malicious TX with tampered fees
def perform_test_swap_wrong_fees(self):
Expand Down Expand Up @@ -265,7 +265,7 @@ def perform_test_fund_refuse_double_sign(self):
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, "")
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, "")
assert e.value.status == Errors.INVALID_INSTRUCTION
assert e.value.status != 0x9000

# Test fund with a malicious TX with tampered fees
def perform_test_fund_wrong_fees(self):
Expand Down Expand Up @@ -325,7 +325,7 @@ def perform_test_sell_refuse_double_sign(self):
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, "")
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, "")
assert e.value.status == Errors.INVALID_INSTRUCTION
assert e.value.status != 0x9000

# Test sell with a malicious TX with tampered fees
def perform_test_sell_wrong_fees(self):
Expand Down
9 changes: 4 additions & 5 deletions test/python/apps/exchange_transaction_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def encode_signature(self, signature_to_encode: bytes) -> bytes:
return signature_to_encode

def create_transaction(self, conf: Dict, transaction_id: bytes) -> bytes:
conf[self.transaction_id_field] = transaction_id
raw_transaction = self.transaction_type(**conf).SerializeToString()
print(f"raw transaction {raw_transaction.hex()}")
print(f"encoded transaction {self.encode_payload(raw_transaction).hex()}")
# Alter a copy of conf to not modify the actual conf
c = conf.copy()
c[self.transaction_id_field] = transaction_id
raw_transaction = self.transaction_type(**c).SerializeToString()
return self.encode_payload(raw_transaction)


Expand Down Expand Up @@ -169,7 +169,6 @@ def craft_tx(subcommand: SubCommand, conf: Dict, transaction_id: bytes) -> bytes
def encode_tx(subcommand: SubCommand, signer: SigningAuthority, tx: bytes) -> bytes:
subcommand_specs = SUBCOMMAND_TO_SPECS[subcommand]
formated_transaction = subcommand_specs.format_transaction(tx)
print(f"signing {formated_transaction.hex()}")
signed_transaction = signer.sign(formated_transaction)
return subcommand_specs.encode_signature(signed_transaction)

Expand Down
2 changes: 1 addition & 1 deletion test/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

configuration.OPTIONAL.SIDELOADED_APPS_DIR = "test/python/lib_binaries/"

configuration.OPTIONAL.BACKEND_SCOPE = "class"
configuration.OPTIONAL.BACKEND_SCOPE = "function"

#########################
### CONFIGURATION END ###
Expand Down

0 comments on commit 315c65b

Please sign in to comment.