Made it easier to change your PIN, added PIN file deletion when needed

This commit is contained in:
Aurora 2016-08-28 15:50:11 +02:00
parent 3f8ad17e86
commit 92328c6a7e
7 changed files with 25 additions and 18 deletions

View File

@ -27,6 +27,7 @@
#include "screen.h"
#include "draw.h"
#include "buttons.h"
#include "pin.h"
bool readConfig(const char *configPath)
{
@ -64,7 +65,7 @@ void writeConfig(const char *configPath, u32 configTemp)
}
}
void configMenu(void)
void configMenu(bool oldPinStatus)
{
initScreens();
@ -231,6 +232,11 @@ void configMenu(void)
for(u32 i = 0; i < singleOptionsAmount; i++)
configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 16);
if(CONFIG(8)) newPin(oldPinStatus);
else if(oldPinStatus) fileDelete("/luma/pin.bin");
//Wait for the pressed buttons to change
while(HID_PAD == BUTTON_START);
while(HID_PAD & PIN_BUTTONS);
chrono(2);
}

View File

@ -43,4 +43,4 @@ extern cfgData configData;
bool readConfig(const char *configPath);
void writeConfig(const char *configPath, u32 configTemp);
void configMenu(void);
void configMenu(bool oldPinStatus);

View File

@ -141,11 +141,7 @@ void main(void)
if(shouldLoadConfigMenu)
{
configMenu();
if(!pinExists && CONFIG(8)) newPin();
chrono(2);
configMenu(pinExists);
//Update pressed buttons
pressed = HID_PAD;

View File

@ -76,6 +76,11 @@ bool fileWrite(const void *buffer, const char *path, u32 size)
return false;
}
void fileDelete(const char *path)
{
f_unlink(path);
}
void createDirectory(const char *path)
{
f_mkdir(path);

View File

@ -32,6 +32,7 @@ void mountFs(void);
u32 fileRead(void *dest, const char *path);
u32 getFileSize(const char *path);
bool fileWrite(const void *buffer, const char *path, u32 size);
void fileDelete(const char *path);
void createDirectory(const char *path);
void loadPayload(u32 pressed);
u32 firmRead(void *dest, u32 firmType);

View File

@ -60,11 +60,12 @@ static inline char PINKeyToLetter(u32 pressed)
return keys[31 - i];
}
void newPin(void)
void newPin(bool allowSkipping)
{
clearScreens();
drawString("Enter a new PIN to proceed", 10, 10, COLOR_TITLE);
char *title = allowSkipping ? "Press START to skip or enter a new PIN" : "Enter a new PIN to proceed";
drawString(title, 10, 10, COLOR_TITLE);
drawString("PIN: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE);
//Pad to AES block length with zeroes
@ -80,10 +81,12 @@ void newPin(void)
{
pressed = waitInput();
}
while(!(pressed & PIN_BUTTONS & ~BUTTON_START));
while(!(pressed & PIN_BUTTONS));
pressed &= PIN_BUTTONS & ~BUTTON_START;
pressed &= PIN_BUTTONS;
if(!allowSkipping) pressed &= ~BUTTON_START;
if(pressed & BUTTON_START) return;
if(!pressed) continue;
char key = PINKeyToLetter(pressed);
@ -114,8 +117,6 @@ void newPin(void)
if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)))
error("Error writing the PIN file");
}
while(HID_PAD & PIN_BUTTONS);
}
void verifyPin(PINData *in)
@ -143,9 +144,7 @@ void verifyPin(PINData *in)
if(pressed & BUTTON_START) mcuPowerOff();
pressed &= PIN_BUTTONS & ~BUTTON_START;
if(!pressed) continue;
pressed &= PIN_BUTTONS;
char key = PINKeyToLetter(pressed);
enteredPassword[cnt++] = (u8)key; //Add character to password

View File

@ -44,5 +44,5 @@ typedef struct __attribute__((packed))
} PINData;
bool readPin(PINData* out);
void newPin(void);
void newPin(bool allowSkipping);
void verifyPin(PINData *in);