Skip to content

Commit

Permalink
Merge pull request #13 from onflow/to_merge_with_ledgerHQ_0_9_12
Browse files Browse the repository at this point in the history
Undo getpubkey changes
  • Loading branch information
lpascal-ledger authored Dec 7, 2021
2 parents b4cc00d + 3e51e2d commit 0c7f4dd
Show file tree
Hide file tree
Showing 70 changed files with 277 additions and 535 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ jobs:
command: |
make
- run:
name: Install node + yarn
name: Install node + yarn
command: |
nvm install 12.16.2
nvm use 12.16.2
nvm install 14.4.0
nvm use 14.4.0
npm install -g yarn
- run:
name: Build/Install build js deps
command: |
nvm use 12.16.2
nvm use 14.4.0
make zemu_install
- run:
name: Run zemu tests
command: |
nvm use 12.16.2
nvm use 14.4.0
make zemu_test
no_output_timeout: 30m
no_output_timeout: 20m

build_package:
docker:
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/app/src/uint256.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_impl.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/coin.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/json/json_parser.c
app/src/base32.c
app/src/crypto.c
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ endif

APPVERSION_M=0
APPVERSION_N=9
APPVERSION_P=11
APPVERSION_P=12

$(info COIN = [$(COIN)])
ifeq ($(COIN),FLOW)
Expand Down
40 changes: 9 additions & 31 deletions app/src/account.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
********************************************************************************/
#include "account.h"
#include "coin.h"
#include "zxmacros.h"
#include "stdbool.h"
#include "apdu_codes.h"
Expand All @@ -33,9 +32,6 @@ slot_store_t NV_CONST
N_slot_store_impl __attribute__ ((aligned(64)));
#define N_slot_store (*(NV_VOLATILE slot_store_t *)PIC(&N_slot_store_impl))




