firmware: rework protectChangePin

bootloader: wait for flash operation to finish
This commit is contained in:
Pavol Rusnak 2017-09-04 17:09:34 +02:00
parent 36f3b7fe09
commit 41901a8056
6 changed files with 27 additions and 24 deletions

View File

@ -439,6 +439,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
if (brand_new_firmware || button.YesUp) { if (brand_new_firmware || button.YesUp) {
// backup metadata // backup metadata
backup_metadata(meta_backup); backup_metadata(meta_backup);
flash_wait_for_last_operation();
flash_clear_status_flags(); flash_clear_status_flags();
flash_unlock(); flash_unlock();
// erase metadata area // erase metadata area
@ -452,6 +453,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
flash_erase_sector(i, FLASH_CR_PROGRAM_X32); flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
} }
layoutProgress("INSTALLING ... Please wait", 0); layoutProgress("INSTALLING ... Please wait", 0);
flash_wait_for_last_operation();
flash_lock(); flash_lock();
// check that metadata was succesfully erased // check that metadata was succesfully erased

View File

@ -212,24 +212,27 @@ bool protectPin(bool use_cached)
bool protectChangePin(void) bool protectChangePin(void)
{ {
const char *pin; static CONFIDENTIAL char pin_compare[17];
char pin1[17], pin2[17];
pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewFirst, _("Please enter new PIN:")); const char *pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewFirst, _("Please enter new PIN:"));
if (!pin) { if (!pin) {
return false; return false;
} }
strlcpy(pin1, pin, sizeof(pin1));
strlcpy(pin_compare, pin, sizeof(pin_compare));
pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewSecond, _("Please re-enter new PIN:")); pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewSecond, _("Please re-enter new PIN:"));
if (!pin) {
return false; const bool result = pin && (strncmp(pin_compare, pin, sizeof(pin_compare)) == 0);
}
strlcpy(pin2, pin, sizeof(pin2)); if (result) {
if (strcmp(pin1, pin2) == 0) { storage_setPin(pin_compare);
storage_setPin(pin1);
return true;
} else {
return false;
} }
memset(pin_compare, 0, sizeof(pin_compare));
return result;
} }
bool protectPassphrase(void) bool protectPassphrase(void)

View File

@ -32,7 +32,6 @@
#include "rng.h" #include "rng.h"
#include "hmac.h" #include "hmac.h"
#include "util.h" #include "util.h"
#include "macros.h"
#include "gettext.h" #include "gettext.h"
#include "u2f/u2f.h" #include "u2f/u2f.h"
@ -274,7 +273,7 @@ void u2fhid_wink(const uint8_t *buf, uint32_t len)
dialog_timeout = U2F_TIMEOUT; dialog_timeout = U2F_TIMEOUT;
U2FHID_FRAME f; U2FHID_FRAME f;
MEMSET_BZERO(&f, sizeof(f)); memset(&f, 0, sizeof(f));
f.cid = cid; f.cid = cid;
f.init.cmd = U2FHID_WINK; f.init.cmd = U2FHID_WINK;
f.init.bcntl = 0; f.init.bcntl = 0;
@ -294,7 +293,7 @@ void u2fhid_init(const U2FHID_FRAME *in)
return; return;
} }
MEMSET_BZERO(&f, sizeof(f)); memset(&f, 0, sizeof(f));
f.cid = in->cid; f.cid = in->cid;
f.init.cmd = U2FHID_INIT; f.init.cmd = U2FHID_INIT;
f.init.bcnth = 0; f.init.bcnth = 0;
@ -374,7 +373,7 @@ void send_u2fhid_msg(const uint8_t cmd, const uint8_t *data, const uint32_t len)
// debugLog(0, "", "send_u2fhid_msg"); // debugLog(0, "", "send_u2fhid_msg");
MEMSET_BZERO(&f, sizeof(f)); memset(&f, 0, sizeof(f));
f.cid = cid; f.cid = cid;
f.init.cmd = cmd; f.init.cmd = cmd;
f.init.bcnth = len >> 8; f.init.bcnth = len >> 8;
@ -390,7 +389,7 @@ void send_u2fhid_msg(const uint8_t cmd, const uint8_t *data, const uint32_t len)
// Cont packet(s) // Cont packet(s)
for (; l > 0; l -= psz, p += psz) { for (; l > 0; l -= psz, p += psz) {
// debugLog(0, "", "send_u2fhid_msg con"); // debugLog(0, "", "send_u2fhid_msg con");
MEMSET_BZERO(&f.cont.data, sizeof(f.cont.data)); memset(&f.cont.data, 0, sizeof(f.cont.data));
f.cont.seq = seq++; f.cont.seq = seq++;
psz = MIN(sizeof(f.cont.data), l); psz = MIN(sizeof(f.cont.data), l);
memcpy(f.cont.data, p, psz); memcpy(f.cont.data, p, psz);
@ -407,7 +406,7 @@ void send_u2fhid_error(uint32_t fcid, uint8_t err)
{ {
U2FHID_FRAME f; U2FHID_FRAME f;
MEMSET_BZERO(&f, sizeof(f)); memset(&f, 0, sizeof(f));
f.cid = fcid; f.cid = fcid;
f.init.cmd = U2FHID_ERROR; f.init.cmd = U2FHID_ERROR;
f.init.bcntl = 1; f.init.bcntl = 1;
@ -585,8 +584,7 @@ void u2f_register(const APDU *a)
if (last_req_state == REG_PASS) { if (last_req_state == REG_PASS) {
uint8_t data[sizeof(U2F_REGISTER_RESP) + 2]; uint8_t data[sizeof(U2F_REGISTER_RESP) + 2];
U2F_REGISTER_RESP *resp = (U2F_REGISTER_RESP *)&data; U2F_REGISTER_RESP *resp = (U2F_REGISTER_RESP *)&data;
MEMSET_BZERO(data, sizeof(data)); memset(data, 0, sizeof(data));
resp->registerId = U2F_REGISTER_ID; resp->registerId = U2F_REGISTER_ID;
resp->keyHandleLen = KEY_HANDLE_LEN; resp->keyHandleLen = KEY_HANDLE_LEN;

View File

@ -10,7 +10,7 @@ SECTIONS
{ {
.confidential (NOLOAD) : { .confidential (NOLOAD) : {
*(confidential) *(confidential)
ASSERT ((SIZEOF(.confidential) <= 32K), "Error: Confidential section too big!"); ASSERT ((SIZEOF(.confidential) <= 33K), "Error: Confidential section too big!");
} >ram } >ram
} }

View File

@ -10,7 +10,7 @@ SECTIONS
{ {
.confidential (NOLOAD) : { .confidential (NOLOAD) : {
*(confidential) *(confidential)
ASSERT ((SIZEOF(.confidential) <= 32K), "Error: Confidential section too big!"); ASSERT ((SIZEOF(.confidential) <= 33K), "Error: Confidential section too big!");
} >ram } >ram
} }

View File

@ -10,7 +10,7 @@ SECTIONS
{ {
.confidential (NOLOAD) : { .confidential (NOLOAD) : {
*(confidential) *(confidential)
ASSERT ((SIZEOF(.confidential) <= 32K), "Error: Confidential section too big!"); ASSERT ((SIZEOF(.confidential) <= 33K), "Error: Confidential section too big!");
} >ram } >ram
} }