GNUnet 0.28.0-dev.2-27-gc87478450
 
Loading...
Searching...
No Matches
messenger_api_handle.c File Reference
Include dependency graph for messenger_api_handle.c:

Go to the source code of this file.

Functions

struct GNUNET_MESSENGER_Handlecreate_handle (const struct GNUNET_CONFIGURATION_Handle *config, const struct GNUNET_HashCode *secret, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
 Creates and allocates a new handle using a given configuration, a secret and a custom message callback with a given closure for the client API.
 
static enum GNUNET_GenericReturnValue iterate_destroy_room (void *cls, const struct GNUNET_HashCode *key, void *value)
 
void destroy_handle (struct GNUNET_MESSENGER_Handle *handle)
 Destroys a handle and frees its memory fully from the client API.
 
void set_handle_name (struct GNUNET_MESSENGER_Handle *handle, const char *name)
 Sets the name of a handle to a specific name.
 
const char * get_handle_name (const struct GNUNET_MESSENGER_Handle *handle)
 Returns the current name of a given handle or NULL if no valid name was assigned yet.
 
static void cb_key_error (void *cls)
 
static void read_handle_epoch_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const struct GNUNET_MESSENGER_RoomEpochKeyRecord *record)
 
static void read_handle_encryption_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const struct GNUNET_MESSENGER_EncryptionKeyRecord *record)
 
