Skip to content

Commit a9b9ec3

Browse files
authored
Merge pull request #18 from Zondax/dev
Ledger findings
2 parents 1392d97 + bed3913 commit a9b9ec3

File tree

536 files changed

+122
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

536 files changed

+122
-166
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ jobs:
5353
make
5454
echo "size=$(python3 deps/ledger-zxlib/scripts/getSize.py s)" >> $GITHUB_OUTPUT
5555
56-
size_nano_s:
57-
needs: build_ledger
58-
runs-on: ubuntu-latest
59-
env:
60-
NANOS_LIMIT_SIZE: 136
61-
steps:
62-
- run: |
63-
echo "LNS app size: ${{needs.build_ledger.outputs.size}} KiB"
64-
[ ${{needs.build_ledger.outputs.size}} -le $NANOS_LIMIT_SIZE ]
65-
6656
test_zemu:
6757
runs-on: ubuntu-latest
6858
steps:
@@ -88,47 +78,11 @@ jobs:
8878
make test_all
8979
- name: Upload Snapshots (only failure)
9080
if: ${{ failure() }}
91-
uses: actions/upload-artifact@v3
81+
uses: actions/upload-artifact@v4
9282
with:
9383
name: snapshots-tmp
9484
path: tests_zemu/snapshots-tmp/
9585

96-
build_package_nanos:
97-
needs: [configure, build, build_ledger, test_zemu]
98-
if: ${{ github.ref == 'refs/heads/main' }}
99-
runs-on: ubuntu-latest
100-
container:
101-
image: zondax/ledger-app-builder:latest
102-
options: --user ${{ needs.configure.outputs.uid_gid }}
103-
env:
104-
BOLOS_SDK: /opt/nanos-secure-sdk
105-
steps:
106-
- name: Checkout
107-
uses: actions/checkout@v4
108-
with:
109-
submodules: true
110-
- name: Install deps
111-
run: pip install ledgerblue
112-
113-
- name: Build NanoS
114-
shell: bash -l {0}
115-
run: |
116-
PRODUCTION_BUILD=0 make
117-
mv ./app/pkg/installer_s.sh ./app/pkg/installer_nanos.sh
118-
- name: Set tag
119-
id: nanos
120-
run: echo "tag_name=$(./app/pkg/installer_nanos.sh version)" >> $GITHUB_OUTPUT
121-
- name: Create or Update Release (1)
122-
id: create_release_0
123-
uses: softprops/action-gh-release@v1
124-
env:
125-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
126-
with:
127-
files: ./app/pkg/installer_nanos.sh
128-
tag_name: ${{ steps.nanos.outputs.tag_name }}
129-
draft: false
130-
prerelease: false
131-
13286
build_package_nanosp:
13387
needs: [configure, build, build_ledger, test_zemu]
13488
if: ${{ github.ref == 'refs/heads/main' }}

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ ifeq ($(BOLOS_SDK),)
2525
# In this case, there is not predefined SDK and we run dockerized
2626
# When not using the SDK, we override and build the XL complete app
2727

28-
ZXLIB_COMPILE_STAX ?= 1
2928
PRODUCTION_BUILD ?= 1
29+
SKIP_NANOS = 1
30+
31+
ifeq ($(SKIP_NANOS), 0)
32+
$(error "NanoS device is not supported")
33+
endif
34+
3035
include $(CURDIR)/deps/ledger-zxlib/dockerized_build.mk
3136

3237
else

app/Makefile

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,8 @@ endif
2222

2323
MY_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
2424

25-
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.installer_script
26-
27-
include $(BOLOS_SDK)/Makefile.defines
28-
2925
# Set the default value for PRODUCTION_BUILD to 0 if not already defined
30-
PRODUCTION_BUILD ?= 0
31-
32-
$(info ************ TARGET_NAME = [$(TARGET_NAME)])
26+
PRODUCTION_BUILD ?= 1
3327

3428
# Display whether this is a production build or for internal use
3529
ifeq ($(PRODUCTION_BUILD), 1)
@@ -38,9 +32,15 @@ else
3832
$(info ************ PRODUCTION_BUILD = [INTERNAL USE])
3933
endif
4034

41-
DEFINES += APP_BLINDSIGN_MODE_ENABLED
35+
# Display whether swap functionality is enabled or not
36+
ifeq ($(ENABLE_SWAP), 1)
37+
$(info ************ HAVE_SWAP = [ENABLED])
38+
else
39+
$(info ************ HAVE_SWAP = [DISABLED])
40+
endif
4241

4342
# Add the PRODUCTION_BUILD definition to the compiler flags
43+
DEFINES += APP_BLINDSIGN_MODE_ENABLED
4444
DEFINES += PRODUCTION_BUILD=$(PRODUCTION_BUILD)
4545

