libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit d493b7c96a3d09b8c06b093c59017717c8d41f06
parent b7253a37674ef6b1f9df1ad4dff88f5d501dbf53
Author: Jacki <jacki@thejackimonster.de>
Date:   Sat, 10 May 2025 04:01:41 +0200

Use room properties for room key selection

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/gnunet_chat_group_intern.c | 13+++++++------
Msrc/gnunet_chat_handle.c | 14++++++--------
Msrc/gnunet_chat_invitation.h | 4++--
Msrc/gnunet_chat_lib.c | 47+++++++++++++++++++----------------------------
Msrc/gnunet_chat_lobby.c | 12+++++-------
Mtools/gnunet_messenger_ping.c | 24+++++++++++++-----------
Mtools/gnunet_messenger_uml.c | 23+++++++++++++++++------
7 files changed, 69 insertions(+), 68 deletions(-)

diff --git a/src/gnunet_chat_group_intern.c b/src/gnunet_chat_group_intern.c @@ -54,8 +54,11 @@ search_group_by_topic(void *cls, if (0 == GNUNET_memcmp(&peer, door)) return; - const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( - group->context->room + union GNUNET_MESSENGER_RoomKey key; + GNUNET_memcpy( + &(key.hash), + GNUNET_MESSENGER_room_get_key(group->context->room), + sizeof(key.hash) ); if ((GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains( @@ -65,11 +68,9 @@ search_group_by_topic(void *cls, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) return; - struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_enter_room( + GNUNET_MESSENGER_enter_room( group->handle->messenger, door, - key + &key ); - - GNUNET_MESSENGER_use_room_keys(room, GNUNET_NO); } diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -29,6 +29,7 @@ #include "gnunet_chat_message.h" #include <gnunet/gnunet_arm_service.h> #include <gnunet/gnunet_common.h> +#include <gnunet/gnunet_messenger_service.h> #include <gnunet/gnunet_reclaim_service.h> #include <gnunet/gnunet_scheduler_lib.h> @@ -1089,12 +1090,12 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, if (!record) return NULL; - struct GNUNET_HashCode key; - GNUNET_memcpy (&key, &(record->key), sizeof(key)); + union GNUNET_MESSENGER_RoomKey key; + GNUNET_memcpy (&(key.hash), &(record->key), sizeof(key)); struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get( handle->contexts, - &key + &(key.hash) ); if ((context) && (context->room)) @@ -1121,11 +1122,8 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, context = context_create_from_room(handle, room); context_read_records(context, label, count, data); - GNUNET_MESSENGER_use_room_keys( - room, context->topic? GNUNET_NO : GNUNET_YES); - if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( - handle->contexts, &key, context, + handle->contexts, &(key.hash), context, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) { context_destroy(context); @@ -1142,7 +1140,7 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, group_publish(group); if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( - handle->groups, &key, group, + handle->groups, &(key.hash), group, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) group_destroy(group); diff --git a/src/gnunet_chat_invitation.h b/src/gnunet_chat_invitation.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2024 GNUnet e.V. + Copyright (C) 2021--2025 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -36,7 +36,7 @@ struct GNUNET_CHAT_Invitation struct GNUNET_HashCode hash; - struct GNUNET_HashCode key; + union GNUNET_MESSENGER_RoomKey key; GNUNET_PEER_Id door; }; diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -1020,14 +1020,10 @@ GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle, (!(handle->groups)) || (!(handle->contexts))) return NULL; - struct GNUNET_HashCode key; + union GNUNET_MESSENGER_RoomKey key; + GNUNET_MESSENGER_create_room_key(&key, topic, topic? GNUNET_YES : GNUNET_NO, GNUNET_YES); - if (topic) - GNUNET_CRYPTO_hash(topic, strlen(topic), &key); - else - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key)); - - if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(handle->contexts, &key)) + if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(handle->contexts, &(key.hash))) return NULL; struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room( @@ -1042,11 +1038,8 @@ GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle, util_set_name_field(topic, &(context->topic)); - // TODO: wrong key usage! - GNUNET_MESSENGER_use_room_keys(room, GNUNET_YES); // GNUNET_NO); - if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( - handle->contexts, &key, context, + handle->contexts, &(key.hash), context, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) goto destroy_context; @@ -1056,7 +1049,7 @@ GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle, group_publish(group); if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( - handle->groups, &key, group, + handle->groups, &(key.hash), group, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) { context_write_records(context); @@ -1065,7 +1058,7 @@ GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle, group_destroy(group); - GNUNET_CONTAINER_multihashmap_remove(handle->contexts, &key, context); + GNUNET_CONTAINER_multihashmap_remove(handle->contexts, &(key.hash), context); destroy_context: context_destroy(context); @@ -1456,12 +1449,15 @@ GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group, if (!context) return GNUNET_SYSERR; - const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( - group->context->room + union GNUNET_MESSENGER_RoomKey key; + GNUNET_memcpy( + &(key.hash), + GNUNET_MESSENGER_room_get_key(group->context->room), + sizeof(key.hash) ); handle_send_room_name(group->handle, GNUNET_MESSENGER_open_room( - group->handle->messenger, key + group->handle->messenger, &key )); struct GNUNET_MESSENGER_Message msg; @@ -1469,7 +1465,7 @@ GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group, msg.header.kind = GNUNET_MESSENGER_KIND_INVITE; GNUNET_CRYPTO_get_peer_identity(group->handle->cfg, &(msg.body.invite.door)); - GNUNET_memcpy(&(msg.body.invite.key), key, sizeof(msg.body.invite.key)); + GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key)); GNUNET_MESSENGER_send_message(context->room, &msg, contact->member); return GNUNET_OK; @@ -1598,11 +1594,11 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) if (!other) goto cleanup_contact; - struct GNUNET_HashCode key; - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key)); + union GNUNET_MESSENGER_RoomKey key; + GNUNET_MESSENGER_create_room_key(&key, NULL, GNUNET_NO, GNUNET_NO); if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains( - handle->contexts, &key)) + handle->contexts, &(key.hash))) goto cleanup_contact; struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room( @@ -1615,12 +1611,10 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) context_update_room(context, room, GNUNET_YES); if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( - handle->contexts, &key, context, + handle->contexts, &(key.hash), context, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) goto cleanup_room; - GNUNET_MESSENGER_use_room_keys(room, GNUNET_YES); - struct GNUNET_MESSENGER_Message msg; memset(&msg, 0, sizeof(msg)); @@ -2902,13 +2896,10 @@ GNUNET_CHAT_invitation_accept (struct GNUNET_CHAT_Invitation *invitation) struct GNUNET_PeerIdentity door; GNUNET_PEER_resolve(invitation->door, &door); - struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_enter_room( + GNUNET_MESSENGER_enter_room( invitation->context->handle->messenger, &door, &(invitation->key) ); - - // TODO: guessing forward-secrecy is expected after invite? - GNUNET_MESSENGER_use_room_keys(room, GNUNET_YES); } @@ -2949,7 +2940,7 @@ GNUNET_CHAT_invitation_is_accepted (const struct GNUNET_CHAT_Invitation *invitat return GNUNET_CONTAINER_multihashmap_contains( invitation->context->handle->contexts, - &(invitation->key) + &(invitation->key.hash) ); } diff --git a/src/gnunet_chat_lobby.c b/src/gnunet_chat_lobby.c @@ -26,6 +26,7 @@ #include "gnunet_chat_handle.h" #include "gnunet_chat_lobby_intern.c" +#include <gnunet/gnunet_messenger_service.h> struct GNUNET_CHAT_Lobby* lobby_create (struct GNUNET_CHAT_Handle *handle) @@ -95,8 +96,8 @@ lobby_open (struct GNUNET_CHAT_Lobby *lobby, goto open_zone; } - struct GNUNET_HashCode key; - GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key)); + union GNUNET_MESSENGER_RoomKey key; + GNUNET_MESSENGER_create_room_key(&key, NULL, GNUNET_NO, GNUNET_NO); struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room( lobby->handle->messenger, @@ -108,11 +109,8 @@ lobby_open (struct GNUNET_CHAT_Lobby *lobby, lobby->context = context_create_from_room(lobby->handle, room); - // TODO: would be better to include key usage into lobby somehow! - GNUNET_MESSENGER_use_room_keys(room, GNUNET_YES); - if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( - lobby->handle->contexts, &key, lobby->context, + lobby->handle->contexts, &(key.hash), lobby->context, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) { context_destroy(lobby->context); @@ -123,7 +121,7 @@ lobby_open (struct GNUNET_CHAT_Lobby *lobby, } open_zone: - util_lobby_name(&key, &name); + util_lobby_name(&(key.hash), &name); lobby->op = GNUNET_IDENTITY_create( lobby->handle->identity, diff --git a/tools/gnunet_messenger_ping.c b/tools/gnunet_messenger_ping.c @@ -498,22 +498,28 @@ ego_lookup (void *cls, printf("%s", GNUNET_i2s(&peer)); - struct GNUNET_HashCode hash; + union GNUNET_MESSENGER_RoomKey rkey; if (tool->room_name) { printf(":%s", tool->room_name); - GNUNET_CRYPTO_hash( + GNUNET_MESSENGER_create_room_key( + &rkey, tool->room_name, - strlen(tool->room_name), - &hash + tool->public_room? GNUNET_YES : GNUNET_NO, + GNUNET_YES ); } else - memset(&hash, 0, sizeof(hash)); + { + memset(&(rkey.hash), 0, sizeof(rkey.hash)); + + rkey.code.public_bit = tool->public_room? 1 : 0; + rkey.code.group_bit = 1; + } printf(" (%s): ", - GNUNET_h2s(&hash)); + GNUNET_h2s(&(rkey.hash))); if (0 == tool->count) { @@ -526,12 +532,8 @@ ego_lookup (void *cls, tool->room = GNUNET_MESSENGER_enter_room( tool->handle, &peer, - &hash + &rkey ); - - if (tool->room) - GNUNET_MESSENGER_use_room_keys( - tool->room, tool->public_room? GNUNET_NO : GNUNET_YES); if (tool->timeout) tool->task = GNUNET_SCHEDULER_add_delayed_with_priority( diff --git a/tools/gnunet_messenger_uml.c b/tools/gnunet_messenger_uml.c @@ -62,6 +62,7 @@ struct GNUNET_MESSENGER_Tool char *ego_name; char *room_name; + int public_room; int ignore_targets; int ignore_epochs; int simplify_merges; @@ -424,16 +425,20 @@ ego_lookup (void *cls, ); else memset(&hash, 0, sizeof(hash)); + + union GNUNET_MESSENGER_RoomKey rkey; + GNUNET_MESSENGER_create_room_key( + &rkey, + tool->room_name, + tool->public_room? GNUNET_YES : GNUNET_NO, + GNUNET_YES + ); - struct GNUNET_MESSENGER_Room *room; - room = GNUNET_MESSENGER_enter_room( + GNUNET_MESSENGER_enter_room( tool->handle, &peer, - &hash + &rkey ); - - if (room) - GNUNET_MESSENGER_use_room_keys(room, GNUNET_NO); } static void @@ -486,6 +491,12 @@ main (int argc, &(tool.room_name) ), GNUNET_GETOPT_option_flag( + 'P', + "public", + "disable forward secrecy in public rooms", + &(tool.public_room) + ), + GNUNET_GETOPT_option_flag( 'i', "ignore-targets", "ignore indirect connections between messages and their targets",