Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit cede2db

Browse files
authored
Merge pull request #204 from Zondax/fix-audit
2 parents 3fe6d9a + 017ce1e commit cede2db

12 files changed

Lines changed: 61 additions & 28 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ if(ENABLE_FUZZING)
4444
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,bugprone-*,cert-*,clang-analyzer-*,-cert-err58-cpp,misc-*)
4545

4646
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
47-
# require at least clang 3.2
47+
# require at least clang 10.0
4848
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
4949
message(FATAL_ERROR "Clang version must be at least 10.0!")
5050
endif()
5151
else()
5252
message(FATAL_ERROR
53-
"You are using an unsupported compiler! Fuzzing only works with Clang 10.\n"
54-
"1. Install clang-10 \n"
55-
"2. Pass -DCMAKE_C_COMPILER=clang-10 -DCMAKE_CXX_COMPILER=clang++-10")
53+
"You are using an unsupported compiler! Fuzzing only works with Clang >10.\n"
54+
"1. Install any clang >10")
5655
endif()
5756

5857
string(APPEND CMAKE_C_FLAGS " -fsanitize=fuzzer-no-link")

app/Makefile.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This is the `transaction_version` field of `Runtime`
22
APPVERSION_M=24
33
# This is the `spec_version` field of `Runtime`
4-
APPVERSION_N=1000000
4+
APPVERSION_N=10000
55
# This is the patch version of this release
66
APPVERSION_P=0

app/src/apdu_handler.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile
118118
G_io_apdu_buffer[5] = (LEDGER_PATCH_VERSION >> 8) & 0xFF;
119119
G_io_apdu_buffer[6] = (LEDGER_PATCH_VERSION >> 0) & 0xFF;
120120

121-
G_io_apdu_buffer[7] = !IS_UX_ALLOWED;
121+
// sdk won't pass the apdu message if device is locked
122+
// keeping it for backwards compatibility
123+
G_io_apdu_buffer[7] = 0;
122124

123125
G_io_apdu_buffer[8] = (TARGET_ID >> 24) & 0xFF;
124126
G_io_apdu_buffer[9] = (TARGET_ID >> 16) & 0xFF;

docs/APDUSPEC.md

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,49 @@ The general structure of commands and responses is as follows:
2727
| Return code | Description |
2828
| ----------- | ----------------------- |
2929
| 0x6400 | Execution Error |
30+
| 0x6400 | Wrong buffer length |
3031
| 0x6982 | Empty buffer |
3132
| 0x6983 | Output buffer too small |
33+
| 0x6984 | Data is invalid |
3234
| 0x6986 | Command not allowed |
35+
| 0x6987 | Tx is not initialized |
36+
| 0x6B00 | P1/P2 are invalid |
3337
| 0x6D00 | INS not supported |
3438
| 0x6E00 | CLA not supported |
3539
| 0x6F00 | Unknown |
40+
| 0x6F01 | Sign / verify error |
3641
| 0x9000 | Success |
3742

3843
---
3944

4045
## Command definition
4146

47+
### GET_DEVICE_INFO
48+
49+
#### Command
50+
51+
| Field | Type | Content | Expected |
52+
| ----- | -------- | ---------------------- | -------- |
53+
| CLA | byte (1) | Application Identifier | 0xE0 |
54+
| INS | byte (1) | Instruction ID | 0x01 |
55+
| P1 | byte (1) | Parameter 1 | 0x00 |
56+
| P2 | byte (1) | Parameter 2 | 0x00 |
57+
| L | byte (1) | Bytes in payload | 0x00 |
58+
59+
#### Response
60+
61+
| Field | Type | Content | Note |
62+
| --------- | -------- | ------------------ | ------------------------ |
63+
| TARGET_ID | byte (4) | Target Id | |
64+
| OS_LEN | byte (1) | OS version length | 0..64 |
65+
| OS | byte (?) | OS version | Non terminated string |
66+
| FLAGS_LEN | byte (1) | Flags length | 0 |
67+
| MCU_LEN | byte (1) | MCU version length | 0..64 |
68+
| MCU | byte (?) | MCU version | Non terminated string |
69+
| SW1-SW2 | byte (2) | Return code | see list of return codes |
70+
71+
---
72+
4273
### GET_VERSION
4374

