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
|
||||
**.fap
|
||||
|
||||
# Confidential Files
|
||||
**/archive.txt
|
||||
|
||||
# IDEs
|
||||
*.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_ARCHIVE EXT_PATH("apps_data/fpass/archive.txt")
|
||||
|
||||
#define F_DELIMITER '\v'
|
||||
|
||||
// Functions
|
||||
char** split_string(const char* str, char delimiter, int* count);
|
||||
|
||||
#endif
|
|
@ -2,39 +2,6 @@
|
|||
#include "manager.h"
|
||||
|
||||
// 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){
|
||||
// Loading the names of all passwords
|
||||
char* data = secure_storage_load(manager->secure_storage, Store_File_Path_Data, "Data");
|
||||
|
@ -53,7 +20,7 @@ void manager_loadnames(Manager* manager){
|
|||
|
||||
// Splitting string
|
||||
int count = 0;
|
||||
char** split = split_string(data, '|', &count);
|
||||
char** split = split_string(data, F_DELIMITER, &count);
|
||||
|
||||
// Freeing data
|
||||
free(data);
|
||||
|
@ -111,7 +78,10 @@ void manager_savepass(Manager* manager, Password* pass) {
|
|||
FuriString* n_result = furi_string_alloc();
|
||||
|
||||
// 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
|
||||
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();
|
||||
|
||||
// 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
|
||||
char* data = malloc(sizeof(char) * furi_string_size(new_result));
|
||||
|
@ -156,7 +130,7 @@ void manager_loadpass(Manager* manager, char* name) {
|
|||
|
||||
// Splitting string
|
||||
int count = 0;
|
||||
char** split = split_string(data, '|', &count);
|
||||
char** split = split_string(data, F_DELIMITER, &count);
|
||||
|
||||
// Unloading data
|
||||
free(data);
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
// Header
|
||||
#include "import.h"
|
||||
|
||||
// Others
|
||||
#include "../../backend/archive.h"
|
||||
|
||||
// Functions
|
||||
void FP_Scene_Callback_Import(DialogExResult result, void* context){
|
||||
// Setting context
|
||||
|
@ -81,13 +84,25 @@ bool FP_Scene_Event_Import(void* context, SceneManagerEvent event){
|
|||
// What should we do?
|
||||
switch (event.event) {
|
||||
case DialogExResultCenter: // Yes
|
||||
// Importing the passwords
|
||||
bool success = archive_import(app->manager);
|
||||
|
||||
// Telling the user it worked!
|
||||
dialog_ex_set_text(
|
||||
app->dialog,
|
||||
"Imported Successfully.",
|
||||
5, 15,
|
||||
AlignLeft, AlignTop
|
||||
);
|
||||
if (success) {
|
||||
dialog_ex_set_text(
|
||||
app->dialog,
|
||||
"Imported Successfully.",
|
||||
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(
|
||||
app->dialog,
|
||||
"Okay"
|
||||
|
|
|
@ -10,6 +10,7 @@ import sys
|
|||
import json
|
||||
|
||||
# Variables
|
||||
file_delimiter = '\v'
|
||||
all_passwords = ""
|
||||
|
||||
# Functions
|
||||
|
@ -39,7 +40,7 @@ def insert_passwords(json_data):
|
|||
password = item["login"]["password"]
|
||||
|
||||
# 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():
|
||||
# Global
|
||||
global all_passwords
|
||||
|
|
Loading…
Reference in a new issue