aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-01-04 21:01:58 +0100
committerJacki <jacki@thejackimonster.de>2024-01-04 21:01:58 +0100
commitf20fb24047d2416023425e657cb141acc08065c4 (patch)
treee4d6acebca901ca5a59d3d0ee18eef7949069129
parent2ee30f372acad534246beaf579b7bbfefab0b246 (diff)
downloadlibgnunetchat-f20fb24047d2416023425e657cb141acc08065c4.tar.gz
libgnunetchat-f20fb24047d2416023425e657cb141acc08065c4.zip
Revoke tickets on account deletion/update
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r--meson.build3
-rw-r--r--src/gnunet_chat_handle.c81
-rw-r--r--src/gnunet_chat_handle.h24
-rw-r--r--src/gnunet_chat_handle_intern.c112
4 files changed, 209 insertions, 11 deletions
diff --git a/meson.build b/meson.build
index 0893776..5a4ab0a 100644
--- a/meson.build
+++ b/meson.build
@@ -1,6 +1,6 @@
1# 1#
2# This file is part of GNUnet. 2# This file is part of GNUnet.
3# Copyright (C) 2023 GNUnet e.V. 3# Copyright (C) 2023--2024 GNUnet e.V.
4# 4#
5# GNUnet is free software: you can redistribute it and/or modify it 5# GNUnet is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Affero General Public License as published 6# under the terms of the GNU Affero General Public License as published
@@ -37,6 +37,7 @@ gnunetchat_deps = [
37 dependency('gnunetidentity'), 37 dependency('gnunetidentity'),
38 dependency('gnunetmessenger'), 38 dependency('gnunetmessenger'),
39 dependency('gnunetnamestore'), 39 dependency('gnunetnamestore'),
40 dependency('gnunetreclaim'),
40 dependency('gnunetregex'), 41 dependency('gnunetregex'),
41 dependency('gnunetutil'), 42 dependency('gnunetutil'),
42] 43]
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index 97fff80..25eecc6 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -25,6 +25,7 @@
25#include "gnunet_chat_handle.h" 25#include "gnunet_chat_handle.h"
26 26
27#include "gnunet_chat_handle_intern.c" 27#include "gnunet_chat_handle_intern.c"
28#include <gnunet/gnunet_reclaim_service.h>
28 29
29static const unsigned int initial_map_size_of_handle = 8; 30static const unsigned int initial_map_size_of_handle = 8;
30static const unsigned int minimum_amount_of_other_members_in_group = 2; 31static const unsigned int minimum_amount_of_other_members_in_group = 2;
@@ -95,8 +96,11 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
95 handle->lobbies_head = NULL; 96 handle->lobbies_head = NULL;
96 handle->lobbies_tail = NULL; 97 handle->lobbies_tail = NULL;
97 98
98 handle->lobbies_head = NULL; 99 handle->lookups_head = NULL;
99 handle->lobbies_tail = NULL; 100 handle->lookups_tail = NULL;
101
102 handle->tickets_head = NULL;
103 handle->tickets_tail = NULL;
100 104
101 handle->files = NULL; 105 handle->files = NULL;
102 handle->contexts = NULL; 106 handle->contexts = NULL;
@@ -122,6 +126,10 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
122 handle->cfg 126 handle->cfg
123 ); 127 );
124 128
129 handle->reclaim = GNUNET_RECLAIM_connect(
130 handle->cfg
131 );
132
125 handle->fs = NULL; 133 handle->fs = NULL;
126 handle->gns = NULL; 134 handle->gns = NULL;
127 handle->messenger = NULL; 135 handle->messenger = NULL;
@@ -171,6 +179,29 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle)
171 if (handle->namestore) 179 if (handle->namestore)
172 GNUNET_NAMESTORE_disconnect(handle->namestore); 180 GNUNET_NAMESTORE_disconnect(handle->namestore);
173 181
182 struct GNUNET_CHAT_TicketProcess *tickets;
183 while (handle->tickets_head)
184 {
185 tickets = handle->tickets_head;
186
187 if (tickets->iter)
188 GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter);
189
190 if (tickets->op)
191 GNUNET_RECLAIM_cancel(tickets->op);
192
193 GNUNET_CONTAINER_DLL_remove(
194 handle->tickets_head,
195 handle->tickets_tail,
196 tickets
197 );
198
199 GNUNET_free(tickets);
200 }
201
202 if (handle->reclaim)
203 GNUNET_RECLAIM_disconnect(handle->reclaim);
204
174 struct GNUNET_CHAT_InternalAccounts *accounts; 205 struct GNUNET_CHAT_InternalAccounts *accounts;
175 206
176 while (handle->accounts_head) 207 while (handle->accounts_head)
@@ -298,10 +329,6 @@ handle_connect (struct GNUNET_CHAT_Handle *handle,
298 329
299 const char *name = account->name; 330 const char *name = account->name;
300 331
301 const struct GNUNET_CRYPTO_PrivateKey *key = NULL;
302 if (account->ego)
303 key = GNUNET_IDENTITY_ego_get_private_key(account->ego);
304
305 char* fs_client_name = NULL; 332 char* fs_client_name = NULL;
306 GNUNET_asprintf ( 333 GNUNET_asprintf (
307 &fs_client_name, 334 &fs_client_name,
@@ -321,6 +348,10 @@ handle_connect (struct GNUNET_CHAT_Handle *handle,
321 348
322 handle->gns = GNUNET_GNS_connect(handle->cfg); 349 handle->gns = GNUNET_GNS_connect(handle->cfg);
323 350
351 const struct GNUNET_CRYPTO_PrivateKey *key = NULL;
352 if (account->ego)
353 key = GNUNET_IDENTITY_ego_get_private_key(account->ego);
354
324 handle->messenger = GNUNET_MESSENGER_connect( 355 handle->messenger = GNUNET_MESSENGER_connect(
325 handle->cfg, name, key, 356 handle->cfg, name, key,
326 on_handle_message, 357 on_handle_message,
@@ -962,3 +993,41 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle,
962 993
963 return context; 994 return context;
964} 995}
996
997void
998handle_update_tickets (struct GNUNET_CHAT_Handle *handle,
999 const struct GNUNET_CRYPTO_PrivateKey *identity)
1000{
1001 GNUNET_assert((handle) && (identity));
1002
1003 struct GNUNET_CHAT_TicketProcess *tickets = GNUNET_new(
1004 struct GNUNET_CHAT_TicketProcess
1005 );
1006
1007 if (!tickets)
1008 return;
1009
1010 memset(tickets, 0, sizeof(struct GNUNET_CHAT_TicketProcess));
1011 GNUNET_memcpy(
1012 &(tickets->identity),
1013 identity,
1014 sizeof(tickets->identity)
1015 );
1016
1017 tickets->iter = GNUNET_RECLAIM_ticket_iteration_start(
1018 handle->reclaim,
1019 identity,
1020 cb_task_error_ticket_update,
1021 tickets,
1022 cb_iterate_ticket_update,
1023 tickets,
1024 cb_task_finish_ticket_update,
1025 tickets
1026 );
1027
1028 GNUNET_CONTAINER_DLL_insert_tail(
1029 handle->tickets_head,
1030 handle->tickets_tail,
1031 tickets
1032 );
1033}
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 0ac3bc8..f10c1e2 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -31,6 +31,7 @@
31#include <gnunet/gnunet_identity_service.h> 31#include <gnunet/gnunet_identity_service.h>
32#include <gnunet/gnunet_messenger_service.h> 32#include <gnunet/gnunet_messenger_service.h>
33#include <gnunet/gnunet_namestore_service.h> 33#include <gnunet/gnunet_namestore_service.h>
34#include <gnunet/gnunet_reclaim_service.h>
34#include <gnunet/gnunet_util_lib.h> 35#include <gnunet/gnunet_util_lib.h>
35 36
36#include "gnunet_chat_lib.h" 37#include "gnunet_chat_lib.h"
@@ -80,6 +81,19 @@ struct GNUNET_CHAT_UriLookups
80 struct GNUNET_CHAT_UriLookups *prev; 81 struct GNUNET_CHAT_UriLookups *prev;
81}; 82};
82 83
84struct GNUNET_CHAT_TicketProcess
85{
86 struct GNUNET_CHAT_Handle *handle;
87
88 struct GNUNET_CRYPTO_PrivateKey identity;
89
90 struct GNUNET_RECLAIM_TicketIterator *iter;
91 struct GNUNET_RECLAIM_Operation *op;
92
93 struct GNUNET_CHAT_TicketProcess *next;
94 struct GNUNET_CHAT_TicketProcess *prev;
95};
96
83struct GNUNET_CHAT_Handle 97struct GNUNET_CHAT_Handle
84{ 98{
85 const struct GNUNET_CONFIGURATION_Handle* cfg; 99 const struct GNUNET_CONFIGURATION_Handle* cfg;
@@ -106,6 +120,9 @@ struct GNUNET_CHAT_Handle
106 struct GNUNET_CHAT_UriLookups *lookups_head; 120 struct GNUNET_CHAT_UriLookups *lookups_head;
107 struct GNUNET_CHAT_UriLookups *lookups_tail; 121 struct GNUNET_CHAT_UriLookups *lookups_tail;
108 122
123 struct GNUNET_CHAT_TicketProcess *tickets_head;
124 struct GNUNET_CHAT_TicketProcess *tickets_tail;
125
109 struct GNUNET_CONTAINER_MultiHashMap *files; 126 struct GNUNET_CONTAINER_MultiHashMap *files;
110 struct GNUNET_CONTAINER_MultiHashMap *contexts; 127 struct GNUNET_CONTAINER_MultiHashMap *contexts;
111 struct GNUNET_CONTAINER_MultiShortmap *contacts; 128 struct GNUNET_CONTAINER_MultiShortmap *contacts;
@@ -117,6 +134,7 @@ struct GNUNET_CHAT_Handle
117 struct GNUNET_IDENTITY_Handle *identity; 134 struct GNUNET_IDENTITY_Handle *identity;
118 struct GNUNET_MESSENGER_Handle *messenger; 135 struct GNUNET_MESSENGER_Handle *messenger;
119 struct GNUNET_NAMESTORE_Handle *namestore; 136 struct GNUNET_NAMESTORE_Handle *namestore;
137 struct GNUNET_RECLAIM_Handle *reclaim;
120 138
121 char *public_key; 139 char *public_key;
122 void *user_pointer; 140 void *user_pointer;
@@ -326,4 +344,10 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle,
326 unsigned int count, 344 unsigned int count,
327 const struct GNUNET_GNSRECORD_Data *data); 345 const struct GNUNET_GNSRECORD_Data *data);
328 346
347/**
348 */
349void
350handle_update_tickets (struct GNUNET_CHAT_Handle *handle,
351 const struct GNUNET_CRYPTO_PrivateKey *identity);
352
329#endif /* GNUNET_CHAT_HANDLE_H_ */ 353#endif /* GNUNET_CHAT_HANDLE_H_ */
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index 5df5bed..f9bc0fe 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -31,9 +31,13 @@
31#include "gnunet_chat_message.h" 31#include "gnunet_chat_message.h"
32#include "gnunet_chat_util.h" 32#include "gnunet_chat_util.h"
33 33
34#include <gnunet/gnunet_common.h>
35#include <gnunet/gnunet_identity_service.h>
34#include <gnunet/gnunet_messenger_service.h> 36#include <gnunet/gnunet_messenger_service.h>
37#include <gnunet/gnunet_reclaim_service.h>
35#include <gnunet/gnunet_util_lib.h> 38#include <gnunet/gnunet_util_lib.h>
36#include <stdio.h> 39#include <stdio.h>
40#include <string.h>
37 41
38#define GNUNET_UNUSED __attribute__ ((unused)) 42#define GNUNET_UNUSED __attribute__ ((unused))
39 43
@@ -242,11 +246,98 @@ notify_handle_fs_progress(void* cls,
242} 246}
243 247
244void 248void
245on_handle_gnunet_identity(void *cls, 249cb_task_finish_ticket_update (void *cls)
246 struct GNUNET_IDENTITY_Ego *ego,
247 void **ctx,
248 const char *name)
249{ 250{
251 GNUNET_assert(cls);
252
253 struct GNUNET_CHAT_TicketProcess *tickets = (
254 (struct GNUNET_CHAT_TicketProcess*) cls
255 );
256
257 struct GNUNET_CHAT_Handle *handle = tickets->handle;
258
259 if (tickets->iter)
260 GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter);
261
262 if (tickets->op)
263 GNUNET_RECLAIM_cancel(tickets->op);
264
265 GNUNET_CONTAINER_DLL_remove(
266 handle->tickets_head,
267 handle->tickets_tail,
268 tickets
269 );
270
271 GNUNET_free(tickets);
272}
273
274void
275cb_task_error_ticket_update (void *cls)
276{
277 GNUNET_assert(cls);
278
279 struct GNUNET_CHAT_TicketProcess *tickets = (
280 (struct GNUNET_CHAT_TicketProcess*) cls
281 );
282
283 handle_send_internal_message(
284 tickets->handle,
285 NULL,
286 GNUNET_CHAT_FLAG_WARNING,
287 "Ticket update failed!"
288 );
289
290 cb_task_finish_ticket_update(cls);
291}
292
293static void
294cont_revoke_ticket_with_status (void *cls,
295 int32_t success,
296 const char *emsg)
297{
298 GNUNET_assert(cls);
299
300 struct GNUNET_CHAT_TicketProcess *tickets = (
301 (struct GNUNET_CHAT_TicketProcess*) cls
302 );
303
304 tickets->op = NULL;
305
306 GNUNET_RECLAIM_ticket_iteration_next(tickets->iter);
307}
308
309void
310cb_iterate_ticket_update (void *cls,
311 const struct GNUNET_RECLAIM_Ticket *ticket)
312{
313 GNUNET_assert(cls);
314
315 struct GNUNET_CHAT_TicketProcess *tickets = (
316 (struct GNUNET_CHAT_TicketProcess*) cls
317 );
318
319 struct GNUNET_CHAT_Handle *handle = tickets->handle;
320
321 if (tickets->op)
322 GNUNET_RECLAIM_cancel(tickets->op);
323
324 tickets->op = GNUNET_RECLAIM_ticket_revoke(
325 handle->reclaim,
326 &(tickets->identity),
327 ticket,
328 cont_revoke_ticket_with_status,
329 tickets
330 );
331}
332
333void
334on_handle_gnunet_identity (void *cls,
335 struct GNUNET_IDENTITY_Ego *ego,
336 void **ctx,
337 const char *name)
338{
339 GNUNET_assert(cls);
340
250 struct GNUNET_CHAT_Handle* handle = cls; 341 struct GNUNET_CHAT_Handle* handle = cls;
251 342
252 if (!ctx) 343 if (!ctx)
@@ -279,6 +370,12 @@ on_handle_gnunet_identity(void *cls,
279 } 370 }
280 else 371 else
281 { 372 {
373 const struct GNUNET_CRYPTO_PrivateKey *key;
374 key = GNUNET_IDENTITY_ego_get_private_key(ego);
375
376 if (key)
377 handle_update_tickets(handle, key);
378
282 if (handle->current == accounts->account) 379 if (handle->current == accounts->account)
283 handle_disconnect(handle); 380 handle_disconnect(handle);
284 381
@@ -465,7 +562,14 @@ cb_account_update_completion (void *cls,
465 struct GNUNET_CHAT_Handle *handle = accounts->handle; 562 struct GNUNET_CHAT_Handle *handle = accounts->handle;
466 563
467 if ((GNUNET_EC_NONE == ec) && (key)) 564 if ((GNUNET_EC_NONE == ec) && (key))
565 {
566 const struct GNUNET_CRYPTO_PrivateKey *prev= handle_get_key(handle);
567
568 if (prev)
569 handle_update_tickets(handle, prev);
570
468 GNUNET_MESSENGER_set_key(handle->messenger, key); 571 GNUNET_MESSENGER_set_key(handle->messenger, key);
572 }
469 573
470 cb_account_creation(cls, key, ec); 574 cb_account_creation(cls, key, ec);
471} 575}