4646
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.app_testing
@@ -49,6 +49,9 @@ ifndef COIN
4949
COIN=SEI
5050
endif
5151

52+
VARIANT_PARAM=COIN
53+
VARIANT_VALUES=$(COIN)
54+
5255
include $(CURDIR)/Makefile.version
5356

5457
$(info COIN = [$(COIN)])
@@ -65,20 +68,32 @@ endef
6568
$(error "$(error_message)")
6669
endif
6770

71+
$(info PATHS LIST = $(APPPATH))
72+
6873
APP_LOAD_PARAMS = --curve secp256k1 --delete $(COMMON_LOAD_PARAMS) --path $(APPPATH)
74+
APP_SOURCE_PATH += $(MY_DIR)/../deps/jsmn/src
75+
INCLUDES_PATH += $(CURDIR)/src/common
76+
77+
ENABLE_NBGL_QRCODE ?= 1
78+
ENABLE_BLUETOOTH = 1
79+
80+
include $(BOLOS_SDK)/Makefile.target
6981

7082
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices
7183

84+
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform
85+
86+
CFLAGS += -Wvla
87+
88+
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.installer_script
89+
7290
$(info TARGET_NAME = [$(TARGET_NAME)])
7391
$(info ICONNAME = [$(ICONNAME)])
7492

7593
ifndef ICONNAME
7694
$(error ICONNAME is not set)
7795
endif
7896

79-
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform
80-
APP_SOURCE_PATH += $(MY_DIR)/../deps/jsmn/src
81-
CFLAGS += -Wvla
8297

8398
.PHONY: rust
8499
rust:
@@ -93,17 +108,10 @@ rust_clean:
93108

94109
clean: rust_clean
95110

96-
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.side_loading
97-
98-
# Import generic rules from the SDK
99-
include $(BOLOS_SDK)/Makefile.rules
100111

101112
#add dependency on custom makefile filename
102113
dep/%.d: %.c Makefile
103114

104-
listvariants:
105-
@echo VARIANTS COIN SEI
106-
107115
.PHONY: version
108116
version:
109117
@echo "v$(APPVERSION)" > app.version

app/Makefile.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ APPVERSION_M=0
33
# This is the minor version
44
APPVERSION_N=1
55
# This is the patch version
6-
APPVERSION_P=3
6+
APPVERSION_P=4

app/src/apdu_handler.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile
9797
G_io_apdu_buffer[0] = 0x01;
9898
#endif
9999

100-
G_io_apdu_buffer[1] = (LEDGER_MAJOR_VERSION >> 8) & 0xFF;
101-
G_io_apdu_buffer[2] = (LEDGER_MAJOR_VERSION >> 0) & 0xFF;
100+
G_io_apdu_buffer[1] = (MAJOR_VERSION >> 8) & 0xFF;
101+
G_io_apdu_buffer[2] = (MAJOR_VERSION >> 0) & 0xFF;
102102

103-
G_io_apdu_buffer[3] = (LEDGER_MINOR_VERSION >> 8) & 0xFF;
104-
G_io_apdu_buffer[4] = (LEDGER_MINOR_VERSION >> 0) & 0xFF;
103+
G_io_apdu_buffer[3] = (MINOR_VERSION >> 8) & 0xFF;
104+
G_io_apdu_buffer[4] = (MINOR_VERSION >> 0) & 0xFF;
105105

106-
G_io_apdu_buffer[5] = (LEDGER_PATCH_VERSION >> 8) & 0xFF;
107-
G_io_apdu_buffer[6] = (LEDGER_PATCH_VERSION >> 0) & 0xFF;
106+
G_io_apdu_buffer[5] = (PATCH_VERSION >> 8) & 0xFF;
107+
G_io_apdu_buffer[6] = (PATCH_VERSION >> 0) & 0xFF;
108108

109109
G_io_apdu_buffer[7] = !IS_UX_ALLOWED;
110110

app/src/evm/apdu_handler_evm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,6 @@ void handleSignEip191(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t
304304
CHECK_APP_CANARY()
305305

306306
view_review_init(eip191_msg_getItem, eip191_msg_getNumItems, app_sign_eip191);
307-
view_review_show(REVIEW_TXN);
307+
view_review_show(REVIEW_MSG);
308308
*flags |= IO_ASYNCH_REPLY;
309309
}

