GNUnet 0.27.0
 
Loading...
Searching...
No Matches
messenger_api_message.h File Reference
Include dependency graph for messenger_api_message.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY    "gnunet-messenger-announcement-key-k*d-p!80"
 
#define GNUNET_MESSENGER_SALT_EPOCH_KEY    "gnunet-messenger-epoch-key-ePGN3bGR-}*i$<2"
 
#define GNUNET_MESSENGER_SALT_GROUP_KEY    "gnunet-messenger-group-key-L)&7{4i(WSEPpR-"
 
#define GNUNET_MESSENGER_SALT_SECRET_KEY    "gnunet-messenger-secret-key-}xJ(eTuk[+xu{S"
 
#define GNUNET_MESSENGER_SALT_ENCRYPTION_KEY    "gnunet-messenger-encryption-key-9*Qaj7A+zv"
 
#define GNUNET_MESSENGER_SALT_EPOCH_IV   "gnunet-messenger-epoch-iv"
 
#define GNUNET_MESSENGER_SALT_ENCRYPTION_IV   "gnunet-messenger-encryption-iv"
 
#define GNUNET_MESSENGER_SALT_SECRET_IV   "gnunet-messenger-secret-iv"
 
#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE
 
#define GNUNET_MESSENGER_PADDING_MIN   (sizeof(uint16_t) + sizeof(char))
 
#define GNUNET_MESSENGER_PADDING_LEVEL0   (512)
 
#define GNUNET_MESSENGER_PADDING_LEVEL1   (4096)
 
#define GNUNET_MESSENGER_PADDING_LEVEL2   (32768)
 

Enumerations

enum  GNUNET_MESSENGER_PackMode { GNUNET_MESSENGER_PACK_MODE_ENVELOPE = 0x1 , GNUNET_MESSENGER_PACK_MODE_UNKNOWN = 0x0 }
 

Functions

struct GNUNET_MESSENGER_Messagecreate_message (enum GNUNET_MESSENGER_MessageKind kind)
 Creates and allocates a new message with a specific kind.
 
struct GNUNET_MESSENGER_Messagecopy_message (const struct GNUNET_MESSENGER_Message *message)
 Creates and allocates a copy of a given message.
 
void copy_message_header (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_MessageHeader *header)
 Copy message header details from another message to a given message.
 
void cleanup_message (struct GNUNET_MESSENGER_Message *message)
 Frees the messages body memory.
 
void destroy_message (struct GNUNET_MESSENGER_Message *message)
 Destroys a message and frees its memory fully.
 
enum GNUNET_GenericReturnValue is_message_session_bound (const struct GNUNET_MESSENGER_Message *message)
 Returns if the message should be bound to a member session.
 
uint16_t get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
 Returns the minimal size in bytes to encode a message of a specific kind.
 
