GNUnet 0.26.2-14-ga82e62fdc
 
Loading...
Searching...
No Matches
plugin_gnsrecord_messenger.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021--2026 GNUnet e.V.
4
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
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
27#include "gnunet_common.h"
28#include "platform.h"
29#include "gnunet_util_lib.h"
33
34
44static char *
46 uint32_t type,
47 const void *data,
48 size_t data_size)
49{
50 (void) cls;
51 switch (type)
52 {
54 {
55 if (data_size != sizeof(struct GNUNET_MESSENGER_RoomEntryRecord))
56 {
58 return NULL;
59 }
60 {
62
64 &(record->door.public_key));
66 &(record->key), sizeof(struct GNUNET_HashCode));
67
68 char *ret;
69 GNUNET_asprintf (&ret, "%s-%s", key, door);
72 return ret;
73 }
74 }
76 {
78 {
80 return NULL;
81 }
82 {
84
85 char *name = GNUNET_strndup (record->name, 256);
87 &(record->flags), sizeof(uint32_t));
88
89 char *ret;
90 GNUNET_asprintf (&ret, "%s-%s", flags, name);
93 return ret;
94 }
95 }
97 {
99 {
100 GNUNET_break_op (0);
101 return NULL;
102 }
103 {
105
107 &(record->key),
108 sizeof(struct GNUNET_HashCode));
110 &(record->hash),
111 sizeof(struct GNUNET_HashCode));
113 &(record->identifier),
114 sizeof(struct GNUNET_ShortHashCode));
116 &(record->shared_key),
117 sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey));
119 &(record->flags),
120 sizeof(uint32_t));
122 &(record->checksum),
123 sizeof(int32_t));
124
125 char *ret;
127 &ret,
128 "%s-%s-%s-%s-%s-%s",
129 checksum,
130 flags,
133 hash,
134 key);
135
142 return ret;
143 }
144 }
146 {
148 {
149 GNUNET_break_op (0);
150 return NULL;
151 }
152 {
154
156 &(record->key),
157 sizeof(struct GNUNET_HashCode));
159 &(record->nonce_data),
160 sizeof(record->nonce_data));
161 char *encryption_key_length = GNUNET_STRINGS_data_to_string_alloc (
162 &(record->encrypted_key_length),
163 sizeof(uint32_t));
164 char *encryption_key_checksum = GNUNET_STRINGS_data_to_string_alloc (
165 &(record->encrypted_key_checksum),
166 sizeof(int32_t));
167 char *encryption_key = GNUNET_STRINGS_data_to_string_alloc (
168 &(record->encrypted_key_data),
169 sizeof(record->encrypted_key_data));
170
171 char *ret;
173 &ret,
174 "%s-%s-%s-%s-%s",
175 encryption_key,
176 encryption_key_checksum,
177 encryption_key_length,
178 nonce,
179 key);
180
181 GNUNET_free (encryption_key);
182 GNUNET_free (encryption_key_checksum);
183 GNUNET_free (encryption_key_length);
184 GNUNET_free (nonce);
186 return ret;
187 }
188 }
189 default:
190 return NULL;
191 }
192}
193
194
206static int
208 uint32_t type,
209 const char *s,
210 void **data,
211 size_t *data_size)
212{
213 (void) cls;
214 if (NULL == s)
215 {
216 GNUNET_break (0);
217 return GNUNET_SYSERR;
218 }
219
220 switch (type)
221 {
223 {
224 char key[104];
225 const char *dash;
226 struct GNUNET_PeerIdentity door;
227
228 if ((NULL == (dash = strchr (s, '-'))) ||
229 (1 != sscanf (s, "%103s-", key)) ||
231 dash + 1, strlen (dash + 1), &(door.public_key))))
232 {
233 GNUNET_log (
235 _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"),
236 s);
237
238 return GNUNET_SYSERR;
239 }
240 {
243
245 key, strlen (key),
246 &(record->key), sizeof(struct GNUNET_HashCode)))
247 {
248 GNUNET_log (
250 _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"),
251 s);
252
254 return GNUNET_SYSERR;
255 }
256
257 record->door = door;
258 *data = record;
260 return GNUNET_OK;
261 }
262 }
264 {
265 char flags[8];
266 const char *dash;
267
268 if ((NULL == (dash = strchr (s, '-'))) ||
269 (1 != sscanf (s, "%7s-", flags)) ||
270 (strlen (dash + 1) > 256))
271 {
272 GNUNET_log (
274 _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
275 s);
276
277 return GNUNET_SYSERR;
278 }
279 {
282
284 flags, strlen (flags),
285 &(record->flags), sizeof(uint32_t)))
286 {
287 GNUNET_log (
289 _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
290 s);
291
293 return GNUNET_SYSERR;
294 }
295
296 GNUNET_memcpy (record->name, dash + 1, strlen (dash + 1));
297
298 *data = record;
300 return GNUNET_OK;
301 }
302 }
304 {
305 char key[104];
306 char hash[104];
307 char identifier[53];
308 char shared_key[104];
309 char flags[8];
310 char checksum[8];
311 const char *dash;
312 const char *s0;
313
314 s0 = s;
315 if ((NULL == (dash = strchr (s0, '-'))) ||
316 (1 != sscanf (s0, "%7s-", checksum)) ||
317 (strlen (dash + 1) < 8))
318 {
319 GNUNET_log (
321 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
322 s);
323
324 return GNUNET_SYSERR;
325 }
326
327 s0 = dash + 1;
328 if ((NULL == (dash = strchr (s0, '-'))) ||
329 (1 != sscanf (s0, "%7s-", flags)) ||
330 (strlen (dash + 1) < 104))
331 {
332 GNUNET_log (
334 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
335 s);
336
337 return GNUNET_SYSERR;
338 }
339
340 s0 = dash + 1;
341 if ((NULL == (dash = strchr (s0, '-'))) ||
342 (1 != sscanf (s0, "%103s-", shared_key)) ||
343 (strlen (dash + 1) < 53))
344 {
345 GNUNET_log (
347 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
348 s);
349
350 return GNUNET_SYSERR;
351 }
352
353 s0 = dash + 1;
354 if ((NULL == (dash = strchr (s0, '-'))) ||
355 (1 != sscanf (s0, "%52s-", identifier)) ||
356 (strlen (dash + 1) < 104))
357 {
358 GNUNET_log (
360 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
361 s);
362
363 return GNUNET_SYSERR;
364 }
365
366 s0 = dash + 1;
367 if ((NULL == (dash = strchr (s0, '-'))) ||
368 (1 != sscanf (s0, "%103s-", hash)) ||
369 (strlen (dash + 1) != 103))
370 {
371 GNUNET_log (
373 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
374 s);
375
376 return GNUNET_SYSERR;
377 }
378
379 GNUNET_memcpy (key, dash + 1, strlen (dash + 1));
380 key[103] = '\0';
381
382 {
385
387 checksum, strlen (checksum),
388 &(record->checksum), sizeof(int32_t))) ||
390 flags, strlen (flags),
391 &(record->flags), sizeof(uint32_t))) ||
393 shared_key, strlen (shared_key),
394 &(record->shared_key),
395 sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)))
396 ||
398 identifier, strlen (identifier),
399 &(record->identifier),
400 sizeof(struct GNUNET_ShortHashCode)))
401 ||
403 hash, strlen (hash),
404 &(record->hash),
405 sizeof(struct GNUNET_HashCode))) ||
407 key, strlen (key),
408 &(record->key),
409 sizeof(struct GNUNET_HashCode))))
410 {
411 GNUNET_log (
413 _ ("Unable to parse MESSENGER_ROOM_EPOCH_KEY record `%s'\n"),
414 s);
415
417 return GNUNET_SYSERR;
418 }
419
420 *data = record;
422 return GNUNET_OK;
423 }
424 }
426 {
427 char key[104];
428 char nonce[53];
429 char encryption_key_length[8];
430 char encryption_key_checksum[8];
431 char encryption_key[827];
432 const char *dash;
433 const char *s0;
434
435 s0 = s;
436 if ((NULL == (dash = strchr (s0, '-'))) ||
437 (1 != sscanf (s0, "%826s-", encryption_key)) ||
438 (strlen (dash + 1) < 8))
439 {
440 GNUNET_log (
442 _ ("Unable to parse MESSENGER_ENCRYPTION_KEY record `%s'\n"),
443 s);
444
445 return GNUNET_SYSERR;
446 }
447
448 s0 = dash + 1;
449 if ((NULL == (dash = strchr (s0, '-'))) ||
450 (1 != sscanf (s0, "%7s-", encryption_key_checksum)) ||
451 (strlen (dash + 1) < 8))
452 {
453 GNUNET_log (
455 _ ("Unable to parse MESSENGER_ENCRYPTION_KEY record `%s'\n"),
456 s);
457
458 return GNUNET_SYSERR;
459 }
460
461 s0 = dash + 1;
462 if ((NULL == (dash = strchr (s0, '-'))) ||
463 (1 != sscanf (s0, "%7s-", encryption_key_length)) ||
464 (strlen (dash + 1) < 53))
465 {
466 GNUNET_log (
468 _ ("Unable to parse MESSENGER_ENCRYPTION_KEY record `%s'\n"),
469 s);
470
471 return GNUNET_SYSERR;
472 }
473
474 s0 = dash + 1;
475 if ((NULL == (dash = strchr (s0, '-'))) ||
476 (1 != sscanf (s0, "%52s-", nonce)) ||
477 (strlen (dash + 1) != 103))
478 {
479 GNUNET_log (
481 _ ("Unable to parse MESSENGER_ENCRYPTION_KEY record `%s'\n"),
482 s);
483
484 return GNUNET_SYSERR;
485 }
486
487 GNUNET_memcpy (key, dash + 1, strlen (dash + 1));
488 key[103] = '\0';
489
490 {
493
495 encryption_key, strlen (encryption_key),
496 record->encrypted_key_data,
497 sizeof(record->encrypted_key_data)))
498 ||
500 encryption_key_checksum, strlen (encryption_key_checksum),
501 &(record->encrypted_key_checksum),
502 sizeof(record->encrypted_key_checksum)))
503 ||
505 encryption_key_length, strlen (encryption_key_length),
506 &(record->encrypted_key_length),
507 sizeof(record->encrypted_key_length)))
508 ||
510 nonce, strlen (nonce),
511 record->nonce_data,
512 sizeof(record->nonce_data))) ||
514 key, strlen (key),
515 &(record->key),
516 sizeof(struct GNUNET_HashCode))))
517 {
518 GNUNET_log (
520 _ ("Unable to parse MESSENGER_ENCRYPTION_KEY record `%s'\n"),
521 s);
522
524 return GNUNET_SYSERR;
525 }
526
527 *data = record;
529 return GNUNET_OK;
530 }
531 }
532 default:
533 return GNUNET_SYSERR;
534 }
535}
536
537
542static struct
543{
544 const char *name;
545 uint32_t number;
546} name_map[] = {
547 { "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY },
548 { "MESSENGER_ROOM_DETAILS", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS },
549 { "MESSENGER_ROOM_EPOCH_KEY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY }
550 ,
551 { "MESSENGER_ENCRYPTION_KEY", GNUNET_GNSRECORD_TYPE_MESSENGER_ENCRYPTION_KEY }
552 ,
553 { NULL, UINT32_MAX }
555
556
564static uint32_t
566 const char *gns_typename)
567{
568 unsigned int i;
569
570 (void) cls;
571 i = 0;
572 while ((name_map[i].name != NULL) &&
573 (0 != strcasecmp (gns_typename, name_map[i].name)))
574 i++;
575 return name_map[i].number;
576}
577
578
586static const char *
588 uint32_t type)
589{
590 unsigned int i;
591
592 (void) cls;
593 i = 0;
594 while ((name_map[i].name != NULL) &&
595 (type != name_map[i].number))
596 i++;
597 return name_map[i].name;
598}
599
600
601void *
603
610void *
623
624
625void *
627
634void *
636{
638
639 GNUNET_free (api);
640 return NULL;
641}
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ENCRYPTION_KEY
Record type to store encryption keys used in messenger rooms.
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY
Record type to store epoch keys from a messenger room.
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY
Record type to share an entry of a messenger room.
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS
Record type to store details about a messenger room.
static int ret
Final status code.
Definition gnunet-arm.c:93
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Plugin API for GNS record types.
#define GNUNET_log(kind,...)
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition crypto_ecc.c:255
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition crypto_ecc.c:361
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition strings.c:812
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition strings.c:837
#define _(String)
GNU gettext support macro.
Definition platform.h:179
void * libgnunet_plugin_gnsrecord_messenger_init(void *cls)
Entry point for the plugin.
void * libgnunet_plugin_gnsrecord_messenger_done(void *cls)
Exit point from the plugin.
static char * messenger_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
const char * name
static const char * messenger_number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
static uint32_t messenger_typename_to_number(void *cls, const char *gns_typename)
Convert a type name (e.g.
static int messenger_string_to_value(void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'value' of a record to the binary representation.
static struct @44 name_map[]
Mapping of record type numbers to human-readable record type names.
uint32_t number
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
void * cls
Closure for all of the callbacks.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
A 512-bit hashcode.
An encryption key record specifies an encryption key for a given room that can be identified via a gi...
A room details record specifies a custom name for a given room and some additional space for flags.
A room entry record specifies which peer is hosting a given room and may also specify the key to ente...
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
A room epoch key record specifies an epoch key for a given room that can be identified via a given ke...
int32_t checksum
The encrypted checksum of the shared key.
uint32_t flags
The flags of the epoch or group key.
struct GNUNET_ShortHashCode identifier
The short hash identifying the epoch or group key.
struct GNUNET_CRYPTO_SymmetricSessionKey shared_key
The encrypted shared epoch or group key in the room.
struct GNUNET_HashCode hash
The hash identifying the epoch.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
A 256-bit hashcode.