app/src/evm/evm_eip191.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,17 @@ zxerr_t eip191_msg_getItem(int8_t displayIdx, char *outKey, uint16_t outKeyLen,
6565
}
6666
case 1: {
6767
snprintf(outKey, outKeyLen, "Msg hex");
68-
uint16_t npc = 0; // Non Printable Chars Counter
68+
uint8_t is_printable = 1;
6969

70+
// Check if all characters are printable
7071
for (uint16_t i = 0; i < messageLength; i++) {
71-
npc += IS_PRINTABLE(message[i]) ? 0 /* Printable Char */ : 1 /* Non Printable Char */;
72+
if (!IS_PRINTABLE(message[i])) {
73+
is_printable = 0;
74+
break;
75+
}
7276
}
7377

74-
// msg in hex in case >= than 40% is non printable
75-
// or first char is not printable.
76-
if (messageLength > 0 && (npc * 100) / messageLength >= 40) {
78+
if (messageLength > 0 && is_printable == 0) {
7779
pageStringHex(outVal, outValLen, (const char *)message, messageLength, pageIdx, pageCount);
7880
return zxerr_ok;
7981
}
@@ -93,16 +95,14 @@ zxerr_t eip191_msg_getItem(int8_t displayIdx, char *outKey, uint16_t outKeyLen,
9395
bool eip191_msg_parse() {
9496
const uint8_t *message = tx_get_buffer() + sizeof(uint32_t);
9597
const uint16_t messageLength = tx_get_buffer_length() - sizeof(uint32_t);
96-
uint16_t npc = 0; // Non Printable Chars Counter
98+
// Check if all characters are printable
9799
for (uint16_t i = 0; i < messageLength; i++) {
98-
npc += IS_PRINTABLE(message[i]) ? 0 /* Printable Char */ : 1 /* Non Printable Char */;
99-
}
100-
// msg in hex in case >= than 40% is non printable
101-
// or first char is not printable.
102-
if (messageLength > 0 && (npc * 100) / messageLength >= 40 && !app_mode_blindsign()) {
103-
return false;
104-
} else if (messageLength > 0 && (npc * 100) / messageLength < 40) {
105-
app_mode_skip_blindsign_ui();
100+
if (!IS_PRINTABLE(message[i])) {
101+
if (!app_mode_blindsign()) {
102+
return false;
103+
}
104+
break;
105+
}
106106
}
107107

108108
return true;

fuzz/parser_parse.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
#error "This fuzz target won't work correctly with NDEBUG defined, which will cause asserts to be eliminated"
1010
#endif
1111

12-
1312
using std::size_t;
1413

1514
namespace {
16-
char PARSER_KEY[16384];
17-
char PARSER_VALUE[16384];
18-
}
15+
char PARSER_KEY[16384];
16+
char PARSER_VALUE[16384];
17+
} // namespace
1918

20-
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
21-
{
19+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
2220
parser_tx_t txObj;
2321
MEMZERO(&txObj, sizeof(txObj));
2422
parser_context_t ctx;
@@ -37,9 +35,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
3735
uint8_t num_items;
3836
rc = parser_getNumItems(&ctx, &num_items);
3937
if (rc != parser_ok) {
40-
fprintf(stderr,
41-
"error in parser_getNumItems: %s\n",
42-
parser_getErrorDescription(rc));
38+
fprintf(stderr, "error in parser_getNumItems: %s\n", parser_getErrorDescription(rc));
4339
assert(false);
4440
}
4541

@@ -49,19 +45,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
4945
uint8_t page_idx = 0;
5046
uint8_t page_count = 1;
5147
while (page_idx < page_count) {
52-
rc = parser_getItem(&ctx, i,
53-
PARSER_KEY, sizeof(PARSER_KEY),
54-
PARSER_VALUE, sizeof(PARSER_VALUE),
55-
page_idx, &page_count);
48+
rc = parser_getItem(&ctx, i, PARSER_KEY, sizeof(PARSER_KEY), PARSER_VALUE, sizeof(PARSER_VALUE), page_idx,
49+
&page_count);
5650

57-
// (void)fprintf(stderr, "%s = %s\n", PARSER_KEY, PARSER_VALUE);
51+
// (void)fprintf(stderr, "%s = %s\n", PARSER_KEY, PARSER_VALUE);
5852

5953
if (rc != parser_ok) {
60-
(void)fprintf(stderr,
61-
"error getting item %u at page index %u: %s\n",
62-
(unsigned)i,
63-
(unsigned)page_idx,
64-
parser_getErrorDescription(rc));
54+
(void)fprintf(stderr, "error getting item %u at page index %u: %s\n", (unsigned)i, (unsigned)page_idx,
55+
parser_getErrorDescription(rc));
6556
assert(false);
6657
}
6758

tests/expected_output.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
/*******************************************************************************
2-
* (c) 2019 Zondax GmbH
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
********************************************************************************/
2+
* (c) 2019 Zondax GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
********************************************************************************/
1616
#pragma once
17+
#include <json/json.h>
18+
1719
#include <fstream>
1820
#include <vector>
19-
#include <json/json.h>
2021

2122
std::vector<std::string> EVMGenerateExpectedUIOutput(const Json::Value &json, bool expertMode);

0 commit comments

Comments
 (0)