uint16_t get_message_size (const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
 Returns the exact size in bytes to encode a given message.
 
void encode_message_signature (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
 Encodes the signature of a given message into a buffer of a maximum length in bytes.
 
void encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
 Encodes a given message into a buffer of a maximum length in bytes.
 
enum GNUNET_GenericReturnValue decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
 Decodes a message from a given buffer of a maximum length in bytes.
 
void hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
 Calculates a hash of a given buffer with a length in bytes from a message.
 
void sign_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
 Signs the hash of a message with a given private key.
 
struct GNUNET_PILS_Operationsign_message_by_peer (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, struct GNUNET_PILS_Handle *pils, const GNUNET_PILS_SignResultCallback sign_cb, void *cls)
 Signs the hash of a message with the peer identity of a given pils service going into a callback with a custom closure on success.
 
enum GNUNET_GenericReturnValue 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.
 
enum GNUNET_GenericReturnValue verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
 Verifies the signature of a given message and its hash with a specific public key.
 
enum GNUNET_GenericReturnValue verify_message_by_peer (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_PeerIdentity *identity)
 Verifies the signature of a given message and its hash with a specific peer's identity.
 
enum GNUNET_GenericReturnValue verify_message_by_key (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Verifies the hmac of a given message body with a specific shared key.
 
enum GNUNET_GenericReturnValue encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
 Encrypts a message using a given public key and replaces its body and kind with the now private encrypted message.
 
enum GNUNET_GenericReturnValue decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key)
 Decrypts a private message using a given private key and replaces its body and kind with the inner encrypted message.
 
struct GNUNET_MESSENGER_Messagetranscribe_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
 Transcribes a message as a new transcript message using a given public key from the recipient of the encrypted message content.
 
enum GNUNET_GenericReturnValue encrypt_secret_message (struct GNUNET_MESSENGER_Message *message, const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Encrypts a message using a given shared key from an announcement of an epoch and replaces its body and kind with the inner encrypted message.
 
enum GNUNET_GenericReturnValue decrypt_secret_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Decrypts a secret message using a given shared key and replaces its body and kind with the inner encrypted message.
 
enum GNUNET_GenericReturnValue read_transcript_message (struct GNUNET_MESSENGER_Message *message)
 Read the original message from a transcript message and replaces its body and kind with the inner encrypted message.
 
enum GNUNET_GenericReturnValue extract_access_message_key (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
 Extracts the shared epoch or group key from an access message using the private ephemeral key from an epoch and verifies it via the HMAC from the message body.
 
enum GNUNET_GenericReturnValue extract_authorization_message_key (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
 Extracts the shared epoch or group key from an authorization message using a previously exchanged shared key and verifies it via the HMAC from the message body.
 
struct GNUNET_TIME_Relative get_message_timeout (const struct GNUNET_MESSENGER_Message *message)
 Return the relative timeout of the content from a given message that controls when a delayed handling action of this message needs to be processed at least.
 
struct GNUNET_MQ_Envelopepack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_PackMode mode)
 Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE.
 
enum GNUNET_GenericReturnValue is_peer_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message can be sent by the service without usage of a clients private key.
 
enum GNUNET_GenericReturnValue is_service_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message contains service critical information.
 
enum GNUNET_GenericReturnValue is_epoch_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a certain kind of message from storage contains some specific details that might be required for the overall message graph to function as intended.
 
enum GNUNET_GenericReturnValue filter_message_sending (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message should be sent by a client.
 
const struct GNUNET_ShortHashCodeget_message_discourse (const struct GNUNET_MESSENGER_Message *message)
 Returns the discourse hash of a message depending on its kind.
 

Macro Definition Documentation

◆ GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY

#define GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY    "gnunet-messenger-announcement-key-k*d-p!80"

Definition at line 35 of file messenger_api_message.h.

40 {4i(WSEPpR-"
41#define GNUNET_MESSENGER_SALT_SECRET_KEY \
42 "gnunet-messenger-secret-key-}xJ(eTuk[+xu{S"
43#define GNUNET_MESSENGER_SALT_ENCRYPTION_KEY \
44 "gnunet-messenger-encryption-key-9*Qaj7A+zv"
45
46#define GNUNET_MESSENGER_SALT_EPOCH_IV "gnunet-messenger-epoch-iv"
47#define GNUNET_MESSENGER_SALT_ENCRYPTION_IV "gnunet-messenger-encryption-iv"
48#define GNUNET_MESSENGER_SALT_SECRET_IV "gnunet-messenger-secret-iv"
49
50#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE \
51 - GNUNET_MIN_MESSAGE_SIZE)
52
53#define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char))
54#define GNUNET_MESSENGER_PADDING_LEVEL0 (512)
55#define GNUNET_MESSENGER_PADDING_LEVEL1 (4096)
56#define GNUNET_MESSENGER_PADDING_LEVEL2 (32768)
57
58enum GNUNET_MESSENGER_PackMode
59{
60 GNUNET_MESSENGER_PACK_MODE_ENVELOPE = 0x1,
61 GNUNET_MESSENGER_PACK_MODE_UNKNOWN = 0x0,
62};
63
70struct GNUNET_MESSENGER_Message*
71create_message (enum GNUNET_MESSENGER_MessageKind kind);
72
79struct GNUNET_MESSENGER_Message*
80copy_message (const struct GNUNET_MESSENGER_Message *message);
81
89void
90copy_message_header (struct GNUNET_MESSENGER_Message *message,
91 const struct GNUNET_MESSENGER_MessageHeader *header);
92
98void
99cleanup_message (struct GNUNET_MESSENGER_Message *message);
100
106void
107destroy_message (struct GNUNET_MESSENGER_Message *message);
108
115enum GNUNET_GenericReturnValue
116is_message_session_bound (const struct GNUNET_MESSENGER_Message *message);
117
125uint16_t
126get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind,
127 enum GNUNET_GenericReturnValue include_header);
128
136uint16_t
137get_message_size (const struct GNUNET_MESSENGER_Message *message,
138 enum GNUNET_GenericReturnValue include_header);
139
148void
149encode_message_signature (const struct GNUNET_MESSENGER_Message *message,
150 uint16_t length,
151 char *buffer);
152
161void
162encode_message (const struct GNUNET_MESSENGER_Message *message,
163 uint16_t length,
164 char *buffer,
165 enum GNUNET_GenericReturnValue include_header);
166
182enum GNUNET_GenericReturnValue
183decode_message (struct GNUNET_MESSENGER_Message *message,
184 uint16_t length,
185 const char *buffer,
186 enum GNUNET_GenericReturnValue include_header,
187 uint16_t *padding);
188
198void
199hash_message (const struct GNUNET_MESSENGER_Message *message,
200 uint16_t length,
201 const char *buffer,
202 struct GNUNET_HashCode *hash);
203
211void
212sign_message (struct GNUNET_MESSENGER_Message *message,
213 const struct GNUNET_HashCode *hash,
214 const struct GNUNET_CRYPTO_BlindablePrivateKey *key);
215
227struct GNUNET_PILS_Operation*
228sign_message_by_peer (struct GNUNET_MESSENGER_Message *message,
229 const struct GNUNET_HashCode *hash,
230 struct GNUNET_PILS_Handle *pils,
231 const GNUNET_PILS_SignResultCallback sign_cb,
232 void *cls);
233
245enum GNUNET_GenericReturnValue
246sign_message_by_key (struct GNUNET_MESSENGER_Message *message,
247 const struct GNUNET_CRYPTO_SymmetricSessionKey *key);
248
259enum GNUNET_GenericReturnValue
260verify_message (const struct GNUNET_MESSENGER_Message *message,
261 const struct GNUNET_HashCode *hash,
262 const struct GNUNET_CRYPTO_BlindablePublicKey *key);
263
274enum GNUNET_GenericReturnValue
275verify_message_by_peer (const struct GNUNET_MESSENGER_Message *message,
276 const struct GNUNET_HashCode *hash,
277 const struct GNUNET_PeerIdentity *identity);
278
287enum GNUNET_GenericReturnValue
288verify_message_by_key (const struct GNUNET_MESSENGER_Message *message,
289 const struct GNUNET_CRYPTO_SymmetricSessionKey *key);
290
300enum GNUNET_GenericReturnValue
301encrypt_message (struct GNUNET_MESSENGER_Message *message,
302 const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key);
303
313enum GNUNET_GenericReturnValue
314decrypt_message (struct GNUNET_MESSENGER_Message *message,
315 const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key);
316
325struct GNUNET_MESSENGER_Message*
326transcribe_message (const struct GNUNET_MESSENGER_Message *message,
327 const struct GNUNET_CRYPTO_BlindablePublicKey *key);
328
339enum GNUNET_GenericReturnValue
340encrypt_secret_message (struct GNUNET_MESSENGER_Message *message,
341 const union GNUNET_MESSENGER_EpochIdentifier *identifier
342 ,
343 const struct GNUNET_CRYPTO_SymmetricSessionKey *key);
344
354enum GNUNET_GenericReturnValue
355decrypt_secret_message (struct GNUNET_MESSENGER_Message *message,
356 const struct GNUNET_CRYPTO_SymmetricSessionKey *key);
357
366enum GNUNET_GenericReturnValue
367read_transcript_message (struct GNUNET_MESSENGER_Message *message);
368
380enum GNUNET_GenericReturnValue
381extract_access_message_key (const struct GNUNET_MESSENGER_Message *message,
382 const struct GNUNET_CRYPTO_HpkePrivateKey *key,
383 struct GNUNET_CRYPTO_SymmetricSessionKey *
384 shared_key);
385
397enum GNUNET_GenericReturnValue
398extract_authorization_message_key (struct GNUNET_MESSENGER_Message *message,
399 const struct
400 GNUNET_CRYPTO_SymmetricSessionKey *key,
401 struct GNUNET_CRYPTO_SymmetricSessionKey *
402 shared_key);
403
412struct GNUNET_TIME_Relative
413get_message_timeout (const struct GNUNET_MESSENGER_Message *message);
414
425struct GNUNET_MQ_Envelope*
426pack_message (struct GNUNET_MESSENGER_Message *message,
427 struct GNUNET_HashCode *hash,
428 enum GNUNET_MESSENGER_PackMode mode);
429
438enum GNUNET_GenericReturnValue
439is_peer_message (const struct GNUNET_MESSENGER_Message *message);
440
452enum GNUNET_GenericReturnValue
453is_service_message (const struct GNUNET_MESSENGER_Message *message);
454
464enum GNUNET_GenericReturnValue
465is_epoch_message (const struct GNUNET_MESSENGER_Message *message);
466
475enum GNUNET_GenericReturnValue
476filter_message_sending (const struct GNUNET_MESSENGER_Message *message);
477
485const struct GNUNET_ShortHashCode*
486get_message_discourse (const struct GNUNET_MESSENGER_Message *message);
487
488#endif // GNUNET_MESSENGER_API_MESSAGE_H
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_MESSENGER_Handle * messenger

◆ GNUNET_MESSENGER_SALT_EPOCH_KEY

#define GNUNET_MESSENGER_SALT_EPOCH_KEY    "gnunet-messenger-epoch-key-ePGN3bGR-}*i$<2"

Definition at line 37 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_SALT_GROUP_KEY

#define GNUNET_MESSENGER_SALT_GROUP_KEY    "gnunet-messenger-group-key-L)&7{4i(WSEPpR-"

Definition at line 39 of file messenger_api_message.h.

40 {4i(WSEPpR-"

◆ GNUNET_MESSENGER_SALT_SECRET_KEY

#define GNUNET_MESSENGER_SALT_SECRET_KEY    "gnunet-messenger-secret-key-}xJ(eTuk[+xu{S"

Definition at line 41 of file messenger_api_message.h.

42 {S"

◆ GNUNET_MESSENGER_SALT_ENCRYPTION_KEY

#define GNUNET_MESSENGER_SALT_ENCRYPTION_KEY    "gnunet-messenger-encryption-key-9*Qaj7A+zv"

Definition at line 43 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_SALT_EPOCH_IV

#define GNUNET_MESSENGER_SALT_EPOCH_IV   "gnunet-messenger-epoch-iv"

Definition at line 46 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_SALT_ENCRYPTION_IV

#define GNUNET_MESSENGER_SALT_ENCRYPTION_IV   "gnunet-messenger-encryption-iv"

Definition at line 47 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_SALT_SECRET_IV

#define GNUNET_MESSENGER_SALT_SECRET_IV   "gnunet-messenger-secret-iv"

Definition at line 48 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_MAX_MESSAGE_SIZE

#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE
Value:
#define GNUNET_MIN_MESSAGE_SIZE
Smallest supported message.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...

Definition at line 50 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_PADDING_MIN

#define GNUNET_MESSENGER_PADDING_MIN   (sizeof(uint16_t) + sizeof(char))

Definition at line 53 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_PADDING_LEVEL0

#define GNUNET_MESSENGER_PADDING_LEVEL0   (512)

Definition at line 54 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_PADDING_LEVEL1

#define GNUNET_MESSENGER_PADDING_LEVEL1   (4096)

Definition at line 55 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_PADDING_LEVEL2

#define GNUNET_MESSENGER_PADDING_LEVEL2   (32768)

Definition at line 56 of file messenger_api_message.h.

Enumeration Type Documentation

◆ GNUNET_MESSENGER_PackMode

Enumerator
GNUNET_MESSENGER_PACK_MODE_ENVELOPE 
GNUNET_MESSENGER_PACK_MODE_UNKNOWN 

Definition at line 58 of file messenger_api_message.h.

59{
62};
@ GNUNET_MESSENGER_PACK_MODE_UNKNOWN
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE

Function Documentation

◆ create_message()

struct GNUNET_MESSENGER_Message * create_message ( enum GNUNET_MESSENGER_MessageKind  kind)

Creates and allocates a new message with a specific kind.

Parameters
[in]kindKind of message
Returns
New message

Definition at line 50 of file messenger_api_message.c.

51{
52 struct GNUNET_MESSENGER_Message *message;
53
54 message = GNUNET_new (struct GNUNET_MESSENGER_Message);
55 message->header.kind = kind;
56
57 switch (message->header.kind)
58 {
60 message->body.name.name = NULL;
61 break;
63 message->body.text.text = NULL;
64 break;
66 message->body.file.uri = NULL;
67 break;
69 message->body.privacy.length = 0;
70 message->body.privacy.data = NULL;
71 break;
73 message->body.ticket.identifier = NULL;
74 break;
76 message->body.transcript.length = 0;
77 message->body.transcript.data = NULL;
78 break;
80 message->body.tag.tag = NULL;
81 break;
83 message->body.talk.length = 0;
84 message->body.talk.data = NULL;
85 break;
87 message->body.secret.length = 0;
88 message->body.secret.data = NULL;
89 break;
90 default:
91 break;
92 }
93
94 return message;
95}
#define GNUNET_new(type)
Allocate a struct or union of the given type.
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_KIND_TAG
The tag kind.
@ GNUNET_MESSENGER_KIND_FILE
The file kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_TRANSCRIPT
The transcript kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_SECRET
The secret kind.
@ GNUNET_MESSENGER_KIND_TICKET
The ticket kind.
struct GNUNET_MESSENGER_MessageSecret secret
struct GNUNET_MESSENGER_MessagePrivate privacy
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageTranscript transcript
struct GNUNET_MESSENGER_MessageTalk talk
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageTag tag
struct GNUNET_MESSENGER_MessageTicket ticket
char * uri
The uri of the encrypted file.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
char * name
The new name which replaces the current senders name.
uint16_t length
The length of the encrypted message.
char * data
The data of the encrypted message.
char * data
The data of the encrypted message.
uint16_t length
The length of the encrypted message.
uint16_t length
The length of the talk message data.
char * data
The data of the talk message.
char * identifier
The identifier of a ticket.
uint16_t length
The length of the transcribed message.
char * data
The data of the transcribed message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageSecret::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_new, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by create_message_access(), create_message_announcement(), create_message_appeal(), create_message_authorization(), create_message_connection(), create_message_deletion(), create_message_group(), create_message_id(), create_message_info(), create_message_join(), create_message_key(), create_message_leave(), create_message_merge(), create_message_miss(), create_message_name(), create_message_peer(), create_message_request(), create_message_revolution(), create_message_subscription(), get_store_message(), and transcribe_message().

Here is the caller graph for this function:

◆ copy_message()

struct GNUNET_MESSENGER_Message * copy_message ( const struct GNUNET_MESSENGER_Message message)

Creates and allocates a copy of a given message.

Parameters
[in]messageMessage
Returns
New message

Definition at line 99 of file messenger_api_message.c.

100{
101 struct GNUNET_MESSENGER_Message *copy;
102
103 GNUNET_assert (message);
104
105 copy = GNUNET_new (struct GNUNET_MESSENGER_Message);
106 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
107
108 switch (message->header.kind)
109 {
111 copy->body.name.name = message->body.name.name? GNUNET_strdup (
112 message->body.name.name) : NULL;
113 break;
115 copy->body.text.text = message->body.text.text? GNUNET_strdup (
116 message->body.text.text) : NULL;
117 break;
119 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
120 message->body.file.uri) : NULL;
121 break;
124 copy->body.privacy.length) : NULL;
125
126 if (copy->body.privacy.data)
127 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
128 copy->body.privacy.length);
129
130 break;
132 copy->body.ticket.identifier = message->body.ticket.identifier?
134 message->body.ticket.identifier) : NULL;
135 break;
138 copy->body.transcript.length) : NULL;
139
140 if (copy->body.transcript.data)
142 copy->body.transcript.length);
143
144 break;
146 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
147 message->body.tag.tag) : NULL;
148 break;
150 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
151 copy->body.talk.length) : NULL;
152
153 if (copy->body.talk.data)
154 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
155 copy->body.talk.length);
156
157 break;
159 copy->body.secret.data = copy->body.secret.length ? GNUNET_malloc (
160 copy->body.secret.length) : NULL;
161
162 if (copy->body.secret.data)
163 GNUNET_memcpy (copy->body.secret.data, message->body.secret.data,
164 copy->body.secret.length);
165
166 break;
167 default:
168 break;
169 }
170
171 return copy;
172}
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc(size)
Wrapper around malloc.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageSecret::data, GNUNET_MESSENGER_MessageBody::file, GNUNET_assert, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_new, GNUNET_strdup, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by enqueue_message_control(), forward_tunnel_message(), GNUNET_MESSENGER_send_message(), handle_private_message(), handle_room_message(), handle_transcript_message(), handle_tunnel_message(), send_srv_handle_message(), and update_room_secret_message().

