GNUnet 0.25.2-4-g62730f57f
 
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
29#include <string.h>
30
33{
34 struct GNUNET_MESSENGER_Message *message;
35
36 if (! key)
37 return NULL;
38
40
41 if (! message)
42 return NULL;
43
44 memset (&(message->body.leave.epoch), 0,
45 sizeof (struct GNUNET_HashCode));
46
48 return message;
49}
50
51
54{
55 struct GNUNET_MESSENGER_Message *message;
56
58
59 if (! message)
60 return NULL;
61
62 memset (&(message->body.leave.epoch), 0,
63 sizeof (struct GNUNET_HashCode));
64
65 return message;
66}
67
68
71{
72 struct GNUNET_MESSENGER_Message *message;
73
74 if (! name)
75 return NULL;
76
78
79 if (! message)
80 return NULL;
81
82 message->body.name.name = GNUNET_strdup (name);
83 return message;
84}
85
86
89{
90 struct GNUNET_MESSENGER_Message *message;
91
92 if (! key)
93 return NULL;
94
96
97 if (! message)
98 return NULL;
99
101 return message;
102}
103
104
107{
108 struct GNUNET_MESSENGER_Message *message;
109
110 if (! unique_id)
111 return NULL;
112
114
115 if (! message)
116 return NULL;
117
118 GNUNET_memcpy (&(message->body.id.id), unique_id,
119 sizeof(struct GNUNET_ShortHashCode));
120
121 return message;
122}
123
124
127{
128 struct GNUNET_MESSENGER_Message *message;
129
130 if (! hash)
131 return NULL;
132
133 {
134 struct GNUNET_HashCode zero;
135 memset (&zero, 0, sizeof(zero));
136
137 if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero))
138 return NULL;
139 }
140
142
143 if (! message)
144 return NULL;
145
146 GNUNET_memcpy (&(message->body.request.hash), hash, sizeof(struct
148
149 return message;
150}
151
152
155 const struct GNUNET_TIME_Relative delay)
156{
157 struct GNUNET_MESSENGER_Message *message;
158
159 if (! hash)
160 return NULL;
161
163
164 if (! message)
165 return NULL;
166
167 GNUNET_memcpy (&(message->body.deletion.hash), hash, sizeof(struct
169 message->body.deletion.delay = GNUNET_TIME_relative_hton (delay);
170
171 return message;
172}
173
174
177 const struct GNUNET_TIME_Relative time,
178 uint32_t flags)
179{
180 struct GNUNET_MESSENGER_Message *message;
181
182 if (! discourse)
183 return NULL;
184
186
187 if (! message)
188 return NULL;
189
190 GNUNET_memcpy (&(message->body.subscription.discourse), discourse,
191 sizeof (struct GNUNET_ShortHashCode));
192
194 message->body.subscription.flags = flags;
195
196 return message;
197}
198
199
202 identifier,
203 const struct GNUNET_CRYPTO_EcdhePrivateKey *
204 private_key,
206 shared_key,
207 const struct GNUNET_TIME_Relative timeout)
208{
209 struct GNUNET_MESSENGER_Message *message;
210
211 if ((! identifier) || (! private_key) || (! shared_key))
212 return NULL;
213
215
216 if (! message)
217 return NULL;
218
219 GNUNET_memcpy (&(message->body.announcement.identifier), identifier,
220 sizeof (message->body.announcement.identifier));
221
223 private_key, &(message->body.announcement.key));
224
228
230
231 sign_message_by_key (message, shared_key);
232
233 return message;
234}
235
236
239 const struct GNUNET_CRYPTO_EcdhePrivateKey *private_key,
240 const struct GNUNET_TIME_Relative timeout)
241{
242 struct GNUNET_MESSENGER_Message *message;
243
244 if ((! event) || (! private_key))
245 return NULL;
246
248
249 if (! message)
250 return NULL;
251
252 GNUNET_memcpy (&(message->body.appeal.event), event,
253 sizeof (message->body.appeal.event));
254
256 private_key, &(message->body.appeal.key));
257
259
260 return message;
261}
262
263
266 const struct GNUNET_CRYPTO_EcdhePublicKey *public_key,
268 shared_key)
269{
270 struct GNUNET_MESSENGER_Message *message;
271 struct GNUNET_CRYPTO_HpkePublicKey public_hpke;
272
273 if ((! event) || (! public_key) || (! shared_key))
274 return NULL;
275
277
278 if (! message)
279 return NULL;
280
281 GNUNET_memcpy (&public_hpke.ecdhe_key,
282 public_key,
283 sizeof *public_key);
284 if (GNUNET_OK != GNUNET_CRYPTO_hpke_seal_oneshot (&public_hpke,
285 (const uint8_t*)
286 "messenger",
287 strlen ("messenger"),
288 NULL,
289 0,
290 (const uint8_t*) shared_key,
291 sizeof (*shared_key),
292 message->body.access.key,
293 NULL))
294 {
295 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting key failed!\n");
296
297 destroy_message (message);
298 return NULL;
299 }
300
301 GNUNET_memcpy (&(message->body.access.event), event,
302 sizeof (message->body.access.event));
303
304 sign_message_by_key (message, shared_key);
305
306 return message;
307}
308
309
312 identifier,
314 shared_key)
315{
316 struct GNUNET_MESSENGER_Message *message;
317
318 if ((! identifier) || (! shared_key))
319 return NULL;
320
322
323 if (! message)
324 return NULL;
325
326 GNUNET_memcpy (&(message->body.revolution.identifier), identifier,
327 sizeof (message->body.revolution.identifier));
328
330 message->body.revolution.nonce.data.nonce,
332
333 sign_message_by_key (message, shared_key);
334
335 return message;
336}
337
338
341 const struct GNUNET_HashCode *initiator,
342 const struct GNUNET_HashCode *partner,
343 const struct GNUNET_TIME_Relative timeout)
344{
345 struct GNUNET_MESSENGER_Message *message;
346
347 if ((! identifier) || (! initiator) || (! partner) ||
348 (! identifier->code.group_bit))
349 return NULL;
350
352
353 if (! message)
354 return NULL;
355
356 GNUNET_memcpy (&(message->body.group.identifier), identifier,
357 sizeof (message->body.group.identifier));
358 GNUNET_memcpy (&(message->body.group.initiator), initiator,
359 sizeof (message->body.group.initiator));
360 GNUNET_memcpy (&(message->body.group.partner), partner,
361 sizeof (message->body.group.partner));
362
364
365 return message;
366}
367
368
371 identifier,
372 const struct GNUNET_HashCode *event,
374 group_key,
376 shared_key)
377{
378 struct GNUNET_MESSENGER_Message *message;
380
381 if ((! identifier) || (! event) || (! group_key) || (! shared_key))
382 return NULL;
383
385
386 if (! message)
387 return NULL;
388
389 GNUNET_CRYPTO_symmetric_derive_iv (&iv, group_key,
390 event, sizeof (*event),
391 identifier, sizeof (*identifier),
392 NULL);
393
394 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (shared_key,
396 group_key,
397 &iv,
398 message->body.authorization.key))
399 {
400 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting key failed!\n");
401
402 destroy_message (message);
403 return NULL;
404 }
405
406 GNUNET_memcpy (&(message->body.authorization.identifier), identifier,
407 sizeof (message->body.authorization.identifier));
408 GNUNET_memcpy (&(message->body.authorization.event), event,
409 sizeof (message->body.authorization.event));
410
411 sign_message_by_key (message, shared_key);
412
413 return message;
414}
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.
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
@ 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:620
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_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_key(const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
Creates and allocates a new key message containing the public key to change to derived from its priva...
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_join(const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
Creates and allocates a new join message containing the clients public key.
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.
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 public key to verify its signatures.
struct GNUNET_CRYPTO_BlindablePublicKey key
The new public key which replaces the current senders 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