Made it easier to change your PIN, added PIN file deletion when needed
This commit is contained in:
parent
3f8ad17e86
commit
92328c6a7e
@ -27,6 +27,7 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
|
#include "pin.h"
|
||||||
|
|
||||||
bool readConfig(const char *configPath)
|
bool readConfig(const char *configPath)
|
||||||
{
|
{
|
||||||
@ -64,7 +65,7 @@ void writeConfig(const char *configPath, u32 configTemp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void configMenu(void)
|
void configMenu(bool oldPinStatus)
|
||||||
{
|
{
|
||||||
initScreens();
|
initScreens();
|
||||||
|
|
||||||
@ -231,6 +232,11 @@ void configMenu(void)
|
|||||||
for(u32 i = 0; i < singleOptionsAmount; i++)
|
for(u32 i = 0; i < singleOptionsAmount; i++)
|
||||||
configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 16);
|
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
|
//Wait for the pressed buttons to change
|
||||||
while(HID_PAD == BUTTON_START);
|
while(HID_PAD & PIN_BUTTONS);
|
||||||
|
|
||||||
|
chrono(2);
|
||||||
}
|
}
|
@ -43,4 +43,4 @@ extern cfgData configData;
|
|||||||
|
|
||||||
bool readConfig(const char *configPath);
|
bool readConfig(const char *configPath);
|
||||||
void writeConfig(const char *configPath, u32 configTemp);
|
void writeConfig(const char *configPath, u32 configTemp);
|
||||||
void configMenu(void);
|
void configMenu(bool oldPinStatus);
|
@ -141,11 +141,7 @@ void main(void)
|
|||||||
|
|
||||||
if(shouldLoadConfigMenu)
|
if(shouldLoadConfigMenu)
|
||||||
{
|
{
|
||||||
configMenu();
|
configMenu(pinExists);
|
||||||
|
|
||||||
if(!pinExists && CONFIG(8)) newPin();
|
|
||||||
|
|
||||||
chrono(2);
|
|
||||||
|
|
||||||
//Update pressed buttons
|
//Update pressed buttons
|
||||||
pressed = HID_PAD;
|
pressed = HID_PAD;
|
||||||
|
@ -76,6 +76,11 @@ bool fileWrite(const void *buffer, const char *path, u32 size)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fileDelete(const char *path)
|
||||||
|
{
|
||||||
|
f_unlink(path);
|
||||||
|
}
|
||||||
|
|
||||||
void createDirectory(const char *path)
|
void createDirectory(const char *path)
|
||||||
{
|
{
|
||||||
f_mkdir(path);
|
f_mkdir(path);
|
||||||
|
@ -32,6 +32,7 @@ void mountFs(void);
|
|||||||
u32 fileRead(void *dest, const char *path);
|
u32 fileRead(void *dest, const char *path);
|
||||||
u32 getFileSize(const char *path);
|
u32 getFileSize(const char *path);
|
||||||
bool fileWrite(const void *buffer, const char *path, u32 size);
|
bool fileWrite(const void *buffer, const char *path, u32 size);
|
||||||
|
void fileDelete(const char *path);
|
||||||
void createDirectory(const char *path);
|
void createDirectory(const char *path);
|
||||||
void loadPayload(u32 pressed);
|
void loadPayload(u32 pressed);
|
||||||
u32 firmRead(void *dest, u32 firmType);
|
u32 firmRead(void *dest, u32 firmType);
|
17
source/pin.c
17
source/pin.c
@ -60,11 +60,12 @@ static inline char PINKeyToLetter(u32 pressed)
|
|||||||
return keys[31 - i];
|
return keys[31 - i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void newPin(void)
|
void newPin(bool allowSkipping)
|
||||||
{
|
{
|
||||||
clearScreens();
|
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);
|
drawString("PIN: ", 10, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
||||||
|
|
||||||
//Pad to AES block length with zeroes
|
//Pad to AES block length with zeroes
|
||||||
@ -80,10 +81,12 @@ void newPin(void)
|
|||||||
{
|
{
|
||||||
pressed = waitInput();
|
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;
|
if(!pressed) continue;
|
||||||
|
|
||||||
char key = PINKeyToLetter(pressed);
|
char key = PINKeyToLetter(pressed);
|
||||||
@ -114,8 +117,6 @@ void newPin(void)
|
|||||||
if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)))
|
if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)))
|
||||||
error("Error writing the PIN file");
|
error("Error writing the PIN file");
|
||||||
}
|
}
|
||||||
|
|
||||||
while(HID_PAD & PIN_BUTTONS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifyPin(PINData *in)
|
void verifyPin(PINData *in)
|
||||||
@ -143,9 +144,7 @@ void verifyPin(PINData *in)
|
|||||||
|
|
||||||
if(pressed & BUTTON_START) mcuPowerOff();
|
if(pressed & BUTTON_START) mcuPowerOff();
|
||||||
|
|
||||||
pressed &= PIN_BUTTONS & ~BUTTON_START;
|
pressed &= PIN_BUTTONS;
|
||||||
|
|
||||||
if(!pressed) continue;
|
|
||||||
|
|
||||||
char key = PINKeyToLetter(pressed);
|
char key = PINKeyToLetter(pressed);
|
||||||
enteredPassword[cnt++] = (u8)key; //Add character to password
|
enteredPassword[cnt++] = (u8)key; //Add character to password
|
||||||
|
@ -44,5 +44,5 @@ typedef struct __attribute__((packed))
|
|||||||
} PINData;
|
} PINData;
|
||||||
|
|
||||||
bool readPin(PINData* out);
|
bool readPin(PINData* out);
|
||||||
void newPin(void);
|
void newPin(bool allowSkipping);
|
||||||
void verifyPin(PINData *in);
|
void verifyPin(PINData *in);
|
Reference in New Issue
Block a user