Here is the caller graph for this function:

◆ copy_message_header()

void copy_message_header ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_MESSENGER_MessageHeader header 
)

Copy message header details from another message to a given message.

Parameters
[in,out]messageMessage
[in]headerMessage header

Definition at line 176 of file messenger_api_message.c.

178{
180
181 GNUNET_assert ((message) && (header));
182
183 kind = message->header.kind;
184
185 GNUNET_memcpy (&(message->header), header,
186 sizeof(struct GNUNET_MESSENGER_MessageHeader));
187
188 message->header.kind = kind;
189}
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
The header of a GNUNET_MESSENGER_Message.

References GNUNET_assert, GNUNET_memcpy, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by handle_room_message(), and handle_transcript_message().

Here is the caller graph for this function:

◆ cleanup_message()

void cleanup_message ( struct GNUNET_MESSENGER_Message message)

Frees the messages body memory.

Parameters
[in,out]messageMessage

Definition at line 243 of file messenger_api_message.c.

244{
245 GNUNET_assert (message);
246
247 destroy_message_body (message->header.kind, &(message->body));
248}
static void destroy_message_body(enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)

References GNUNET_MESSENGER_Message::body, destroy_message_body(), GNUNET_assert, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by check_recv_message(), check_send_message(), handle_recv_message(), handle_send_message(), and handle_tunnel_message().

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

◆ destroy_message()

void destroy_message ( struct GNUNET_MESSENGER_Message message)

Destroys a message and frees its memory fully.

Parameters
[in,out]messageMessage

Definition at line 252 of file messenger_api_message.c.

253{
254 GNUNET_assert (message);
255
256 destroy_message_body (message->header.kind, &(message->body));
257
258 GNUNET_free (message);
259}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_MESSENGER_Message::body, destroy_message_body(), GNUNET_assert, GNUNET_free, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by callback_tunnel_message_signed(), clear_queue_messages(), create_message_access(), create_message_announcement(), create_message_authorization(), create_message_peer(), create_message_revolution(), dequeue_from_messages(), dequeue_message_from_room(), destroy_message_control(), enqueue_to_messages(), forward_tunnel_message(), get_store_message(), handle_discourse_subscription(), handle_private_message(), handle_room_delayed_deletion(), handle_transcript_message(), iterate_cancel_signature(), iterate_destroy_message(), iterate_destroy_messages(), iterate_destroy_subscription(), iterate_flag_for_cleanup_discourse_message(), keep_subscription_alive(), send_message_to_room_with_key(), sign_srv_room_message(), task_message_control(), update_room_message(), and update_room_secret_message().

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

◆ is_message_session_bound()

enum GNUNET_GenericReturnValue is_message_session_bound ( const struct GNUNET_MESSENGER_Message message)

Returns if the message should be bound to a member session.

Parameters
[in]messageMessage
Returns
GNUNET_YES or GNUNET_NO

Definition at line 263 of file messenger_api_message.c.

264{
265 GNUNET_assert (message);
266
267 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
269 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
270 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
272 return GNUNET_YES;
273 else
274 return GNUNET_NO;
275}
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.

References GNUNET_assert, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_NAME, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by enqueue_message_to_room(), and update_member_session_history().

Here is the caller graph for this function:

◆ get_message_kind_size()

uint16_t get_message_kind_size ( enum GNUNET_MESSENGER_MessageKind  kind,
enum GNUNET_GenericReturnValue  include_header 
)

Returns the minimal size in bytes to encode a message of a specific kind.

Parameters
[in]kindKind of message
[in]include_headerFlag to include header
Returns
Minimal size to encode

Definition at line 459 of file messenger_api_message.c.

461{
462 uint16_t length;
463
464 length = 0;
465
466 if (GNUNET_YES == include_header)
467 {
468 length += member_size (struct GNUNET_MESSENGER_Message, header.timestamp);
469 length += member_size (struct GNUNET_MESSENGER_Message, header.sender_id);
470 length += member_size (struct GNUNET_MESSENGER_Message, header.previous);
471 }
472
473 length += sizeof(kind_t);
474
475 return length + get_message_body_kind_size (kind);
476}
static uint16_t get_message_body_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
uint32_t kind_t
#define member_size(type, member)

References get_message_body_kind_size(), GNUNET_YES, GNUNET_MESSENGER_Message::header, member_size, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by calc_usual_padding(), check_recv_message(), check_send_message(), check_tunnel_message(), decode_message(), get_message_size(), and get_store_message().

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

◆ get_message_size()

uint16_t get_message_size ( const struct GNUNET_MESSENGER_Message message,
enum GNUNET_GenericReturnValue  include_header 
)

Returns the exact size in bytes to encode a given message.

Parameters
[in]messageMessage
[in]include_headerFlag to include header
Returns
Size to encode

Definition at line 534 of file messenger_api_message.c.

536{
537 uint16_t length;
538
539 GNUNET_assert (message);
540
541 length = 0;
542
543 if (GNUNET_YES == include_header)
545 &(message->header.signature));
546
547 length += get_message_kind_size (message->header.kind, include_header);
548 length += get_message_body_size (message->header.kind, &(message->body));
549
550 return length;
551}
ssize_t GNUNET_CRYPTO_blinded_key_signature_get_length(const struct GNUNET_CRYPTO_BlindableKeySignature *sig)
Get the compacted length of a #GNUNET_CRYPTO_Signature.
static uint16_t get_message_body_size(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body)
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
struct GNUNET_CRYPTO_BlindableKeySignature signature
The signature of the senders private key.

