Review fixes

This commit is contained in:
Alexandre Paillier
2022-10-05 10:21:52 +02:00
parent d297a66951
commit c803322f3c
6 changed files with 45 additions and 28 deletions

View File

@@ -30,6 +30,8 @@
#define P2_CHAINCODE 0x01
#define P1_FIRST 0x00
#define P1_MORE 0x80
#define P2_EIP712_LEGACY_IMPLEM 0x00
#define P2_EIP712_FULL_IMPLEM 0x01
#define COMMON_CLA 0xB0
#define COMMON_INS_GET_WALLET_ID 0x04

View File

@@ -674,21 +674,24 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
break;
case INS_SIGN_EIP_712_MESSAGE:
if (G_io_apdu_buffer[OFFSET_P2] == 0) {
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_ITEMS);
handleSignEIP712Message_v0(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
} else {
switch (G_io_apdu_buffer[OFFSET_P2]) {
case P2_EIP712_LEGACY_IMPLEM:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_ITEMS);
handleSignEIP712Message_v0(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
#ifdef HAVE_EIP712_FULL_SUPPORT
*flags |= IO_ASYNCH_REPLY;
handle_eip712_sign(G_io_apdu_buffer);
#else
THROW(0x6B00);
case P2_EIP712_FULL_IMPLEM:
*flags |= IO_ASYNCH_REPLY;
handle_eip712_sign(G_io_apdu_buffer);
break;
#endif // HAVE_EIP712_FULL_SUPPORT
default:
THROW(APDU_RESPONSE_INVALID_P1_P2);
}
break;

View File

@@ -222,6 +222,6 @@ extern uint32_t eth2WithdrawalIndex;
#endif
void reset_app_context(void);
const uint8_t *parseBip32(const uint8_t *, uint8_t *, bip32_path_t *);
const uint8_t *parseBip32(const uint8_t *dataBuffer, uint8_t *dataLength, bip32_path_t *bip32);
#endif // _SHARED_CONTEXT_H_

View File

@@ -1,5 +1,11 @@
#include "shared_context.h"
#include "ui_callbacks.h"
#include "common_ui.h"
#include "utils.h"
#define ENABLED_STR "Enabled"
#define DISABLED_STR "Disabled"
#define BUF_INCREMENT (MAX(strlen(ENABLED_STR), strlen(DISABLED_STR)) + 1)
void display_settings(const ux_flow_step_t* const start_step);
void switch_settings_blind_signing(void);
@@ -69,7 +75,7 @@ UX_STEP_CB(
switch_settings_display_data(),
{
.title = "Debug data",
.text = strings.common.fullAddress + 9
.text = strings.common.fullAddress + BUF_INCREMENT
});
UX_STEP_CB(
@@ -78,7 +84,7 @@ UX_STEP_CB(
switch_settings_display_nonce(),
{
.title = "Account nonce",
.text = strings.common.fullAddress + 18
.text = strings.common.fullAddress + (BUF_INCREMENT * 2)
});
#else
@@ -102,7 +108,7 @@ UX_STEP_CB(
"Debug data",
"Show contract data",
"details",
strings.common.fullAddress + 9
strings.common.fullAddress + BUF_INCREMENT
});
UX_STEP_CB(
@@ -113,7 +119,7 @@ UX_STEP_CB(
"Nonce",
"Show account nonce",
"in transactions",
strings.common.fullAddress + 18
strings.common.fullAddress + (BUF_INCREMENT * 2)
});
#endif
@@ -127,7 +133,7 @@ UX_STEP_CB(
"Verbose EIP-712",
"Ignore filtering &",
"display raw content",
strings.common.fullAddress + 27
strings.common.fullAddress + (BUF_INCREMENT * 3)
});
#endif // HAVE_EIP712_FULL_SUPPORT
@@ -152,7 +158,6 @@ UX_FLOW(ux_settings_flow,
&ux_settings_flow_back_step);
void display_settings(const ux_flow_step_t* const start_step) {
const char* const values[] = {"Enabled", "Disabled"};
bool settings[] = {N_storage.dataAllowed,
N_storage.contractDetails,
N_storage.displayNonce,
@@ -161,13 +166,12 @@ void display_settings(const ux_flow_step_t* const start_step) {
#endif // HAVE_EIP712_FULL_SUPPORT
};
uint8_t offset = 0;
uint8_t increment = MAX(strlen(values[0]), strlen(values[1])) + 1;
for (unsigned int i = 0; i < (sizeof(settings) / sizeof(settings[0])); ++i) {
for (unsigned int i = 0; i < ARRAY_SIZE(settings); ++i) {
strlcpy(strings.common.fullAddress + offset,
(settings[i] ? values[0] : values[1]),
(settings[i] ? ENABLED_STR : DISABLED_STR),
sizeof(strings.common.fullAddress) - offset);
offset += increment;
offset += BUF_INCREMENT;
}
ux_flow_init(0, ux_settings_flow, start_step);

View File

@@ -1,3 +1,11 @@
/**
* Dynamic allocator that uses a fixed-length buffer that is hopefully big enough
*
* The two functions alloc & dealloc use the buffer as a simple stack.
* Especially useful when an unpredictable amount of data will be received and have to be stored
* during the transaction but discarded right after.
*/
#ifdef HAVE_DYN_MEM_ALLOC
#include <stdint.h>
@@ -23,7 +31,7 @@ void mem_reset(void) {
}
/**
* Allocates a chunk of the memory buffer of a given size.
* Allocates (push) a chunk of the memory buffer of a given size.
*
* Checks to see if there are enough space left in the memory buffer, returns
* the current location in the memory buffer and moves the index accordingly.
@@ -41,7 +49,7 @@ void *mem_alloc(size_t size) {
}
/**
* De-allocates a chunk of memory buffer by a given size.
* De-allocates (pop) a chunk of memory buffer by a given size.
*
* @param[in] size Requested deallocation size in bytes
*/

View File

@@ -14,7 +14,7 @@ void handleSignEIP712Message_v0(uint8_t p1,
(void) tx;
(void) p2;
if (p1 != 00) {
THROW(0x6B00);
THROW(APDU_RESPONSE_INVALID_P1_P2);
}
if (appState != APP_STATE_IDLE) {
reset_app_context();
@@ -23,7 +23,7 @@ void handleSignEIP712Message_v0(uint8_t p1,
workBuffer = parseBip32(workBuffer, &dataLength, &tmpCtx.messageSigningContext.bip32);
if ((workBuffer == NULL) || (dataLength < (KECCAK256_HASH_BYTESIZE * 2))) {
THROW(0x6a80);
THROW(APDU_RESPONSE_INVALID_DATA);
}
memmove(tmpCtx.messageSigningContext712.domainHash, workBuffer, KECCAK256_HASH_BYTESIZE);
memmove(tmpCtx.messageSigningContext712.messageHash,