Skip to content

Commit 2c50cbc

Browse files
Merge pull request #674 from LedgerHQ/misc/apa/fixes
Various QoL changes & small fixes
2 parents 5633f4b + afff82e commit 2c50cbc

File tree

10 files changed

+38
-59
lines changed

10 files changed

+38
-59
lines changed

client/src/ledger_app_clients/ethereum/command_builder.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,11 @@ def sign(self, bip32_path: str, rlp_data: bytes, vrs: list) -> list[bytes]:
267267
payload += rlp_data
268268
p1 = P1Type.SIGN_FIRST_CHUNK
269269
while len(payload) > 0:
270-
chunk_size = 0xff
271-
272-
# TODO: Fix the app & remove this, issue #409
273-
if len(vrs) == 3:
274-
if len(payload) > chunk_size:
275-
import rlp
276-
diff = len(rlp.encode(vrs)) - (len(payload) - chunk_size)
277-
if diff > 0:
278-
chunk_size -= diff
279-
280270
apdus.append(self._serialize(InsType.SIGN,
281271
p1,
282272
0x00,
283-
payload[:chunk_size]))
284-
payload = payload[chunk_size:]
273+
payload[:0xff]))
274+
payload = payload[0xff:]
285275
p1 = P1Type.SIGN_SUBSQT_CHUNK
286276
return apdus
287277

