Skip to content

Commit 5cbe512

Browse files
authored
Fix HDPath validation and CLA in recovery app (#10)
* fix hdpath validation * bump version * fix cla for generic * add API avail recovery app * update zxlib and js
1 parent 0a064c6 commit 5cbe512

File tree

198 files changed

+152
-12
lines changed

Some content is hidden

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

198 files changed

+152
-12
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ zemu_install: tests_tools_build
4848

4949
test_all:
5050
make zemu_install
51+
52+
echo "Testing recovery"
53+
make clean
54+
SUBSTRATE_PARSER_FULL=1 COIN=AVAIL_RECOVERY make
55+
cd tests_zemu && yarn test_recovery && cd ..
56+
57+
echo "Testing standard"
58+
make clean
5159
SUBSTRATE_PARSER_FULL=1 make
5260
make clean_build
5361
SUBSTRATE_PARSER_FULL=1 SUPPORT_SR25519=1 make buildS

app/Makefile.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ APPVERSION_M=1
33
# This is the `spec_version` field of `Runtime`
44
APPVERSION_N=39
55
# This is the patch version of this release
6-
APPVERSION_P=0
6+
APPVERSION_P=1

app/src/apdu_handler.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ void extractHDPath(uint32_t rx, uint32_t offset) {
4343

4444
memcpy(hdPath, G_io_apdu_buffer + offset, sizeof(uint32_t) * HDPATH_LEN_DEFAULT);
4545

46+
#ifdef RECOVERY_APP
47+
const bool mainnet = hdPath[0] == HDPATH_0_DEFAULT &&
48+
hdPath[1] == HDPATH_1_RECOVERY;
49+
#else
4650
const bool mainnet = hdPath[0] == HDPATH_0_DEFAULT &&
4751
hdPath[1] == HDPATH_1_DEFAULT;
52+
#endif
4853

4954
if (!mainnet) {
5055
THROW(APDU_CODE_DATA_INVALID);
@@ -249,9 +254,15 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
249254
{
250255
TRY
251256
{
257+
#ifdef RECOVERY_APP
258+
if (G_io_apdu_buffer[OFFSET_CLA] != CLA_RECOVERY) {
259+
THROW(APDU_CODE_CLA_NOT_SUPPORTED);
260+
}
261+
#else
252262
if (G_io_apdu_buffer[OFFSET_CLA] != CLA) {
253263
THROW(APDU_CODE_CLA_NOT_SUPPORTED);
254264
}
265+
#endif
255266

256267
if (rx < APDU_MIN_LENGTH) {
257268
THROW(APDU_CODE_WRONG_LENGTH);

app/src/substrate/substrate_coin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ extern "C" {
2121

2222
#define COIN_ADDR_TYPE 42
2323
#define CLA 0xbc
24+
#define CLA_RECOVERY 0xbe
2425

2526
#define INS_SIGN_RAW 0x03
2627

2728
#define HDPATH_LEN_DEFAULT 5
2829
#define HDPATH_0_DEFAULT (0x80000000 | 0x2c)
2930
#define HDPATH_1_DEFAULT (0x80000000 | 0x2c5)
30-
#define HDPATH_1_RECOVERY (0x80000000 | 0x2c5)
31+
#define HDPATH_1_RECOVERY (0x80000000 | 0x162)
3132

3233
#define HDPATH_2_DEFAULT (0x80000000u | 0u)
3334
#define HDPATH_3_DEFAULT (0u)

tests_zemu/package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,31 @@
1515
],
1616
"scripts": {
1717
"clean": "ts-node tests/pullImageKillOld.ts",
18-
"test": "yarn clean && jest --maxConcurrency 3"
18+
"test": "yarn clean && jest --maxConcurrency 3 --testPathIgnorePatterns recovery.test.ts",
19+
"test_recovery": "yarn clean && jest --maxConcurrency 3 recovery.test.ts"
1920
},
2021
"dependencies": {
21-
"@zondax/ledger-substrate": "^1.0.0",
22-
"@zondax/zemu": "^0.51.0"
22+
"@zondax/ledger-substrate": "^1.0.1",
23+
"@zondax/zemu": "^0.53.0"
2324
},
2425
"devDependencies": {
2526
"@types/jest": "^29.5.14",
2627
"@types/ledgerhq__hw-transport": "^4.21.8",
27-
"@typescript-eslint/eslint-plugin": "^8.12.2",
28-
"@typescript-eslint/parser": "^8.12.2",
28+
"@typescript-eslint/eslint-plugin": "^8.18.1",
29+
"@typescript-eslint/parser": "^8.18.1",
2930
"blakejs": "^1.2.1",
3031
"crypto-js": "4.2.0",
3132
"ed25519-supercop": "^2.0.1",
32-
"eslint": "^9.13.0",
33+
"eslint": "^9.17.0",
3334
"eslint-config-prettier": "^9.1.0",
3435
"eslint-plugin-import": "^2.31.0",
35-
"eslint-plugin-jest": "^28.8.3",
36+
"eslint-plugin-jest": "^28.9.0",
3637
"eslint-plugin-prettier": "^5.2.1",
3738
"jest": "29.7.0",
3839
"jssha": "^3.3.1",
39-
"prettier": "^3.3.3",
40+
"prettier": "^3.4.2",
4041
"ts-jest": "^29.2.5",
4142
"ts-node": "^10.9.2",
42-
"typescript": "^5.6.3"
43+
"typescript": "^5.7.2"
4344
}
4445
}
-210 Bytes
10.7 KB
16.7 KB
14 KB

0 commit comments

Comments
 (0)