commit 127b2f34dc6189c830e013c7c3fec42ae1cc47f1
parent 3c8e120e8c207d7f235ca6d15f189eb237009d34
Author: Jacki <jacki@thejackimonster.de>
Date: Mon, 22 Apr 2024 17:00:01 +0200
Fix file decryption without key and unmatching hash
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
4 files changed, 39 insertions(+), 65 deletions(-)
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
@@ -342,17 +342,10 @@ context_delete_message (struct GNUNET_CHAT_Context *context,
}
case GNUNET_MESSENGER_KIND_FILE:
{
- struct GNUNET_CHAT_File *file = GNUNET_CONTAINER_multihashmap_get(
- context->files, &(message->hash)
- );
-
- if (! file)
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains(context->files, &(message->hash)))
break;
- if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(
- context->files, &(message->hash), file))
- file_destroy(file);
-
+ GNUNET_CONTAINER_multihashmap_remove_all(context->files, &(message->hash));
break;
}
case GNUNET_MESSENGER_KIND_TAG:
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c
@@ -28,6 +28,30 @@
#include <gnunet/gnunet_common.h>
#include <string.h>
+static void
+file_initialize (struct GNUNET_CHAT_File *file)
+{
+ GNUNET_assert(file);
+
+ file->download = NULL;
+ file->publish = NULL;
+ file->unindex = NULL;
+
+ file->upload_head = NULL;
+ file->upload_tail = NULL;
+
+ file->download_head = NULL;
+ file->download_tail = NULL;
+
+ file->unindex_head = NULL;
+ file->unindex_tail = NULL;
+
+ file->status = 0;
+ file->preview = NULL;
+
+ file->user_pointer = NULL;
+}
+
struct GNUNET_CHAT_File*
file_create_from_message (struct GNUNET_CHAT_Handle *handle,
const struct GNUNET_MESSENGER_MessageFile *message)
@@ -55,25 +79,9 @@ file_create_from_message (struct GNUNET_CHAT_Handle *handle,
GNUNET_memcpy(&(file->hash), &(message->hash), sizeof(file->hash));
file->meta = GNUNET_FS_meta_data_create();
-
file->uri = GNUNET_FS_uri_parse(message->uri, NULL);
- file->download = NULL;
- file->publish = NULL;
- file->unindex = NULL;
- file->upload_head = NULL;
- file->upload_tail = NULL;
-
- file->download_head = NULL;
- file->download_tail = NULL;
-
- file->unindex_head = NULL;
- file->unindex_tail = NULL;
-
- file->status = 0;
- file->preview = NULL;
-
- file->user_pointer = NULL;
+ file_initialize(file);
return file;
}
@@ -102,25 +110,9 @@ file_create_from_chk_uri (struct GNUNET_CHAT_Handle *handle,
GNUNET_memcpy(&(file->hash), hash, sizeof(file->hash));
file->meta = GNUNET_FS_meta_data_create();
-
file->uri = GNUNET_FS_uri_dup(uri);
- file->download = NULL;
- file->publish = NULL;
- file->unindex = NULL;
-
- file->upload_head = NULL;
- file->upload_tail = NULL;
-
- file->download_head = NULL;
- file->download_tail = NULL;
-
- file->unindex_head = NULL;
- file->unindex_tail = NULL;
-
- file->status = 0;
- file->preview = NULL;
-
- file->user_pointer = NULL;
+
+ file_initialize(file);
return file;
}
@@ -162,25 +154,9 @@ skip_key:
GNUNET_memcpy(&(file->hash), hash, sizeof(file->hash));
file->meta = GNUNET_FS_meta_data_create();
-
file->uri = NULL;
- file->download = NULL;
- file->publish = NULL;
- file->unindex = NULL;
-
- file->upload_head = NULL;
- file->upload_tail = NULL;
- file->download_head = NULL;
- file->download_tail = NULL;
-
- file->unindex_head = NULL;
- file->unindex_tail = NULL;
-
- file->status = 0;
- file->preview = NULL;
-
- file->user_pointer = NULL;
+ file_initialize(file);
return file;
}
@@ -190,6 +166,12 @@ file_destroy (struct GNUNET_CHAT_File *file)
{
GNUNET_assert(file);
+ if (file->preview)
+ {
+ remove(file->preview);
+ GNUNET_free(file->preview);
+ }
+
struct GNUNET_CHAT_FileUpload *upload;
while (file->upload_head)
{
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h
@@ -76,11 +76,10 @@ struct GNUNET_CHAT_File
char *name;
struct GNUNET_HashCode hash;
-
struct GNUNET_CRYPTO_SymmetricSessionKey *key;
struct GNUNET_FS_MetaData *meta;
-
struct GNUNET_FS_Uri *uri;
+
struct GNUNET_FS_DownloadContext *download;
struct GNUNET_FS_PublishContext *publish;
struct GNUNET_FS_UnindexContext *unindex;
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -2416,8 +2416,8 @@ GNUNET_CHAT_file_open_preview (struct GNUNET_CHAT_File *file)
remove(file->preview);
if ((GNUNET_OK != GNUNET_DISK_file_copy(filename, file->preview)) ||
- (GNUNET_OK != util_decrypt_file(file->preview,
- &(file->hash), file->key)))
+ ((file->key) && (GNUNET_OK != util_decrypt_file(file->preview,
+ &(file->hash), file->key))))
{
GNUNET_free(file->preview);
file->preview = NULL;