diff --git a/app/Makefile b/app/Makefile index 5b1c71b..b0fd8ee 100755 --- a/app/Makefile +++ b/app/Makefile @@ -202,7 +202,6 @@ SDK_SOURCE_PATH += lib_ux .PHONY: rust rust: @echo "No rust code" -# cd rust && CARGO_HOME="$(CURDIR)/rust/.cargo" cargo build --target thumbv6m-none-eabi --release # Before linking, we need to be sure rust lib is there bin/app.elf: rust diff --git a/app/Makefile.version b/app/Makefile.version index c18eb82..1869e56 100644 --- a/app/Makefile.version +++ b/app/Makefile.version @@ -3,4 +3,4 @@ APPVERSION_M=2 # This is the `spec_version` field of `Runtime` APPVERSION_N=0 # This is the patch version of this release -APPVERSION_P=0 +APPVERSION_P=1 diff --git a/app/src/apdu_handler.c b/app/src/apdu_handler.c index cfcaa45..efd6e45 100644 --- a/app/src/apdu_handler.c +++ b/app/src/apdu_handler.c @@ -106,11 +106,17 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) { } case INS_GET_ADDR_SECP256K1: { + if( os_global_pin_is_validated() != BOLOS_UX_OK ) { + THROW(APDU_CODE_COMMAND_NOT_ALLOWED); + } handleGetAddrSecp256K1(flags, tx, rx); break; } case INS_SIGN_SECP256K1: { + if( os_global_pin_is_validated() != BOLOS_UX_OK ) { + THROW(APDU_CODE_COMMAND_NOT_ALLOWED); + } handleSignSecp256K1(flags, tx, rx); break; } diff --git a/app/src/crypto.c b/app/src/crypto.c index 054b2c3..355d624 100644 --- a/app/src/crypto.c +++ b/app/src/crypto.c @@ -39,6 +39,7 @@ zxerr_t crypto_extractPublicKey(const uint32_t path[HDPATH_LEN_DEFAULT], uint8_t return zxerr_invalid_crypto_settings; } + zxerr_t err = zxerr_ok; BEGIN_TRY { TRY { @@ -50,10 +51,21 @@ zxerr_t crypto_extractPublicKey(const uint32_t path[HDPATH_LEN_DEFAULT], uint8_t cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &cx_privateKey); cx_ecfp_init_public_key(CX_CURVE_256K1, NULL, 0, &cx_publicKey); cx_ecfp_generate_pair(CX_CURVE_256K1, &cx_publicKey, &cx_privateKey, 1); + + // Format pubkey + for (int i = 0; i < 32; i++) { + pubKey[i] = cx_publicKey.W[64 - i]; + } + cx_publicKey.W[0] = cx_publicKey.W[64] & 1 ? 0x03 : 0x02; // "Compress" public key in place + if ((cx_publicKey.W[32] & 1) != 0) { + pubKey[31] |= 0x80; + } + ////////////////////// + MEMCPY(pubKey, cx_publicKey.W, PK_LEN_SECP256K1); + } - CATCH_OTHER(e) { - CLOSE_TRY; - return zxerr_ledger_api_error; + CATCH_ALL { + err = zxerr_ledger_api_error; } FINALLY { MEMZERO(&cx_privateKey, sizeof(cx_privateKey)); @@ -62,18 +74,7 @@ zxerr_t crypto_extractPublicKey(const uint32_t path[HDPATH_LEN_DEFAULT], uint8_t } END_TRY; - // Format pubkey - for (int i = 0; i < 32; i++) { - pubKey[i] = cx_publicKey.W[64 - i]; - } - cx_publicKey.W[0] = cx_publicKey.W[64] & 1 ? 0x03 : 0x02; // "Compress" public key in place - if ((cx_publicKey.W[32] & 1) != 0) { - pubKey[31] |= 0x80; - } - ////////////////////// - MEMCPY(pubKey, cx_publicKey.W, PK_LEN_SECP256K1); - - return zxerr_ok; + return err; } zxerr_t crypto_sign(uint8_t *signature, @@ -91,6 +92,8 @@ zxerr_t crypto_sign(uint8_t *signature, uint8_t privateKeyData[32]; unsigned int info = 0; int signatureLength = 0; + + zxerr_t err = zxerr_ok; BEGIN_TRY { TRY @@ -113,6 +116,10 @@ zxerr_t crypto_sign(uint8_t *signature, signatureMaxlen, &info); } + CATCH_ALL { + signatureLength = 0; + err = zxerr_ledger_api_error; + } FINALLY { MEMZERO(&cx_privateKey, sizeof(cx_privateKey)); MEMZERO(privateKeyData, 32); @@ -121,7 +128,7 @@ zxerr_t crypto_sign(uint8_t *signature, END_TRY; *sigSize = signatureLength; - return zxerr_ok; + return err; } #else @@ -182,7 +189,7 @@ zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrR } // extract pubkey - crypto_extractPublicKey(hdPath, buffer, buffer_len); + CHECK_ZXERR(crypto_extractPublicKey(hdPath, buffer, buffer_len)) // Hash it uint8_t hashed1_pk[CX_SHA256_SIZE]; @@ -192,7 +199,7 @@ zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrR ripemd160_32(hashed2_pk, hashed1_pk); char *addr = (char *) (buffer + PK_LEN_SECP256K1); - bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed2_pk, CX_RIPEMD160_SIZE, 1); + CHECK_ZXERR(bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed2_pk, CX_RIPEMD160_SIZE, 1)) *addrResponseLen = PK_LEN_SECP256K1 + strlen(addr); diff --git a/tests/testcases/manual.json b/tests/testcases/manual.json index 1a7481c..214ee19 100644 --- a/tests/testcases/manual.json +++ b/tests/testcases/manual.json @@ -1517,5 +1517,64 @@ "6 | Fee : 0.000600 AXL" ], "expert": false + }, + { + "name": "completeTransferExpertAxl", + "tx": { + "account_number": "0", + "chain_id": "axelar-dojo-1", + "fee": { + "amount": [ + { + "amount": "150", + "denom": "uaxl" + } + ], + "gas": "10000" + }, + "memo": "testmemo", + "msgs": [ + { + "inputs": [ + { + "address": "axelaraccaddr1d9h8qat5e4ehc5", + "coins": [ + { + "amount": "50", + "denom": "axl" + } + ] + } + ], + "outputs": [ + { + "address": "axelaraccaddr1da6hgur4wse3jx32", + "coins": [ + { + "amount": "10", + "denom": "axl" + } + ] + } + ] + } + ], + "sequence": "1" + }, + "parsingErr": "No error", + "validationErr": "No error", + "expected": [ + "0 | Chain ID : axelar-dojo-1", + "1 | Account : 0", + "2 | Sequence : 1", + "3 | Source Address : axelaraccaddr1d9h8qat5e4ehc5", + "4 | Source Coins : 50 axl", + "5 | Dest Address : axelaraccaddr1da6hgur4wse3jx32", + "6 | Dest Coins : 10 axl", + "7 | Memo : testmemo", + "8 | Fee : 150 uaxl", + "9 | Gas : 10000" + ], + "expert": true } ] diff --git a/tests_zemu/snapshots/s-mainmenu/00004.png b/tests_zemu/snapshots/s-mainmenu/00004.png index 8d46929..131ba7b 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00004.png and b/tests_zemu/snapshots/s-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00010.png b/tests_zemu/snapshots/s-mainmenu/00010.png index 8d46929..131ba7b 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00010.png and b/tests_zemu/snapshots/s-mainmenu/00010.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00004.png b/tests_zemu/snapshots/sp-mainmenu/00004.png index 608ea97..63db780 100644 Binary files a/tests_zemu/snapshots/sp-mainmenu/00004.png and b/tests_zemu/snapshots/sp-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00010.png b/tests_zemu/snapshots/sp-mainmenu/00010.png index 608ea97..63db780 100644 Binary files a/tests_zemu/snapshots/sp-mainmenu/00010.png and b/tests_zemu/snapshots/sp-mainmenu/00010.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00004.png b/tests_zemu/snapshots/x-mainmenu/00004.png index 608ea97..63db780 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00004.png and b/tests_zemu/snapshots/x-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00010.png b/tests_zemu/snapshots/x-mainmenu/00010.png index 608ea97..63db780 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00010.png and b/tests_zemu/snapshots/x-mainmenu/00010.png differ