Skip to content

Commit

Permalink
Upgrade to v2.15.0 (LedgerHQ#4)
Browse files Browse the repository at this point in the history
* change main screen text

* fix left arrow in first screen

* removing webusb url

* upgrading zxlib

* disable getdeviceinfo APDU command

* adjusting tx sign fixed options
  • Loading branch information
jleni authored Jun 14, 2020
1 parent 7e20150 commit a511b01
Show file tree
Hide file tree
Showing 32 changed files with 129 additions and 77 deletions.
27 changes: 13 additions & 14 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include $(BOLOS_SDK)/Makefile.defines
# Main app configuration
APPNAME = "Cosmos"
APPVERSION_M=2
APPVERSION_N=14
APPVERSION_N=15
APPVERSION_P=0

APPPATH = "44'/118'"
Expand Down Expand Up @@ -62,24 +62,23 @@ all: default
############
# Platform

DEFINES += UNUSED\(x\)=\(void\)x
DEFINES += PRINTF\(...\)=
DEFINES += UNUSED\(x\)=\(void\)x
DEFINES += PRINTF\(...\)=

APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
DEFINES += APPVERSION=\"$(APPVERSION)\"
DEFINES += APPVERSION=\"$(APPVERSION)\"

DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_BAGL HAVE_SPRINTF
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=7 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_BAGL HAVE_SPRINTF
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=7 IO_HID_EP_LENGTH=64 HAVE_USB_APDU

DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P)
DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P)

DEFINES += USB_SEGMENT_SIZE=64
DEFINES += HAVE_BOLOS_APP_STACK_CANARY
DEFINES += NDEBUG
DEFINES += USB_SEGMENT_SIZE=64
DEFINES += HAVE_BOLOS_APP_STACK_CANARY
DEFINES += NDEBUG

WEBUSB_URL = www.ledgerwallet.com
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")
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""

ifeq ($(TARGET_NAME),TARGET_NANOX)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
Expand All @@ -91,7 +90,7 @@ DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX

DEFINES += HAVE_UX_FLOW
DEFINES += HAVE_UX_FLOW

DEFINES += HAVE_BLE
DEFINES += HAVE_BLE_APDU BLE_COMMAND_TIMEOUT_MS=2000
Expand Down
2 changes: 1 addition & 1 deletion app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef enum {
#define VIEW_ADDRESS_LAST_PAGE_DEFAULT 0

#define MENU_MAIN_APP_LINE1 "Cosmos"
#define MENU_MAIN_APP_LINE2 "Hub"
#define MENU_MAIN_APP_LINE2 "ready"
#define APPVERSION_LINE1 "Version:"
#define APPVERSION_LINE2 ("v" APPVERSION)

Expand Down
7 changes: 4 additions & 3 deletions app/src/common/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void app_init() {
// grab the current plane mode setting
G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
#endif // TARGET_NANOX

USB_power(0);
USB_power(1);

Expand Down Expand Up @@ -214,8 +214,9 @@ void app_main() {
if (rx == 0)
THROW(APDU_CODE_EMPTY_BUFFER);

handle_generic_apdu(&flags, &tx, rx);
CHECK_APP_CANARY()
// NOTE: Requested by Ledger
// handle_generic_apdu(&flags, &tx, rx);
// CHECK_APP_CANARY()

handleApdu(&flags, &tx, rx);
CHECK_APP_CANARY()
Expand Down
2 changes: 1 addition & 1 deletion app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ uint16_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len) {
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);
bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed2_pk, CX_RIPEMD160_SIZE, 1);

return PK_LEN_SECP256K1 + strlen(addr);
}
23 changes: 23 additions & 0 deletions deps/ledger-zxlib/app/common/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ void h_paging_init() {
viewdata.pageCount = 1;
}

uint8_t h_paging_can_increase() {
if (viewdata.pageIdx + 1 < viewdata.pageCount) {
return 1;
} else {
// passed page count, go to next index
if (viewdata.itemIdx + 1 < viewdata.itemCount) {
return 1;
}
}
return 0;
}