static void cb_key_monitor (void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
 
static enum GNUNET_GenericReturnValue it_announcement_store_key (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
static enum GNUNET_GenericReturnValue it_group_store_key (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
static enum GNUNET_GenericReturnValue it_epoch_store_keys (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static enum GNUNET_GenericReturnValue it_room_store_keys (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static void cb_key_sync (void *cls)
 
void set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
 Sets the keypair of a given handle to the keypair of a specific private key.
 
const struct GNUNET_CRYPTO_BlindablePrivateKeyget_handle_key (const struct GNUNET_MESSENGER_Handle *handle)
 Returns the private key of a given handle.
 
const struct GNUNET_CRYPTO_BlindablePublicKeyget_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle)
 Returns the public key of a given handle.
 
struct GNUNET_MESSENGER_ContactStoreget_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle)
 Returns the used contact store of a given handle.
 
struct GNUNET_MESSENGER_Contactget_handle_contact (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
 Returns the contact of a given handle in a room identified by a given key.
 
void open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
 Marks a room known to a handle identified by a given key as open.
 
void entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
 Adds a tunnel for a room known to a handle identified by a given key to a list of opened connections.
 
void close_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
 Destroys and so implicitly closes a room known to a handle identified by a given key.
 
struct GNUNET_MESSENGER_Roomget_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key, enum GNUNET_GenericReturnValue init)
 Returns the room known to a handle identified by a given key.
 
enum GNUNET_GenericReturnValue store_handle_epoch_key (const struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash, const struct GNUNET_ShortHashCode *identifier, const struct GNUNET_CRYPTO_AeadSecretKey *shared_key, uint32_t flags, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls, struct GNUNET_NAMESTORE_QueueEntry **query)
 Stores/deletes a shared_key for a given room from a handle in an epoch with certain hash using a specific identifier for this epoch key.
 
enum GNUNET_GenericReturnValue store_handle_encryption_key (const struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_CRYPTO_HpkePrivateKey *encryption_key, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls, struct GNUNET_NAMESTORE_QueueEntry **query)
 Stores an encryption_key for a given room from a handle.
 

Function Documentation

◆ create_handle()

struct GNUNET_MESSENGER_Handle * create_handle ( const struct GNUNET_CONFIGURATION_Handle cfg,
const struct GNUNET_HashCode secret,
GNUNET_MESSENGER_MessageCallback  msg_callback,
void *  msg_cls 
)

Creates and allocates a new handle using a given configuration, a secret and a custom message callback with a given closure for the client API.

Parameters
[in]cfgConfiguration
[in]secretStorage secret
[in]msg_callbackMessage callback
[in,out]msg_clsClosure
Returns
New handle

Definition at line 41 of file messenger_api_handle.c.

45{
47
49
51
52 handle->config = config;
53 handle->mq = NULL;
54
56 handle->config,
58 "MESSENGER_GROUP_KEYS");
59
60 if (handle->config)
61 handle->namestore = GNUNET_NAMESTORE_connect (handle->config);
62
63 if (secret)
64 GNUNET_memcpy (&(handle->secret), secret, sizeof (handle->secret));
65 else
66 GNUNET_CRYPTO_zero_keys (&(handle->secret), sizeof (handle->secret));
67
68 handle->msg_callback = msg_callback;
69 handle->msg_cls = msg_cls;
70
71 handle->name = NULL;
72 handle->key = NULL;
73 handle->pubkey = NULL;
74
75 handle->reconnect_time = GNUNET_TIME_relative_get_zero_ ();
76 handle->reconnect_task = NULL;
77
78 handle->key_monitor = NULL;
79
81
83
84 return handle;
85}
const struct GNUNET_CONFIGURATION_Handle * config
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition gnunet-vpn.c:35
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
void GNUNET_CRYPTO_zero_keys(void *buffer, size_t length)
Zero out buffer, securely against compiler optimizations.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MESSENGER_SERVICE_NAME
Identifier of GNUnet MESSENGER Service.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition time.c:133
void init_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Initializes a contact store as fully empty.
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
GNUNET_MESSENGER_MessageCallback msg_callback
struct GNUNET_HashCode secret
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition vpn_api.c:44

References config, get_handle_contact_store(), GNUNET_assert, GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CRYPTO_zero_keys(), GNUNET_memcpy, GNUNET_MESSENGER_SERVICE_NAME, GNUNET_NAMESTORE_connect(), GNUNET_new, GNUNET_NO, GNUNET_TIME_relative_get_zero_(), handle, init_contact_store(), GNUNET_VPN_Handle::mq, GNUNET_MESSENGER_Handle::msg_callback, GNUNET_MESSENGER_Handle::msg_cls, and GNUNET_MESSENGER_Handle::secret.

Referenced by GNUNET_MESSENGER_connect().

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

◆ iterate_destroy_room()

static enum GNUNET_GenericReturnValue iterate_destroy_room ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 89 of file messenger_api_handle.c.

92{
93 struct GNUNET_MESSENGER_Room *room;
94
96
97 room = value;
98
99 destroy_room (room);
100 return GNUNET_YES;
101}
static char * value
Value of the record to add/remove.
@ GNUNET_YES
void destroy_room(struct GNUNET_MESSENGER_Room *room)
Destroys a room and frees its memory fully from the client API.

References destroy_room(), GNUNET_assert, GNUNET_YES, and value.

Referenced by destroy_handle().

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

◆ destroy_handle()

void destroy_handle ( struct GNUNET_MESSENGER_Handle handle)

Destroys a handle and frees its memory fully from the client API.

Parameters
[in,out]handleHandle

Definition at line 105 of file messenger_api_handle.c.

106{
108
110
111 if (handle->rooms)
112 {
114 handle->rooms, iterate_destroy_room, NULL);
115
117 }
118
119 if (handle->key_monitor)
121
122 if (handle->reconnect_task)
123 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
124
125 if (handle->mq)
127
128 if (handle->namestore)
130
131 GNUNET_CRYPTO_zero_keys (&(handle->secret), sizeof (handle->secret));
132
133 if (handle->name)
134 GNUNET_free (handle->name);
135
136 if (handle->key)
137 GNUNET_free (handle->key);
138
139 if (handle->pubkey)
140 GNUNET_free (handle->pubkey);
141
143}
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition mq.c:700
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
void GNUNET_NAMESTORE_zone_monitor_stop(struct GNUNET_NAMESTORE_ZoneMonitor *zm)
Stop monitoring a zone for changes.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
void clear_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Clears a contact store, wipes its content and deallocates its memory.
static enum GNUNET_GenericReturnValue iterate_destroy_room(void *cls, const struct GNUNET_HashCode *key, void *value)

References clear_contact_store(), get_handle_contact_store(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CRYPTO_zero_keys(), GNUNET_free, GNUNET_MQ_destroy(), GNUNET_NAMESTORE_disconnect(), GNUNET_NAMESTORE_zone_monitor_stop(), GNUNET_SCHEDULER_cancel(), handle, iterate_destroy_room(), and GNUNET_VPN_Handle::mq.

Referenced by GNUNET_MESSENGER_connect(), and GNUNET_MESSENGER_disconnect().

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

◆ set_handle_name()

void set_handle_name ( struct GNUNET_MESSENGER_Handle handle,
const char *  name 
)

Sets the name of a handle to a specific name.

Parameters
[in,out]handleHandle
[in]nameNew name

Definition at line 147 of file messenger_api_handle.c.

149{
151
152 if (handle->name)
153 GNUNET_free (handle->name);
154
155 handle->name = name ? GNUNET_strdup (name) : NULL;
156}
static char * name
Name (label) of the records to list.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References GNUNET_assert, GNUNET_free, GNUNET_strdup, handle, and name.

Referenced by GNUNET_MESSENGER_connect(), and GNUNET_MESSENGER_set_name().

Here is the caller graph for this function:

◆ get_handle_name()

const char * get_handle_name ( const struct GNUNET_MESSENGER_Handle handle)

Returns the current name of a given handle or NULL if no valid name was assigned yet.

Parameters
[in]handleHandle
Returns
Name of the handle or NULL

Definition at line 160 of file messenger_api_handle.c.

161{
163
164 return handle->name;
165}

References GNUNET_assert, and handle.

Referenced by cb_key_error(), cb_key_sync(), GNUNET_MESSENGER_get_name(), handle_name_message(), iterate_send_name_to_room(), and send_message_to_room_with_key().

Here is the caller graph for this function:

◆ cb_key_error()

static void cb_key_error ( void *  cls)
static

Definition at line 169 of file messenger_api_handle.c.

170{
172 const char *name;
173
174 GNUNET_assert (cls);
175
176 handle = cls;
178
179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on monitoring records: %s\n",
180 name);
181}
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR
const char * get_handle_name(const struct GNUNET_MESSENGER_Handle *handle)
Returns the current name of a given handle or NULL if no valid name was assigned yet.

References get_handle_name(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, handle, and name.

Referenced by set_handle_key().

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

◆ read_handle_epoch_key()

static void read_handle_epoch_key ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_CRYPTO_BlindablePrivateKey zone,
const struct GNUNET_MESSENGER_RoomEpochKeyRecord record 
)
static

Definition at line 185 of file messenger_api_handle.c.

188{
189 struct GNUNET_MESSENGER_Room *room;
190 const struct GNUNET_HashCode *room_key;
191 struct GNUNET_MESSENGER_Epoch *epoch;
192 union GNUNET_MESSENGER_EpochIdentifier identifier;
193 enum GNUNET_GenericReturnValue valid;
194 struct GNUNET_CRYPTO_AeadSecretKey shared_key;
195
196 GNUNET_assert ((handle) && (zone) && (record));
197
198 room = get_handle_room (handle, &(record->key), GNUNET_YES);
199
200 if (! room)
201 return;
202
203 room_key = get_room_key (room);
204
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Monitor epoch key record of room: %s\n",
207
208 epoch = get_room_epoch (room, &(record->hash), GNUNET_NO);
209
210 if (! epoch)
211 return;
212
214 &identifier,
215 &(record->identifier),
216 sizeof (record->identifier));
218 GNUNET_NO);
219
220 {
221 struct GNUNET_CRYPTO_AeadSecretKey skey;
222
224 sizeof (skey),
226 strlen (
228 &(handle->secret),
229 sizeof (handle->secret),
231 room_key),
233 &(epoch->hash)),
235 &(identifier.hash))))
236 return;
237
238 if (GNUNET_OK != GNUNET_CRYPTO_aead_decrypt (sizeof (record->shared_key),
239 (const uint8_t*) &(record->
240 shared_key),
241 0,
242 NULL,
243 &skey,
244 &(record->nonce),
245 &(record->mac),
246 &shared_key))
247 return;
248
249 GNUNET_CRYPTO_zero_keys (&skey, sizeof (skey));
250 }
251
252 if (identifier.code.group_bit)
253 {
254 struct GNUNET_MESSENGER_EpochGroup *group;
255
257
258 if (! group)
259 goto clear_key;
260
262 }
263 else
264 {
266
268
269 if (! announcement)
270 goto clear_key;
271
273 }
274
275clear_key:
277}
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
char * room_key
struct GNUNET_REGEX_Announcement * announcement
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_decrypt(size_t ct_len, const unsigned char ct[ct_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, const struct GNUNET_CRYPTO_AeadMac *mac, void *pt)
Decrypt the given data using XChaCha20-Poly1305.
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
#define GNUNET_CRYPTO_kdf_arg_auto(d)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_MESSENGER_FLAG_EPOCH_VALID
The valid flag.
struct GNUNET_MESSENGER_EpochGroup * get_epoch_group(struct GNUNET_MESSENGER_Epoch *epoch, const union GNUNET_MESSENGER_EpochIdentifier *identifier, enum GNUNET_GenericReturnValue valid)
Returns the epoch group of a given epoch using a specific unique identifier or NULL.
struct GNUNET_MESSENGER_EpochAnnouncement * get_epoch_announcement(struct GNUNET_MESSENGER_Epoch *epoch, const union GNUNET_MESSENGER_EpochIdentifier *identifier, enum GNUNET_GenericReturnValue valid)
Returns the epoch announcement of a given epoch using a specific unique identifier or NULL.
void set_epoch_announcement_key(struct GNUNET_MESSENGER_EpochAnnouncement *announcement, const struct GNUNET_CRYPTO_AeadSecretKey *shared_key, enum GNUNET_GenericReturnValue write_record)
Sets the secret key of a given epoch announcement to a shared key.
void set_epoch_group_key(struct GNUNET_MESSENGER_EpochGroup *group, const struct GNUNET_CRYPTO_AeadSecretKey *shared_key, enum GNUNET_GenericReturnValue write_record)
Sets the secret key of a given epoch group to a shared key.
struct GNUNET_MESSENGER_Room * get_handle_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key, enum GNUNET_GenericReturnValue init)
Returns the room known to a handle identified by a given key.
#define GNUNET_MESSENGER_SALT_SECRET_KEY
struct GNUNET_MESSENGER_Epoch * get_room_epoch(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue recent)
Returns the epoch in a given room from a specific epoch hash that represents the exact message the ep...
const struct GNUNET_HashCode * get_room_key(const struct GNUNET_MESSENGER_Room *room)
Return a the hash representation of a given room.
A 512-bit hashcode.
struct GNUNET_CRYPTO_AeadSecretKey * shared_key
union GNUNET_MESSENGER_EpochIdentifier identifier
enum GNUNET_GenericReturnValue valid
struct GNUNET_MESSENGER_Epoch * epoch
struct GNUNET_CRYPTO_AeadSecretKey * shared_key
union GNUNET_MESSENGER_EpochIdentifier identifier
struct GNUNET_HashCode hash
An epoch identifier unifies an epoch identifier code and its 256bit hash representation.

