From 47fd0968cba25383eff642c9974ed1dd53050479 Mon Sep 17 00:00:00 2001 From: night0721 Date: Mon, 16 Sep 2024 13:19:02 +0100 Subject: [PATCH] Change encrypted structure --- lib/packet.c | 7 ++----- src/server/server.c | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/packet.c b/lib/packet.c index 21fec35..c43abb5 100644 --- a/lib/packet.c +++ b/lib/packet.c @@ -263,9 +263,7 @@ int encrypt_packet(int sockfd, key_pair *kp) /* Pad with null characters up to max length */ memset(recipient + length, 0, MAX_NAME - length); } - memcpy(raw_data, kp->pk.username, MAX_NAME); - memcpy(raw_data + MAX_NAME, recipient, MAX_NAME); - memcpy(raw_data + MAX_NAME * 2, line, length_line); + memcpy(raw_data, line, length_line); size_t raw_data_size = MAX_NAME * 2 + strlen(line); uint8_t *data = encrypt_data(kp->pk.username, recipient, raw_data, raw_data_size, &data_len); @@ -331,7 +329,6 @@ uint8_t *encrypt_data(uint8_t *from, uint8_t *to, uint8_t *raw, uint32_t raw_len uint8_t encrypted[encrypted_len]; /* Generate random nonce(number used once) */ - printf("raw: %s\n", raw); randombytes_buf(nonce, sizeof(nonce)); crypto_aead_xchacha20poly1305_ietf_encrypt(encrypted, NULL, raw, raw_length, NULL, 0, NULL, nonce, shared_key); @@ -383,7 +380,7 @@ uint8_t *decrypt_data(packet *pkt) } else { /* Terminate decrypted message so we don't print random bytes */ decrypted[data_len] = '\0'; - printf("<%s> to <%s>: %s\n", from, to, decrypted + MAX_NAME * 2); + printf("<%s> to <%s>: %s\n", from, to, decrypted); return decrypted; } } diff --git a/src/server/server.c b/src/server/server.c index 1117bc2..9794a02 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -128,7 +128,7 @@ void *thread_worker(void *arg) for (int j = 0; j < thread.num_clients; j++) { client_t client = thread.clients[j]; if (strcmp(client.username, to) == 0) { - error(0, "Relaying message to %s\n", client.username); + error(0, "Relaying message to %s", client.username); send_packet(verified_pkt, client.fd); } }