Skip to content

Commit

Permalink
Merge pull request #92 from cosmos/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
ftheirs authored May 25, 2023
2 parents d532a94 + 201e322 commit 29acf41
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=35
# This is the patch version of this release
APPVERSION_P=8
APPVERSION_P=9
6 changes: 3 additions & 3 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ __Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint
if (!process_chunk(tx, rx)) {
THROW(APDU_CODE_OK);
}

// Let grab P2 value and if it's not valid, the parser should reject it
const tx_type_e sign_type = (tx_type_e) G_io_apdu_buffer[OFFSET_P2];

Expand Down Expand Up @@ -179,7 +179,7 @@ __Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint
}

void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
uint16_t sw = 0;
volatile uint16_t sw = 0;

BEGIN_TRY
{
Expand Down Expand Up @@ -231,7 +231,7 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
break;
}
G_io_apdu_buffer[*tx] = sw >> 8;
G_io_apdu_buffer[*tx + 1] = sw;
G_io_apdu_buffer[*tx + 1] = sw & 0xFF;
*tx += 2;
}
FINALLY
Expand Down
16 changes: 8 additions & 8 deletions app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ zxerr_t crypto_extractUncompressedPublicKey(const uint32_t path[HDPATH_LEN_DEFAU
return zxerr_invalid_crypto_settings;
}

zxerr_t err = zxerr_unknown;
volatile zxerr_t err = zxerr_unknown;
BEGIN_TRY
{
TRY {
Expand Down Expand Up @@ -86,8 +86,8 @@ __Z_INLINE zxerr_t compressPubkey(const uint8_t *pubkey, uint16_t pubkeyLen, uin
}

zxerr_t crypto_sign(uint8_t *signature,
uint16_t signatureMaxlen,
uint16_t *sigSize) {
uint16_t signatureMaxlen,
uint16_t *sigSize) {
uint8_t messageDigest[CX_SHA256_SIZE] = {0};

// Hash it
Expand All @@ -112,12 +112,12 @@ zxerr_t crypto_sign(uint8_t *signature,
break;
}

cx_ecfp_private_key_t cx_privateKey;
uint8_t privateKeyData[32];
cx_ecfp_private_key_t cx_privateKey = {0};
uint8_t privateKeyData[32] = {0};
unsigned int info = 0;
int signatureLength = 0;
volatile int signatureLength = 0;

zxerr_t err = zxerr_unknown;
volatile zxerr_t err = zxerr_unknown;
BEGIN_TRY
{
TRY
Expand Down Expand Up @@ -197,7 +197,7 @@ zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrR
CHECK_ZXERR(compressPubkey(uncompressedPubkey, sizeof(uncompressedPubkey), buffer, buffer_len))
char *addr = (char *) (buffer + PK_LEN_SECP256K1);

uint8_t hashed1_pk[CX_SHA256_SIZE];
uint8_t hashed1_pk[CX_SHA256_SIZE] = {0};
if (isEthPath) {
cx_sha3_t ctx;
if (cx_keccak_init_no_throw(&ctx, 256) != CX_OK) {
Expand Down
12 changes: 11 additions & 1 deletion app/src/tx_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,20 +530,30 @@ parser_error_t tx_display_translation(char *dst, uint16_t dstLen, char *src, uin
char *p = src;
uint16_t count = 0;

while (*p) {
while (p < src + srcLen) {
utf8_int32_t tmp_codepoint = 0;
p = utf8codepoint(p, &tmp_codepoint);

if (tmp_codepoint < 0x0F || tmp_codepoint == 0x5C) {
bool found = false;
for (size_t i = 0; i < array_length(ascii_substitutions); i++) {
if ((char)tmp_codepoint == ascii_substitutions[i].ascii_code) {
ASSERT_PTR_BOUNDS(count, dstLen);
*dst++ = '\\';
ASSERT_PTR_BOUNDS(count, dstLen);
*dst++ = ascii_substitutions[i].str;
found = true;
break;
}
}
if (!found) {
// Write out the value as a hex escape, \xNN
if (count > dstLen) {
return parser_unexpected_value;
}
snprintf(dst, 4, "\\x%.02X", tmp_codepoint);
dst += 4;
}
} else if (tmp_codepoint >= 32 && tmp_codepoint<=((int32_t) 0x7F)) {
ASSERT_PTR_BOUNDS(count, dstLen);
*dst++ = (char) tmp_codepoint;
Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib
1 change: 1 addition & 0 deletions docs/APDUSPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The general structure of commands and responses is as follows:
| MINOR | byte (1) | Version Minor | |
| PATCH | byte (1) | Version Patch | |
| LOCKED | byte (1) | Device is locked | |
| TARGET_ID | byte (4) | Device ID | Identifier for NanoS/SP/X/ or Stax |
| SW1-SW2 | byte (2) | Return code | see list of return codes |

--------------
Expand Down
2 changes: 1 addition & 1 deletion tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@zondax/ledger-cosmos-js": "^3.0.2",
"@zondax/zemu": "^0.42.0"
"@zondax/zemu": "^0.42.1"
},
"devDependencies": {
"@types/jest": "^29.2.3",
Expand Down
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 29acf41

Please sign in to comment.