References announcement, GNUNET_MESSENGER_EpochIdentifier::code, GNUNET_MESSENGER_EpochAnnouncement::epoch, GNUNET_MESSENGER_EpochGroup::epoch, get_epoch_announcement(), get_epoch_group(), get_handle_room(), get_room_epoch(), get_room_key(), GNUNET_assert, GNUNET_CRYPTO_aead_decrypt(), GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_kdf_arg_auto, GNUNET_CRYPTO_zero_keys(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSENGER_FLAG_EPOCH_VALID, GNUNET_MESSENGER_SALT_SECRET_KEY, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_EpochIdentifierCode::group_bit, handle, GNUNET_MESSENGER_EpochIdentifier::hash, GNUNET_MESSENGER_Epoch::hash, GNUNET_MESSENGER_EpochAnnouncement::identifier, GNUNET_MESSENGER_EpochGroup::identifier, record(), room_key, set_epoch_announcement_key(), set_epoch_group_key(), GNUNET_MESSENGER_EpochAnnouncement::shared_key, GNUNET_MESSENGER_EpochGroup::shared_key, GNUNET_MESSENGER_EpochAnnouncement::valid, and GNUNET_MESSENGER_EpochGroup::valid.

Referenced by cb_key_monitor().

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

◆ read_handle_encryption_key()

static void read_handle_encryption_key ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_CRYPTO_BlindablePrivateKey zone,
const struct GNUNET_MESSENGER_EncryptionKeyRecord record 
)
static

Definition at line 281 of file messenger_api_handle.c.

