GNUnet 0.26.2-14-ga82e62fdc
 
Loading...
Searching...
No Matches
messenger_api_handle.h File Reference
Include dependency graph for messenger_api_handle.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_Handle
 

Functions

struct GNUNET_MESSENGER_Handlecreate_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.
 
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.
 
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_HashCode *key, const struct GNUNET_HashCode *hash, const struct GNUNET_ShortHashCode *identifier, const struct GNUNET_CRYPTO_SymmetricSessionKey *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 identified by its key 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_HashCode *key, 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 identified by its key/i>.
 

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 40 of file messenger_api_handle.c.

44{
46
48
50
51 handle->config = config;
52 handle->mq = NULL;
53
55 handle->config,
57 "MESSENGER_GROUP_KEYS");
58
59 if (handle->config)
60 handle->namestore = GNUNET_NAMESTORE_connect (handle->config);
61
62 if (secret)
63 GNUNET_memcpy (&(handle->secret), secret, sizeof (handle->secret));
64 else
65 memset (&(handle->secret), 0, sizeof (handle->secret));
66
67 handle->msg_callback = msg_callback;
68 handle->msg_cls = msg_cls;
69
70 handle->name = NULL;
71 handle->key = NULL;
72 handle->pubkey = NULL;
73
74 handle->reconnect_time = GNUNET_TIME_relative_get_zero_ ();
75 handle->reconnect_task = NULL;
76
77 handle->key_monitor = NULL;
78
80
82
83 return handle;
84}
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".
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_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:

◆ 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 104 of file messenger_api_handle.c.

105{
107
109
110 if (handle->rooms)
111 {
113 handle->rooms, iterate_destroy_room, NULL);
114
116 }
117
118 if (handle->key_monitor)
120
121 if (handle->reconnect_task)
122 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
123
124 if (handle->mq)
126
127 if (handle->namestore)
129
130 if (handle->name)
131 GNUNET_free (handle->name);
132
133 if (handle->key)
134 GNUNET_free (handle->key);
135
136 if (handle->pubkey)
137 GNUNET_free (handle->pubkey);
138
140}
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:980
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_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 144 of file messenger_api_handle.c.

146{
148
149 if (handle->name)
150 GNUNET_free (handle->name);
151
152 handle->name = name ? GNUNET_strdup (name) : NULL;
153}
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 157 of file messenger_api_handle.c.

158{
160
161 return handle->name;
162}

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:

◆ 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 536 of file messenger_api_handle.c.

538{
540
541 if (handle->key_monitor)
542 {
544 handle->key_monitor = NULL;
545 }
546
547 if (! key)
548 {
549 if (handle->key)
550 GNUNET_free (handle->key);
551
552 if (handle->pubkey)
553 GNUNET_free (handle->pubkey);
554
555 handle->key = NULL;
556 handle->pubkey = NULL;
557 return;
558 }
559
560 if (! handle->key)
562
563 if (! handle->pubkey)
565
566 GNUNET_memcpy (handle->key, key, sizeof(*key));
568
569 // Resets epoch and group keys as not stored yet
571 handle->rooms, it_room_store_keys, NULL);
572
574 handle->config,
575 handle->key,
578 handle,
580 handle,
582 handle,
584}
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.
@ GNUNET_YES
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 enum GNUNET_GenericReturnValue it_room_store_keys(void *cls, const struct GNUNET_HashCode *key, void *value)
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 588 of file messenger_api_handle.c.

589{
591
592 if (handle->key)
593 return handle->key;
594
596}
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 600 of file messenger_api_handle.c.

601{
603
604 if (handle->pubkey)
605 return handle->pubkey;
606
607 return get_anonymous_public_key ();
608}
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 612 of file messenger_api_handle.c.

613{
615
616 return &(handle->contact_store);
617}

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 621 of file messenger_api_handle.c.

623{
624 struct GNUNET_MESSENGER_Room *room;
625 const struct GNUNET_ShortHashCode *contact_id;
626
627 GNUNET_assert ((handle) && (key));
628
630
631 if (! room)
632 return NULL;
633
634 contact_id = get_room_sender_id (room);
635
636 if (! contact_id)
637 return NULL;
638
639 {
641 get_context_from_member (key, contact_id, &context);
642
644 &context,
646 }
647}
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 512-bit hashcode.
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 651 of file messenger_api_handle.c.

