Working on importing existing passwords from other password managers
This commit is contained in:
parent
5360e26581
commit
644251c57a
8 changed files with 155 additions and 44 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -55,6 +55,9 @@ dkms.conf
|
||||||
# Executables
|
# Executables
|
||||||
**.fap
|
**.fap
|
||||||
|
|
||||||
|
# Confidential Files
|
||||||
|
**/archive.txt
|
||||||
|
|
||||||
# IDEs
|
# IDEs
|
||||||
*.vscode
|
*.vscode
|
||||||
|
|
||||||
|
|
60
project/backend/archive.c
Normal file
60
project/backend/archive.c
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
// Header
|
||||||
|
#include "archive.h"
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
bool archive_import(Manager* manager) {
|
||||||
|
// Loading the file
|
||||||
|
char* data = store_load(Store_File_Path_Archive, "Data");
|
||||||
|
|
||||||
|
// Did we fail to load the data?
|
||||||
|
if (!data) {return false;}
|
||||||
|
|
||||||
|
// Splitting the string up
|
||||||
|
int count = 0;
|
||||||
|
char** split = split_string(data, F_DELIMITER, &count);
|
||||||
|
|
||||||
|
// Free data after split
|
||||||
|
free(data);
|
||||||
|
|
||||||
|
// Going through all passwords
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
// Skipping to each password
|
||||||
|
if (i % 4 == 0) {
|
||||||
|
// DEBUG
|
||||||
|
FURI_LOG_D(TAG, "(%i) Adding password.", i);
|
||||||
|
|
||||||
|
// Allocating memory for a password
|
||||||
|
Password* new_password = pass_init(
|
||||||
|
split[i],
|
||||||
|
split[i+1],
|
||||||
|
split[i+2],
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
// Saving the new password
|
||||||
|
manager_savepass(manager, new_password);
|
||||||
|
|
||||||
|
// Freeing that password
|
||||||
|
pass_free(new_password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wiping the original file
|
||||||
|
store_save(Store_File_Path_Archive, "Data", "Done.");
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
free(split);
|
||||||
|
|
||||||
|
// Return result
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool archive_export(Manager* manager) {
|
||||||
|
// Result
|
||||||
|
bool result = true;
|
||||||
|
|
||||||
|
// UNUSED variable
|
||||||
|
UNUSED(manager);
|
||||||
|
|
||||||
|
// Return result
|
||||||
|
return result;
|
||||||
|
}
|
13
project/backend/archive.h
Normal file
13
project/backend/archive.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// Define once
|
||||||
|
#ifndef H_ARCHIVE
|
||||||
|
#define H_ARCHIVE
|
||||||
|
|
||||||
|
// Libraries
|
||||||
|
#include "base.h"
|
||||||
|
#include "manager.h"
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
bool archive_import(Manager* manager);
|
||||||
|
bool archive_export(Manager* manager);
|
||||||
|
|
||||||
|
#endif
|
40
project/backend/base.c
Normal file
40
project/backend/base.c
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// Header
|
||||||
|
#include "base.h"
|
||||||
|
|
||||||
|
// Libraries
|
||||||
|
#include <furi.h>
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
char** split_string(const char* str, char delimiter, int* count) {
|
||||||
|
// Calculate how many substrings will be created
|
||||||
|
int i, numSubstrings = 1;
|
||||||
|
for (i = 0; str[i] != '\0'; i++) {
|
||||||
|
if (str[i] == delimiter) {
|
||||||
|
numSubstrings++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate memory for the array of strings
|
||||||
|
char** result = malloc(numSubstrings * sizeof(char*));
|
||||||
|
*count = numSubstrings;
|
||||||
|
|
||||||
|
// Split the string
|
||||||
|
int start = 0, substringIndex = 0;
|
||||||
|
for (i = 0; str[i] != '\0'; i++) {
|
||||||
|
if (str[i] == delimiter) {
|
||||||
|
int length = i - start;
|
||||||
|
result[substringIndex] = malloc((length + 1) * sizeof(char));
|
||||||
|
strncpy(result[substringIndex], str + start, length);
|
||||||
|
result[substringIndex][length] = '\0';
|
||||||
|
start = i + 1;
|
||||||
|
substringIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add the last substring
|
||||||
|
int length = i - start;
|
||||||
|
result[substringIndex] = malloc((length + 1) * sizeof(char));
|
||||||
|
strncpy(result[substringIndex], str + start, length);
|
||||||
|
result[substringIndex][length] = '\0';
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
|
@ -9,4 +9,9 @@
|
||||||
#define F_DATA EXT_PATH("apps_data/fpass/data.bin")
|
#define F_DATA EXT_PATH("apps_data/fpass/data.bin")
|
||||||
#define F_ARCHIVE EXT_PATH("apps_data/fpass/archive.txt")
|
#define F_ARCHIVE EXT_PATH("apps_data/fpass/archive.txt")
|
||||||
|
|
||||||
|
#define F_DELIMITER '\v'
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
char** split_string(const char* str, char delimiter, int* count);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -2,39 +2,6 @@
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
|
|
||||||
// Functions - Private
|
// Functions - Private
|
||||||
char** split_string(const char* str, char delimiter, int* count) {
|
|
||||||
// Calculate how many substrings will be created
|
|
||||||
int i, numSubstrings = 1;
|
|
||||||
for (i = 0; str[i] != '\0'; i++) {
|
|
||||||
if (str[i] == delimiter) {
|
|
||||||
numSubstrings++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate memory for the array of strings
|
|
||||||
char** result = malloc(numSubstrings * sizeof(char*));
|
|
||||||
*count = numSubstrings;
|
|
||||||
|
|
||||||
// Split the string
|
|
||||||
int start = 0, substringIndex = 0;
|
|
||||||
for (i = 0; str[i] != '\0'; i++) {
|
|
||||||
if (str[i] == delimiter) {
|
|
||||||
int length = i - start;
|
|
||||||
result[substringIndex] = malloc((length + 1) * sizeof(char));
|
|
||||||
strncpy(result[substringIndex], str + start, length);
|
|
||||||
result[substringIndex][length] = '\0';
|
|
||||||
start = i + 1;
|
|
||||||
substringIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add the last substring
|
|
||||||
int length = i - start;
|
|
||||||
result[substringIndex] = malloc((length + 1) * sizeof(char));
|
|
||||||
strncpy(result[substringIndex], str + start, length);
|
|
||||||
result[substringIndex][length] = '\0';
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
void manager_loadnames(Manager* manager){
|
void manager_loadnames(Manager* manager){
|
||||||
// Loading the names of all passwords
|
// Loading the names of all passwords
|
||||||
char* data = secure_storage_load(manager->secure_storage, Store_File_Path_Data, "Data");
|
char* data = secure_storage_load(manager->secure_storage, Store_File_Path_Data, "Data");
|
||||||
|
@ -53,7 +20,7 @@ void manager_loadnames(Manager* manager){
|
||||||
|
|
||||||
// Splitting string
|
// Splitting string
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char** split = split_string(data, '|', &count);
|
char** split = split_string(data, F_DELIMITER, &count);
|
||||||
|
|
||||||
// Freeing data
|
// Freeing data
|
||||||
free(data);
|
free(data);
|
||||||
|
@ -111,7 +78,10 @@ void manager_savepass(Manager* manager, Password* pass) {
|
||||||
FuriString* n_result = furi_string_alloc();
|
FuriString* n_result = furi_string_alloc();
|
||||||
|
|
||||||
// Setting stuff
|
// Setting stuff
|
||||||
furi_string_printf(n_result, "%s|%s|%s|0", pass->name, pass->user, pass->phrase);
|
furi_string_printf(n_result, "%s%c%s%c%s%c0",
|
||||||
|
pass->name, F_DELIMITER,
|
||||||
|
pass->user, F_DELIMITER,
|
||||||
|
pass->phrase, F_DELIMITER);
|
||||||
|
|
||||||
// Saving the data
|
// Saving the data
|
||||||
char* data = malloc(sizeof(char) * furi_string_size(n_result));
|
char* data = malloc(sizeof(char) * furi_string_size(n_result));
|
||||||
|
@ -126,7 +96,11 @@ void manager_savepass(Manager* manager, Password* pass) {
|
||||||
FuriString* new_result = furi_string_alloc();
|
FuriString* new_result = furi_string_alloc();
|
||||||
|
|
||||||
// Appending addon to result
|
// Appending addon to result
|
||||||
furi_string_printf(new_result, "%s|%s|%s|%s|0", result, pass->name, pass->user, pass->phrase);
|
furi_string_printf(new_result, "%s%c%s%c%s%c%s%c0",
|
||||||
|
result, F_DELIMITER,
|
||||||
|
pass->name, F_DELIMITER,
|
||||||
|
pass->user, F_DELIMITER,
|
||||||
|
pass->phrase, F_DELIMITER);
|
||||||
|
|
||||||
// Saving the data
|
// Saving the data
|
||||||
char* data = malloc(sizeof(char) * furi_string_size(new_result));
|
char* data = malloc(sizeof(char) * furi_string_size(new_result));
|
||||||
|
@ -156,7 +130,7 @@ void manager_loadpass(Manager* manager, char* name) {
|
||||||
|
|
||||||
// Splitting string
|
// Splitting string
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char** split = split_string(data, '|', &count);
|
char** split = split_string(data, F_DELIMITER, &count);
|
||||||
|
|
||||||
// Unloading data
|
// Unloading data
|
||||||
free(data);
|
free(data);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
// Header
|
// Header
|
||||||
#include "import.h"
|
#include "import.h"
|
||||||
|
|
||||||
|
// Others
|
||||||
|
#include "../../backend/archive.h"
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
void FP_Scene_Callback_Import(DialogExResult result, void* context){
|
void FP_Scene_Callback_Import(DialogExResult result, void* context){
|
||||||
// Setting context
|
// Setting context
|
||||||
|
@ -81,13 +84,25 @@ bool FP_Scene_Event_Import(void* context, SceneManagerEvent event){
|
||||||
// What should we do?
|
// What should we do?
|
||||||
switch (event.event) {
|
switch (event.event) {
|
||||||
case DialogExResultCenter: // Yes
|
case DialogExResultCenter: // Yes
|
||||||
|
// Importing the passwords
|
||||||
|
bool success = archive_import(app->manager);
|
||||||
|
|
||||||
// Telling the user it worked!
|
// Telling the user it worked!
|
||||||
dialog_ex_set_text(
|
if (success) {
|
||||||
app->dialog,
|
dialog_ex_set_text(
|
||||||
"Imported Successfully.",
|
app->dialog,
|
||||||
5, 15,
|
"Imported Successfully.",
|
||||||
AlignLeft, AlignTop
|
5, 15,
|
||||||
);
|
AlignLeft, AlignTop
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
dialog_ex_set_text(
|
||||||
|
app->dialog,
|
||||||
|
"Failed to import passwords",
|
||||||
|
5, 15,
|
||||||
|
AlignLeft, AlignTop
|
||||||
|
);
|
||||||
|
}
|
||||||
dialog_ex_set_center_button_text(
|
dialog_ex_set_center_button_text(
|
||||||
app->dialog,
|
app->dialog,
|
||||||
"Okay"
|
"Okay"
|
||||||
|
|
|
@ -10,6 +10,7 @@ import sys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
file_delimiter = '\v'
|
||||||
all_passwords = ""
|
all_passwords = ""
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
@ -39,7 +40,7 @@ def insert_passwords(json_data):
|
||||||
password = item["login"]["password"]
|
password = item["login"]["password"]
|
||||||
|
|
||||||
# Adding it into our password array
|
# Adding it into our password array
|
||||||
all_passwords += name + "|" + username + "|" + password + "|0|"
|
all_passwords += name + file_delimiter + username + file_delimiter + password + file_delimiter + "0" + file_delimiter
|
||||||
def save_data():
|
def save_data():
|
||||||
# Global
|
# Global
|
||||||
global all_passwords
|
global all_passwords
|
||||||
|
|
Loading…
Reference in a new issue