286{
287 struct GNUNET_MESSENGER_Room *room;
288 const struct GNUNET_HashCode *room_key;
289 struct GNUNET_CRYPTO_HpkePrivateKey encryption_key;
290
291 GNUNET_assert ((handle) && (zone) && (record));
292
293 room = get_handle_room (handle, &(record->key), GNUNET_YES);
294
295 if (! room)
296 return;
297
298 room_key = get_room_key (room);
299
301 "Monitor encryption key record of room: %s\n",
303
304 {
305 uint8_t encryption_key_data[sizeof (record->encrypted_key_data)];
306 struct GNUNET_CRYPTO_AeadSecretKey skey;
307 size_t encryption_key_len;
308
310 sizeof (skey),
312 strlen (
314 &(handle->secret),
315 sizeof (handle->secret),
317 room_key)))
318 return;
319
321 encrypted_key_data),
322 record->encrypted_key_data,
323 0,
324 NULL,
325 &skey,
326 &(record->nonce),
327 &(record->mac),
328 encryption_key_data))
329 return;
330
331 GNUNET_CRYPTO_zero_keys (&skey, sizeof (skey));
332
334 encryption_key_data, record->encrypted_key_length, &encryption_key, &
335 encryption_key_len))
336 return;
337
338 if (encryption_key_len < record->encrypted_key_length)
339 goto clear_key;
340 }
341
342 add_room_encryption_key (room, &encryption_key);
343
344clear_key:
345 GNUNET_CRYPTO_hpke_sk_clear (&encryption_key);
346}
void GNUNET_CRYPTO_hpke_sk_clear(struct GNUNET_CRYPTO_HpkePrivateKey *key)
Clear memory that was used to store a GNUNET_CRYPTO_HpkePrivateKey.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_hpke_sk_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_HpkePrivateKey *key, size_t *read)
Reads a GNUNET_CRYPTO_HpkePrivateKey from a compact buffer.
enum GNUNET_GenericReturnValue add_room_encryption_key(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_CRYPTO_HpkePrivateKey *key)
Adds an encryption key by the current user to memory of a given room and will be placed to the second...
A public key used for decryption.

References add_room_encryption_key(), get_handle_room(), get_room_key(), GNUNET_assert, GNUNET_CRYPTO_aead_decrypt(), GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_hpke_sk_clear(), GNUNET_CRYPTO_kdf_arg_auto, GNUNET_CRYPTO_read_hpke_sk_from_buffer(), GNUNET_CRYPTO_zero_keys(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_SALT_SECRET_KEY, GNUNET_OK, GNUNET_YES, handle, record(), and room_key.

Referenced by cb_key_monitor().

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

◆ cb_key_monitor()

static void cb_key_monitor ( void *  cls,
const struct GNUNET_CRYPTO_BlindablePrivateKey zone,
const char *  label,
unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd,
struct GNUNET_TIME_Absolute  expiry 
)
static

Definition at line 350 of file messenger_api_handle.c.

356{
358
360 (cls) && (zone) && (label) && (rd_count) && (rd));
361
362 handle = cls;
363
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Monitor record with label: %s\n",
365 label);
366
367 switch (rd->record_type)
368 {
370 if ((sizeof (struct GNUNET_MESSENGER_RoomEpochKeyRecord) == rd->data_size)
371 && (rd->data))
373
374 break;
376 if ((sizeof (struct GNUNET_MESSENGER_EncryptionKeyRecord) == rd->data_size)
377 && (rd->data))
379
380 break;
381 default:
382 break;
383 }
384
386}
#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.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
void GNUNET_NAMESTORE_zone_monitor_next(struct GNUNET_NAMESTORE_ZoneMonitor *zm, uint64_t limit)
Calls the monitor processor specified in GNUNET_NAMESTORE_zone_monitor_start for the next record(s).
static void read_handle_encryption_key(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const struct GNUNET_MESSENGER_EncryptionKeyRecord *record)
static void read_handle_epoch_key(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const struct GNUNET_MESSENGER_RoomEpochKeyRecord *record)
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
An encryption key record specifies an encryption key for a given room that can be identified via a gi...
A room epoch key record specifies an epoch key for a given room that can be identified via a given ke...

References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_TYPE_MESSENGER_ENCRYPTION_KEY, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY, GNUNET_log, GNUNET_NAMESTORE_zone_monitor_next(), handle, rd, rd_count, read_handle_encryption_key(), read_handle_epoch_key(), and GNUNET_GNSRECORD_Data::record_type.

Referenced by set_handle_key().

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

◆ it_announcement_store_key()

static enum GNUNET_GenericReturnValue it_announcement_store_key ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 390 of file messenger_api_handle.c.

393{
395
397
399
400 if ((cls) && (GNUNET_YES != announcement->stored))
402 else if (! cls)
403 announcement->stored = GNUNET_NO;
404
405 return GNUNET_YES;
406}
void write_epoch_announcement_record(struct GNUNET_MESSENGER_EpochAnnouncement *announcement, enum GNUNET_GenericReturnValue deleted)
Writes/Deletes the GNS record of a given epoch announcement depending on a provided flag that states ...

References announcement, GNUNET_assert, GNUNET_NO, GNUNET_YES, value, and write_epoch_announcement_record().

Referenced by it_epoch_store_keys().

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

◆ it_group_store_key()

static enum GNUNET_GenericReturnValue it_group_store_key ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 410 of file messenger_api_handle.c.

413{
414 struct GNUNET_MESSENGER_EpochGroup *group;
415
417
418 group = value;
419
420 if ((cls) && (GNUNET_YES != group->stored))
422 else if (! cls)
423 group->stored = GNUNET_NO;
424
425 return GNUNET_YES;
426}
void write_epoch_group_record(struct GNUNET_MESSENGER_EpochGroup *group, enum GNUNET_GenericReturnValue deleted)
Writes/Deletes the GNS record of a given epoch group depending on a provided flag that states whether...
enum GNUNET_GenericReturnValue stored

References GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_EpochGroup::stored, value, and write_epoch_group_record().

Referenced by it_epoch_store_keys().

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

◆ it_epoch_store_keys()

static enum GNUNET_GenericReturnValue it_epoch_store_keys ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 430 of file messenger_api_handle.c.

