GNUnet debian-0.24.3-29-g453fda2cf
 
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.subscribtion.discourse), discourse,
191 sizeof (struct GNUNET_ShortHashCode));
192
194 message->body.subscribtion.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
272 if ((! event) || (! public_key) || (! shared_key))
273 return NULL;
274
276
277 if (! message)
278 return NULL;
279
281 (const uint8_t*)
282 "messenger",
283 strlen ("messenger"),
284 NULL,
285 0,
286 (const uint8_t*) shared_key,
287 sizeof (*shared_key),
288 message->body.access.key,
289 NULL))
290 {
291 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting key failed!\n");
292
293 destroy_message (message);
294 return NULL;
295 }
296
297 GNUNET_memcpy (&(message->body.access.event), event,
298 sizeof (message->body.access.event));
299
300 sign_message_by_key (message, shared_key);
301
302 return message;
303}
304
305
308 identifier,
310 shared_key)
311{
312 struct GNUNET_MESSENGER_Message *message;
313
314 if ((! identifier) || (! shared_key))
315 return NULL;
316
318
319 if (! message)
320 return NULL;
321
322 GNUNET_memcpy (&(message->body.revolution.identifier), identifier,
323 sizeof (message->body.revolution.identifier));
324
326 message->body.revolution.nonce.data.nonce,
328
329 sign_message_by_key (message, shared_key);
330
331 return message;
332}
333
334
337 const struct GNUNET_HashCode *initiator,
338 const struct GNUNET_HashCode *partner,
339 const struct GNUNET_TIME_Relative timeout)
340{
341 struct GNUNET_MESSENGER_Message *message;
342
343 if ((! identifier) || (! initiator) || (! partner) ||
344 (! identifier->code.group_bit))
345 return NULL;
346
348
349 if (! message)
350 return NULL;
351
352 GNUNET_memcpy (&(message->body.group.identifier), identifier,
353 sizeof (message->body.group.identifier));
354 GNUNET_memcpy (&(message->body.group.initiator), initiator,
355 sizeof (message->body.group.initiator));
356 GNUNET_memcpy (&(message->body.group.partner), partner,
357 sizeof (message->body.group.partner));
358
360
361 return message;
362}
363
364
367 identifier,
368 const struct GNUNET_HashCode *event,
370 group_key,
372 shared_key)
373{
374 struct GNUNET_MESSENGER_Message *message;
376
377 if ((! identifier) || (! event) || (! group_key) || (! shared_key))
378 return NULL;
379
381
382 if (! message)
383 return NULL;
384
385 GNUNET_CRYPTO_symmetric_derive_iv (&iv, group_key,
386 event, sizeof (*event),
387 identifier, sizeof (*identifier),
388 NULL);
389
390 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (shared_key,
392 group_key,
393 &iv,
394 message->body.authorization.key))
395 {
396 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting key failed!\n");
397
398 destroy_message (message);
399 return NULL;
400 }
401
402 GNUNET_memcpy (&(message->body.authorization.identifier), identifier,
403 sizeof (message->body.authorization.identifier));
404 GNUNET_memcpy (&(message->body.authorization.event), event,
405 sizeof (message->body.authorization.event));
406
407 sign_message_by_key (message, shared_key);
408
409 return message;
410}
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_PrivateKey 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.
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot(const struct GNUNET_CRYPTO_EcdhePublicKey *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.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
#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 subscribtion 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_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_subscribtion(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_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_join(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates and allocates a new join message containing the clients public key.
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_key(const struct GNUNET_CRYPTO_PrivateKey *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_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.
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
A private key for an identity as per LSD0001.
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_MessageSubscribtion subscribtion
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_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_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_CRYPTO_PublicKey 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 subscribtion.
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