Skip to content

Commit 65c5f3d

Browse files
committed
Merge branch 'release-2.2.1'
2 parents d527b8b + d06d96c commit 65c5f3d

File tree

16 files changed

+379
-238
lines changed

16 files changed

+379
-238
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [2.2.1] - 2020-12-11
9+
10+
### Added
11+
- merged LedgerHQ downstream changes ([#102])
12+
13+
### Fixed
14+
- various bounds checking, value handling, and safety improvements ([#cb7f1ef])
15+
816
## [2.2.0] - 2020-11-06
917

1018
### Added
@@ -59,3 +67,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5967
[#94]: https://github.com/ArkEcosystem/ledger/pull/94
6068
[#97]: https://github.com/ArkEcosystem/ledger/pull/97
6169
[2.2.0]: https://github.com/ArkEcosystem/ledger/compare/2.1.0...2.2.0
70+
[#102]: https://github.com/ArkEcosystem/ledger/pull/102
71+
[#cb7f1ef]: https://github.com/ArkEcosystem/ledger/compare/7ed7885605453bd67af14e62bce17c2ca6f17a26...cb7f1efc5a362fe618731e122afc728da53370ba
72+
[2.2.1]: https://github.com/ArkEcosystem/ledger/compare/2.2.0...2.2.1

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ APP_LOAD_PARAMS=--appFlags 0x240 --curve secp256k1 --path "44'/111'" --path "44'
5252

5353
APPVERSION_M=2
5454
APPVERSION_N=2
55-
APPVERSION_P=0
55+
APPVERSION_P=1
5656
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
5757

5858
ifeq ($(TARGET_NAME),TARGET_BLUE)
@@ -81,7 +81,7 @@ DEFINES += HAVE_BOLOS_SDK
8181

8282
DEFINES += OS_IO_SEPROXYHAL
8383
DEFINES += HAVE_BAGL HAVE_SPRINTF
84-
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=6 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
84+
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=4 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
8585
DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P)
8686
DEFINES += COMPLIANCE_UX_160
8787
DEFINES += HAVE_UX_FLOW
@@ -94,8 +94,9 @@ DEFINES += U2F_PROXY_MAGIC=\"w0w\"
9494
DEFINES += UNUSED\(x\)=\(void\)x
9595
DEFINES += APPVERSION=\"$(APPVERSION)\"
9696

97-
WEBUSB_URL = www.ledgerwallet.com
98-
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=$(shell echo -n $(WEBUSB_URL) | wc -c) WEBUSB_URL=$(shell echo -n $(WEBUSB_URL) | sed -e "s/./\\\'\0\\\',/g")
97+
#WEBUSB_URL = www.ledgerwallet.com
98+
#DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=$(shell echo -n $(WEBUSB_URL) | wc -c) WEBUSB_URL=$(shell echo -n $(WEBUSB_URL) | sed -e "s/./\\\'\0\\\',/g")
99+
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""
99100

100101
# Nano X Defines
101102
ifeq ($(TARGET_NAME),TARGET_NANOX)

ark.png

1.72 KB
Loading

nanox_app_ark.gif

1.09 KB
Loading

src/approval.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,39 @@ unsigned int ioApprove(const bagl_element_t *e) {
7575
uint8_t privateKeyData[HASH_32_LEN];
7676
cx_ecfp_private_key_t privateKey;
7777

78-
os_perso_derive_node_bip32(CX_CURVE_256K1,
79-
tmpCtx.signing.bip32Path,
80-
tmpCtx.signing.pathLength,
81-
privateKeyData,
82-
NULL);
83-
84-
cx_ecfp_init_private_key(tmpCtx.signing.curve,
85-
privateKeyData,
86-
HASH_32_LEN,
87-
&privateKey);
88-
89-
MEMSET_BZERO(privateKeyData, sizeof(privateKeyData));
90-
91-
if (tmpCtx.signing.curve == CX_CURVE_256K1) {
92-
uint8_t hash[CX_SHA256_SIZE];
93-
hash256(tmpCtx.signing.data,
94-
tmpCtx.signing.dataLength,
95-
hash);
96-
97-
tx = tmpCtx.signing.isSchnorr
98-
? signSchnorr(&privateKey, hash, G_io_apdu_buffer)
99-
: signEcdsa(&privateKey, hash, G_io_apdu_buffer, SIG_ECDSA_MAX_LEN);
78+
BEGIN_TRY {
79+
TRY {
80+
os_perso_derive_node_bip32(CX_CURVE_256K1,
81+
tmpCtx.signing.bip32Path,
82+
tmpCtx.signing.pathLength,
83+
privateKeyData,
84+
NULL);
85+
86+
cx_ecfp_init_private_key(tmpCtx.signing.curve,
87+
privateKeyData,
88+
HASH_32_LEN,
89+
&privateKey);
90+
91+
if (tmpCtx.signing.curve == CX_CURVE_256K1) {
92+
uint8_t hash[CX_SHA256_SIZE];
93+
hash256(tmpCtx.signing.data,
94+
tmpCtx.signing.dataLength,
95+
hash);
96+
97+
tx = tmpCtx.signing.isSchnorr
98+
? signSchnorr(&privateKey, hash, G_io_apdu_buffer)
99+
: signEcdsa(&privateKey, hash,
100+
G_io_apdu_buffer, SIG_ECDSA_MAX_LEN);
101+
}
102+
}
103+
104+
FINALLY {
105+
MEMSET_BZERO(privateKeyData, sizeof(privateKeyData));
106+
MEMSET_TYPE_BZERO(&privateKey, cx_ecfp_private_key_t);
107+
MEMSET_BZERO(&tmpCtx, sizeof(tmpCtx));
108+
}
100109
}
101-
102-
MEMSET_TYPE_BZERO(&privateKey, cx_ecfp_private_key_t);
103-
MEMSET_BZERO(&tmpCtx, sizeof(tmpCtx));
110+
END_TRY;
104111

105112
G_io_apdu_buffer[tx++] = 0x90;
106113
G_io_apdu_buffer[tx++] = 0x00;

src/constants.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,8 @@ static const size_t SIG_ECDSA_MIN_LEN = 64;
7373
static const size_t SIG_ECDSA_MAX_LEN = 72;
7474
static const size_t SIG_SCHNORR_LEN = HASH_64_LEN;
7575

76-
////////////////////////////////////////////////////////////////////////////////
77-
// Strings
78-
static const size_t UINT64_MAX_STRING_SIZE = 20U;
79-
8076
////////////////////////////////////////////////////////////////////////////////
8177
// Token
82-
static const size_t TOKEN_AMOUNT_MAX_CHARS = 25U;
8378
static const size_t TOKEN_DECIMALS = 8U;
8479
static const char *const TOKEN_NAME = "ARK";
8580
static const size_t TOKEN_NAME_LEN = 3U; // strlen("ARK")
@@ -93,4 +88,7 @@ static const uint8_t TRANSACTION_VERSION_LEGACY = 0;
9388
static const uint8_t TRANSACTION_VERSION_TYPE_1 = 1;
9489
static const uint8_t TRANSACTION_VERSION_TYPE_2 = 2;
9590

91+
static const uint8_t VENDORFIELD_V1_MAX_LEN = 64;
92+
static const uint8_t VENDORFIELD_V2_MAX_LEN = 255;
93+
9694
#endif // #define ARK_CONSTANTS_H

src/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ __attribute__((section(".boot"))) int main(void) {
129129
TRY {
130130
io_seproxyhal_init();
131131

132+
#ifdef TARGET_NANOX
133+
// grab the current plane mode setting
134+
G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
135+
#endif // TARGET_NANOX
136+
132137
USB_power(0U);
133138
USB_power(1U);
134139

src/operations.c

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,29 @@ static void handlePublicKeyContext(volatile unsigned int *tx) {
145145

146146
tmpCtx.publicKey.needsChainCode = (p2Chain == P2_CHAINCODE);
147147

148-
// Derive the privateKey using the HD path.
149-
os_perso_derive_node_bip32(curve,
150-
bip32Path,
151-
bip32PathLength,
152-
privateKeyData,
153-
(tmpCtx.publicKey.needsChainCode
154-
? tmpCtx.publicKey.chainCode
155-
: NULL));
156-
157-
// Initialize the privateKey to generate the publicKey,
158-
// clearing the private data sources after each respective use.
159-
cx_ecfp_init_private_key(curve, privateKeyData, HASH_32_LEN, &privateKey);
160-
MEMSET_BZERO(&privateKeyData, sizeof(privateKeyData));
161-
162-
cx_ecfp_generate_pair(curve, &publicKey, &privateKey, 1U);
163-
MEMSET_TYPE_BZERO(&privateKey, cx_ecfp_private_key_t);
148+
BEGIN_TRY {
149+
TRY {
150+
// Derive the privateKey using the HD path.
151+
os_perso_derive_node_bip32(curve,
152+
bip32Path, bip32PathLength,
153+
privateKeyData,
154+
(tmpCtx.publicKey.needsChainCode
155+
? tmpCtx.publicKey.chainCode
156+
: NULL));
157+
158+
// Initialize the privateKey to generate the publicKey,
159+
cx_ecfp_init_private_key(curve,
160+
privateKeyData, HASH_32_LEN,
161+
&privateKey);
162+
cx_ecfp_generate_pair(curve, &publicKey, &privateKey, 1U);
163+
}
164+
165+
FINALLY {
166+
MEMSET_BZERO(&privateKeyData, sizeof(privateKeyData));
167+
MEMSET_TYPE_BZERO(&privateKey, cx_ecfp_private_key_t);
168+
}
169+
}
170+
END_TRY;
164171

165172
// Compress and write the publicKey to the APDU buffer.
166173
// (compressedPublicKeyLength(33) + publicKey)
@@ -200,6 +207,10 @@ static void handleSigningContext() {
200207
// - Set the curve-type.
201208
if (p1 == P1_FIRST) {
202209
// Set and check the path length.
210+
if (dataLength < 1) {
211+
// Not enough data
212+
THROW(0x6A80);
213+
}
203214
tmpCtx.signing.pathLength = workBuffer[0];
204215
if (tmpCtx.signing.pathLength < 1 ||
205216
tmpCtx.signing.pathLength > ADDRESS_MAX_BIP32_PATH) {
@@ -212,6 +223,10 @@ static void handleSigningContext() {
212223

213224
// Unpack the path.
214225
for (uint32_t i = 0U; i < tmpCtx.signing.pathLength; ++i) {
226+
if (dataLength < 4) {
227+
// Not enough data
228+
THROW(0x6A80);
229+
}
215230
tmpCtx.signing.bip32Path[i] = U4BE(workBuffer, 0U);
216231
workBuffer += 4U;
217232
dataLength -= 4U;
@@ -232,6 +247,9 @@ static void handleSigningContext() {
232247

233248
// Iff first payload, copy to the signing context data.
234249
if (p1 == P1_FIRST) {
250+
if (dataLength > MAX_RAW_OPERATION) {
251+
THROW(0x6A80);
252+
}
235253
tmpCtx.signing.dataLength = dataLength;
236254
MEMCOPY(tmpCtx.signing.data, workBuffer, dataLength);
237255
}

src/operations/message_op.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ bool handleMessage(const uint8_t *buffer, size_t length) {
6969
UintToString(length, displayCtx.text[0], sizeof(displayCtx.text[0]));
7070

7171
// Message Text
72-
SNPRINTF(displayCtx.text_ext, length + 1, "%s", buffer);
72+
if (!IsPrintableAscii((const char*)buffer, length, false)) {
73+
return false;
74+
}
75+
76+
SNPRINTF(displayCtx.text_ext, length + 1, "%.*s", (int)length, buffer);
7377

7478
SetUxDisplay(UX_MESSAGE_STEPS, true);
7579

0 commit comments

Comments
 (0)