GNUnet 0.26.2-16-ge86b66bd5
 
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--2025 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 sign_message_by_key (message, shared_key);
246
247 return message;
248}
249
250
253 const struct GNUNET_CRYPTO_EcdhePrivateKey *private_key,
254 const struct GNUNET_TIME_Relative timeout)
255{
256 struct GNUNET_MESSENGER_Message *message;
257
258 if ((! event) || (! private_key))
259 return NULL;
260
262
263 if (! message)
264 return NULL;
265
266 GNUNET_memcpy (&(message->body.appeal.event), event,
267 sizeof (message->body.appeal.event));
268
270 private_key, &(message->body.appeal.key));
271
273
274 return message;
275}
276
277
280 const struct GNUNET_CRYPTO_EcdhePublicKey *public_key,
282 shared_key)
283{
284 struct GNUNET_MESSENGER_Message *message;
285 struct GNUNET_CRYPTO_HpkePublicKey public_hpke;
286
287 if ((! event) || (! public_key) || (! shared_key))
288 return NULL;
289
291
292 if (! message)
293 return NULL;
294
295 GNUNET_memcpy (&public_hpke.ecdhe_key,
296 public_key,
297 sizeof *public_key);
298 if (GNUNET_OK != GNUNET_CRYPTO_hpke_seal_oneshot (&public_hpke,
299 (const uint8_t*)
300 "messenger",
301 strlen ("messenger"),
302 NULL,
303 0,
304 (const uint8_t*) shared_key,
305 sizeof (*shared_key),
306 message->body.access.key,
307 NULL))
308 {
309 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting key failed!\n");
310
311 destroy_message (message);
312 return NULL;
313 }
314
315 GNUNET_memcpy (&(message->body.access.event), event,
316 sizeof (message->body.access.event));
317
318 sign_message_by_key (message, shared_key);
319
320 return message;
321}
322
323
326 identifier,
328 shared_key)
329{
330 struct GNUNET_MESSENGER_Message *message;
331
332 if ((! identifier) || (! shared_key))
333 return NULL;
334
336
337 if (! message)
338 return NULL;
339
340 GNUNET_memcpy (&(message->body.revolution.identifier), identifier,
341 sizeof (message->body.revolution.identifier));
342
344 message->body.revolution.nonce.data.nonce,
346
347 sign_message_by_key (message, shared_key);
348
349 return message;
350}
351
352
355 const struct GNUNET_HashCode *initiator,
356 const struct GNUNET_HashCode *partner,
357 const struct GNUNET_TIME_Relative timeout)
358{
359 struct GNUNET_MESSENGER_Message *message;
360
361 if ((! identifier) || (! initiator) || (! partner) ||
362 (! identifier->code.group_bit))
363 return NULL;
364
366
367 if (! message)
368 return NULL;
369
370 GNUNET_memcpy (&(message->body.group.identifier), identifier,
371 sizeof (message->body.group.identifier));
372 GNUNET_memcpy (&(message->body.group.initiator), initiator,
373 sizeof (message->body.group.initiator));
374 GNUNET_memcpy (&(message->body.group.partner), partner,
375 sizeof (message->body.group.partner));
376
378
379 return message;
380}
381
382
385 identifier,
386 const struct GNUNET_HashCode *event,
388 group_key,
390 shared_key)
391{
392 struct GNUNET_MESSENGER_Message *message;
394
395 if ((! identifier) || (! event) || (! group_key) || (! shared_key))
396 return NULL;
397
399
400 if (! message)
401 return NULL;
402
403 GNUNET_CRYPTO_symmetric_derive_iv (&iv, group_key,
404 event, sizeof (*event),
405 identifier, sizeof (*identifier),
406 NULL);
407
408 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (shared_key,
410 group_key,
411 &iv,
412 message->body.authorization.key))
413 {
414 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting key failed!\n");
415
416 destroy_message (message);
417 return NULL;
418 }
419
420 GNUNET_memcpy (&(message->body.authorization.identifier), identifier,
421 sizeof (message->body.authorization.identifier));
422 GNUNET_memcpy (&(message->body.authorization.event), event,
423 sizeof (message->body.authorization.event));
424
425 sign_message_by_key (message, shared_key);
426
427 return message;
428}
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_symmetric_derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len,...)
Derive an IV.
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.
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_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
#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
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
void 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.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
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