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

Various QoL changes & small fixes #674

Merged
merged 7 commits into from
Nov 25, 2024
Merged
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
14 changes: 2 additions & 12 deletions client/src/ledger_app_clients/ethereum/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,21 +267,11 @@ def sign(self, bip32_path: str, rlp_data: bytes, vrs: list) -> list[bytes]:
payload += rlp_data
p1 = P1Type.SIGN_FIRST_CHUNK
while len(payload) > 0:
chunk_size = 0xff

# TODO: Fix the app & remove this, issue #409
if len(vrs) == 3:
if len(payload) > chunk_size:
import rlp
diff = len(rlp.encode(vrs)) - (len(payload) - chunk_size)
if diff > 0:
chunk_size -= diff

apdus.append(self._serialize(InsType.SIGN,
p1,
0x00,
payload[:chunk_size]))
payload = payload[chunk_size:]
payload[:0xff]))
payload = payload[0xff:]
p1 = P1Type.SIGN_SUBSQT_CHUNK
return apdus

Expand Down
13 changes: 0 additions & 13 deletions src/ethUstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,6 @@ static parserStatus_e processTxInternal(txContext_t *context) {
PRINTF("parsing is done\n");
return USTREAM_FINISHED;
}
// Old style transaction (pre EIP-155). Transactions could just skip `v,r,s` so we needed to
// cut parsing here. commandLength == 0 could happen in two cases :
// 1. We are in an old style transaction : just return `USTREAM_FINISHED`.
// 2. We are at the end of an APDU in a multi-apdu process. This would make us return
// `USTREAM_FINISHED` preemptively. Case number 2 should NOT happen as it is up to
// `ledgerjs` to correctly decrease the size of the APDU (`commandLength`) so that this
// situation doesn't happen.
if ((context->txType == LEGACY && context->currentField == LEGACY_RLP_V) &&
(context->commandLength == 0)) {
context->content->vLength = 0;
PRINTF("finished\n");
return USTREAM_FINISHED;
}
if (context->commandLength == 0) {
PRINTF("Command length done\n");
return USTREAM_PROCESSING;
Expand Down
3 changes: 0 additions & 3 deletions src/ledger_pki.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "apdu_constants.h"
#include "public_keys.h"
#ifdef HAVE_LEDGER_PKI
#include "os_pki.h"
#endif

#define KEY_USAGE_STR(x) \
(x == CERTIFICATE_PUBLIC_KEY_USAGE_GENUINE_CHECK ? "GENUINE_CHECK" \
Expand Down
2 changes: 2 additions & 0 deletions src/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <stdint.h>
#include "mem.h"
#include "os_print.h"

#define SIZE_MEM_BUFFER 10240

Expand Down Expand Up @@ -42,6 +43,7 @@ void mem_reset(void) {
void *mem_alloc(size_t size) {
if ((mem_idx + size) > SIZE_MEM_BUFFER) // Buffer exceeded
{
PRINTF("Error: mem_alloc(%u) failed!\n", size);
return NULL;
}
mem_idx += size;
Expand Down
29 changes: 16 additions & 13 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "shared_context.h"
#include "common_utils.h"

static const char *unknown_ticker = "???";
const char g_unknown_ticker[] = "???";

// Mapping of chain ids to networks.
static const network_info_t NETWORK_MAPPING[] = {
Expand Down Expand Up @@ -111,18 +111,21 @@ static const network_info_t NETWORK_MAPPING[] = {
};

static const network_info_t *get_network_from_chain_id(const uint64_t *chain_id) {
// Look if the network is available
for (size_t i = 0; i < MAX_DYNAMIC_NETWORKS; i++) {
if (DYNAMIC_NETWORK_INFO[i].chain_id == *chain_id) {
PRINTF("[NETWORK] - Found dynamic %s\n", DYNAMIC_NETWORK_INFO[i].name);
return (const network_info_t *) &DYNAMIC_NETWORK_INFO[i];
if (*chain_id != 0) {
// Look if the network is available
for (size_t i = 0; i < MAX_DYNAMIC_NETWORKS; i++) {
if (DYNAMIC_NETWORK_INFO[i].chain_id == *chain_id) {
PRINTF("[NETWORK] - Found dynamic %s\n", DYNAMIC_NETWORK_INFO[i].name);
return (const network_info_t *) &DYNAMIC_NETWORK_INFO[i];
}
}
}
// Fallback to hardcoded table
for (size_t i = 0; i < ARRAYLEN(NETWORK_MAPPING); i++) {
if (NETWORK_MAPPING[i].chain_id == *chain_id) {
PRINTF("[NETWORK] - Fallback on hardcoded list. Found %s\n", NETWORK_MAPPING[i].name);
return (const network_info_t *) &NETWORK_MAPPING[i];
// Fallback to hardcoded table
for (size_t i = 0; i < ARRAYLEN(NETWORK_MAPPING); i++) {
if (NETWORK_MAPPING[i].chain_id == *chain_id) {
PRINTF("[NETWORK] - Fallback on hardcoded list. Found %s\n",
NETWORK_MAPPING[i].name);
return (const network_info_t *) &NETWORK_MAPPING[i];
}
}
}
return NULL;
Expand Down Expand Up @@ -177,7 +180,7 @@ const char *get_displayable_ticker(const uint64_t *chain_id, const chain_config_
if (*chain_id == chain_cfg->chainId) {
ticker = chain_cfg->coinName;
} else {
ticker = unknown_ticker;
ticker = g_unknown_ticker;
}
}
return ticker;
Expand Down
1 change: 1 addition & 0 deletions src/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct network_info_s {
} while (0)

extern network_info_t DYNAMIC_NETWORK_INFO[];
extern const char g_unknown_ticker[];

const char *get_network_name_from_chain_id(const uint64_t *chain_id);
const char *get_network_ticker_from_chain_id(const uint64_t *chain_id);
Expand Down
20 changes: 12 additions & 8 deletions src/public_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
********************************************************************************/

#pragma once

#include <stdint.h>
#ifdef HAVE_LEDGER_PKI
#include "os_pki.h"
#endif

static const uint8_t LEDGER_SIGNATURE_PUBLIC_KEY[] = {
#if defined(HAVE_CAL_TEST_KEY)
Expand Down Expand Up @@ -105,13 +109,13 @@ static const uint8_t LEDGER_NFT_SELECTOR_PUBLIC_KEY[] = {
#endif
};

extern int check_signature_with_pubkey(const char *tag,
uint8_t *buffer,
const uint8_t bufLen,
const uint8_t *PubKey,
const uint8_t keyLen,
int check_signature_with_pubkey(const char *tag,
uint8_t *buffer,
const uint8_t bufLen,
const uint8_t *PubKey,
const uint8_t keyLen,
#ifdef HAVE_LEDGER_PKI
const uint8_t keyUsageExp,
const uint8_t keyUsageExp,
#endif
uint8_t *signature,
const uint8_t sigLen);
uint8_t *signature,
const uint8_t sigLen);
4 changes: 0 additions & 4 deletions src_features/provideNFTInformation/cmd_provideNFTInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ uint16_t handleProvideNFTInformation(const uint8_t *workBuffer,

PRINTF("In handle provide NFTInformation\n");

if ((pluginType != ERC721) && (pluginType != ERC1155)) {
PRINTF("NFT metadata provided without proper plugin loaded!\n");
return APDU_RESPONSE_CONDITION_NOT_SATISFIED;
}
nft = &get_current_asset_info()->nft;

PRINTF("Provisioning currentAssetIndex %d\n", tmpCtx.transactionContext.currentAssetIndex);
Expand Down
7 changes: 5 additions & 2 deletions src_features/signMessageEIP712/ui_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "uint_common.h"
#include "filtering.h"
#include "trusted_name.h"
#include "network.h"

#define AMOUNT_JOIN_FLAG_TOKEN (1 << 0)
#define AMOUNT_JOIN_FLAG_VALUE (1 << 1)
Expand Down Expand Up @@ -449,12 +450,14 @@ static bool ui_712_format_amount_join(void) {
ismaxint(ui_ctx->amount.joins[ui_ctx->amount.idx].value,
ui_ctx->amount.joins[ui_ctx->amount.idx].value_length)) {
strlcpy(strings.tmp.tmp, "Unlimited ", sizeof(strings.tmp.tmp));
strlcat(strings.tmp.tmp, (token != NULL) ? token->ticker : "???", sizeof(strings.tmp.tmp));
strlcat(strings.tmp.tmp,
(token != NULL) ? token->ticker : g_unknown_ticker,
sizeof(strings.tmp.tmp));
} else {
if (!amountToString(ui_ctx->amount.joins[ui_ctx->amount.idx].value,
ui_ctx->amount.joins[ui_ctx->amount.idx].value_length,
(token != NULL) ? token->decimals : 0,
(token != NULL) ? token->ticker : "???",
(token != NULL) ? token->ticker : g_unknown_ticker,
strings.tmp.tmp,
sizeof(strings.tmp.tmp))) {
return false;
Expand Down
4 changes: 0 additions & 4 deletions src_features/signTx/cmd_signTx.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ uint16_t handleSign(uint8_t p1,
uint16_t sw = APDU_NO_RESPONSE;
cx_err_t error = CX_INTERNAL_ERROR;

if (os_global_pin_is_validated() != BOLOS_UX_OK) {
PRINTF("Device is PIN-locked");
return APDU_RESPONSE_SECURITY_NOT_SATISFIED;
}
if (p1 == P1_FIRST) {
if (appState != APP_STATE_IDLE) {
reset_app_context();
Expand Down
Loading