433{
434 const struct GNUNET_MESSENGER_Epoch *epoch;
435
437
438 epoch = value;
439
443 cls);
444 return GNUNET_YES;
445}
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
static enum GNUNET_GenericReturnValue it_group_store_key(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
static enum GNUNET_GenericReturnValue it_announcement_store_key(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
struct GNUNET_CONTAINER_MultiShortmap * announcements
struct GNUNET_CONTAINER_MultiShortmap * groups

References GNUNET_MESSENGER_Epoch::announcements, GNUNET_assert, GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_YES, GNUNET_MESSENGER_Epoch::groups, it_announcement_store_key(), it_group_store_key(), and value.

Referenced by it_room_store_keys().

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

◆ it_room_store_keys()

static enum GNUNET_GenericReturnValue it_room_store_keys ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 449 of file messenger_api_handle.c.

452{
453 const struct GNUNET_MESSENGER_Room *room;
454
456
457 room = value;
458
460 room->epochs,
462 cls);
463 return GNUNET_YES;
464}
static enum GNUNET_GenericReturnValue it_epoch_store_keys(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONTAINER_MultiHashMap * epochs

References GNUNET_MESSENGER_Room::epochs, GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_YES, it_epoch_store_keys(), and value.

Referenced by cb_key_sync(), and set_handle_key().

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

◆ cb_key_sync()

static void cb_key_sync ( void *  cls)
static

Definition at line 468 of file messenger_api_handle.c.

469{
471 const char *name;
472
473 GNUNET_assert (cls);
474
475 handle = cls;
477
479 "Syncing keys from records completed: %s\n",
480 name);
481
484}
static enum GNUNET_GenericReturnValue it_room_store_keys(void *cls, const struct GNUNET_HashCode *key, void *value)

References get_handle_name(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, handle, it_room_store_keys(), and name.

Referenced by set_handle_key().

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

◆ set_handle_key()

void set_handle_key ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_CRYPTO_BlindablePrivateKey key 
)

Sets the keypair of a given handle to the keypair of a specific private key.

Parameters
[in,out]handleHandle
[in]keyPrivate key or NULL

Definition at line 488 of file messenger_api_handle.c.

490{
492
493 if (handle->key_monitor)
494 {
496 handle->key_monitor = NULL;
497 }
498
499 if (! key)
500 {
501 if (handle->key)
502 GNUNET_free (handle->key);
503
504 if (handle->pubkey)
505 GNUNET_free (handle->pubkey);
506
507 handle->key = NULL;
508 handle->pubkey = NULL;
509 return;
510 }
511
512 if (! handle->key)
514
515 if (! handle->pubkey)
517
518 GNUNET_memcpy (handle->key, key, sizeof(*key));
520
521 // Resets epoch and group keys as not stored yet
523 handle->rooms, it_room_store_keys, NULL);
524
526 handle->config,
527 handle->key,
530 handle,
532 handle,
534 handle,
536}
struct GNUNET_HashCode key
The key used in the DHT.
@ GNUNET_GNSRECORD_FILTER_NONE
No filter flags set.
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.
struct GNUNET_NAMESTORE_ZoneMonitor * GNUNET_NAMESTORE_zone_monitor_start2(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, int iterate_first, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordSetMonitor monitor, void *monitor_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, enum GNUNET_GNSRECORD_Filter filter)
Begin monitoring a zone for changes.
static void cb_key_monitor(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
static void cb_key_error(void *cls)
static void cb_key_sync(void *cls)
A private key for an identity as per LSD0001.
An identity key as per LSD0001.

References cb_key_error(), cb_key_monitor(), cb_key_sync(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CRYPTO_blindable_key_get_public(), GNUNET_free, GNUNET_GNSRECORD_FILTER_NONE, GNUNET_memcpy, GNUNET_NAMESTORE_zone_monitor_start2(), GNUNET_NAMESTORE_zone_monitor_stop(), GNUNET_new, GNUNET_YES, handle, it_room_store_keys(), and key.

Referenced by GNUNET_MESSENGER_connect(), and GNUNET_MESSENGER_set_key().

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

◆ get_handle_key()

const struct GNUNET_CRYPTO_BlindablePrivateKey * get_handle_key ( const struct GNUNET_MESSENGER_Handle handle)

Returns the private key of a given handle.

Parameters
[in]handleHandle
Returns
Private key of the handle

Definition at line 540 of file messenger_api_handle.c.

541{
543
544 if (handle->key)
545 return handle->key;
546
548}
const struct GNUNET_CRYPTO_BlindablePrivateKey * get_anonymous_private_key(void)
Returns the private identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it ever...

References get_anonymous_private_key(), GNUNET_assert, and handle.

Referenced by enqueue_message_to_room(), handle_member_id(), store_handle_encryption_key(), and store_handle_epoch_key().

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

◆ get_handle_pubkey()

const struct GNUNET_CRYPTO_BlindablePublicKey * get_handle_pubkey ( const struct GNUNET_MESSENGER_Handle handle)

Returns the public key of a given handle.

Parameters
[in]handleHandle
Returns
Public key of the handle

Definition at line 552 of file messenger_api_handle.c.

553{
555
556 if (handle->pubkey)
557 return handle->pubkey;
558
559 return get_anonymous_public_key ();
560}
const struct GNUNET_CRYPTO_BlindablePublicKey * get_anonymous_public_key(void)
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...

References get_anonymous_public_key(), GNUNET_assert, and handle.

Referenced by get_handle_contact(), GNUNET_MESSENGER_get_key(), handle_join_message(), send_enter_room(), send_message_to_room_with_key(), and send_open_room().

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

◆ get_handle_contact_store()

struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store ( struct GNUNET_MESSENGER_Handle handle)

Returns the used contact store of a given handle.

Parameters
[in,out]handleHandle
Returns
Contact store

Definition at line 564 of file messenger_api_handle.c.

565{
567
568 return &(handle->contact_store);
569}

References GNUNET_assert, and handle.

Referenced by create_handle(), destroy_handle(), get_handle_contact(), handle_id_message(), handle_join_message(), handle_key_message(), handle_transcript_message(), process_message_control(), and task_message_control().

Here is the caller graph for this function:

◆ get_handle_contact()

struct GNUNET_MESSENGER_Contact * get_handle_contact ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_HashCode key 
)

Returns the contact of a given handle in a room identified by a given key.

Parameters
[in,out]handleHandle
[in]keyKey of room
Returns
Contact

Definition at line 573 of file messenger_api_handle.c.

575{
576 struct GNUNET_MESSENGER_Room *room;
577 const struct GNUNET_ShortHashCode *contact_id;
578
579 GNUNET_assert ((handle) && (key));
580
582
583 if (! room)
584 return NULL;
585
586 contact_id = get_room_sender_id (room);
587
588 if (! contact_id)
589 return NULL;
590
591 {
593 get_context_from_member (key, contact_id, &context);
594
596 &context,
598 }
599}
static pa_context * context
Pulseaudio context.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
void get_context_from_member(const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context)
Calculates the context hash of a member in a room and returns it.
struct GNUNET_MESSENGER_Contact * get_store_contact(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_CRYPTO_BlindablePublicKey *pubkey)
Returns a contact using a specific public key.
const struct GNUNET_CRYPTO_BlindablePublicKey * get_handle_pubkey(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
const struct GNUNET_ShortHashCode * get_room_sender_id(const struct GNUNET_MESSENGER_Room *room)
Returns the member id of the room's sender.
A 256-bit hashcode.

References context, get_context_from_member(), get_handle_contact_store(), get_handle_pubkey(), get_room_sender_id(), get_store_contact(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), handle, and key.

Referenced by get_room_availble_epoch_entry(), handle_appeal_message(), handle_epoch_announcement(), and handle_private_message().

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

◆ open_handle_room()

void open_handle_room ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_HashCode key 
)

Marks a room known to a handle identified by a given key as open.

Parameters
[in,out]handleHandle
[in]keyKey of room

Definition at line 603 of file messenger_api_handle.c.

605{
606 struct GNUNET_MESSENGER_Room *room;
607
608 GNUNET_assert ((handle) && (key));
609
611
612 if (room)
613 room->opened = GNUNET_YES;
614}
enum GNUNET_GenericReturnValue opened

References get_handle_room(), GNUNET_assert, GNUNET_YES, handle, key, and GNUNET_MESSENGER_Room::opened.

Referenced by handle_room_open().

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

◆ entry_handle_room_at()

void entry_handle_room_at ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_PeerIdentity door,
const struct GNUNET_HashCode key 
)

