Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions src/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ static uint8_t bootloader_unlocked(void)

static void bootloader_blink(void)
{
led_toggle();
delay_ms(300);
led_toggle();
led_wink();
bootloader_report_status(OP_STATUS_OK);
}

Expand Down Expand Up @@ -344,27 +342,17 @@ void bootloader_jump(void)
binary_exec(app_start_addr);
/* no return */
}
if (touch_button_press(DBB_TOUCH_TIMEOUT) == DBB_ERR_TOUCH_TIMEOUT) {
if (touch_button_press(TOUCH_TIMEOUT) == DBB_ERR_TOUCH_TIMEOUT) {
binary_exec(app_start_addr);
/* no return */
}
} else {
for (int i = 0; i < 9; i++) {
led_toggle();
delay_ms(100);
led_toggle();
delay_ms(150);
}
led_off();
led_abort();
led_abort();
}

// App not entered. Start USB API to receive boot commands
usb_suspend_action();
udc_start();

for (int i = 0; i < 6; i++) {
led_toggle();
delay_ms(100);
}
led_off();
led_abort();
}
24 changes: 15 additions & 9 deletions src/commander.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The MIT License (MIT)

Copyright (c) 2015-2018 Douglas J. Bakkum
Copyright (c) 2015-2019 Douglas J. Bakkum, Shift Cryptosecurity

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -424,7 +424,7 @@ static void commander_process_backup(yajl_val json_node)