References GNUNET_MESSENGER_Message::body, get_message_body_size(), get_message_kind_size(), GNUNET_assert, GNUNET_CRYPTO_blinded_key_signature_get_length(), GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_MessageHeader::signature.

Referenced by iterate_save_messages(), notify_srv_handle_message(), pack_message(), and send_message_to_room().

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

◆ encode_message_signature()

void encode_message_signature ( const struct GNUNET_MESSENGER_Message message,
uint16_t  length,
char *  buffer 
)

Encodes the signature of a given message into a buffer of a maximum length in bytes.

Parameters
[in]messageMessage
[in]lengthMaximal length to encode
[out]bufferBuffer

Definition at line 863 of file messenger_api_message.c.

866{
867 uint16_t offset = 0;
868
869 GNUNET_assert ((message) && (buffer));
870
871 encode_step_signature (buffer, offset, &(message->header.signature),
872 length);
873}
#define encode_step_signature(dst, offset, src, length)

References encode_step_signature, GNUNET_assert, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::signature.

Referenced by callback_srv_room_sign_result(), and send_message_to_room().

Here is the caller graph for this function:

◆ encode_message()

void encode_message ( const struct GNUNET_MESSENGER_Message message,
uint16_t  length,
char *  buffer,
enum GNUNET_GenericReturnValue  include_header 
)

Encodes a given message into a buffer of a maximum length in bytes.

Parameters
[in]messageMessage
[in]lengthMaximal length to encode
[out]bufferBuffer
[in]include_headerFlag to include header

Definition at line 877 of file messenger_api_message.c.

881{
882 uint16_t offset;
883 kind_t kind;
884
885 GNUNET_assert ((message) && (buffer));
886
887 offset = 0;
888
889 if (GNUNET_YES == include_header)
890 encode_step_signature (buffer, offset, &(message->header.signature),
891 length);
892
893 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
894
895 if (GNUNET_YES == include_header)
896 {
897 encode_step (buffer, offset, &(message->header.timestamp));
898 encode_step (buffer, offset, &(message->header.sender_id));
899 encode_step (buffer, offset, &(message->header.previous));
900 }
901
902 encode_step (buffer, offset, &kind);
903
904 encode_message_body (message->header.kind, &(message->body),
905 length, buffer, offset);
906}
#define GNUNET_htobe32(x)
#define encode_step(dst, offset, src)
static void encode_message_body(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.

References GNUNET_MESSENGER_Message::body, encode_message_body(), encode_step, encode_step_signature, GNUNET_assert, GNUNET_htobe32, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::sender_id, GNUNET_MESSENGER_MessageHeader::signature, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by iterate_save_messages(), notify_srv_handle_message(), pack_message(), and send_message_to_room().

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

◆ decode_message()

enum GNUNET_GenericReturnValue decode_message ( struct GNUNET_MESSENGER_Message message,
uint16_t  length,
const char *  buffer,
enum GNUNET_GenericReturnValue  include_header,
uint16_t *  padding 
)

Decodes a message from a given buffer of a maximum length in bytes.

If the buffer is too small for a message of its decoded kind the function fails with resulting GNUNET_NO after decoding only the messages header.

On success the function returns GNUNET_YES.

Parameters
[out]messageMessage
[in]lengthMaximal length to decode
[in]bufferBuffer
[in]include_headerFlag to include header
[out]paddingPadding
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1204 of file messenger_api_message.c.

1209{
1210 uint16_t offset;
1211 uint16_t count;
1212 kind_t kind;
1213
1215 (message) &&
1216 (buffer) &&
1218 include_header)));
1219
1220 offset = 0;
1221
1222 if (GNUNET_YES == include_header)
1223 {
1224 ssize_t result;
1225
1227 &(message->header.signature), buffer, length - offset);
1228
1229 if (result < 0)
1230 return GNUNET_NO;
1231 else
1232 offset += result;
1233 }
1234
1235 count = length - offset;
1237 include_header))
1238 return GNUNET_NO;
1239
1240 if (GNUNET_YES == include_header)
1241 {
1242 decode_step (buffer, offset, &(message->header.timestamp));
1243 decode_step (buffer, offset, &(message->header.sender_id));
1244 decode_step (buffer, offset, &(message->header.previous));
1245 }
1246
1247 decode_step (buffer, offset, &kind);
1248 kind = GNUNET_be32toh (kind);
1249
1250 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1251
1252 if (count < get_message_kind_size (message->header.kind, include_header))
1253 return GNUNET_NO;
1254
1255 {
1256 uint16_t result;
1257 result = decode_message_body (&(message->header.kind),
1258 &(message->body), length, buffer, offset);
1259
1260 if (padding)
1261 *padding = result;
1262 }
1263
1264 return GNUNET_YES;
1265}
static int result
Global testing status.
#define GNUNET_be32toh(x)
ssize_t GNUNET_CRYPTO_read_blinded_key_signature_from_buffer(struct GNUNET_CRYPTO_BlindableKeySignature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_BlindableKeySignature from a compact buffer.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
#define decode_step(src, offset, dst)
static uint16_t decode_message_body(enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)

References GNUNET_MESSENGER_Message::body, decode_message_body(), decode_step, get_message_kind_size(), GNUNET_assert, GNUNET_be32toh, GNUNET_CRYPTO_read_blinded_key_signature_from_buffer(), GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::previous, result, GNUNET_MESSENGER_MessageHeader::sender_id, GNUNET_MESSENGER_MessageHeader::signature, and GNUNET_MESSENGER_MessageHeader::timestamp.

Referenced by check_recv_message(), check_send_message(), check_tunnel_message(), get_store_message(), handle_recv_message(), handle_send_message(), and handle_tunnel_message().

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

◆ hash_message()

void hash_message ( const struct GNUNET_MESSENGER_Message message,
uint16_t  length,
const char *  buffer,
struct GNUNET_HashCode hash 
)

Calculates a hash of a given buffer with a length in bytes from a message.

Parameters
[in]messageMessage
[in]lengthLength of buffer
[in]bufferBuffer
[out]hashHash

Definition at line 1313 of file messenger_api_message.c.

1317{
1318 ssize_t offset;
1319
1320 GNUNET_assert ((message) && (buffer) && (hash));
1321
1323 signature));
1324
1325 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1326}
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

References GNUNET_assert, GNUNET_CRYPTO_blinded_key_signature_get_length(), GNUNET_CRYPTO_hash(), and GNUNET_MESSENGER_Message::header.

Referenced by check_tunnel_message(), get_store_message(), handle_tunnel_message(), pack_message(), and send_message_to_room().

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

◆ sign_message()

void sign_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
const struct GNUNET_CRYPTO_BlindablePrivateKey key 
)

Signs the hash of a message with a given private key.

Parameters
[in,out]messageMessage
[in]hashHash of message
[in]keyPrivate key

Definition at line 1330 of file messenger_api_message.c.

1333{
1334 struct GNUNET_MESSENGER_MessageSignature signature;
1335
1336 GNUNET_assert ((message) && (hash) && (key));
1337
1338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1339 GNUNET_h2s (hash));
1340
1341 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1342 signature.purpose.size = htonl (sizeof(signature));
1343
1344 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1345
1347 &(message->header.signature));
1348 message->header.signature.type = key->type;
1349}
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
#define GNUNET_log(kind,...)
#define GNUNET_CRYPTO_blinded_key_sign(priv, ps, sig)
Sign a given block with GNUNET_CRYPTO_BlindablePrivateKey.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_assert, GNUNET_CRYPTO_blinded_key_sign, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, key, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_CRYPTO_BlindableKeySignature::type.

Referenced by send_message_to_room().

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

◆ sign_message_by_peer()

struct GNUNET_PILS_Operation * sign_message_by_peer ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
struct GNUNET_PILS_Handle pils,
const GNUNET_PILS_SignResultCallback  sign_cb,
void *  cls 
)

Signs the hash of a message with the peer identity of a given pils service going into a callback with a custom closure on success.

Parameters
[in,out]messageMessage
[in]hashHash of message
[in,out]pilsPils handle
[in]sign_cbSignature callback
[in,out]clsClosure
Returns
Signature operation or NULL on failure

Definition at line 1353 of file messenger_api_message.c.