Adds a tunnel for a room known to a handle identified by a given key to a list of opened connections.

Parameters
[in,out]handleHandle
[in]doorPeer identity
[in]keyKey of room

Definition at line 618 of file messenger_api_handle.c.

621{
622 struct GNUNET_MESSENGER_Room *room;
623
624 GNUNET_assert ((handle) && (door) && (key));
625
627
628 if (room)
629 add_to_list_tunnels (&(room->entries), door, NULL);
630}
void add_to_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *hash)
Adds a specific peer from a tunnel to the end of the list.
struct GNUNET_MESSENGER_ListTunnels entries

References add_to_list_tunnels(), GNUNET_MESSENGER_Room::entries, get_handle_room(), GNUNET_assert, GNUNET_YES, handle, and key.

Referenced by handle_room_entry().

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

◆ close_handle_room()

void close_handle_room ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_HashCode key 
)

Destroys and so implicitly closes a room known to a handle identified by a given key.

Parameters
[in,out]handleHandle
[in]keyKey of room

Definition at line 634 of file messenger_api_handle.c.

636{
637 struct GNUNET_MESSENGER_Room *room;
638
639 GNUNET_assert ((handle) && (key));
640
642
644 handle->rooms, key, room)))
645 destroy_room (room);
646}
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.

References destroy_room(), get_handle_room(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_YES, handle, and key.

Referenced by handle_room_close().

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

◆ get_handle_room()

struct GNUNET_MESSENGER_Room * get_handle_room ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_HashCode key,
enum GNUNET_GenericReturnValue  init 
)

Returns the room known to a handle identified by a given key.

Parameters
[in,out]handlehandle Handle
[in]keyKey of room
[in]initCreates room if necessary when GNUNET_YES is provided
Returns
Room or NULL

Definition at line 650 of file messenger_api_handle.c.

653{
654 struct GNUNET_MESSENGER_Room *room;
655
656 GNUNET_assert ((handle) && (key));
657
659
660 if ((! room) && (GNUNET_YES == init))
661 {
663 GNUNET_memcpy (&(room_key.hash), key, sizeof (struct GNUNET_HashCode));
664
665 room = create_room (handle, &room_key);
666
668 handle->rooms, key, room,
670 {
671 destroy_room (room);
672 return NULL;
673 }
674 }
675
676 return room;
677}
static char * init
Set to the name of a service to start.
Definition gnunet-arm.c:73
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
struct GNUNET_MESSENGER_Room * create_room(struct GNUNET_MESSENGER_Handle *handle, const union GNUNET_MESSENGER_RoomKey *key)
Creates and allocates a new room for a handle with a given key for the client API.
A room key unifies a room key code and its 512bit hash representation.