if (strlens(erase)) {
// Erase single file
int status = touch_button_press(DBB_TOUCH_LONG);
int status = touch_button_press(TOUCH_LONG_WARN);
if (status == DBB_TOUCHED) {
sd_erase(CMD_backup, erase);
} else {
Expand Down Expand Up @@ -690,7 +690,8 @@ static int commander_check_change_keypath(yajl_val data, yajl_val checkpub)
commander_fill_report(cmd_str(CMD_sign), NULL, DBB_ERR_SIGN_KEYPATH);
return DBB_ERROR;
}
if (wallet_check_keypath_prefix(keypath_utxo_0, keypath_utxo_i, keypath_depth_0) != DBB_OK) {
if (wallet_check_keypath_prefix(keypath_utxo_0, keypath_utxo_i,
keypath_depth_0) != DBB_OK) {
commander_fill_report(cmd_str(CMD_sign), NULL, DBB_ERR_SIGN_KEYPATH);
return DBB_ERROR;
}
Expand Down Expand Up @@ -894,7 +895,7 @@ static void commander_process_device(yajl_val json_node)

if (STREQ(value, attr_str(ATTR_lock))) {
if (wallet_seeded() == DBB_OK) {
int status = touch_button_press(DBB_TOUCH_LONG);
int status = touch_button_press(TOUCH_LONG_WARN);
if (status == DBB_TOUCHED) {
char msg[256];
memory_write_unlocked(0);
Expand Down Expand Up @@ -1026,7 +1027,7 @@ static void commander_process_led(yajl_val json_node)
}

if (STREQ(value, attr_str(ATTR_blink))) {
led_abort();
led_wink();
commander_fill_report(cmd_str(CMD_led), attr_str(ATTR_success), DBB_OK);
} else {
commander_fill_report(cmd_str(CMD_led), NULL, DBB_ERR_IO_INVALID_CMD);
Expand Down Expand Up @@ -1492,11 +1493,16 @@ static int commander_touch_button(int found_cmd)
if ((found_cmd == CMD_seed || found_cmd == CMD_reset) && wallet_seeded() != DBB_OK) {
// Do not require touch if not yet seeded
return DBB_OK;
} else if ((found_cmd == CMD_seed || found_cmd == CMD_reset) &&
wallet_seeded() == DBB_OK) {
return touch_button_press(TOUCH_LONG_WARN);
} else if (found_cmd == CMD_bootloader && commander_bootloader_unlocked()) {
// Do not require touch to relock bootloader
return DBB_OK;
} else if (found_cmd < CMD_REQUIRE_TOUCH) {
return touch_button_press(DBB_TOUCH_LONG);
} else if (found_cmd == CMD_password || found_cmd == CMD_hidden_password) {
return touch_button_press(TOUCH_LONG_PW);
} else if (found_cmd == CMD_bootloader) {
return touch_button_press(TOUCH_LONG_BOOT);
} else {
return DBB_OK;
}
Expand Down Expand Up @@ -1566,7 +1572,7 @@ static void commander_parse(char *command)
memset(TFA_PIN, 0, sizeof(TFA_PIN));
}
}
status = touch_button_press(DBB_TOUCH_LONG_BLINK);
status = touch_button_press(TOUCH_LONG_SIGN);
if (status == DBB_TOUCHED) {
yajl_tree_free(json_node);
json_node = yajl_tree_parse(sign_command, NULL, 0);
Expand Down Expand Up @@ -1765,7 +1771,7 @@ static int commander_check_init(const char *encrypted_command)
}

if (memory_report_access_err_count() >= COMMANDER_TOUCH_ATTEMPTS) {
if (touch_button_press(DBB_TOUCH_LONG) != DBB_TOUCHED) {
if (touch_button_press(TOUCH_LONG_PW) != DBB_TOUCHED) {
commander_fill_report(cmd_str(CMD_input), NULL, DBB_ERR_IO_TOUCH_BUTTON);
return DBB_ERROR;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ecdh.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The MIT License (MIT)

Copyright (c) 2015-2018 Douglas J. Bakkum, Stephanie Stroka, Shift Cryptosecurity
Copyright (c) 2015-2019 Douglas J. Bakkum, Stephanie Stroka, Shift Cryptosecurity

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -103,7 +103,7 @@ static void ecdh_hash_pubkey_command(const char *pair_hash_pubkey)
return;
}

int status = touch_button_press(DBB_TOUCH_LONG);
int status = touch_button_press(TOUCH_LONG_PAIR);
if (status != DBB_TOUCHED) {
utils_zero(TFA_IN_HASH_PUB, SHA256_DIGEST_LENGTH);
commander_fill_report(cmd_str(CMD_ecdh), NULL, status);
Expand Down Expand Up @@ -222,7 +222,7 @@ static void ecdh_challenge_command(void)
TFA_VERIFY_BYTEPOS = (TFA_VERIFY_BYTEPOS + 1) % SIZE_ECDH_SHARED_SECRET;
TFA_VERIFY_BITPOS = 1;
}
led_code(two_bit + 1);
led_2FA_pairing_code(two_bit + 1);

utils_zero(encryption_and_authentication_key, SHA512_DIGEST_LENGTH);
utils_zero(encryption_and_authentication_challenge, SHA256_DIGEST_LENGTH);
Expand Down
6 changes: 2 additions & 4 deletions src/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The MIT License (MIT)

Copyright (c) 2015-2016 Douglas J. Bakkum
Copyright (c) 2015-2019 Douglas J. Bakkum, Shift Cryptosecurity

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -139,9 +139,7 @@ int main (void)
usb_suspend_action();
udc_start();

led_on();
delay_ms(300);
led_off();
led_success();

while (1) {
sleepmgr_enter_sleep();
Expand Down
23 changes: 17 additions & 6 deletions src/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The MIT License (MIT)

Copyright (c) 2015-2018 Douglas J. Bakkum
Copyright (c) 2015-2019 Douglas J. Bakkum, Shift Cryptosecurity

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -157,6 +157,18 @@ X(__FORCE__) \
X(NUM) /* keep last */


// Types of touch
#define TOUCH_TYPE_TABLE \
X(LONG_PW) /* LONG_XXXX: brief touch 'reject'; hold 3s 'accept' */\
X(LONG_SIGN) \
X(LONG_WARN) \
X(LONG_BOOT) \
X(LONG_PAIR) \
X(REQUIRE_LONG_TOUCH) /* placeholder - do not move */\
X(TIMEOUT) /* any touch 'accept'; 3s timeout 'reject' */\
X(SHORT) /* brief touch 'accept'; hold 3s 'reject' */\
X(REQUIRE_TOUCH) /* placeholder - do not move */

// Status and error flags
#define FLAG_TABLE \
X(OK, 0, 0)\
Expand All @@ -165,11 +177,6 @@ X(ERROR_MEM, 0, 0)\
X(TOUCHED, 0, 0)\
X(NOT_TOUCHED, 0, 0)\
X(TOUCHED_ABORT, 0, 0)\
X(TOUCH_SHORT, 0, 0) /* brief touch accept; hold 3s reject */\
X(TOUCH_LONG, 0, 0) /* brief touch reject; hold 3s accept (led) */\
X(TOUCH_LONG_BLINK, 0, 0) /* brief touch reject; hold 3s accept (led) */\
X(TOUCH_TIMEOUT, 0, 0) /* touch accept; 3s timeout reject */\
X(TOUCH_REJECT_TIMEOUT, 0, 0) /* touch reject; 3s timeout accept */\
X(KEY_PRESENT, 0, 0)\
X(KEY_ABSENT, 0, 0)\
X(RESET, 0, 0)\
Expand Down Expand Up @@ -255,6 +262,10 @@ enum CMD_ENUM { CMD_TABLE };
enum CMD_ATTR_ENUM { ATTR_TABLE };
#undef X

#define X(a) TOUCH_ ## a,
enum TOUCH_TYPE_ENUM { TOUCH_TYPE_TABLE };
#undef X

#define X(a, b, c) DBB_ ## a,
enum FLAG_ENUM { FLAG_TABLE };
#undef X
Expand Down
Loading