1358{
1359 struct GNUNET_MESSENGER_MessageSignature signature;
1360 struct GNUNET_PILS_Operation *operation;
1361
1362 GNUNET_assert ((message) && (hash) && (pils));
1363
1364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1365 GNUNET_h2s (hash));
1366
1367 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1368 signature.purpose.size = htonl (sizeof (signature));
1369
1370 GNUNET_memcpy (&(signature.hash), hash, sizeof (signature.hash));
1371
1372 operation = GNUNET_PILS_sign_by_peer_identity (pils, &(signature.purpose),
1373 sign_cb, cls);
1374
1375 if (! operation)
1376 return NULL;
1377
1379 return operation;
1380}
static void sign_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Definition gnunet-abd.c:675
static struct GNUNET_PILS_Handle * pils
Handle to PILS.
Definition gnunet-pils.c:44
struct GNUNET_PILS_Operation * GNUNET_PILS_sign_by_peer_identity(struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
Sign data with the peer id.
Definition pils_api.c:528
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_PILS_sign_by_peer_identity(), GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, pils, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, sign_cb(), GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_CRYPTO_BlindableKeySignature::type.

Referenced by sign_srv_room_message().

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

◆ sign_message_by_key()

enum GNUNET_GenericReturnValue 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.

It requires the message to be of a supported kind of message which contains such an hmac.

On success the message can be verified via verify_message_by_key() afterwards.

Parameters
[in,out]messageMessage
[in]keyShared key
Returns
GNUNET_YES on success, GNUNET_NO on failure, otherwise GNUNET_SYSERR

Definition at line 1460 of file messenger_api_message.c.

1462{
1463 struct GNUNET_HashCode *hmac;
1464
1465 GNUNET_assert ((message) && (key));
1466
1467 switch (message->header.kind)
1468 {
1470 hmac = &(message->body.announcement.hmac);
1471 break;
1473 hmac = &(message->body.access.hmac);
1474 break;
1476 hmac = &(message->body.revolution.hmac);
1477 break;
1479 hmac = &(message->body.authorization.hmac);
1480 break;
1481 default:
1482 hmac = NULL;
1483 break;
1484 }
1485
1486 if (! hmac)
1487 return GNUNET_SYSERR;
1488
1489 return calc_message_hmac (message, key, hmac);
1490}
@ GNUNET_SYSERR
@ GNUNET_MESSENGER_KIND_AUTHORIZATION
The authorization kind.
@ GNUNET_MESSENGER_KIND_ANNOUNCEMENT
The announcement kind.
@ GNUNET_MESSENGER_KIND_ACCESS
The access kind.
@ GNUNET_MESSENGER_KIND_REVOLUTION
The revolution kind.
static enum GNUNET_GenericReturnValue calc_message_hmac(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_HashCode *hmac)
A 512-bit hashcode.
struct GNUNET_HashCode hmac
The hmac of the access.
struct GNUNET_HashCode hmac
The hmac of the announcement.
struct GNUNET_HashCode hmac
The hmac of the authorization.
struct GNUNET_MESSENGER_MessageAnnouncement announcement
struct GNUNET_MESSENGER_MessageRevolution revolution
struct GNUNET_MESSENGER_MessageAccess access
struct GNUNET_MESSENGER_MessageAuthorization authorization
struct GNUNET_HashCode hmac
The hmac of the revolution.

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, calc_message_hmac(), GNUNET_assert, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_SYSERR, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, key, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_MessageBody::revolution.

Referenced by create_message_access(), create_message_announcement(), create_message_authorization(), and create_message_revolution().

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

◆ verify_message()

enum GNUNET_GenericReturnValue verify_message ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
const struct GNUNET_CRYPTO_BlindablePublicKey key 
)

Verifies the signature of a given message and its hash with a specific public key.

The function returns GNUNET_OK if the signature was valid, otherwise GNUNET_SYSERR.

Parameters
[in]messageMessage
[in]hashHash of message
[in]keyPublic key
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 1494 of file messenger_api_message.c.

1497{
1498 struct GNUNET_MESSENGER_MessageSignature signature;
1499
1500 GNUNET_assert ((message) && (hash) && (key));
1501
1502 if (key->type != message->header.signature.type)
1503 return GNUNET_SYSERR;
1504
1505 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1506 signature.purpose.size = htonl (sizeof(signature));
1507
1508 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1509
1512 &(message->header.signature), key);
1513}
#define GNUNET_CRYPTO_blinded_key_signature_verify(purp, ps, sig, pub)
Verify a given signature with GNUNET_CRYPTO_BlindablePublicKey.

References GNUNET_assert, GNUNET_CRYPTO_blinded_key_signature_verify, GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_SYSERR, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, key, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_CRYPTO_BlindableKeySignature::type.

Referenced by verify_member_session_as_sender().

Here is the caller graph for this function:

◆ verify_message_by_peer()

enum GNUNET_GenericReturnValue verify_message_by_peer ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
const struct GNUNET_PeerIdentity identity 
)

Verifies the signature of a given message and its hash with a specific peer's identity.

The function returns GNUNET_OK if the signature was valid, otherwise GNUNET_SYSERR.

Parameters
[in]messageMessage
[in]hashHash of message
[in]identityPeer identity
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 1517 of file messenger_api_message.c.

1520{
1521 struct GNUNET_MESSENGER_MessageSignature signature;
1522
1523 GNUNET_assert ((message) && (hash) && (identity));
1524
1525 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1526 return GNUNET_SYSERR;
1527
1528 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1529 signature.purpose.size = htonl (sizeof(signature));
1530
1531 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1532
1534 GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &(signature.purpose),
1535 &(message->header.signature.
1536 eddsa_signature), identity);
1537}
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_verify_peer_identity(uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_PeerIdentity *identity)
Verify a given signature with a peer's identity.

References GNUNET_assert, GNUNET_CRYPTO_verify_peer_identity(), GNUNET_memcpy, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_SYSERR, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, identity, GNUNET_CRYPTO_SignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_CRYPTO_BlindableKeySignature::type.

Referenced by get_store_peer_of(), and verify_store_peer().

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

◆ verify_message_by_key()

enum GNUNET_GenericReturnValue verify_message_by_key ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_SymmetricSessionKey key 
)

Verifies the hmac of a given message body with a specific shared key.

The function returns GNUNET_OK if the signature was valid, otherwise GNUNET_SYSERR.

Parameters
[in]messageMessage
[in]keyShared key
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 1541 of file messenger_api_message.c.

1543{
1544 const struct GNUNET_HashCode *msg_hmac;
1545 struct GNUNET_HashCode hmac;
1546
1547 GNUNET_assert ((message) && (key));
1548
1549 switch (message->header.kind)
1550 {
1552 msg_hmac = &(message->body.announcement.hmac);
1553 break;
1555 msg_hmac = &(message->body.access.hmac);
1556 break;
1558 msg_hmac = &(message->body.revolution.hmac);
1559 break;
1561 msg_hmac = &(message->body.authorization.hmac);
1562 break;
1563 default:
1564 msg_hmac = NULL;
1565 break;
1566 }
1567
1568 if (! msg_hmac)
1569 return GNUNET_SYSERR;
1570
1571 if (GNUNET_YES != calc_message_hmac (message, key, &hmac))
1572 return GNUNET_SYSERR;
1573
1574 if (0 == GNUNET_CRYPTO_hash_cmp (&hmac, msg_hmac))
1575 return GNUNET_OK;
1576
1577 return GNUNET_SYSERR;
1578}
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.
@ GNUNET_OK

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, calc_message_hmac(), GNUNET_assert, GNUNET_CRYPTO_hash_cmp(), GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, key, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_MessageBody::revolution.

Referenced by extract_access_message_key(), extract_authorization_message_key(), handle_access_message(), handle_authorization_message(), handle_epoch_announcement(), handle_epoch_group_announcement(), handle_revolution_message(), and send_epoch_announcement_authorization().

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

◆ encrypt_message()

enum GNUNET_GenericReturnValue encrypt_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_HpkePublicKey hpke_key 
)

Encrypts a message using a given public key and replaces its body and kind with the now private encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]keyPublic key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1582 of file messenger_api_message.c.

1584{
1586 struct GNUNET_MESSENGER_ShortMessage shortened;
1587 uint16_t length, padded_length, encoded_length;
1588 uint8_t *data;
1589
1590 GNUNET_assert ((message) && (hpke_key));
1591
1592 if (GNUNET_YES == is_service_message (message))
1593 return GNUNET_NO;
1594
1595 fold_short_message (message, &shortened);
1596
1597 length = get_short_message_size (&shortened, GNUNET_YES);
1598 padded_length = calc_padded_length (length + encryption_overhead);
1599
1600 GNUNET_assert (padded_length >= length + encryption_overhead);
1601
1603 message->body.privacy.data = GNUNET_malloc (padded_length);
1604 message->body.privacy.length = padded_length;
1605
1606 encoded_length = (padded_length - encryption_overhead);
1607
1608 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1609
1610 result = GNUNET_NO;
1611 data = GNUNET_malloc (encoded_length);
1612
1613 encode_short_message (&shortened, encoded_length, (char *) data);
1614
1616 (const uint8_t*)
1617 "messenger",
1618 strlen ("messenger"),
1619 NULL, 0,
1620 (const uint8_t*) data,
1621 encoded_length,
1622 (uint8_t*) message->body.
1623 privacy.data,
1624 NULL))
1625 {
1626 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1627
1628 unfold_short_message (&shortened, message);
1629 goto cleanup;
1630 }
1631
1632 destroy_message_body (shortened.kind, &(shortened.body));
1634
1635cleanup:
1636 GNUNET_free (data);
1637 return result;
1638}
static char * data
The data to insert into the dht.
static void cleanup()
Cleanup task.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot(const struct GNUNET_CRYPTO_HpkePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len)
RFC9180 HPKE encryption.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_ERROR_TYPE_WARNING
static uint16_t get_short_message_size(const struct GNUNET_MESSENGER_ShortMessage *message, enum GNUNET_GenericReturnValue include_body)
enum GNUNET_GenericReturnValue is_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
static void fold_short_message(const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened)
static uint16_t calc_padded_length(uint16_t length)
const uint16_t encryption_overhead
static void encode_short_message(const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer)
static void unfold_short_message(struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, calc_padded_length(), cleanup(), data, GNUNET_MESSENGER_MessagePrivate::data, destroy_message_body(), encode_short_message(), encryption_overhead, fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_CRYPTO_hpke_seal_oneshot(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_service_message(), GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_ShortMessage::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::privacy, result, and unfold_short_message().

Referenced by dequeue_message_from_room(), and send_message_to_room_with_key().

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

◆ decrypt_message()

enum GNUNET_GenericReturnValue decrypt_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_HpkePrivateKey hpke_key 
)

Decrypts a private message using a given private key and replaces its body and kind with the inner encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]keyPrivate key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1642 of file messenger_api_message.c.