4475
#### Command
@@ -53,34 +84,35 @@ The general structure of commands and responses is as follows:
5384

5485
#### Response
5586

56-
| Field | Type | Content | Note |
57-
| ------- | -------- | ---------------- | ------------------------------- |
58-
| TEST | byte (1) | Test Mode | 0xFF means test mode is enabled |
59-
| MAJOR | byte (2) | Version Major | 0..65535 |
60-
| MINOR | byte (2) | Version Minor | 0..65535 |
61-
| PATCH | byte (2) | Version Patch | 0..65535 |
62-
| LOCKED | byte (1) | Device is locked | |
63-
| SW1-SW2 | byte (2) | Return code | see list of return codes |
87+
| Field | Type | Content | Note |
88+
| --------- | -------- | ---------------- | ------------------------------- |
89+
| TEST | byte (1) | Test Mode | 0x01 means test mode is enabled |
90+
| MAJOR | byte (2) | Version Major | 0..65535 |
91+
| MINOR | byte (2) | Version Minor | 0..65535 |
92+
| PATCH | byte (2) | Version Patch | 0..65535 |
93+
| LOCKED | byte (1) | Device is locked | It'll always be 0 |
94+
| TARGET_ID | byte (4) | Target Id | |
95+
| SW1-SW2 | byte (2) | Return code | see list of return codes |
6496

6597
---
6698

6799
### INS_GET_ADDR
68100

69101
#### Command
70102

71-
| Field | Type | Content | Expected | |
72-
| ------- | -------- | ------------------------- | ----------- | --- |
73-
| CLA | byte (1) | Application Identifier | 0x99 | |
74-
| INS | byte (1) | Instruction ID | 0x01 | |
75-
| P1 | byte (1) | Request User confirmation | No = 0 | |
76-
| P2 | byte (1) | Signature scheme | Ed25519 = 0 | |
77-
| | | | Sr25519 = 1 | |
78-
| L | byte (1) | Bytes in payload | (depends) | |
79-
| Path[0] | byte (4) | Derivation Path Data | 0x80000000 | 44 |
80-
| Path[1] | byte (4) | Derivation Path Data | 0x80000000 | 434 |
81-
| Path[2] | byte (4) | Derivation Path Data | ? | |
82-
| Path[3] | byte (4) | Derivation Path Data | ? | |
83-
| Path[4] | byte (4) | Derivation Path Data | ? | |
103+
| Field | Type | Content | Expected |
104+
| ------- | -------- | ------------------------- | ----------------- |
105+
| CLA | byte (1) | Application Identifier | 0x99 |
106+
| INS | byte (1) | Instruction ID | 0x01 |
107+
| P1 | byte (1) | Request User confirmation | No = 0 |
108+
| P2 | byte (1) | Signature scheme | Ed25519 = 0 |
109+
| | | | Sr25519 = 1 |
110+
| L | byte (1) | Bytes in payload | (depends) |
111+
| Path[0] | byte (4) | Derivation Path Data | 0x80000000 \| 44 |
112+
| Path[1] | byte (4) | Derivation Path Data | 0x80000000 \| 434 |
113+
| Path[2] | byte (4) | Derivation Path Data | ? |
114+
| Path[3] | byte (4) | Derivation Path Data | ? |
115+
| Path[4] | byte (4) | Derivation Path Data | ? |
84116

85117
#### Response
86118

3 Bytes
Loading
3 Bytes
Loading
2 Bytes
Loading
2 Bytes
Loading
-7 Bytes
Loading

0 commit comments

Comments
 (0)