From 22353ed86900e24fc37d695eb7e49b5306c568d7 Mon Sep 17 00:00:00 2001 From: AfonsoCMSousa Date: Thu, 27 Feb 2025 13:06:33 +0000 Subject: [PATCH] Trying to fix password issues. --- src/main.c | 154 --------------------------------------------------- src/server.c | 3 + 2 files changed, 3 insertions(+), 154 deletions(-) delete mode 100644 src/main.c diff --git a/src/main.c b/src/main.c deleted file mode 100644 index c8c06e0..0000000 --- a/src/main.c +++ /dev/null @@ -1,154 +0,0 @@ -#include -#include -#include - -#include "herror.h" -#include "dynmem.h" -#include "ui/ui.h" - -#define PASS_FILE "./files/KEYS.bin" -#define SERVER_IP "XXX.XXX.XXX.XXX" - -void clear_input_buffer(void) -{ - int c; - while ((c = getchar()) != '\n' && c != EOF) - ; -} - -int main(void) -{ - char *password = create(char); - password = size(password, 256); - - if (password == NULL) - { - fprintf(stderr, "Memory allocation failure\n"); - return 1; - } - - int fP = readl(PASS_FILE, password, strlen(password)); - if (fP == -1) - { - printf("Couldnt find the password file\nWould you like to create a new one? (y/n): "); - char c; - scanf("%c", &c); - clear_input_buffer(); - if (c == 'y' || c == 'Y') - { - if (prompPassword(password) == -1) - { - return 1; - } - printf("\n"); - - int *buffer = create(int); - buffer = size(buffer, 256); - - emcryptText(buffer, password); - writel(PASS_FILE, buffer, 256); - - free(buffer); - } - else - { - return 0; - } - } - printf("KeyMaster\nVersion: 0.2\n\n"); - - try - { - int *key = create(int); - key = size(key, 256); - if (key == NULL) - { - throw(MEMORY_ALLOC_FAILURE); - } - - readl(PASS_FILE, key, 256) == -1 ? throw(FILE_NOT_FOUND) : 0; - decryptText(password, key); - - char *askedPass = create(char); - askedPass = size(askedPass, 256); - if (askedPass == NULL) - { - throw(MEMORY_ALLOC_FAILURE); - } - - for (size_t i = 0; i < 4; i++) - { - prompPassword(askedPass); - if (strcmp(password, askedPass) != 0) - { - printf("Invalid password, tries left: %zu\n", 2 - i); - } - else - { - break; - } - - if (i == 2) - { - printf("Too many tries, exiting...\n"); - return 1; - } - } - - printf("Welcome to KeyMaster\n"); - free(askedPass); - free(key); - } - catch (MEMORY_ALLOC_FAILURE) - { - fprintf(stderr, "Memory allocation failure\n"); - return 1; - } - catch (FILE_NOT_FOUND) - { - fprintf(stderr, "Couldnt find the password file or its empty\n"); - return 1; - } - end_try; - - char *choice = NULL; - - try - { - choice = create(char); - choice = size(choice, 256); - - if (choice == NULL) - { - throw(MEMORY_ALLOC_FAILURE); - } - } - catch (MEMORY_ALLOC_FAILURE) - { - fprintf(stderr, "Memory allocation failure\n"); - return 1; - } - end_try; - - // Menu loop - while (1) - { - printf("List of existing passwords:\n<------->\n"); - - // Show passwords that are stored in the server - printf("<------->\n\n"); - choice = prompNormalRequest(">> "); - if (strcmp(choice, "exit") == 0 || strcmp(choice, "quit") == 0 || strcmp(choice, "q") == 0) - { - break; - } - else - { - printf("Invalid command (%s)\n\"Q\" or \"quit\" or \"exit\" to close the program\n", choice); - } - } - free(choice); - - free(password); - return 0; -} \ No newline at end of file diff --git a/src/server.c b/src/server.c index 404e7d2..a212337 100644 --- a/src/server.c +++ b/src/server.c @@ -119,6 +119,9 @@ int main(void) send(connfd, &aux, sizeof(aux), 0); } + // debug + printf("Sending key: [%s]\n", buffer); + aux.ID = req.ID; memccpy(aux.key, buffer, 0, 256); aux.level = req.level;