1644{
1646 uint16_t padded_length, encoded_length;
1647 uint8_t *data;
1648
1649 GNUNET_assert ((message) && (hpke_key) &&
1651
1652 padded_length = message->body.privacy.length;
1653
1654 if (padded_length < encryption_overhead)
1655 {
1657 "Message length too short to decrypt!\n");
1658
1659 return GNUNET_NO;
1660 }
1661
1662 encoded_length = (padded_length - encryption_overhead);
1663
1664 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1665
1666 result = GNUNET_NO;
1667 data = GNUNET_malloc (encoded_length);
1668
1669 if (GNUNET_OK !=
1671 (uint8_t*) "messenger",
1672 strlen ("messenger"),
1673 NULL, 0,
1674 (uint8_t*) message->body.privacy.data,
1675 padded_length,
1676 (uint8_t*) data,
1677 NULL))
1678 {
1679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1680
1681 goto cleanup;
1682 }
1683
1684 {
1685 struct GNUNET_MESSENGER_ShortMessage shortened;
1686 if (GNUNET_YES != decode_short_message (&shortened,
1687 encoded_length,
1688 (char*) data))
1689 {
1691 "Decoding decrypted message failed!\n");
1692
1693 goto cleanup;
1694 }
1695
1696 unfold_short_message (&shortened, message);
1698 }
1699
1700cleanup:
1701 GNUNET_free (data);
1702 return result;
1703}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open_oneshot(const struct GNUNET_CRYPTO_HpkePrivateKey *skR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len)
RFC9180 HPKE encryption.
static enum GNUNET_GenericReturnValue decode_short_message(struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)

References GNUNET_MESSENGER_Message::body, cleanup(), data, GNUNET_MESSENGER_MessagePrivate::data, decode_short_message(), encryption_overhead, GNUNET_assert, GNUNET_CRYPTO_hpke_open_oneshot(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::privacy, result, and unfold_short_message().

Referenced by handle_private_message().

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

◆ transcribe_message()

struct GNUNET_MESSENGER_Message * transcribe_message ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_BlindablePublicKey key 
)

Transcribes a message as a new transcript message using a given public key from the recipient of the encrypted message content.

Parameters
[in]messageMessage
[in]keyPublic key
Returns
Message transcript

Definition at line 1707 of file messenger_api_message.c.

1709{
1710 struct GNUNET_MESSENGER_Message *transcript;
1711
1712 GNUNET_assert ((message) && (key));
1713
1714 if (GNUNET_YES == is_service_message (message))
1715 return NULL;
1716
1718
1719 if (! transcript)
1720 {
1721 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1722 return NULL;
1723 }
1724
1725 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1726 sizeof(transcript->body.transcript.key));
1727
1728 {
1729 struct GNUNET_MESSENGER_ShortMessage shortened;
1730 uint16_t data_length;
1731
1732 fold_short_message (message, &shortened);
1733
1734 data_length = get_short_message_size (&shortened, GNUNET_YES);
1735
1736 transcript->body.transcript.data = GNUNET_malloc (data_length);
1737 transcript->body.transcript.length = data_length;
1738
1739 encode_short_message (&shortened, data_length,
1740 transcript->body.transcript.data);
1741 }
1742
1743 return transcript;
1744}
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_CRYPTO_BlindablePublicKey key
The key from the recipient of the original message.

References GNUNET_MESSENGER_Message::body, create_message(), GNUNET_MESSENGER_MessageTranscript::data, encode_short_message(), fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_YES, is_service_message(), key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageTranscript::length, and GNUNET_MESSENGER_MessageBody::transcript.

Referenced by send_message_to_room_with_key().

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

◆ encrypt_secret_message()

enum GNUNET_GenericReturnValue encrypt_secret_message ( struct GNUNET_MESSENGER_Message message,
const union GNUNET_MESSENGER_EpochIdentifier identifier,
const struct GNUNET_CRYPTO_SymmetricSessionKey key 
)

Encrypts a message using a given shared key from an announcement of an epoch and replaces its body and kind with the inner encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]identifierEpoch identifier
[in]keyShared secret key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1748 of file messenger_api_message.c.

1752{
1754 struct GNUNET_MESSENGER_ShortMessage shortened;
1755 uint16_t length, padded_length;
1756 uint8_t *data;
1757
1758 GNUNET_assert ((message) && (identifier) && (key));
1759
1760 fold_short_message (message, &shortened);
1761
1762 length = get_short_message_size (&shortened, GNUNET_YES);
1763 padded_length = calc_padded_length (length + 0);
1764
1765 GNUNET_assert (padded_length >= length + 0);
1766
1768
1769 GNUNET_memcpy (&(message->body.secret.identifier), identifier,
1770 sizeof (message->body.secret.identifier));
1771
1773 &(message->body.secret.iv),
1775
1776 message->body.secret.data = GNUNET_malloc (padded_length);
1777 message->body.secret.length = padded_length;
1778
1779 result = GNUNET_NO;
1780 data = GNUNET_malloc (padded_length);
1781
1782 encode_short_message (&shortened, padded_length, (char *) data);
1783
1784 {
1786
1788 &iv, sizeof (iv),
1791 key, sizeof (*key),
1793 {
1794 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving initialization vector failed!\n");
1795 unfold_short_message (&shortened, message);
1796 goto cleanup;
1797 }
1798
1799 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (data, padded_length, key,
1800 &iv, message->body.secret.data))
1801 {
1802 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1803 unfold_short_message (&shortened, message);
1804 goto cleanup;
1805 }
1806 }
1807
1808 {
1809 struct GNUNET_CRYPTO_AuthKey auth_key;
1810
1812 &auth_key, sizeof (auth_key),
1815 key, sizeof (*key),
1817 {
1818 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving authentication key failed!\n");
1819 unfold_short_message (&shortened, message);
1820 goto cleanup;
1821 }
1822
1823 GNUNET_CRYPTO_hmac (&auth_key, message->body.secret.data, padded_length,
1824 &(message->body.secret.hmac));
1825 }
1826
1827 destroy_message_body (shortened.kind, &(shortened.body));
1829
1830cleanup:
1831 GNUNET_free (data);
1832 return result;
1833}
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.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
#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(d, s)
#define GNUNET_MESSENGER_SECRET_IV_BYTES
#define GNUNET_MESSENGER_SALT_SECRET_KEY
#define GNUNET_MESSENGER_SALT_SECRET_IV
type for (message) authentication keys
uint8_t iv[sizeof(struct GNUNET_CRYPTO_SymmetricInitializationVector)]
The IV of the secret message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_HashCode hmac
The hmac of the encrypted message.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, calc_padded_length(), cleanup(), data, GNUNET_MESSENGER_MessageSecret::data, destroy_message_body(), encode_short_message(), fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_hmac(), GNUNET_CRYPTO_kdf_arg, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_block(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_SALT_SECRET_IV, GNUNET_MESSENGER_SALT_SECRET_KEY, GNUNET_MESSENGER_SECRET_IV_BYTES, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageSecret::hmac, GNUNET_MESSENGER_MessageSecret::identifier, GNUNET_MESSENGER_MessageSecret::iv, key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_ShortMessage::kind, GNUNET_MESSENGER_MessageSecret::length, result, GNUNET_MESSENGER_MessageBody::secret, and unfold_short_message().

Referenced by send_message_to_room().

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

◆ decrypt_secret_message()

enum GNUNET_GenericReturnValue decrypt_secret_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_SymmetricSessionKey key 
)

Decrypts a secret message using a given shared key and replaces its body and kind with the inner encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage
[in]keyShared secret key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1837 of file messenger_api_message.c.