653{
654 struct GNUNET_MESSENGER_Room *room;
655
656 GNUNET_assert ((handle) && (key));
657
659
660 if (room)
661 room->opened = GNUNET_YES;
662}
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.
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 666 of file messenger_api_handle.c.

669{
670 struct GNUNET_MESSENGER_Room *room;
671
672 GNUNET_assert ((handle) && (door) && (key));
673
675
676 if (room)
677 add_to_list_tunnels (&(room->entries), door, NULL);
678}
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 682 of file messenger_api_handle.c.

684{
685 struct GNUNET_MESSENGER_Room *room;
686
687 GNUNET_assert ((handle) && (key));
688
690
692 handle->rooms, key, room)))
693 destroy_room (room);
694}
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.
void destroy_room(struct GNUNET_MESSENGER_Room *room)
Destroys a room and frees its memory fully from the client API.

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 698 of file messenger_api_handle.c.

701{
702 struct GNUNET_MESSENGER_Room *room;
703
704 GNUNET_assert ((handle) && (key));
705
707
708 if ((! room) && (GNUNET_YES == init))
709 {
711 GNUNET_memcpy (&(room_key.hash), key, sizeof (struct GNUNET_HashCode));
712
713 room = create_room (handle, &room_key);
714
716 handle->rooms, key, room,
718 {
719 destroy_room (room);
720 return NULL;
721 }
722 }
723
724 return room;
725}
static char * init
Set to the name of a service to start.
Definition gnunet-arm.c:73
char * room_key
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...
@ GNUNET_OK
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_HashCode key,
const struct GNUNET_HashCode hash,
const struct GNUNET_ShortHashCode identifier,
const struct GNUNET_CRYPTO_SymmetricSessionKey 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 identified by its key in an epoch with certain hash using a specific identifier for this epoch key.

