Skip to content

Commit

Permalink
Some additional fixes addressed on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
italo-sampaio committed Nov 14, 2022
1 parent 964df1f commit 5d0fa7e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ledger/src/ui/src/bolos_ux.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ void bolos_ux_main(void) {
// PIN is invalidated so we must check it again. The pin value
// used here is the same as in RSK_UNLOCK_CMD, so we also
// don't have a prepended length byte
validate_pin(false);
unlock_with_pin(false);
G_bolos_ux_context.exit_code = BOLOS_UX_OK;
clear_pin();
break;
Expand Down
9 changes: 5 additions & 4 deletions ledger/src/ui/src/onboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "onboard.h"

// Global onboarding flag
const unsigned char *N_onboarded_ui[1];
const unsigned char N_onboarded_ui[1];

/*
* Reset the given onboard context
Expand Down Expand Up @@ -76,7 +76,8 @@ unsigned int onboard_device(onboard_t *onboard_ctx) {
onboard_ctx->seed[i] ^= onboard_ctx->host_seed[i];
}
// The seed is now in onboard_ctx->seed, generate the mnemonic
os_memset(onboard_ctx->words_buffer, 0, sizeof(onboard_ctx->words_buffer));
explicit_bzero(onboard_ctx->words_buffer,
sizeof(onboard_ctx->words_buffer));
onboard_ctx->words_buffer_length =
bolos_ux_mnemonic_from_data((unsigned char *)onboard_ctx->seed,
sizeof(onboard_ctx->seed),
Expand Down Expand Up @@ -106,7 +107,7 @@ unsigned int onboard_device(onboard_t *onboard_ctx) {
os_global_pin_invalidate();
unsigned char output_index = CMDPOS;
SET_APDU_AT(output_index++, 2);
SET_APDU_AT(output_index++, validate_pin(true));
SET_APDU_AT(output_index++, unlock_with_pin(true));

// Turn the onboarding flag on to mark onboarding
// has been done using the UI
Expand Down Expand Up @@ -135,7 +136,7 @@ unsigned int set_host_seed(volatile unsigned int rx, onboard_t *onboard_ctx) {
}

unsigned char index = APDU_OP();
if ((index >= 0) && ((size_t)index <= sizeof(onboard_ctx->host_seed))) {
if ((index >= 0) && ((size_t)index < sizeof(onboard_ctx->host_seed))) {
onboard_ctx->host_seed[index] = APDU_AT(3);
}

Expand Down
2 changes: 0 additions & 2 deletions ledger/src/ui/src/onboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#ifndef __ONBOARD
#define __ONBOARD

#include "os.h"
#include "os_io_seproxyhal.h"
#include "pin.h"

// 128 of words (215 => hashed to 64, or 128) + HMAC_LENGTH*2 = 256
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/ui/src/pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ void clear_pin() {
}

/*
* Validates the pin currently saved to the internal pin buffer
* Uses the pin currently saved to the internal pin buffer to unlock the device
*
* @arg[in] prepended_length true if the internal buffer includes a prepended
* length byte, false otherwise
* @ret 1 if pin validated successfully, 0 otherwise
*/
unsigned int validate_pin(bool prepended_length) {
unsigned int unlock_with_pin(bool prepended_length) {
if (prepended_length) {
return os_global_pin_check(GET_PIN(), GET_PIN_LENGTH());
} else {
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/ui/src/pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ bool is_pin_valid();
void clear_pin();

/*
* Validates the pin currently saved to the internal pin buffer
* Uses the pin currently saved to the internal pin buffer to unlock the device
*
* @arg[in] prepended_length true if the internal buffer includes a prepended
* length byte, false otherwise
* @ret 1 if pin validated successfully, 0 otherwise
*/
unsigned int validate_pin(bool prepended_length);
unsigned int unlock_with_pin(bool prepended_length);

/*
* Sets the pin currently saved to the internal pin buffer as the device's pin.
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/ui/src/unlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
*/
unsigned int unlock() {
unsigned char output_index = OP;
SET_APDU_AT(output_index++, validate_pin(false));
SET_APDU_AT(output_index++, unlock_with_pin(false));
return output_index;
}

0 comments on commit 5d0fa7e

Please sign in to comment.