1839{
1841 uint16_t padded_length;
1842 uint8_t *data;
1843
1844 GNUNET_assert ((message) && (key) &&
1846
1847 padded_length = message->body.secret.length;
1848
1849 {
1850 struct GNUNET_CRYPTO_AuthKey auth_key;
1851 struct GNUNET_HashCode hmac;
1852
1854 &auth_key, sizeof (auth_key),
1857 key, sizeof (*key),
1859 {
1860 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving authentication key failed!\n");
1861 return GNUNET_NO;
1862 }
1863
1864 GNUNET_CRYPTO_hmac (&auth_key, message->body.secret.data, padded_length,
1865 &hmac);
1866
1867 if (0 != GNUNET_CRYPTO_hash_cmp (&(message->body.secret.hmac), &hmac))
1868 {
1870 "Decrypted message does not match HMAC!\n");
1871 return GNUNET_NO;
1872 }
1873 }
1874
1875 result = GNUNET_NO;
1876 data = GNUNET_malloc (padded_length);
1877
1878 {
1880
1882 &iv, sizeof (iv),
1885 key,
1886 sizeof (*key),
1888 {
1889 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving initialization vector failed!\n");
1890 goto cleanup;
1891 }
1892
1893 if (-1 == GNUNET_CRYPTO_symmetric_decrypt (message->body.secret.data,
1894 padded_length,
1895 key, &iv, data))
1896 {
1897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1898 goto cleanup;
1899 }
1900 }
1901
1902 {
1903 struct GNUNET_MESSENGER_ShortMessage shortened;
1904 if (GNUNET_YES != decode_short_message (&shortened,
1905 padded_length,
1906 (char*) data))
1907 {
1909 "Decoding decrypted message failed!\n");
1910
1911 goto cleanup;
1912 }
1913
1914 unfold_short_message (&shortened, message);
1916 }
1917
1918cleanup:
1919 GNUNET_free (data);
1920 return result;
1921}
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.

References GNUNET_MESSENGER_Message::body, cleanup(), data, GNUNET_MESSENGER_MessageSecret::data, decode_short_message(), GNUNET_assert, GNUNET_CRYPTO_hash_cmp(), GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_hmac(), GNUNET_CRYPTO_kdf_arg, GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_SALT_SECRET_IV, GNUNET_MESSENGER_SALT_SECRET_KEY, GNUNET_MESSENGER_SECRET_IV_BYTES, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageSecret::hmac, GNUNET_MESSENGER_MessageSecret::iv, key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageSecret::length, result, GNUNET_MESSENGER_MessageBody::secret, and unfold_short_message().

Referenced by update_room_secret_message().

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

◆ read_transcript_message()

enum GNUNET_GenericReturnValue read_transcript_message ( struct GNUNET_MESSENGER_Message message)

Read the original message from a transcript message and replaces its body and kind with the inner encrypted message.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in,out]messageMessage transcript
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1925 of file messenger_api_message.c.

1926{
1927 uint16_t data_length;
1928 struct GNUNET_MESSENGER_ShortMessage shortened;
1929
1930 GNUNET_assert ((message) &&
1932
1933 data_length = message->body.transcript.length;
1934
1935 if (GNUNET_YES != decode_short_message (&shortened,
1936 data_length,
1937 message->body.transcript.data))
1938 {
1940 "Decoding decrypted message failed!\n");
1941
1942 return GNUNET_NO;
1943 }
1944
1945 unfold_short_message (&shortened, message);
1946 return GNUNET_YES;
1947}

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageTranscript::data, decode_short_message(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageBody::transcript, and unfold_short_message().

Referenced by handle_transcript_message().

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

◆ extract_access_message_key()

enum GNUNET_GenericReturnValue extract_access_message_key ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_HpkePrivateKey key,
struct GNUNET_CRYPTO_SymmetricSessionKey shared_key 
)

Extracts the shared epoch or group key from an access message using the private ephemeral key from an epoch and verifies it via the HMAC from the message body.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in]messageAccess message
[in]keyPrivate ephemeral key
[out]shared_keyShared key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1951 of file messenger_api_message.c.

1955{
1956 GNUNET_assert ((message) && (key) && (shared_key) &&
1958
1959 if (GNUNET_OK !=
1961 (uint8_t*) "messenger",
1962 strlen ("messenger"),
1963 NULL, 0,
1964 (uint8_t*) message->body.access.key,
1966 (uint8_t*) shared_key,
1967 NULL))
1968 {
1969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1970 return GNUNET_NO;
1971 }
1972
1973 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1974 {
1975 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1976 return GNUNET_NO;
1977 }
1978
1979 return GNUNET_YES;
1980}
#define GNUNET_MESSENGER_ACCESS_KEY_BYTES
enum GNUNET_GenericReturnValue verify_message_by_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Verifies the hmac of a given message body with a specific shared key.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)+16+sizeof(struct GNUNET_CRYPTO_HpkeEncapsulation)]
The encrypted group or epoch key.

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_Message::body, GNUNET_assert, GNUNET_CRYPTO_hpke_open_oneshot(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_ACCESS_KEY_BYTES, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, key, GNUNET_MESSENGER_MessageAccess::key, GNUNET_MESSENGER_MessageHeader::kind, and verify_message_by_key().

Referenced by handle_epoch_announcement_access(), and handle_epoch_group_access().

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

◆ extract_authorization_message_key()

enum GNUNET_GenericReturnValue extract_authorization_message_key ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_SymmetricSessionKey key,
struct GNUNET_CRYPTO_SymmetricSessionKey shared_key 
)

Extracts the shared epoch or group key from an authorization message using a previously exchanged shared key and verifies it via the HMAC from the message body.

The function returns GNUNET_YES if the operation succeeded, otherwise GNUNET_NO.

Parameters
[in]messageAccess message
[in]keyPrevious shared key
[out]shared_keyShared key
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1984 of file messenger_api_message.c.

1989{
1991
1992 GNUNET_assert ((message) && (key) && (shared_key) &&
1994
1996 &iv, sizeof (iv),
1999 key,
2000 sizeof (*key),
2003 {
2004 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving initialization vector failed!\n");
2005 return GNUNET_NO;
2006 }
2007
2010 key,
2011 &iv,
2012 shared_key))
2013 {
2014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
2015 return GNUNET_NO;
2016 }
2017
2018 if (GNUNET_OK != verify_message_by_key (message, shared_key))
2019 {
2020 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
2021 return GNUNET_NO;
2022 }
2023
2024 return GNUNET_YES;
2025}
#define GNUNET_CRYPTO_kdf_arg_auto(d)
#define GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES
#define GNUNET_MESSENGER_SALT_GROUP_KEY
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.

References GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_assert, GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_kdf_arg_auto, GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_SALT_GROUP_KEY, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageAuthorization::identifier, key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageHeader::kind, and verify_message_by_key().

Referenced by handle_authorization_message().

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

◆ get_message_timeout()

struct GNUNET_TIME_Relative get_message_timeout ( const struct GNUNET_MESSENGER_Message message)

Return the relative timeout of the content from a given message that controls when a delayed handling action of this message needs to be processed at least.

Parameters
[in]messageMessage
Returns
Relative timeout of message

Definition at line 2029 of file messenger_api_message.c.

2030{
2033
2034 GNUNET_assert (message);
2035
2037
2038 switch (message->header.kind)
2039 {
2042 break;
2045 break;
2048 break;
2051 break;
2052 default:
2054 break;
2055 }
2056
2058
2062
2063 return timeout;
2064}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition gnunet-arm.c:118
static uint64_t timestamp(void)
Get current timestamp.
@ GNUNET_MESSENGER_KIND_APPEAL
The appeal kind.
@ GNUNET_MESSENGER_KIND_DELETION
The deletion kind.
@ GNUNET_MESSENGER_KIND_GROUP
The group kind.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition time.c:344
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition time.c:133
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition time.c:626
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_(void)
Return relative time of 1 minute.
Definition time.c:178
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition time.c:452
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the announcement.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the appeal.
struct GNUNET_MESSENGER_MessageGroup group
struct GNUNET_MESSENGER_MessageDeletion deletion
struct GNUNET_MESSENGER_MessageAppeal appeal
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.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.

References GNUNET_assert, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_GROUP, GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_get_minute_(), GNUNET_TIME_relative_get_zero_(), GNUNET_TIME_relative_min(), GNUNET_TIME_relative_ntoh(), timeout, and timestamp().

Referenced by handle_appeal_message(), handle_delete_message(), handle_epoch_announcement(), handle_epoch_announcement_delay(), handle_message_delete(), handle_room_delayed_deletion(), and set_epoch_proposal_group().

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

◆ pack_message()

struct GNUNET_MQ_Envelope * pack_message ( struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash,
enum GNUNET_MESSENGER_PackMode  mode 
)

Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE.

Independent of the mode the message will be hashed if hash is not NULL.

Parameters
[out]messageMessage
[out]hashHash of message
[in]modeMode of packing
Returns
Envelope or NULL

Definition at line 2068 of file messenger_api_message.c.