src/ethUstream.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -530,19 +530,6 @@ static parserStatus_e processTxInternal(txContext_t *context) {
530530
PRINTF("parsing is done\n");
531531
return USTREAM_FINISHED;
532532
}
533-
// Old style transaction (pre EIP-155). Transactions could just skip `v,r,s` so we needed to
534-
// cut parsing here. commandLength == 0 could happen in two cases :
535-
// 1. We are in an old style transaction : just return `USTREAM_FINISHED`.
536-
// 2. We are at the end of an APDU in a multi-apdu process. This would make us return
537-
// `USTREAM_FINISHED` preemptively. Case number 2 should NOT happen as it is up to
538-
// `ledgerjs` to correctly decrease the size of the APDU (`commandLength`) so that this
539-
// situation doesn't happen.
540-
if ((context->txType == LEGACY && context->currentField == LEGACY_RLP_V) &&
541-
(context->commandLength == 0)) {
542-
context->content->vLength = 0;
543-
PRINTF("finished\n");
544-
return USTREAM_FINISHED;
545-
}
546533
if (context->commandLength == 0) {
547534
PRINTF("Command length done\n");
548535
return USTREAM_PROCESSING;

src/ledger_pki.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "apdu_constants.h"
22
#include "public_keys.h"
3-
#ifdef HAVE_LEDGER_PKI
4-
#include "os_pki.h"
5-
#endif
63

74
#define KEY_USAGE_STR(x) \
85
(x == CERTIFICATE_PUBLIC_KEY_USAGE_GENUINE_CHECK ? "GENUINE_CHECK" \

src/mem.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <stdint.h>
1212
#include "mem.h"
13+
#include "os_print.h"
1314

1415
#define SIZE_MEM_BUFFER 10240
1516

@@ -42,6 +43,7 @@ void mem_reset(void) {
4243
void *mem_alloc(size_t size) {
4344
if ((mem_idx + size) > SIZE_MEM_BUFFER) // Buffer exceeded
4445
{
46+
PRINTF("Error: mem_alloc(%u) failed!\n", size);
4547
return NULL;
4648
}
4749
mem_idx += size;

src/network.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "shared_context.h"
77
#include "common_utils.h"
88

9-
static const char *unknown_ticker = "???";
9+
const char g_unknown_ticker[] = "???";
1010

1111
// Mapping of chain ids to networks.
1212
static const network_info_t NETWORK_MAPPING[] = {
@@ -111,18 +111,21 @@ static const network_info_t NETWORK_MAPPING[] = {
111111
};
112112

113113
static const network_info_t *get_network_from_chain_id(const uint64_t *chain_id) {
114-
// Look if the network is available
115-
for (size_t i = 0; i < MAX_DYNAMIC_NETWORKS; i++) {
116-
if (DYNAMIC_NETWORK_INFO[i].chain_id == *chain_id) {
117-
PRINTF("[NETWORK] - Found dynamic %s\n", DYNAMIC_NETWORK_INFO[i].name);
118-
return (const network_info_t *) &DYNAMIC_NETWORK_INFO[i];
114+
if (*chain_id != 0) {
115+
// Look if the network is available
116+
for (size_t i = 0; i < MAX_DYNAMIC_NETWORKS; i++) {
117+
if (DYNAMIC_NETWORK_INFO[i].chain_id == *chain_id) {
118+
PRINTF("[NETWORK] - Found dynamic %s\n", DYNAMIC_NETWORK_INFO[i].name);
119+
return (const network_info_t *) &DYNAMIC_NETWORK_INFO[i];
120+
}
119121
}
120-
}
121-
// Fallback to hardcoded table
122-
for (size_t i = 0; i < ARRAYLEN(NETWORK_MAPPING); i++) {
123-
if (NETWORK_MAPPING[i].chain_id == *chain_id) {
124-
PRINTF("[NETWORK] - Fallback on hardcoded list. Found %s\n", NETWORK_MAPPING[i].name);
125-
return (const network_info_t *) &NETWORK_MAPPING[i];
122+
// Fallback to hardcoded table
123+
for (size_t i = 0; i < ARRAYLEN(NETWORK_MAPPING); i++) {
124+
if (NETWORK_MAPPING[i].chain_id == *chain_id) {
125+
PRINTF("[NETWORK] - Fallback on hardcoded list. Found %s\n",
126+
NETWORK_MAPPING[i].name);
127+
return (const network_info_t *) &NETWORK_MAPPING[i];
128+
}
126129
}
127130
}
128131
return NULL;
@@ -177,7 +180,7 @@ const char *get_displayable_ticker(const uint64_t *chain_id, const chain_config_
177180
if (*chain_id == chain_cfg->chainId) {
178181
ticker = chain_cfg->coinName;
179182
} else {
180-
ticker = unknown_ticker;
183+
ticker = g_unknown_ticker;
181184
}
182185
}
183186
return ticker;

src/network.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct network_info_s {
2424
} while (0)
2525

2626
extern network_info_t DYNAMIC_NETWORK_INFO[];
27+
extern const char g_unknown_ticker[];
2728

2829
const char *get_network_name_from_chain_id(const uint64_t *chain_id);
2930
const char *get_network_ticker_from_chain_id(const uint64_t *chain_id);

src/public_keys.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
********************************************************************************/
1717

1818
#pragma once
19+
1920
#include <stdint.h>
21+
#ifdef HAVE_LEDGER_PKI
22+
#include "os_pki.h"
23+
#endif
2024

2125
static const uint8_t LEDGER_SIGNATURE_PUBLIC_KEY[] = {
2226
#if defined(HAVE_CAL_TEST_KEY)
@@ -105,13 +109,13 @@ static const uint8_t LEDGER_NFT_SELECTOR_PUBLIC_KEY[] = {
105109
#endif
106110
};
107111

108-
extern int check_signature_with_pubkey(const char *tag,
109-
uint8_t *buffer,
110-
const uint8_t bufLen,
111-
const uint8_t *PubKey,
112-
const uint8_t keyLen,
112+
int check_signature_with_pubkey(const char *tag,
113+
uint8_t *buffer,
114+
const uint8_t bufLen,
115+
const uint8_t *PubKey,
116+
const uint8_t keyLen,
113117
#ifdef HAVE_LEDGER_PKI
114-
const uint8_t keyUsageExp,
118+
const uint8_t keyUsageExp,
115119
#endif
116-
uint8_t *signature,
117-
const uint8_t sigLen);
120+
uint8_t *signature,
121+
const uint8_t sigLen);

src_features/provideNFTInformation/cmd_provideNFTInfo.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ uint16_t handleProvideNFTInformation(const uint8_t *workBuffer,
6161

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

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

7066
PRINTF("Provisioning currentAssetIndex %d\n", tmpCtx.transactionContext.currentAssetIndex);

src_features/signMessageEIP712/ui_logic.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "uint_common.h"
2121
#include "filtering.h"
2222
#include "trusted_name.h"
23+
#include "network.h"
2324

2425
#define AMOUNT_JOIN_FLAG_TOKEN (1 << 0)
2526
#define AMOUNT_JOIN_FLAG_VALUE (1 << 1)
@@ -449,12 +450,14 @@ static bool ui_712_format_amount_join(void) {
449450
ismaxint(ui_ctx->amount.joins[ui_ctx->amount.idx].value,
450451
ui_ctx->amount.joins[ui_ctx->amount.idx].value_length)) {
451452
strlcpy(strings.tmp.tmp, "Unlimited ", sizeof(strings.tmp.tmp));
452-
strlcat(strings.tmp.tmp, (token != NULL) ? token->ticker : "???", sizeof(strings.tmp.tmp));
453+
strlcat(strings.tmp.tmp,
454+
(token != NULL) ? token->ticker : g_unknown_ticker,
455+
sizeof(strings.tmp.tmp));
453456
} else {
454457
if (!amountToString(ui_ctx->amount.joins[ui_ctx->amount.idx].value,
455458
ui_ctx->amount.joins[ui_ctx->amount.idx].value_length,
456459
(token != NULL) ? token->decimals : 0,
457-
(token != NULL) ? token->ticker : "???",
460+
(token != NULL) ? token->ticker : g_unknown_ticker,
458461
strings.tmp.tmp,
459462
sizeof(strings.tmp.tmp))) {
460463
return false;

src_features/signTx/cmd_signTx.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ uint16_t handleSign(uint8_t p1,
1212
uint16_t sw = APDU_NO_RESPONSE;
1313
cx_err_t error = CX_INTERNAL_ERROR;
1414

15-
if (os_global_pin_is_validated() != BOLOS_UX_OK) {
16-
PRINTF("Device is PIN-locked");
17-
return APDU_RESPONSE_SECURITY_NOT_SATISFIED;
18-
}
1915
if (p1 == P1_FIRST) {
2016
if (appState != APP_STATE_IDLE) {
2117
reset_app_context();

0 commit comments

Comments
 (0)