void h_paging_increase() {
if (viewdata.pageIdx + 1 < viewdata.pageCount) {
// increase page
Expand All @@ -82,6 +94,17 @@ void h_paging_increase() {
}
}

uint8_t h_paging_can_decrease() {
if (viewdata.pageIdx != 0) {
return 1;
} else {
if (viewdata.itemIdx > 0) {
return 1;
}
}
return 0;
}

void h_paging_decrease() {
if (viewdata.pageIdx != 0) {
viewdata.pageIdx--;
Expand Down
4 changes: 4 additions & 0 deletions deps/ledger-zxlib/app/common/view_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ void h_sign_reject(unsigned int _);

void h_paging_init();

uint8_t h_paging_can_increase();

void h_paging_increase();

uint8_t h_paging_can_decrease();

void h_paging_decrease();

void h_paging_set_page_count(uint8_t pageCount);
Expand Down
11 changes: 9 additions & 2 deletions deps/ledger-zxlib/app/common/view_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ UX_FLOW(
void h_review(unsigned int _) { UNUSED(_); view_sign_show_impl(); }

const ux_menu_entry_t menu_sign[] = {
{NULL, h_review, 0, NULL, "View transaction", NULL, 0, 0},
{NULL, h_sign_accept, 0, NULL, "Sign transaction", NULL, 0, 0},
{NULL, h_sign_accept, 0, NULL, "Approve", NULL, 0, 0},
{NULL, h_sign_reject, 0, NULL, "Reject", NULL, 0, 0},
UX_MENU_END
};
Expand Down Expand Up @@ -164,7 +163,15 @@ static unsigned int view_review_button(unsigned int button_mask, unsigned int bu
const bagl_element_t *view_prepro(const bagl_element_t *element) {
switch (element->component.userid) {
case UIID_ICONLEFT:
if (!h_paging_can_decrease()){
return NULL;
}
UX_CALLBACK_SET_INTERVAL(2000);
break;
case UIID_ICONRIGHT:
if (!h_paging_can_increase()){
return NULL;
}
UX_CALLBACK_SET_INTERVAL(2000);
break;
case UIID_LABELSCROLL:
Expand Down
4 changes: 2 additions & 2 deletions deps/ledger-zxlib/dockerized_build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ build: build_rust
$(info Replacing app icon)
@cp $(LEDGER_SRC)/nanos_icon.gif $(LEDGER_SRC)/glyphs/icon_app.gif
$(info calling make inside docker)
$(call run_docker,$(DOCKER_BOLOS_SDK),make -C $(DOCKER_APP_SRC))
$(call run_docker,$(DOCKER_BOLOS_SDK),make -j `nproc` -C $(DOCKER_APP_SRC))

.PHONY: buildX
buildX: build_rust
@cp $(LEDGER_SRC)/nanos_icon.gif $(LEDGER_SRC)/glyphs/icon_app.gif
@convert $(LEDGER_SRC)/nanos_icon.gif -crop 14x14+1+1 +repage -negate $(LEDGER_SRC)/nanox_icon.gif
$(call run_docker,$(DOCKER_BOLOS_SDKX),make -C $(DOCKER_APP_SRC))
$(call run_docker,$(DOCKER_BOLOS_SDKX),make -j `nproc` -C $(DOCKER_APP_SRC))

.PHONY: clean
clean:
Expand Down
3 changes: 2 additions & 1 deletion deps/ledger-zxlib/include/bech32.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ zxerr_t bech32EncodeFromBytes(char *out,
size_t out_len,
const char *hrp,
const uint8_t *in,
size_t in_len);
size_t in_len,
uint8_t pad);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/include/zxformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ __Z_INLINE uint32_t array_to_hexstr(char *dst, uint16_t dstLen, const uint8_t *s
return 0;
}

const char hexchars[] = "0123456789ABCDEF";
const char hexchars[] = "0123456789abcdef";
for (uint8_t i = 0; i < count; i++, src++) {
*dst++ = hexchars[*src >> 4u];
*dst++ = hexchars[*src & 0x0Fu];
Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/include/zxversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
#pragma once

#define ZXLIB_MAJOR 2
#define ZXLIB_MINOR 0
#define ZXLIB_MINOR 2
#define ZXLIB_PATCH 0
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/scripts/template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ python3 -m ledgerblue.loadApp -h &>/dev/null;
if [ $? -ne 0 ]; then
echo
echo "ERR: ledgerblue pip package not found."
echo "please install using 'pip3 install ledgerblue'"
echo "please install using 'pip install ledgerblue'"
echo
exit
fi
Expand Down
8 changes: 5 additions & 3 deletions deps/ledger-zxlib/src/bech32.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ zxerr_t bech32EncodeFromBytes(char *out,
size_t out_len,
const char *hrp,
const uint8_t *in,
size_t in_len) {
size_t in_len,
uint8_t pad) {
MEMZERO(out, out_len);

if (in_len > MAX_INPUT_SIZE) {
Expand All @@ -34,15 +35,16 @@ zxerr_t bech32EncodeFromBytes(char *out,

size_t hrplen = strlen(hrp);
// We set a lower bound to ensure this is safe
if (out_len < hrplen + (in_len*2) + 7) {
if (out_len < hrplen + (in_len * 2) + 7) {
return zxerr_buffer_too_small;
}

// Overestimate required size *2==(8/4) instead of *(8/5)
uint8_t tmp_data[MAX_INPUT_SIZE * 2];
size_t tmp_size = 0;
MEMZERO(tmp_data, sizeof(tmp_data));

convert_bits(tmp_data, &tmp_size, 5, in, in_len, 8, 0);
convert_bits(tmp_data, &tmp_size, 5, in, in_len, 8, pad);
if (tmp_size >= out_len) {
return zxerr_out_of_bounds;
}
Expand Down
4 changes: 2 additions & 2 deletions deps/ledger-zxlib/src/bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void bignumLittleEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen,

// get bit
const uint16_t byteIdx = bitIdx >> 3u;
const uint8_t mask = 0x80u >> (bitIdx & 0x7u);
const uint8_t mask = 0x80u >> (bitIdx & 0b111u);
carry = (binValue[binValueLen - byteIdx - 1] & mask) > 0;

// Shift bcd
Expand Down Expand Up @@ -134,7 +134,7 @@ void bignumBigEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen,

// get bit
const uint16_t byteIdx = bitIdx >> 3u;
const uint8_t mask = 0x80u >> (bitIdx & 0x7u);
const uint8_t mask = 0x80u >> (bitIdx & 0b111u);
carry = (binValue[byteIdx] & mask) > 0;

// Shift bcd
Expand Down
20 changes: 16 additions & 4 deletions deps/ledger-zxlib/tests/bech32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <gmock/gmock.h>
#include <zxmacros.h>
#include <bech32.h>
#include <hexutils.h>

namespace {
TEST(BECH32, hex_to_address) {
Expand All @@ -25,15 +26,26 @@ namespace {
uint8_t data1[] = {1, 3, 5};
uint8_t data2[] = {1, 3, 5, 7, 9, 11, 13};

auto err = bech32EncodeFromBytes(addr_out, sizeof(addr_out), hrp, data1, sizeof(data1));
auto err = bech32EncodeFromBytes(addr_out, sizeof(addr_out), hrp, data1, sizeof(data1), 0);
ASSERT_EQ(err, zxerr_ok);
std::cout << addr_out << std::endl;
ASSERT_STREQ("zx1qypse825ac", addr_out);

err = bech32EncodeFromBytes(addr_out, sizeof(addr_out), hrp, data2, sizeof(data2));
err = bech32EncodeFromBytes(addr_out, sizeof(addr_out), hrp, data2, sizeof(data2), 0);
ASSERT_EQ(err, zxerr_ok);
std::cout << addr_out << std::endl;
ASSERT_STREQ("zx1qyps2pcfpvx20dk22", addr_out);

///
err = bech32EncodeFromBytes(addr_out, sizeof(addr_out), hrp, data1, sizeof(data1), 1);
ASSERT_EQ(err, zxerr_ok);
std::cout << addr_out << std::endl;
ASSERT_STREQ("zx1qyps2ucfnzd", addr_out);

err = bech32EncodeFromBytes(addr_out, sizeof(addr_out), hrp, data2, sizeof(data2), 1);
ASSERT_EQ(err, zxerr_ok);
std::cout << addr_out << std::endl;
ASSERT_STREQ("zx1qyps2pcfpvxshamanz", addr_out);
}

TEST(BECH32, huge_input) {
Expand All @@ -42,7 +54,7 @@ namespace {

auto data = std::vector<uint8_t>(1000, 0x55);

auto err = bech32EncodeFromBytes(addr_out, sizeof(addr_out), hrp, data.data(), data.size());
auto err = bech32EncodeFromBytes(addr_out, sizeof(addr_out), hrp, data.data(), data.size(),0);
ASSERT_EQ(err, zxerr_out_of_bounds);

std::cout << addr_out << std::endl;
Expand All @@ -59,7 +71,7 @@ namespace {
// declare size to be smaller
const size_t declared_size = 52;

auto err = bech32EncodeFromBytes(addr_out, declared_size, hrp, data.data(), data.size());
auto err = bech32EncodeFromBytes(addr_out, declared_size, hrp, data.data(), data.size(), 0);
ASSERT_EQ(err, zxerr_buffer_too_small);

for (int i = declared_size; i < sizeof(addr_out); i++) {
Expand Down
Binary file modified tests_zemu/snapshots/show-address-and-sign-basic/13.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/show-address-and-sign-basic/14.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/show-address-and-sign-basic/5.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/show-address-and-sign-basic/6.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/show-address-huge/7.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/show-address/5.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/sign-basic-combined/0.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 removed tests_zemu/snapshots/sign-basic-combined/10.png
Binary file not shown.
Binary file modified tests_zemu/snapshots/sign-basic-combined/9.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/sign-basic/0.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/sign-basic/7.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 removed tests_zemu/snapshots/sign-basic/8.png
Binary file not shown.
Binary file modified tests_zemu/snapshots/sign-expert/0.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/sign-expert/14.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 removed tests_zemu/snapshots/sign-expert/15.png
Binary file not shown.
Loading

0 comments on commit a511b01

Please sign in to comment.