References create_room(), destroy_room(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_memcpy, GNUNET_OK, GNUNET_YES, handle, init, key, and room_key.

Referenced by close_handle_room(), entry_handle_room_at(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_open_room(), handle_member_id(), handle_miss_message(), handle_recv_message(), handle_room_close(), handle_room_entry(), handle_room_open(), handle_room_sync(), open_handle_room(), read_handle_encryption_key(), and read_handle_epoch_key().

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

◆ store_handle_epoch_key()

enum GNUNET_GenericReturnValue store_handle_epoch_key ( const struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_MESSENGER_Room room,
const struct GNUNET_HashCode hash,
const struct GNUNET_ShortHashCode identifier,
const struct GNUNET_CRYPTO_AeadSecretKey shared_key,
uint32_t  flags,
GNUNET_NAMESTORE_ContinuationWithStatus  cont,
void *  cont_cls,
struct GNUNET_NAMESTORE_QueueEntry **  query 
)

Stores/deletes a shared_key for a given room from a handle in an epoch with certain hash using a specific identifier for this epoch key.

Parameters
[in]handleHandle
[in]roomRoom
[in]hashEpoch hash
[in]identifierEpoch key identifier
[in]shared_keyShared epoch key or NULL
[in]flagsEpoch key flags
[in]contContinuation status callback or NULL
[in]cont_clsContinuation closure or NULL
[out]query
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 681 of file messenger_api_handle.c.

691{
692 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone;
694 const struct GNUNET_HashCode *room_key;
697 char *label;
698
699 GNUNET_assert ((handle) && (room) && (hash) && (identifier) && (query));
700
701 if (! handle->namestore)
702 return GNUNET_SYSERR;
703
704 zone = get_handle_key (handle);
705
706 if (! zone)
707 return GNUNET_SYSERR;
708
710
711 memset (&data, 0, sizeof (data));
712 memset (&record, 0, sizeof (record));
713
714 room_key = get_room_key (room);
715
716 if (shared_key)
717 {
718 struct GNUNET_CRYPTO_AeadSecretKey skey;
719
721 sizeof (skey),
723 strlen (
725 &(handle->secret),
726 sizeof (handle->secret),
728 room_key),
730 hash),
732 identifier)))
733 return GNUNET_SYSERR;
734
736 sizeof (record.nonce));
737
738 if (GNUNET_OK != GNUNET_CRYPTO_aead_encrypt (sizeof (*shared_key),
739 (const uint8_t*) shared_key,
740 0,
741 NULL,
742 &skey,
743 &(record.nonce),
744 &(record.shared_key),
745 &(record.mac)))
746 return GNUNET_SYSERR;
747
748 GNUNET_CRYPTO_zero_keys (&skey, sizeof (skey));
749
750 GNUNET_memcpy (&(record.key), room_key, sizeof (record.key));
751 GNUNET_memcpy (&(record.hash), hash, sizeof (record.hash));
753 &(record.identifier),
754 identifier,
755 sizeof (record.identifier));
756
757 record.flags = flags;
758
760 data.data = &record;
761 data.data_size = sizeof (record);
762 data.expiration_time = expiration.abs_value_us;
764 }
765
766 {
767 char lower_key [9];
768 char lower_hash [9];
769 char lower_id [7];
770 const char *s;
771
772 memset (lower_key, 0, sizeof (lower_key));
773 memset (lower_hash, 0, sizeof (lower_hash));
774 memset (lower_id, 0, sizeof (lower_id));
775
776 s = GNUNET_h2s (room_key);
777 for (size_t i=0; '\0' != s[i]; i++)
778 {
779 GNUNET_assert (i < sizeof (lower_key));
780 lower_key[i] = (char) tolower ((int) s[i]);
781 }
782 s = GNUNET_h2s (hash);
783 for (size_t i=0; '\0' != s[i]; i++)
784 {
785 GNUNET_assert (i < sizeof (lower_hash));
786 lower_hash[i] = (char) tolower ((int) s[i]);
787 }
788
789 s = GNUNET_sh2s (identifier);
790 for (size_t i=0; '\0' != s[i]; i++)
791 {
792 GNUNET_assert (i < sizeof (lower_id));
793 lower_id[i] = (char) tolower ((int) s[i]);
794 }
795
797 &label,
798 "epoch_key_%s%s%s",
799 lower_key,
800 lower_hash,
801 lower_id);
802 }
803
804 if (! label)
805 return GNUNET_SYSERR;
806
807 if (*query)
809
811 "Store epoch key record with label: %s [%d]\n",
812 label,
813 shared_key? 1 : 0);
814
816 handle->namestore,
817 zone,
818 label,
819 shared_key? 1 : 0,
820 &data,
821 cont,
822 cont_cls);
823
824 GNUNET_free (label);
825 return GNUNET_OK;
826}
static char * data
The data to insert into the dht.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_encrypt(size_t pt_len, const unsigned char pt[pt_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, void *ct, struct GNUNET_CRYPTO_AeadMac *mac)
Encrypt the given data using XChaCha20-Poly1305.
void GNUNET_CRYPTO_random_block(void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be published.
@ GNUNET_SYSERR
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_record_set_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_BlindablePrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_(void)
Return "forever".
Definition time.c:205
const struct GNUNET_CRYPTO_BlindablePrivateKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the private key of a given handle.
struct GNUNET_ShortHashCode identifier
The short hash identifying the epoch or group key.
struct GNUNET_CRYPTO_AeadSecretKey shared_key
The encrypted shared epoch or group key in the room.
struct GNUNET_HashCode hash
The hash identifying the epoch.
Time for absolute times used by GNUnet, in microseconds.

References data, expiration, get_handle_key(), get_room_key(), GNUNET_asprintf(), GNUNET_assert, GNUNET_CRYPTO_aead_encrypt(), GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_kdf_arg_auto, GNUNET_CRYPTO_random_block(), GNUNET_CRYPTO_zero_keys(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_RF_PRIVATE, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSENGER_SALT_SECRET_KEY, GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_record_set_store(), GNUNET_OK, GNUNET_sh2s(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_forever_(), GNUNET_YES, handle, GNUNET_MESSENGER_RoomEpochKeyRecord::hash, GNUNET_MESSENGER_RoomEpochKeyRecord::identifier, record(), room_key, and GNUNET_MESSENGER_RoomEpochKeyRecord::shared_key.

Referenced by write_epoch_announcement_record(), and write_epoch_group_record().

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

◆ store_handle_encryption_key()

enum GNUNET_GenericReturnValue store_handle_encryption_key ( const struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_MESSENGER_Room room,
const struct GNUNET_CRYPTO_HpkePrivateKey encryption_key,
GNUNET_NAMESTORE_ContinuationWithStatus  cont,
void *  cont_cls,
struct GNUNET_NAMESTORE_QueueEntry **  query 
)

Stores an encryption_key for a given room from a handle.

Parameters
[in]handleHandle
[in]roomRoom
[in]encryption_keyEncryption key or NULL
[in]contContinuation status callback or NULL
[in]cont_clsContinuation closure or NULL
[out]query
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 830 of file messenger_api_handle.c.

837{
838 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone;
840 const struct GNUNET_HashCode *room_key;
843 struct GNUNET_HashCode record_hash;
844 char *label;
845
846 GNUNET_assert ((handle) && (room) && (encryption_key) && (query));
847
848 if (! handle->namestore)
849 return GNUNET_SYSERR;
850
851 zone = get_handle_key (handle);
852
853 if (! zone)
854 return GNUNET_SYSERR;
855
857 room_key = get_room_key (room);
858
859 memset (&data, 0, sizeof (data));
860
861 {
862 uint8_t encryption_key_data [sizeof (record.encrypted_key_data)];
863 struct GNUNET_CRYPTO_AeadSecretKey skey;
864 size_t encryption_key_len;
865 ssize_t offset;
866
867 encryption_key_len = GNUNET_CRYPTO_hpke_sk_get_length (encryption_key);
868
869 if ((0 > encryption_key_len) ||
870 (encryption_key_len > sizeof (encryption_key_data)))
871 return GNUNET_SYSERR;
872
873 GNUNET_memcpy (&(record.key), room_key, sizeof (record.key));
874
876 encryption_key, encryption_key_data, encryption_key_len);
877
878 if (offset < 0)
879 return GNUNET_SYSERR;
880
881 if (offset < encryption_key_len)
882 encryption_key_len = offset;
883
884 record.encrypted_key_length = encryption_key_len;
885
886 GNUNET_CRYPTO_random_block (encryption_key_data
887 + encryption_key_len,
888 sizeof (encryption_key_data)
889 - encryption_key_len);
890
892 sizeof (skey),
894 strlen (
896 &(handle->secret),
897 sizeof (handle->secret),
899 room_key)))
900 return GNUNET_SYSERR;
901
903 sizeof (record.nonce));
904
905 if (GNUNET_OK != GNUNET_CRYPTO_aead_encrypt (sizeof (encryption_key_data),
906 encryption_key_data,
907 0,
908 NULL,
909 &skey,
910 &(record.nonce),
911 &(record.encrypted_key_data),
912 &(record.mac)))
913 return GNUNET_SYSERR;
914
915 GNUNET_CRYPTO_zero_keys (&skey, sizeof (skey));
916
917 GNUNET_CRYPTO_hash (record.encrypted_key_data,
918 sizeof (record.encrypted_key_data),
919 &record_hash);
920
922 data.data = &record;
923 data.data_size = sizeof (record);
924 data.expiration_time = expiration.abs_value_us;
926 }
927
928 {
929 char *lower_key;
930 char *lower_hash;
931 const char *s;
932
933 s = GNUNET_h2s (room_key);
934 lower_key = GNUNET_STRINGS_utf8_tolower (s);
935 if (! lower_key)
936 lower_key = GNUNET_strdup (s);
937
938 s = GNUNET_h2s (&record_hash);
939 lower_hash = GNUNET_STRINGS_utf8_tolower (s);
940 if (! lower_hash)
941 lower_hash = GNUNET_strdup (s);
942
944 &label,
945 "encryption_key_%s%s",
946 lower_key,
947 lower_hash);
948
949 if (lower_hash)
950 GNUNET_free (lower_hash);
951 if (lower_key)
952 GNUNET_free (lower_key);
953 }
954
955 if (! label)
956 return GNUNET_SYSERR;
957
958 if (*query)
960
962 "Store encryption key record with label: %s [%d]\n",
963 label,
964 encryption_key? 1 : 0);
965
967 handle->namestore,
968 zone,
969 label,
970 encryption_key? 1 : 0,
971 &data,
972 cont,
973 cont_cls);
974
975 GNUNET_free (label);
976 return GNUNET_OK;
977}
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
ssize_t GNUNET_CRYPTO_hpke_sk_get_length(const struct GNUNET_CRYPTO_HpkePrivateKey *key)
Get the compacted length of a GNUNET_CRYPTO_HpkePrivateKey.
ssize_t GNUNET_CRYPTO_write_hpke_sk_to_buffer(const struct GNUNET_CRYPTO_HpkePrivateKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_HpkePrivateKey to a compact buffer.
char * GNUNET_STRINGS_utf8_tolower(const char *input)
Convert the utf-8 input string to lower case.
Definition strings.c:481

References data, expiration, get_handle_key(), get_room_key(), GNUNET_asprintf(), GNUNET_assert, GNUNET_CRYPTO_aead_encrypt(), GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_hpke_sk_get_length(), GNUNET_CRYPTO_kdf_arg_auto, GNUNET_CRYPTO_random_block(), GNUNET_CRYPTO_write_hpke_sk_to_buffer(), GNUNET_CRYPTO_zero_keys(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_RF_PRIVATE, GNUNET_GNSRECORD_TYPE_MESSENGER_ENCRYPTION_KEY, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSENGER_SALT_SECRET_KEY, GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_record_set_store(), GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_utf8_tolower(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_forever_(), GNUNET_YES, handle, record(), and room_key.

Referenced by add_room_encryption_key().

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