GNUnet 0.27.0
 
Loading...
Searching...
No Matches
messenger_api_message_kind.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--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
28#include "gnunet_common.h"
29#include "gnunet_util_lib.h"
31#include <string.h>
32
35 const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
36{
37 struct GNUNET_MESSENGER_Message *message;
38
39 if (! key)
40 return NULL;
41
43
44 if (! message)
45 return NULL;
46
47 memset (&(message->body.leave.epoch), 0,
48 sizeof (struct GNUNET_HashCode));
49
51 key, &(message->body.join.key)));
52
53 GNUNET_memcpy (&(message->body.join.hpke_key), hpke_key,
54 sizeof (message->body.join.hpke_key));
55
56 return message;
57}
58
59
62{
63 struct GNUNET_MESSENGER_Message *message;
64
66
67 if (! message)
68 return NULL;
69
70 memset (&(message->body.leave.epoch), 0,
71 sizeof (struct GNUNET_HashCode));
72
73 return message;
74}
75
76
79{
80 struct GNUNET_MESSENGER_Message *message;
81
82 if (! name)
83 return NULL;
84
86
87 if (! message)
88 return NULL;
89
90 message->body.name.name = GNUNET_strdup (name);
91 return message;
92}
93
94
97 const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
98{
99 struct GNUNET_MESSENGER_Message *message;
100
101 if (! key)
102 return NULL;
103
105
106 if (! message)
107 return NULL;
108
110 key, &(message->body.key.key)));
111
112 GNUNET_memcpy (&(message->body.join.hpke_key), hpke_key,
113 sizeof (message->body.key.hpke_key));
114
115 return message;
116}
117
118
121{
122 struct GNUNET_MESSENGER_Message *message;
123
124 if (! unique_id)
125 return NULL;
126
128
129 if (! message)
130 return NULL;
131
132 GNUNET_memcpy (&(message->body.id.id), unique_id,
133 sizeof(struct GNUNET_ShortHashCode));
134
135 return message;
136}
137
138
141{
142 struct GNUNET_MESSENGER_Message *message;
143
144 if (! hash)
145 return NULL;
146
147 {
148 struct GNUNET_HashCode zero;
149 memset (&zero, 0, sizeof(zero));
150
151 if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero))
152 return NULL;
153 }
154
156
157 if (! message)
158 return NULL;
159
160 GNUNET_memcpy (&(message->body.request.hash), hash, sizeof(struct
162
163 return message;
164}
165
166
169 const struct GNUNET_TIME_Relative delay)
170{
171 struct GNUNET_MESSENGER_Message *message;
172
173 if (! hash)
174 return NULL;
175
177
178 if (! message)
179 return NULL;
180
181 GNUNET_memcpy (&(message->body.deletion.hash), hash, sizeof(struct
183 message->body.deletion.delay = GNUNET_TIME_relative_hton (delay);
184
185 return message;
186}
187
188
191 const struct GNUNET_TIME_Relative time,
192 uint32_t flags)
193{
194 struct GNUNET_MESSENGER_Message *message;
195
196 if (! discourse)
197 return NULL;
198
200
201 if (! message)
202 return NULL;
203
204 GNUNET_memcpy (&(message->body.subscription.discourse), discourse,
205 sizeof (struct GNUNET_ShortHashCode));
206
208 message->body.subscription.flags = flags;
209
210 return message;
211}
212
213
216 identifier,
217 const struct GNUNET_CRYPTO_EcdhePrivateKey *
218 private_key,
220 shared_key,
221 const struct GNUNET_TIME_Relative timeout)
222{
223 struct GNUNET_MESSENGER_Message *message;
224
225 if ((! identifier) || (! private_key) || (! shared_key))
226 return NULL;
227
229
230 if (! message)
231 return NULL;
232
233 GNUNET_memcpy (&(message->body.announcement.identifier), identifier,
234 sizeof (message->body.announcement.identifier));
235
237 private_key, &(message->body.announcement.key));
238
242
244
245 if (GNUNET_YES != sign_message_by_key (message, shared_key))
246 {
247 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Signing message failed!\n");
248 destroy_message (message);
249 return NULL;
250 }
251
252 return message;
253}
254
255
258 const struct GNUNET_CRYPTO_EcdhePrivateKey *private_key,
259 const struct GNUNET_TIME_Relative timeout)
260{
261 struct GNUNET_MESSENGER_Message *message;
262
263 if ((! event) || (! private_key))
264 return NULL;
265
267
268 if (! message)
269 return NULL;
270
271 GNUNET_memcpy (&(message->body.appeal.event), event,
272 sizeof (message->body.appeal.event));
273
275 private_key, &(message->body.appeal.key));
276
278
279 return message;
280}
281
282
285 const struct GNUNET_CRYPTO_EcdhePublicKey *public_key,
287 shared_key)
288{
289 struct GNUNET_MESSENGER_Message *message;
290 struct GNUNET_CRYPTO_HpkePublicKey public_hpke;
291
292 if ((! event) || (! public_key) || (! shared_key))
293 return NULL;
294
296
297 if (! message)
298 return NULL;
299
300 GNUNET_memcpy (&public_hpke.ecdhe_key,
301 public_key,
302 sizeof *public_key);
303 if (GNUNET_OK != GNUNET_CRYPTO_hpke_seal_oneshot (&public_hpke,
304 (const uint8_t*)
305 "messenger",
306 strlen ("messenger"),
307 NULL,
308 0,
309 (const uint8_t*) shared_key,
310 sizeof (*shared_key),
311 message->body.access.key,
312 NULL))
313 {
314 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting key failed!\n");
315 destroy_message (message);
316 return NULL;
317 }
318
319 GNUNET_memcpy (&(message->body.access.event), event,
320 sizeof (message->body.access.event));
321
322 if (GNUNET_YES != sign_message_by_key (message, shared_key))
323 {
324 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Signing message failed!\n");
325 destroy_message (message);
326 return NULL;
327 }
328
329 return message;
330}
331
332
335 identifier,
337 shared_key)
338{
339 struct GNUNET_MESSENGER_Message *message;
340
341 if ((! identifier) || (! shared_key))
342 return NULL;
343
345
346 if (! message)
347 return NULL;
348
349 GNUNET_memcpy (&(message->body.revolution.identifier), identifier,
350 sizeof (message->body.revolution.identifier));
351
353 message->body.revolution.nonce.data.nonce,
355
356 if (GNUNET_YES != sign_message_by_key (message, shared_key))
357 {
358 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Signing message failed!\n");
359 destroy_message (message);
360 return NULL;
361 }
362
363 return message;
364}
365
366
369 const struct GNUNET_HashCode *initiator,
370 const struct GNUNET_HashCode *partner,
371 const struct GNUNET_TIME_Relative timeout)
372{
373 struct GNUNET_MESSENGER_Message *message;
374
375 if ((! identifier) || (! initiator) || (! partner) ||
376 (! identifier->code.group_bit))
377 return NULL;
378
380
381 if (! message)
382 return NULL;
383
384 GNUNET_memcpy (&(message->body.group.identifier), identifier,
385 sizeof (message->body.group.identifier));
386 GNUNET_memcpy (&(message->body.group.initiator), initiator,
387 sizeof (message->body.group.initiator));
388 GNUNET_memcpy (&(message->body.group.partner), partner,
389 sizeof (message->body.group.partner));
390
392
393 return message;
394}
395
396
399 identifier,
400 const struct GNUNET_HashCode *event,
402 group_key,
404 shared_key)
405{
406 struct GNUNET_MESSENGER_Message *message;
408
409 if ((! identifier) || (! event) || (! group_key) || (! shared_key))
410 return NULL;
411
413
414 if (! message)
415 return NULL;
416
418 &iv, sizeof (iv),
421 group_key,
422 sizeof (*group_key),
423 GNUNET_CRYPTO_kdf_arg_auto (identifier),
425 {
426 destroy_message (message);
427 return NULL;
428 }
429
430 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (shared_key,
432 group_key,
433 &iv,
434 message->body.authorization.key))
435 {
436 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting key failed!\n");
437 destroy_message (message);
438 return NULL;
439 }
440
441 GNUNET_memcpy (&(message->body.authorization.identifier), identifier,
442 sizeof (message->body.authorization.identifier));
443 GNUNET_memcpy (&(message->body.authorization.event), event,
444 sizeof (message->body.authorization.event));
445
446 if (GNUNET_YES != sign_message_by_key (message, shared_key))
447 {
448 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Signing message failed!\n");
449 destroy_message (message);
450 return NULL;
451 }
452
453 return message;
454}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition gnunet-arm.c:118
struct GNUNET_HashCode key
The key used in the DHT.
static char * name
Name (label) of the records to list.
static const struct GNUNET_CRYPTO_BlindablePrivateKey zero
Public key of all zeros.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition crypto_ecc.c:217
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blindable_key_get_public(const struct GNUNET_CRYPTO_BlindablePrivateKey *privkey, struct GNUNET_CRYPTO_BlindablePublicKey *key)
Retrieves the public key representation of a private key.
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot(const struct GNUNET_CRYPTO_HpkePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len)
RFC9180 HPKE encryption.
#define GNUNET_CRYPTO_kdf_arg_auto(d)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES
#define GNUNET_MESSENGER_EPOCH_NONCE_BYTES
@ GNUNET_MESSENGER_KIND_AUTHORIZATION
The authorization kind.
@ GNUNET_MESSENGER_KIND_ANNOUNCEMENT
The announcement kind.
@ GNUNET_MESSENGER_KIND_APPEAL
The appeal kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_ACCESS
The access kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_REVOLUTION
The revolution kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBTION
The subscription kind.
@ GNUNET_MESSENGER_KIND_DELETION
The deletion kind.
@ GNUNET_MESSENGER_KIND_GROUP
The group kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition time.c:616
enum GNUNET_GenericReturnValue sign_message_by_key(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Signs the message body via it's own hmac with a specific shared key.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
#define GNUNET_MESSENGER_SALT_GROUP_KEY
struct GNUNET_MESSENGER_Message * create_message_name(const char *name)
Creates and allocates a new name message containing the name to change to.
struct GNUNET_MESSENGER_Message * create_message_subscription(const struct GNUNET_ShortHashCode *discourse, const struct GNUNET_TIME_Relative time, uint32_t flags)
Creates and allocates a new subscribe message for a subscription of a given discourse with a specific...
struct GNUNET_MESSENGER_Message * create_message_leave(void)
Creates and allocates a new leave message.
struct GNUNET_MESSENGER_Message * create_message_announcement(const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_CRYPTO_EcdhePrivateKey *private_key, const struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key, const struct GNUNET_TIME_Relative timeout)
Creates and allocates a new announcement message for an announcement of a given epoch or group under ...
struct GNUNET_MESSENGER_Message * create_message_join(const struct GNUNET_CRYPTO_BlindablePrivateKey *key, const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
Creates and allocates a new join message containing the clients public key.
struct GNUNET_MESSENGER_Message * create_message_appeal(const struct GNUNET_HashCode *event, const struct GNUNET_CRYPTO_EcdhePrivateKey *private_key, const struct GNUNET_TIME_Relative timeout)
Creates and allocates a new appeal message for an epoch announcement using a specific private_key to ...
struct GNUNET_MESSENGER_Message * create_message_revolution(const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
Creates and allocates a new revolution message for an announced epoch or group selected by its identi...
struct GNUNET_MESSENGER_Message * create_message_deletion(const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
Creates and allocates a new deletion message containing the hash of a message to delete after a speci...
struct GNUNET_MESSENGER_Message * create_message_request(const struct GNUNET_HashCode *hash)
Creates and allocates a new request message containing the hash of a missing message.
struct GNUNET_MESSENGER_Message * create_message_authorization(const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_HashCode *event, const struct GNUNET_CRYPTO_SymmetricSessionKey *group_key, const struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
Creates and allocates a new authorization message to grant access to the shared_key of a specific gro...
struct GNUNET_MESSENGER_Message * create_message_group(const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_HashCode *initiator, const struct GNUNET_HashCode *partner, const struct GNUNET_TIME_Relative timeout)
Creates and allocates a new group message to propose a group formation between an initiator subgroup ...
struct GNUNET_MESSENGER_Message * create_message_access(const struct GNUNET_HashCode *event, const struct GNUNET_CRYPTO_EcdhePublicKey *public_key, const struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
Creates and allocates a new access message to grant access to the shared_key of an announced epoch or...
struct GNUNET_MESSENGER_Message * create_message_id(const struct GNUNET_ShortHashCode *unique_id)
Creates and allocates a new id message containing the unique member id to change to.
struct GNUNET_MESSENGER_Message * create_message_key(const struct GNUNET_CRYPTO_BlindablePrivateKey *key, const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
Creates and allocates a new key message containing the public key to change to derived from its priva...
A private key for an identity as per LSD0001.
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
A public key used for encryption.
struct GNUNET_CRYPTO_EcdhePublicKey ecdhe_key
An ECDHE/X25519 key.
A 512-bit hashcode.
uint8_t nonce[sizeof(struct GNUNET_ShortHashCode)]
struct GNUNET_HashCode event
The hash of the linked announcement or group message event.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)+16+sizeof(struct GNUNET_CRYPTO_HpkeEncapsulation)]
The encrypted group or epoch key.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the announcement.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to appeal access.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to receive access.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the appeal.
struct GNUNET_HashCode event
The hash of the linked announcement message event.
struct GNUNET_HashCode event
The hash of the linked group message event.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)]
The encrypted group or epoch key.
struct GNUNET_MESSENGER_MessageAnnouncement announcement
struct GNUNET_MESSENGER_MessageGroup group
struct GNUNET_MESSENGER_MessageDeletion deletion
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageLeave leave
struct GNUNET_MESSENGER_MessageRevolution revolution
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageAccess access
struct GNUNET_MESSENGER_MessageSubscribtion subscription
struct GNUNET_MESSENGER_MessageAuthorization authorization
struct GNUNET_MESSENGER_MessageAppeal appeal
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_HashCode hash
The hash of the message to delete.
struct GNUNET_TIME_RelativeNBO delay
The delay of the delete operation to get processed.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the group formation.
struct GNUNET_HashCode initiator
The hash of the initiator group announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode partner
The hash of the partner group announcement.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_CRYPTO_BlindablePublicKey key
The senders blindable public key to verify its signatures.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The senders HPKE public key to encrypt private messages with.
struct GNUNET_CRYPTO_BlindablePublicKey key
The new blindable public key which replaces the current senders public key.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The new HPKE public key which replaces the current senders HPKE public key.
struct GNUNET_HashCode epoch
The previous epoch the message was sent from.
char * name
The new name which replaces the current senders name.
struct GNUNET_HashCode hash
The hash of the requested message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the revolution.
uint32_t flags
The flags about the subscription to a discourse.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscription.
struct GNUNET_MESSENGER_MessageBody body
Body.
A 256-bit hashcode.
Time for relative time used by GNUnet, in microseconds.
An epoch identifier unifies an epoch identifier code and its 256bit hash representation.
struct GNUNET_MESSENGER_EpochIdentifierCode code
struct GNUNET_MESSENGER_EpochNonceData data