GNUnet 0.26.2-16-ge86b66bd5
 
Loading...
Searching...
No Matches
plugin_gnsrecord_messenger.c File Reference
Include dependency graph for plugin_gnsrecord_messenger.c:

Go to the source code of this file.

Functions

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.
 
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 uint32_t messenger_typename_to_number (void *cls, const char *gns_typename)
 Convert a type name (e.g.
 
static const char * messenger_number_to_typename (void *cls, uint32_t type)
 Convert a type number to the corresponding type string (e.g.
 
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.
 

Variables

struct { 
 
   const char *   name 
 
   uint32_t   number 
 
name_map [] 
 Mapping of record type numbers to human-readable record type names.
 

Function Documentation

◆ messenger_value_to_string()

static char * messenger_value_to_string ( void *  cls,
uint32_t  type,
const void *  data,
size_t  data_size 
)
static

Convert the 'value' of a record to a string.

Parameters
clsclosure, unused
typetype of the record
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Definition at line 45 of file plugin_gnsrecord_messenger.c.

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}
#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.
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
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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_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
const char * name
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.
A 256-bit hashcode.

References GNUNET_MESSENGER_RoomEpochKeyRecord::checksum, data, data_size, GNUNET_MESSENGER_RoomEntryRecord::door, GNUNET_MESSENGER_RoomDetailsRecord::flags, GNUNET_MESSENGER_RoomEpochKeyRecord::flags, GNUNET_asprintf(), GNUNET_break_op, GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_free, GNUNET_GNSRECORD_TYPE_MESSENGER_ENCRYPTION_KEY, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY, GNUNET_STRINGS_data_to_string_alloc(), GNUNET_strndup, GNUNET_MESSENGER_RoomEpochKeyRecord::hash, GNUNET_MESSENGER_RoomEpochKeyRecord::identifier, key, name, record(), ret, GNUNET_MESSENGER_RoomEpochKeyRecord::shared_key, and type.

Referenced by libgnunet_plugin_gnsrecord_messenger_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messenger_string_to_value()

static int messenger_string_to_value ( void *  cls,
uint32_t  type,
const char *  s,
void **  data,
size_t *  data_size 
)
static

Convert human-readable version of a 'value' of a record to the binary representation.

Parameters
clsclosure, unused
typetype of the record
shuman-readable string
dataset to value in binary encoding (will be allocated)
data_sizeset to number of bytes in data
Returns
GNUNET_OK on success

Definition at line 207 of file plugin_gnsrecord_messenger.c.

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}
#define GNUNET_log(kind,...)
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(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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
The identity of the host (wraps the signing key of the peer).

References _, GNUNET_MESSENGER_RoomEpochKeyRecord::checksum, data, data_size, GNUNET_MESSENGER_RoomEntryRecord::door, GNUNET_MESSENGER_RoomDetailsRecord::flags, GNUNET_MESSENGER_RoomEpochKeyRecord::flags, GNUNET_break, GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNSRECORD_TYPE_MESSENGER_ENCRYPTION_KEY, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY, GNUNET_log, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_MESSENGER_RoomEpochKeyRecord::hash, GNUNET_MESSENGER_RoomEpochKeyRecord::identifier, key, GNUNET_PeerIdentity::public_key, record(), GNUNET_MESSENGER_RoomEpochKeyRecord::shared_key, and type.

Referenced by libgnunet_plugin_gnsrecord_messenger_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messenger_typename_to_number()

static uint32_t messenger_typename_to_number ( void *  cls,
const char *  gns_typename 
)
static

Convert a type name (e.g.

"AAAA") to the corresponding number.

Parameters
clsclosure, unused
gns_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 565 of file plugin_gnsrecord_messenger.c.

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}
static struct @44 name_map[]
Mapping of record type numbers to human-readable record type names.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_messenger_init().

Here is the caller graph for this function:

◆ messenger_number_to_typename()

static const char * messenger_number_to_typename ( void *  cls,
uint32_t  type 
)
static

Convert a type number to the corresponding type string (e.g.

1 to "A")

Parameters
clsclosure, unused
typenumber of a type to convert
Returns
corresponding typestring, NULL on error

Definition at line 587 of file plugin_gnsrecord_messenger.c.

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}

References name, name_map, and type.

Referenced by libgnunet_plugin_gnsrecord_messenger_init().

Here is the caller graph for this function:

◆ libgnunet_plugin_gnsrecord_messenger_init()

void * libgnunet_plugin_gnsrecord_messenger_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 611 of file plugin_gnsrecord_messenger.c.

612{
614
615 (void) cls;
621 return api;
622}
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.
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.
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.

References GNUNET_GNSRECORD_PluginFunctions::cls, GNUNET_new, messenger_number_to_typename(), messenger_string_to_value(), messenger_typename_to_number(), messenger_value_to_string(), GNUNET_GNSRECORD_PluginFunctions::number_to_typename, GNUNET_GNSRECORD_PluginFunctions::string_to_value, GNUNET_GNSRECORD_PluginFunctions::typename_to_number, and GNUNET_GNSRECORD_PluginFunctions::value_to_string.

Here is the call graph for this function:

◆ libgnunet_plugin_gnsrecord_messenger_done()

void * libgnunet_plugin_gnsrecord_messenger_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init
Returns
NULL

Definition at line 635 of file plugin_gnsrecord_messenger.c.

636{
638
639 GNUNET_free (api);
640 return NULL;
641}

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

Variable Documentation

◆ name

◆ number

uint32_t number

Definition at line 545 of file plugin_gnsrecord_messenger.c.

◆ [struct]

struct { ... } name_map[]
Initial value:
= {
{ "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY },
{ "MESSENGER_ROOM_DETAILS", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS },
{ "MESSENGER_ROOM_EPOCH_KEY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY }
,
{ "MESSENGER_ENCRYPTION_KEY", GNUNET_GNSRECORD_TYPE_MESSENGER_ENCRYPTION_KEY }
,
{ NULL, UINT32_MAX }
}

Mapping of record type numbers to human-readable record type names.

Referenced by messenger_number_to_typename(), and messenger_typename_to_number().