uint8_t slot_is_empty(const account_slot_t *tmp) {
return tmp->path.data[0] == 0;
}
Expand Down Expand Up @@ -76,7 +72,7 @@ zxerr_t slot_getItem(int8_t displayIdx,
}
case 1: {
snprintf(outKey, outKeyLen, "Account");
array_to_hexstr_with_0x(outVal, outValLen, tmp_slot.account.data, 8);
array_to_hexstr(outVal, outValLen, tmp_slot.account.data, 8);
return zxerr_ok;
}
case 2: {
Expand All @@ -100,7 +96,7 @@ zxerr_t slot_getItem(int8_t displayIdx,
}
case 1: {
snprintf(outKey, outKeyLen, "Old Account");
array_to_hexstr_with_0x(outVal, outValLen, oldSlot->account.data, 8);
array_to_hexstr(outVal, outValLen, oldSlot->account.data, 8);
return zxerr_ok;
}
case 2: {
Expand All @@ -112,7 +108,7 @@ zxerr_t slot_getItem(int8_t displayIdx,
}
case 3: {
snprintf(outKey, outKeyLen, "New Account");
array_to_hexstr_with_0x(outVal, outValLen, tmp_slot.account.data, 8);
array_to_hexstr(outVal, outValLen, tmp_slot.account.data, 8);
return zxerr_ok;
}
case 4: {
Expand All @@ -137,7 +133,7 @@ zxerr_t slot_getItem(int8_t displayIdx,
}
case 1: {
snprintf(outKey, outKeyLen, "Old Account");
array_to_hexstr_with_0x(outVal, outValLen, oldSlot->account.data, 8);
array_to_hexstr(outVal, outValLen, oldSlot->account.data, 8);
return zxerr_ok;
}
case 2: {
Expand Down Expand Up @@ -208,10 +204,13 @@ zxerr_t slot_parseSlot(uint8_t *buffer, uint16_t bufferLen) {
return zxerr_out_of_bounds;
}

//We copy account and path. Note that path is copied in app_main.c:extractHDPath (for sign transaction call).
MEMCPY(&tmp_slot, buffer + 1, sizeof(account_slot_t));

if (!path_is_mainnet(tmp_slot.path) && !path_is_testnet(tmp_slot.path) && !path_is_empty(tmp_slot.path)) {
const bool mainnet = tmp_slot.path.data[0] == HDPATH_0_DEFAULT && tmp_slot.path.data[1] == HDPATH_1_DEFAULT;
const bool testnet = tmp_slot.path.data[0] == HDPATH_0_TESTNET && tmp_slot.path.data[1] == HDPATH_1_TESTNET;
const bool empty = tmp_slot.path.data[0] == 0 && tmp_slot.path.data[1] == 0;

if (!mainnet && !testnet && !empty) {
array_to_hexstr(bufferUI, sizeof(bufferUI), tmp_slot.account.data, 8);
zemu_log(bufferUI);
zemu_log("\n");
Expand All @@ -224,27 +223,6 @@ zxerr_t slot_parseSlot(uint8_t *buffer, uint16_t bufferLen) {
return zxerr_out_of_bounds;
}

//account validation
if (!path_is_empty(tmp_slot.path)) { //no validation required if the new slot should be empty
uint64_t account = 0;
//LE <-> BE conversion necessary to validate account
for(int i=0; i<SLOT_ACCOUNT_SIZE; i++) account = 256*account + tmp_slot.account.data[i];

if (path_is_mainnet(tmp_slot.path)) {
if (!validateChainAddress(CODEWORD_MAINNET, account)) {
zemu_log_stack("invalid account");
return zxerr_out_of_bounds;
}
}
if (path_is_testnet(tmp_slot.path)) {
if (!validateChainAddress(CODEWORD_TESTNET, account) &&
!validateChainAddress(CODEWORD_EMULATORNET, account)) {
zemu_log_stack("invalid account");
return zxerr_out_of_bounds;
}
}
}

tmp_slotop = SLOT_OP_UPDATE;
if (slot_is_empty(&N_slot_store.slot[tmp_slotIdx])) {
tmp_slotop = SLOT_OP_SET;
Expand Down
20 changes: 4 additions & 16 deletions app/src/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ typedef struct {
uint8_t data[SLOT_ACCOUNT_SIZE];
} flow_account_t;

typedef struct {
uint32_t data[HDPATH_LEN_DEFAULT];
} flow_path_t;

typedef struct {
flow_account_t account;
flow_path_t path;
Expand Down Expand Up @@ -57,22 +61,6 @@ zxerr_t slot_parseSlot(uint8_t *buffer, uint16_t bufferLen);

void app_slot_setSlot();

//To add to zxlib after fork
//For now just plain display
__Z_INLINE uint32_t array_to_hexstr_with_0x(char *dst, uint16_t dstLen, const uint8_t *src, uint8_t count) {
/* if (dstLen < 2) {
return 0;
}
dst[0]='0';
dst[1]='x';
uint32_t res = array_to_hexstr(dst+2, dstLen-2, src, count);
if (res == 0) {
return 0;
}
return res;*/
return array_to_hexstr(dst, dstLen, src, count);
}

#ifdef __cplusplus
}
#endif
40 changes: 7 additions & 33 deletions app/src/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,40 @@
********************************************************************************/

#include <stdio.h>
#include <os.h>
#include "coin.h"
#include "zxerror.h"
#include "zxmacros.h"
#include "app_mode.h"
#include "crypto.h"
#include "account.h"

zxerr_t addr_getNumItems(uint8_t *num_items) {
zemu_log_stack("addr_getNumItems");
*num_items = 1;
if (app_mode_expert()) {
*num_items = 4;
return zxerr_ok;
*num_items = 2;
}
*num_items = 3;
return zxerr_ok;
}

//To add to zxlib after fork
__Z_INLINE void pageHexStringFromBuf(char *outValue, uint16_t outValueLen,
uint8_t *inValue, uint16_t inValueLen,
uint8_t pageIdx, uint8_t *pageCount) {
char buf[2*inValueLen+1];
uint_fast32_t len = array_to_hexstr(buf, sizeof(buf), inValue, inValueLen);
if (len == 0) {
return;
}
pageString(outValue, outValueLen, buf, pageIdx, pageCount);
}


zxerr_t addr_getItem(int8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
zemu_log_stack("addr_getItem");
switch (displayIdx) {
case 0: {
snprintf(outKey, outKeyLen, "Account");
array_to_hexstr_with_0x(outVal, outValLen, G_io_apdu_buffer, sizeof(flow_account_t));
return zxerr_ok;
}
case 1: {
case 0:
snprintf(outKey, outKeyLen, "Pub Key");
pageHexStringFromBuf(outVal, outValLen, G_io_apdu_buffer + sizeof(flow_account_t), PUBLIC_KEY_LEN, pageIdx, pageCount);
// +2 is to skip 0x04 prefix that indicates uncompresed key
pageString(outVal, outValLen, (char *) (G_io_apdu_buffer + VIEW_ADDRESS_OFFSET_SECP256K1 + 2), pageIdx, pageCount);
return zxerr_ok;
}
case 2: {
snprintf(outKey, outKeyLen, "Warning");
pageString(outVal, outValLen, "Ledger does not check if the on-chain account includes the pub key!", pageIdx, pageCount);
return zxerr_ok;
}
case 3: {
case 1: {
if (!app_mode_expert()) {
return zxerr_no_data;
}

snprintf(outKey, outKeyLen, "Your Path");
char buffer[300];
bip32_to_str(buffer, sizeof(buffer), hdPath.data, HDPATH_LEN_DEFAULT);
bip32_to_str(buffer, sizeof(buffer), hdPath, HDPATH_LEN_DEFAULT);
pageString(outVal, outValLen, buffer, pageIdx, pageCount);
return zxerr_ok;
}
Expand Down
39 changes: 5 additions & 34 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,12 @@
#include "zxmacros.h"

__Z_INLINE void handleGetPubkey(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
if (rx != 6) {
THROW(APDU_CODE_DATA_INVALID);
}

uint8_t displayAndConfirm = G_io_apdu_buffer[OFFSET_P1];
const uint8_t slotIdx = G_io_apdu_buffer[OFFSET_DATA];

char buffer[20];
snprintf(buffer, sizeof(buffer), "%d", slotIdx);
zemu_log_stack(buffer);

account_slot_t slot;
zxerr_t err = slot_getSlot(slotIdx,(uint8_t *) &slot, sizeof(slot));
snprintf(buffer, sizeof(buffer), "err: %d", err);
zemu_log_stack(buffer);

if (err == zxerr_no_data) {
zemu_log_stack("Empty slot");
THROW(APDU_CODE_DATA_INVALID);
}
if (err != zxerr_ok) {
THROW(APDU_CODE_EXECUTION_ERROR);
}

MEMCPY(&hdPath, slot.path.data, sizeof(hdPath));

//We fill account and pubkey
MEMCPY(G_io_apdu_buffer, &slot.account, sizeof(slot.account));
extractHDPath(rx, OFFSET_DATA);

*tx = sizeof(slot.account);
*tx += app_fill_pubkey(G_io_apdu_buffer + sizeof(slot.account), IO_APDU_BUFFER_SIZE - sizeof(slot.account));
uint8_t requireConfirmation = G_io_apdu_buffer[OFFSET_P1];

//Display or return the buffer
if (displayAndConfirm) {
//we set the returning length for app_reply_address
action_addr_len = *tx;
if (requireConfirmation) {
app_fill_address();

view_review_init(addr_getItem, addr_getNumItems, app_reply_address);
view_review_show();
Expand All @@ -75,6 +45,7 @@ __Z_INLINE void handleGetPubkey(volatile uint32_t *flags, volatile uint32_t *tx,
return;
}

*tx = app_fill_address();
THROW(APDU_CODE_OK);
}

Expand Down
58 changes: 0 additions & 58 deletions app/src/coin.c

This file was deleted.

Loading

0 comments on commit 0c7f4dd

Please sign in to comment.