Parameters
[in]handleHandle
[in]keyRoom key
[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 729 of file messenger_api_handle.c.

739{
740 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone;
744 char *label;
745
746 GNUNET_assert ((handle) && (key) && (hash) && (identifier) && (query));
747
748 if (! handle->namestore)
749 return GNUNET_SYSERR;
750
751 zone = get_handle_key (handle);
752
753 if (! zone)
754 return GNUNET_SYSERR;
755
757
758 memset (&data, 0, sizeof (data));
759 memset (&record, 0, sizeof (record));
760
761 if (shared_key)
762 {
765 int32_t checksum;
766
767 if (GNUNET_YES != GNUNET_CRYPTO_kdf (&skey, sizeof (skey),
768 key, sizeof (*key),
769 &(handle->secret),
770 sizeof (handle->secret),
771 zone, sizeof (*zone),
772 hash, sizeof (*hash),
773 identifier, sizeof (*identifier),
774 NULL))
775 return GNUNET_SYSERR;
776
777 GNUNET_memcpy (&(record.key), key, sizeof (record.key));
778 GNUNET_memcpy (&(record.hash), hash, sizeof (record.hash));
780 &(record.identifier),
781 identifier,
782 sizeof (record.identifier));
783
785 &iv,
786 &skey,
787 key, sizeof (*key),
788 hash, sizeof (*hash),
789 identifier, sizeof (*identifier),
790 NULL);
791
792 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (shared_key,
793 sizeof (*shared_key),
794 &skey,
795 &iv,
796 &(record.shared_key)))
797 return GNUNET_SYSERR;
798
800 &iv,
801 &skey,
802 &iv, sizeof (iv),
803 NULL);
804
805 checksum = GNUNET_CRYPTO_crc32_n (shared_key, sizeof (*shared_key));
806
807 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&checksum,
808 sizeof (checksum),
809 &skey,
810 &iv,
811 &(record.checksum)))
812 return GNUNET_SYSERR;
813
814 record.flags = flags;
815
817 data.data = &record;
818 data.data_size = sizeof (record);
819 data.expiration_time = expiration.abs_value_us;
821
822 GNUNET_CRYPTO_zero_keys (&skey, sizeof (skey));
823 }
824
825 {
826 char lower_key [9];
827 char lower_hash [9];
828 char lower_id [7];
829 const char *s;
830
831 memset (lower_key, 0, sizeof (lower_key));
832 memset (lower_hash, 0, sizeof (lower_hash));
833 memset (lower_id, 0, sizeof (lower_id));
834
835 s = GNUNET_h2s (key);
836 for (size_t i=0; '\0' != s[i]; i++)
837 {
838 GNUNET_assert (i < sizeof (lower_key));
839 lower_key[i] = (char) tolower ((int) s[i]);
840 }
841 s = GNUNET_h2s (hash);
842 for (size_t i=0; '\0' != s[i]; i++)
843 {
844 GNUNET_assert (i < sizeof (lower_hash));
845 lower_hash[i] = (char) tolower ((int) s[i]);
846 }
847
848 s = GNUNET_sh2s (identifier);
849 for (size_t i=0; '\0' != s[i]; i++)
850 {
851 GNUNET_assert (i < sizeof (lower_id));
852 lower_id[i] = (char) tolower ((int) s[i]);
853 }
854
856 &label,
857 "epoch_key_%s%s%s",
858 lower_key,
859 lower_hash,
860 lower_id);
861 }
862
863 if (! label)
864 return GNUNET_SYSERR;
865
866 if (*query)
868
870 "Store epoch key record with label: %s [%d]\n",
871 label,
872 shared_key? 1 : 0);
873
875 handle->namestore,
876 zone,
877 label,
878 shared_key? 1 : 0,
879 &data,
880 cont,
881 cont_cls);
882
883 GNUNET_free (label);
884 return GNUNET_OK;
885}
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_EPOCH_KEY
Record type to store epoch keys from a messenger room.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * data
The data to insert into the dht.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
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_zero_keys(void *buffer, size_t length)
Zero out buffer, securely against compiler optimizations.
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be published.
int32_t GNUNET_CRYPTO_crc32_n(const void *buf, size_t len)
Compute the CRC32 checksum for the first len bytes of the buffer.
Definition crypto_crc.c:99
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition crypto_kdf.c:62
#define GNUNET_log(kind,...)
@ GNUNET_SYSERR
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
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.
A room epoch key record specifies an epoch key for a given room that can be identified via a given ke...
struct GNUNET_ShortHashCode identifier
The short hash identifying the epoch or group key.
struct GNUNET_CRYPTO_SymmetricSessionKey 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(), GNUNET_asprintf(), GNUNET_assert, GNUNET_CRYPTO_crc32_n(), GNUNET_CRYPTO_kdf(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_CRYPTO_symmetric_encrypt(), 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_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, key, record(), 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_HashCode key,
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 identified by its key/i>.

Parameters
[in]handleHandle
[in]keyRoom key
[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 889 of file messenger_api_handle.c.

896{
897 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone;
901 struct GNUNET_HashCode nonce_hash;
902 char *label;
903
904 GNUNET_assert ((handle) && (key) && (encryption_key) && (query));
905
906 if (! handle->namestore)
907 return GNUNET_SYSERR;
908
909 zone = get_handle_key (handle);
910
911 if (! zone)
912 return GNUNET_SYSERR;
913
915
916 memset (&data, 0, sizeof (data));
917
918 {
921 uint8_t encryption_key_data [GNUNET_MESSENGER_ENCRYPTION_KEY_DATA_BYTES];
922 int32_t encryption_key_checksum;
923 size_t encryption_key_len;
924 ssize_t offset;
925
926 encryption_key_len = GNUNET_CRYPTO_hpke_sk_get_length (encryption_key);
927
928 if ((0 > encryption_key_len) || (encryption_key_len >
930 )
931 return GNUNET_SYSERR;
932
933 GNUNET_memcpy (&(record.key), key, sizeof (record.key));
936
937 if (GNUNET_YES != GNUNET_CRYPTO_kdf (&skey, sizeof (skey),
938 key, sizeof (*key),
939 &(handle->secret),
940 sizeof (handle->secret),
941 zone, sizeof (*zone),
942 record.nonce_data, sizeof (record.
943 nonce_data),
944 NULL))
945 return GNUNET_SYSERR;
946
948 &iv,
949 &skey,
950 key, sizeof (*key),
951 record.nonce_data, sizeof (record.nonce_data),
952 NULL);
953
955 encryption_key, encryption_key_data, encryption_key_len);
956
957 if (offset < 0)
958 return GNUNET_SYSERR;
959
960 if (offset < encryption_key_len)
961 encryption_key_len = offset;
962
963 record.encrypted_key_length = encryption_key_len;
964
966 + encryption_key_len,
967 sizeof (encryption_key_data)
968 - encryption_key_len);
969
970 encryption_key_checksum = GNUNET_CRYPTO_crc32_n (encryption_key_data,
971 sizeof (encryption_key_data
972 ));
973
974 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (encryption_key_data,
975 sizeof (encryption_key_data),
976 &skey,
977 &iv,
978 record.encrypted_key_data))
979 return GNUNET_SYSERR;
980
982 &iv,
983 &skey,
984 &iv, sizeof (iv),
985 NULL);
986
987 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&encryption_key_checksum,
988 sizeof (encryption_key_checksum),
989 &skey,
990 &iv,
991 &(record.encrypted_key_checksum))
992 )
993 return GNUNET_SYSERR;
994
995 GNUNET_CRYPTO_hash (record.nonce_data, sizeof (record.nonce_data), &
996 nonce_hash);
997
999 data.data = &record;
1000 data.data_size = sizeof (record);
1001 data.expiration_time = expiration.abs_value_us;
1003
1004 GNUNET_CRYPTO_zero_keys (&skey, sizeof (skey));
1005 }
1006
1007 {
1008 char *lower_key;
1009 char *lower_nonce;
1010 const char *s;
1011
1012 s = GNUNET_h2s (key);
1013 lower_key = GNUNET_STRINGS_utf8_tolower (s);
1014 if (! lower_key)
1015 lower_key = GNUNET_strdup (s);
1016
1017 s = GNUNET_h2s (&nonce_hash);
1018 lower_nonce = GNUNET_STRINGS_utf8_tolower (s);
1019 if (! lower_nonce)
1020 lower_nonce = GNUNET_strdup (s);
1021
1023 &label,
1024 "encryption_key_%s%s",
1025 lower_key,
1026 lower_nonce);
1027
1028 if (lower_nonce)
1029 GNUNET_free (lower_nonce);
1030 if (lower_key)
1031 GNUNET_free (lower_key);
1032 }
1033
1034 if (! label)
1035 return GNUNET_SYSERR;
1036
1037 if (*query)
1038 GNUNET_NAMESTORE_cancel (*query);
1039
1041 "Store encryption key record with label: %s [%d]\n",
1042 label,
1043 encryption_key? 1 : 0);
1044
1046 handle->namestore,
1047 zone,
1048 label,
1049 encryption_key? 1 : 0,
1050 &data,
1051 cont,
1052 cont_cls);
1053
1054 GNUNET_free (label);
1055 return GNUNET_OK;
1056}
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ENCRYPTION_KEY
Record type to store encryption keys used in messenger rooms.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41
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.
#define GNUNET_MESSENGER_ENCRYPTION_KEY_DATA_BYTES
#define GNUNET_MESSENGER_ENCRYPTION_KEY_NONCE_BYTES
char * GNUNET_STRINGS_utf8_tolower(const char *input)
Convert the utf-8 input string to lower case.
Definition strings.c:475
An encryption key record specifies an encryption key for a given room that can be identified via a gi...

References data, expiration, get_handle_key(), GNUNET_asprintf(), GNUNET_assert, GNUNET_CRYPTO_crc32_n(), GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hpke_sk_get_length(), GNUNET_CRYPTO_kdf(), GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_CRYPTO_symmetric_encrypt(), 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_ENCRYPTION_KEY_DATA_BYTES, GNUNET_MESSENGER_ENCRYPTION_KEY_NONCE_BYTES, 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, key, and record().

Referenced by add_room_encryption_key().

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