2071{
2072 struct GNUNET_MessageHeader *header;
2073 uint16_t length, padded_length;
2074 struct GNUNET_MQ_Envelope *env;
2075 char *buffer;
2076
2077 GNUNET_assert (message);
2078
2080 "Packing message kind=%u and sender: %s\n",
2081 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
2082
2083 length = get_message_size (message, GNUNET_YES);
2084 padded_length = calc_padded_length (length);
2085
2087 {
2088 env = GNUNET_MQ_msg_extra (header, padded_length,
2090 buffer = (char*) &(header[1]);
2091 }
2092 else
2093 {
2094 env = NULL;
2095 buffer = GNUNET_malloc (padded_length);
2096 }
2097
2098 encode_message (message, padded_length, buffer, GNUNET_YES);
2099
2100 if (hash)
2101 hash_message (message, length, buffer, hash);
2102
2104 GNUNET_free (buffer);
2105
2106 return env;
2107}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static enum @52 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a maximum length in bytes.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
Returns the exact size in bytes to encode a given message.
Header for all communications.

References calc_padded_length(), encode_message(), env, get_message_size(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CADET_CLI, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, GNUNET_MQ_msg_extra, GNUNET_sh2s(), GNUNET_YES, hash_message(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, mode, and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by forward_tunnel_message(), handle_tunnel_message(), and sign_srv_room_message().

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

◆ is_peer_message()

enum GNUNET_GenericReturnValue is_peer_message ( const struct GNUNET_MESSENGER_Message message)

Returns whether a specific kind of message can be sent by the service without usage of a clients private key.

The function returns GNUNET_YES if the kind of message can be signed via a peer's identity, otherwise GNUNET_NO.

Parameters
[in]messageMessage
Returns
GNUNET_YES if sending is allowed, GNUNET_NO otherwise

Definition at line 2111 of file messenger_api_message.c.

2112{
2113 GNUNET_assert (message);
2114
2115 switch (message->header.kind)
2116 {
2122 return GNUNET_YES;
2123 default:
2124 return GNUNET_NO;
2125 }
2126}
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.

References GNUNET_assert, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by callback_found_message(), callback_room_handle_message(), enqueue_message_control(), filter_message_sending(), get_store_member_of(), get_store_peer_of(), handle_room_messages(), is_service_message(), notify_about_members(), notify_srv_handle_message(), process_message_control(), sign_srv_room_message(), and task_message_control().

Here is the caller graph for this function:

◆ is_service_message()

enum GNUNET_GenericReturnValue is_service_message ( const struct GNUNET_MESSENGER_Message message)

Returns whether a specific kind of message contains service critical information.

That kind of information should not be encrypted via private messages for example to guarantee the service to work properly. The function returns GNUNET_YES if the kind of message needs to be transferred accessible to all peers and their running service. It returns GNUNET_NO if the message can be encrypted to specific subgroups of members without issues. If the kind of message is unknown it returns GNUNET_SYSERR.

Parameters
[in]messageMessage
Returns
GNUNET_YES if encrypting is disallowed, GNUNET_NO or GNUNET_SYSERR otherwise

Definition at line 2130 of file messenger_api_message.c.

2131{
2132 GNUNET_assert (message);
2133
2134 if (GNUNET_YES == is_peer_message (message))
2135 return GNUNET_YES;
2136
2137 switch (message->header.kind)
2138 {
2140 return GNUNET_YES; // Reserved for connection handling only!
2142 return GNUNET_YES; // Reserved for member handling only!
2144 return GNUNET_YES; // Reserved for member handling only!
2146 return GNUNET_YES; // Reserved for member name handling only!
2148 return GNUNET_YES; // Reserved for member key handling only!
2150 return GNUNET_YES; // Reserved for connection handling only!
2152 return GNUNET_YES; // Reserved for member id handling only!
2154 return GNUNET_YES; // Reserved for connection handling only!
2156 return GNUNET_YES; // Reserved for peers only!
2158 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
2160 return GNUNET_NO;
2162 return GNUNET_NO;
2164 return GNUNET_NO;
2166 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2168 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
2170 return GNUNET_YES; // Reserved for connection handling only!
2172 return GNUNET_NO;
2174 return GNUNET_NO;
2176 return GNUNET_NO;
2178 return GNUNET_YES; // Reserved for subscription handling only!
2180 return GNUNET_NO;
2182 return GNUNET_YES; // Reserved for epoch and group key exchange!
2184 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2186 return GNUNET_YES; // Reserved for epoch key exchange!
2188 return GNUNET_YES; // Reserved for epoch and group key exchange!
2190 return GNUNET_YES; // Reserved for epoch and group key revoking!
2192 return GNUNET_YES; // Reserved for group key exchange!
2194 return GNUNET_YES; // Reserved for epoch and group key exchange!
2195 default:
2196 return GNUNET_SYSERR;
2197 }
2198}
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBTION
The subscription kind.
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...

References GNUNET_assert, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_peer_message(), and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by encrypt_message(), send_message_to_room(), and transcribe_message().

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

◆ is_epoch_message()

enum GNUNET_GenericReturnValue is_epoch_message ( const struct GNUNET_MESSENGER_Message message)

Returns whether a certain kind of message from storage contains some specific details that might be required for the overall message graph to function as intended.

The function returns GNUNET_YES if you may not delete the given message because of that, otherwise it returns GNUNET_NO.

Parameters
[in]messageMessage
Returns
GNUNET_YES if the message contains epoch graph information, GNUNET_NO otherwise

Definition at line 2202 of file messenger_api_message.c.

2203{
2204 GNUNET_assert (message);
2205
2206 switch (message->header.kind)
2207 {
2209 return GNUNET_YES;
2211 return GNUNET_YES;
2213 return GNUNET_YES;
2214 default:
2215 return GNUNET_NO;
2216 }
2217}

References GNUNET_assert, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by delete_store_message(), GNUNET_MESSENGER_delete_message(), handle_message(), request_room_message_step(), send_message_to_room(), and sign_srv_room_message().

Here is the caller graph for this function:

◆ filter_message_sending()

enum GNUNET_GenericReturnValue filter_message_sending ( const struct GNUNET_MESSENGER_Message message)

Returns whether a specific kind of message should be sent by a client.

The function returns GNUNET_YES or GNUNET_NO for recommendations and GNUNET_SYSERR for specific kinds of messages which should not be sent manually at all.

Parameters
[in]messageMessage
Returns
GNUNET_YES if sending is allowed, GNUNET_NO or GNUNET_SYSERR otherwise

Definition at line 2221 of file messenger_api_message.c.

2222{
2223 GNUNET_assert (message);
2224
2225 if (GNUNET_YES == is_peer_message (message))
2226 return GNUNET_SYSERR; // Requires signature of peer rather than member!
2227
2228 switch (message->header.kind)
2229 {
2231 return GNUNET_SYSERR; // Reserved for connection handling only!
2233 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
2235 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
2237 return GNUNET_YES;
2239 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
2241 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
2243 return GNUNET_NO; // Reserved for member id handling only!
2245 return GNUNET_SYSERR; // Reserved for connection handling only!
2247 return GNUNET_SYSERR; // Reserved for peers only!
2249 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
2251 return GNUNET_YES;
2253 return GNUNET_YES;
2255 return GNUNET_YES;
2257 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2259 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
2261 return GNUNET_SYSERR; // Reserved for connection handling only!
2263 return GNUNET_YES;
2265 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2267 return GNUNET_YES;
2269 return GNUNET_YES;
2271 return GNUNET_YES;
2273 return GNUNET_NO; // Should only be used for implicit key exchange!
2275 return GNUNET_NO; // Should only be used for implicit forward secrecy!
2277 return GNUNET_NO; // Should only be used for implicit key exchange!
2279 return GNUNET_NO; // Should only be used for implicit key exchange!
2281 return GNUNET_NO; // Should only be used for implicit key exchange!
2283 return GNUNET_NO; // Should only be used for implicit key exchange!
2285 return GNUNET_NO; // Should only be used for implicit key exchange!
2286 default:
2287 return GNUNET_SYSERR;
2288 }
2289}

References GNUNET_assert, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_peer_message(), and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by check_send_message(), and GNUNET_MESSENGER_send_message().

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

◆ get_message_discourse()

const struct GNUNET_ShortHashCode * get_message_discourse ( const struct GNUNET_MESSENGER_Message message)

Returns the discourse hash of a message depending on its kind.

If a message contains a discourse hash it will not be stored locally on peers.

Parameters
[in]messageMessage
Returns
Discourse hash of message or NULL

Definition at line 2293 of file messenger_api_message.c.

2294{
2295 GNUNET_assert (message);
2296
2297 switch (message->header.kind)
2298 {
2300 return &(message->body.subscription.discourse);
2302 return &(message->body.talk.discourse);
2303 default:
2304 return NULL;
2305 }
2306}
struct GNUNET_MESSENGER_MessageSubscribtion subscription
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to talk.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageSubscribtion::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_assert, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageBody::subscription, and GNUNET_MESSENGER_MessageBody::talk.

Referenced by handle_message_control(), iterate_flag_for_cleanup_discourse_message(), put_store_message(), send_message_to_room(), and update_message_state().

Here is the caller graph for this function: