implemented encrypt_decrypt_message in send/receive fns
Some checks failed
Codacy Scan / Codacy Security Scan (push) Successful in 21s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Failing after 1m33s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m52s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Failing after 1m51s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Failing after 1m53s

This commit is contained in:
Václav Šmejkal 2025-02-02 15:48:18 +01:00
parent 6e67e6225f
commit 06d835e2b9
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -208,21 +208,27 @@ void encrypt_decrypt_message(char **message, char *key, enum ENCRYPTION_DECRYPTI
break;
}
//VARIABLES
size_t length = strlen(*message);
char *message_decoded = base64_before_cb(*message, &length);
//SET FLAGS
if (why2_get_key_length() < strlen(key)) why2_set_key_length(strlen(key));
why2_set_flags((why2_input_flags) { 1, 1, 0, WHY2_v4, WHY2_OUTPUT_TEXT, 0 }); //TODO: Add padding
//ENCRYPT
why2_output_flags output = operation_cb(*message, key);
why2_output_flags output = operation_cb(message_decoded, key);
//COPY OUTPUT IN BASE64
why2_deallocate(*message);
*message = base64_cb(output.output_text, &output.output_text_length);
*message = base64_after_cb(output.output_text, &output.output_text_length);
//DEALLOCATION
why2_deallocate(message_decoded);
why2_deallocate_output(output);
}
char *read_socket_raw(int socket, WHY2_UNUSED char *key)
char *read_socket_raw(int socket, char *key)
{
if (socket == -1)
{
@ -259,6 +265,8 @@ char *read_socket_raw(int socket, WHY2_UNUSED char *key)
content_buffer[content_size] = '\0'; //NULL TERM
encrypt_decrypt_message(&content_buffer, key, DECRYPTION); //DECRYPT
//VALIDATE JSON FORMAT
struct json_object *json = json_tokener_parse(content_buffer);
if (json == NULL)
@ -468,7 +476,7 @@ void send_socket_code_deallocate(char *params, char *username, char *key, int so
why2_toml_read_free(username);
}
void send_socket(char *text, char *username, WHY2_UNUSED char *why2_key, int socket, why2_bool welcome, char *code)
void send_socket(char *text, char *username, char *why2_key, int socket, why2_bool welcome, char *code)
{
//VARIABLES
char *output = why2_strdup("");
@ -528,6 +536,8 @@ void send_socket(char *text, char *username, WHY2_UNUSED char *why2_key, int soc
}
add_brackets(&output);
encrypt_decrypt_message(&output, why2_key, ENCRYPTION); //ENCRYPT
//SEND
send(socket, output, strlen(output), 0);