Skip to content

Commit

Permalink
clean up settings, clear mnemonic memory on scene exit
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 1, 2023
1 parent e924a45 commit 6619222
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
2 changes: 1 addition & 1 deletion flipbip39.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FlipBip39* flipbip39_app_alloc() {
app->haptic = 1;
app->speaker = 1;
app->led = 1;
app->bip39_strength = 256;
app->bip39_strength = 1; // 256 bits (24 words)

view_dispatcher_add_view(app->view_dispatcher, FlipBip39ViewIdMenu, submenu_get_view(app->submenu));
app->flipbip39_startscreen = flipbip39_startscreen_alloc();
Expand Down
4 changes: 2 additions & 2 deletions flipbip39.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ typedef enum {
} FlipBip39LedState;

typedef enum {
FlipBip39Strength128 = 128,
FlipBip39Strength256 = 256,
FlipBip39Strength128,
FlipBip39Strength256,
} FlipBip39StrengthState;
16 changes: 8 additions & 8 deletions scenes/flipbip39_scene_settings.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "../flipbip39.h"
#include <lib/toolbox/value_index.h>

enum SettingsIndex {
SettingsIndexBip39Strength = 10,
SettingsIndexHaptic,
SettingsIndexValue1,
SettingsIndexValue2,
};
// enum SettingsIndex {
// SettingsIndexBip39Strength = 10,
// SettingsIndexHaptic,
// SettingsIndexValue1,
// SettingsIndexValue2,
// };

const char* const haptic_text[2] = {
"OFF",
Expand Down Expand Up @@ -36,12 +36,12 @@ const uint32_t led_value[2] = {
};

const char* const bip39_strength_text[2] = {
"24",
"12",
"24",
};
const uint32_t bip39_strength_value[2] = {
FlipBip39Strength256,
FlipBip39Strength128,
FlipBip39Strength256,
};

static void flipbip39_scene_settings_set_haptic(VariableItem* item) {
Expand Down
43 changes: 37 additions & 6 deletions views/flipbip39_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
#include <input/input.h>
#include <gui/elements.h>
#include <dolphin/dolphin.h>
#include "../helpers/flipbip39_haptic.h"
#include "../helpers/flipbip39_speaker.h"
#include "../helpers/flipbip39_led.h"

#include <string.h>
#include "../crypto/bip32.h"
// #include "../crypto/bip32.h"
#include "../crypto/bip39.h"
#include "../crypto/ecdsa.h"
#include "../crypto/curves.h"
// #include "../crypto/ecdsa.h"
// #include "../crypto/curves.h"
#include "../crypto/memzero.h"

struct FlipBip39Scene1 {
View* view;
Expand All @@ -19,6 +23,7 @@ struct FlipBip39Scene1 {


typedef struct {
int strength;
const char* mnemonic1;
const char* mnemonic2;
const char* mnemonic3;
Expand All @@ -45,6 +50,7 @@ void flipbip39_scene_1_draw(Canvas* canvas, FlipBip39Scene1Model* model) {
//canvas_draw_str_aligned(canvas, 0, 10, AlignLeft, AlignTop, "This is Scene 1");

canvas_set_font(canvas, FontSecondary);
//canvas_draw_str_aligned(canvas, 1, 2, AlignLeft, AlignTop, model->strength == 128 ? "128-bit" : "256-bit");
canvas_draw_str_aligned(canvas, 1, 2, AlignLeft, AlignTop, model->mnemonic1);
canvas_draw_str_aligned(canvas, 1, 12, AlignLeft, AlignTop, model->mnemonic2);
canvas_draw_str_aligned(canvas, 1, 22, AlignLeft, AlignTop, model->mnemonic3);
Expand All @@ -56,6 +62,7 @@ void flipbip39_scene_1_draw(Canvas* canvas, FlipBip39Scene1Model* model) {

static void flipbip39_scene_1_model_init(FlipBip39Scene1Model* const model, const int strength) {
// Generate a random mnemonic using trezor-crypto
model->strength = strength;
const char* mnemonic = mnemonic_generate(strength);

// Delineate 6 sections of the mnemonic
Expand Down Expand Up @@ -128,14 +135,36 @@ bool flipbip39_scene_1_input(InputEvent* event, void* context) {

void flipbip39_scene_1_exit(void* context) {
furi_assert(context);
FlipBip39Scene1* instance = (FlipBip39Scene1*)context;

with_view_model(
instance->view,
FlipBip39Scene1Model * model,
{
// Clear the mnemonic from memory
model->strength = 0;
memzero((void*)model->mnemonic1, strlen(model->mnemonic1));
memzero((void*)model->mnemonic2, strlen(model->mnemonic2));
memzero((void*)model->mnemonic3, strlen(model->mnemonic3));
memzero((void*)model->mnemonic4, strlen(model->mnemonic4));
memzero((void*)model->mnemonic5, strlen(model->mnemonic5));
memzero((void*)model->mnemonic6, strlen(model->mnemonic6));
},
true
);
}

void flipbip39_scene_1_enter(void* context) {
furi_assert(context);
FlipBip39Scene1* instance = (FlipBip39Scene1*)context;

FlipBip39* app = instance->context;
int strength = app->bip39_strength;
int strength_setting = app->bip39_strength;
int strength = 256;
if (strength_setting == 0) strength = 128;

flipbip39_play_happy_bump(app);
flipbip39_led_set_rgb(app, 255, 0, 0);

with_view_model(
instance->view,
Expand All @@ -157,8 +186,10 @@ FlipBip39Scene1* flipbip39_scene_1_alloc() {
view_set_enter_callback(instance->view, flipbip39_scene_1_enter);
view_set_exit_callback(instance->view, flipbip39_scene_1_exit);

// FlipBip39* app = instance->view->context;
// int strength = app->bip39_strength;
// FlipBip39* app = instance->context;
// int strength_setting = app->bip39_strength;
// int strength = 256;
// if (strength_setting == 0) strength = 128;

// with_view_model(
// instance->view,
Expand Down

0 comments on commit 6619222

Please sign in to comment.