GNUnet 0.22.1
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_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)
 

Typedefs

typedef void(* GNUNET_MESSENGER_SignFunction) (const void *cls, struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash)
 

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. More...
 
struct GNUNET_MESSENGER_Messagecopy_message (const struct GNUNET_MESSENGER_Message *message)
 Creates and allocates a copy of a given message. More...
 
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. More...
 
void cleanup_message (struct GNUNET_MESSENGER_Message *message)
 Frees the messages body memory. More...
 
void destroy_message (struct GNUNET_MESSENGER_Message *message)
 Destroys a message and frees its memory fully. More...
 
enum GNUNET_GenericReturnValue is_message_session_bound (const struct GNUNET_MESSENGER_Message *message)
 Returns if the message should be bound to a member session. More...
 
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. More...
 
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. More...
 
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 maximal length in bytes. More...
 
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 maximal length in bytes. More...
 
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. More...
 
void sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PrivateKey *key)
 Signs the hash of a message with a given private key and writes the signature into the buffer as well. More...
 
void sign_message_by_peer (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Signs the hash of a message with the peer identity of a given config and writes the signature into the buffer as well. More...
 
enum GNUNET_GenericReturnValue verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PublicKey *key)
 Verifies the signature of a given message and its hash with a specific public key. More...
 
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. More...
 
enum GNUNET_GenericReturnValue encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
 Encrypts a message using a given public key and replaces its body and kind with the now private encrypted message. More...
 
enum GNUNET_GenericReturnValue decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PrivateKey *key)
 Decrypts a private message using a given private key and replaces its body and kind with the inner encrypted message. More...
 
struct GNUNET_MESSENGER_Messagetranscribe_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
 Transcribes a message as a new transcript message using a given public key from the recipient of the encrypted message content. More...
 
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. More...
 
struct GNUNET_MQ_Envelopepack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const GNUNET_MESSENGER_SignFunction sign, enum GNUNET_MESSENGER_PackMode mode, const void *cls)
 Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE. More...
 
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. More...
 
enum GNUNET_GenericReturnValue is_service_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message contains service critical information. More...
 
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. More...
 
const struct GNUNET_ShortHashCodeget_message_discourse (const struct GNUNET_MESSENGER_Message *message)
 Returns the discourse hash of a message depending on its kind. More...
 

Macro Definition Documentation

◆ 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 33 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_PADDING_MIN

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

Definition at line 36 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_PADDING_LEVEL0

#define GNUNET_MESSENGER_PADDING_LEVEL0   (512)

Definition at line 37 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_PADDING_LEVEL1

#define GNUNET_MESSENGER_PADDING_LEVEL1   (4096)

Definition at line 38 of file messenger_api_message.h.

◆ GNUNET_MESSENGER_PADDING_LEVEL2

#define GNUNET_MESSENGER_PADDING_LEVEL2   (32768)

Definition at line 39 of file messenger_api_message.h.

Typedef Documentation

◆ GNUNET_MESSENGER_SignFunction

typedef void(* GNUNET_MESSENGER_SignFunction) (const void *cls, struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash)

Definition at line 281 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 289 of file messenger_api_message.h.

290{
293};
@ 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 48 of file messenger_api_message.c.

49{
50 struct GNUNET_MESSENGER_Message *message;
51
52 message = GNUNET_new (struct GNUNET_MESSENGER_Message);
53 message->header.kind = kind;
54
55 switch (message->header.kind)
56 {
58 message->body.name.name = NULL;
59 break;
61 message->body.text.text = NULL;
62 break;
64 message->body.file.uri = NULL;
65 break;
67 message->body.privacy.length = 0;
68 message->body.privacy.data = NULL;
69 break;
71 message->body.ticket.identifier = NULL;
72 break;
74 message->body.transcript.length = 0;
75 message->body.transcript.data = NULL;
76 break;
78 message->body.tag.tag = NULL;
79 break;
81 message->body.talk.length = 0;
82 message->body.talk.data = NULL;
83 break;
84 default:
85 break;
86 }
87
88 return message;
89}
#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_TICKET
The ticket kind.
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.
uint16_t length
The length of the talk message data.
char * data
The data of the talk message.
char * text
The containing text.
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_MessageBody::file, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, 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_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, 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_connection(), create_message_delete(), 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_subscribe(), 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 93 of file messenger_api_message.c.

94{
95 struct GNUNET_MESSENGER_Message *copy;
96
97 GNUNET_assert (message);
98
100 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
101
102 switch (message->header.kind)
103 {
105 copy->body.name.name = message->body.name.name? GNUNET_strdup (
106 message->body.name.name) : NULL;
107 break;
109 copy->body.text.text = message->body.text.text? GNUNET_strdup (
110 message->body.text.text) : NULL;
111 break;
113 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
114 message->body.file.uri) : NULL;
115 break;
118 copy->body.privacy.length) : NULL;
119
120 if (copy->body.privacy.data)
121 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
122 copy->body.privacy.length);
123
124 break;
126 copy->body.ticket.identifier = message->body.ticket.identifier?
128 message->body.ticket.identifier) : NULL;
129 break;
132 copy->body.transcript.length) : NULL;
133
134 if (copy->body.transcript.data)
136 copy->body.transcript.length);
137
138 break;
140 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
141 message->body.tag.tag) : NULL;
142 break;
144 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
145 copy->body.talk.length) : NULL;
146
147 if (copy->body.talk.data)
148 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
149 copy->body.talk.length);
150
151 break;
152 default:
153 break;
154 }
155
156 return copy;
157}
#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_MessageBody::file, GNUNET_assert, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, 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_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, 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(), and send_srv_handle_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 161 of file messenger_api_message.c.

163{
165
166 GNUNET_assert ((message) && (header));
167
168 kind = message->header.kind;
169
170 GNUNET_memcpy (&(message->header), header,
171 sizeof(struct GNUNET_MESSENGER_MessageHeader));
172
173 message->header.kind = kind;
174}
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 224 of file messenger_api_message.c.

225{
226 GNUNET_assert (message);
227
228 destroy_message_body (message->header.kind, &(message->body));
229}
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 233 of file messenger_api_message.c.

234{
235 GNUNET_assert (message);
236
237 destroy_message_body (message->header.kind, &(message->body));
238
239 GNUNET_free (message);
240}
#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 clear_queue_messages(), create_message_peer(), dequeue_from_messages(), dequeue_message_from_room(), destroy_message_control(), enqueue_to_messages(), forward_tunnel_message(), get_store_message(), handle_delete_message(), handle_discourse_subscription(), handle_private_message(), handle_transcript_message(), iterate_destroy_message(), iterate_destroy_messages(), iterate_destroy_subscription(), iterate_flag_for_cleanup_discourse_message(), keep_subscription_alive(), send_message_to_room_with_key(), send_tunnel_message(), task_message_control(), and update_room_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 244 of file messenger_api_message.c.

245{
246 GNUNET_assert (message);
247
248 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
250 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
251 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
253 return GNUNET_YES;
254 else
255 return GNUNET_NO;
256}
@ 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 367 of file messenger_api_message.c.

369{
370 uint16_t length;
371
372 length = 0;
373
374 if (GNUNET_YES == include_header)
375 {
376 length += member_size (struct GNUNET_MESSENGER_Message, header.timestamp);
377 length += member_size (struct GNUNET_MESSENGER_Message, header.sender_id);
378 length += member_size (struct GNUNET_MESSENGER_Message, header.previous);
379 }
380
381 length += sizeof(kind_t);
382
383 return length + get_message_body_kind_size (kind);
384}
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 437 of file messenger_api_message.c.

439{
440 uint16_t length;
441
442 GNUNET_assert (message);
443
444 length = 0;
445
446 if (GNUNET_YES == include_header)
448 &(message->header.signature));
449
450 length += get_message_kind_size (message->header.kind, include_header);
451 length += get_message_body_size (message->header.kind, &(message->body));
452
453 return length;
454}
ssize_t GNUNET_CRYPTO_signature_get_length(const struct GNUNET_CRYPTO_Signature *sig)
Get the compacted length of a GNUNET_CRYPTO_Signature.
Definition: crypto_pkey.c:190
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_Signature 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_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()

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 maximal length in bytes.

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

Definition at line 709 of file messenger_api_message.c.

713{
714 uint16_t offset;
715 kind_t kind;
716
717 GNUNET_assert ((message) && (buffer));
718
719 offset = 0;
720
721 if (GNUNET_YES == include_header)
722 encode_step_signature (buffer, offset, &(message->header.signature),
723 length);
724
725 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
726
727 if (GNUNET_YES == include_header)
728 {
729 encode_step (buffer, offset, &(message->header.timestamp));
730 encode_step (buffer, offset, &(message->header.sender_id));
731 encode_step (buffer, offset, &(message->header.previous));
732 }
733
734 encode_step (buffer, offset, &kind);
735
736 encode_message_body (message->header.kind, &(message->body),
737 length, buffer, offset);
738}
#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)
#define encode_step_signature(dst, offset, src, length)
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 maximal 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 970 of file messenger_api_message.c.

975{
976 uint16_t offset;
977 uint16_t count;
978 kind_t kind;
979
981 (message) &&
982 (buffer) &&
984 include_header))
985 );
986
987 offset = 0;
988
989 if (GNUNET_YES == include_header)
990 {
991 ssize_t result;
992
994 &(message->header.signature), buffer, length - offset);
995
996 if (result < 0)
997 return GNUNET_NO;
998 else
999 offset += result;
1000 }
1001
1002 count = length - offset;
1004 include_header))
1005 return GNUNET_NO;
1006
1007 if (GNUNET_YES == include_header)
1008 {
1009 decode_step (buffer, offset, &(message->header.timestamp));
1010 decode_step (buffer, offset, &(message->header.sender_id));
1011 decode_step (buffer, offset, &(message->header.previous));
1012 }
1013
1014 decode_step (buffer, offset, &kind);
1015 kind = GNUNET_be32toh (kind);
1016
1017 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1018
1019 if (count < get_message_kind_size (message->header.kind, include_header))
1020 return GNUNET_NO;
1021
1022 {
1023 uint16_t result;
1024 result = decode_message_body (&(message->header.kind),
1025 &(message->body), length, buffer, offset);
1026
1027 if (padding)
1028 *padding = result;
1029 }
1030
1031 return GNUNET_YES;
1032}
static int result
Global testing status.
ssize_t GNUNET_CRYPTO_read_signature_from_buffer(struct GNUNET_CRYPTO_Signature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_Signature from a compact buffer.
Definition: crypto_pkey.c:227
#define GNUNET_be32toh(x)
@ 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_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 1080 of file messenger_api_message.c.

1084{
1085 ssize_t offset;
1086
1087 GNUNET_assert ((message) && (buffer) && (hash));
1088
1090
1091 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1092}
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_hash(), GNUNET_CRYPTO_signature_get_length(), GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::signature.

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,
uint16_t  length,
char *  buffer,
const struct GNUNET_HashCode hash,
const struct GNUNET_CRYPTO_PrivateKey key 
)

Signs the hash of a message with a given private key and writes the signature into the buffer as well.

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

Definition at line 1096 of file messenger_api_message.c.

1101{
1102 GNUNET_assert ((message) && (buffer) && (hash) && (key));
1103
1104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1105 GNUNET_h2s (hash));
1106
1107 {
1108 struct GNUNET_MESSENGER_MessageSignature signature;
1109
1111 signature.purpose.size = htonl (sizeof(signature));
1112
1113 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1114 GNUNET_CRYPTO_sign (key, &signature, &(message->header.signature));
1115 }
1116
1117 message->header.signature.type = key->type;
1118
1119 {
1120 uint16_t offset = 0;
1121 encode_step_signature (buffer, offset, &(message->header.signature), length);
1122 }
1123}
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_log(kind,...)
#define GNUNET_CRYPTO_sign(priv, ps, sig)
Sign a given block with GNUNET_CRYPTO_PrivateKey.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t type
Type of signature.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose

References encode_step_signature, GNUNET_assert, GNUNET_CRYPTO_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_EccSignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_CRYPTO_Signature::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()

void sign_message_by_peer ( struct GNUNET_MESSENGER_Message message,
uint16_t  length,
char *  buffer,
const struct GNUNET_HashCode hash,
const struct GNUNET_CONFIGURATION_Handle cfg 
)

Signs the hash of a message with the peer identity of a given config and writes the signature into the buffer as well.

Parameters
[in,out]messageMessage
[in]lengthLength of buffer
[out]bufferBuffer
[in]hashHash of message
[in]cfgPeer configuration

Definition at line 1127 of file messenger_api_message.c.

1132{
1133 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
1134
1135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1136 GNUNET_h2s (hash));
1137
1138 {
1139 struct GNUNET_MESSENGER_MessageSignature signature;
1141 signature.purpose.size = htonl (sizeof(signature));
1142
1143 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1144 GNUNET_CRYPTO_sign_by_peer_identity (cfg, &(signature.purpose),
1145 &(message->header.signature.
1146 eddsa_signature));
1147 }
1148
1150
1151 {
1152 uint16_t offset = 0;
1153 encode_step_signature (buffer, offset, &(message->header.signature), length);
1154 }
1155}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_by_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
Sign a given block with a specific purpose using the host's peer identity.
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.

References cfg, encode_step_signature, GNUNET_assert, GNUNET_CRYPTO_sign_by_peer_identity(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_CRYPTO_Signature::type.

Referenced by sign_srv_room_message_by_peer().

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_PublicKey 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 1159 of file messenger_api_message.c.

1162{
1163 struct GNUNET_MESSENGER_MessageSignature signature;
1164
1165 GNUNET_assert ((message) && (hash) && (key));
1166
1167 if (key->type != message->header.signature.type)
1168 return GNUNET_SYSERR;
1169
1170 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1171 signature.purpose.size = htonl (sizeof(signature));
1172
1173 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1174
1177 &(message->header.signature), key);
1178}
#define GNUNET_CRYPTO_signature_verify(purp, ps, sig, pub)
Verify a given signature with GNUNET_CRYPTO_PublicKey.
@ GNUNET_SYSERR

References GNUNET_assert, GNUNET_CRYPTO_signature_verify, GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, GNUNET_SYSERR, GNUNET_MESSENGER_MessageSignature::hash, GNUNET_MESSENGER_Message::header, key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_CRYPTO_Signature::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 1182 of file messenger_api_message.c.

1185{
1186 struct GNUNET_MESSENGER_MessageSignature signature;
1187
1188 GNUNET_assert ((message) && (hash) && (identity));
1189
1190 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1191 return GNUNET_SYSERR;
1192
1193 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1194 signature.purpose.size = htonl (sizeof(signature));
1195
1196 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1197
1199 GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &(signature.purpose),
1200 &(message->header.signature.
1201 eddsa_signature), identity);
1202}
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_EccSignaturePurpose *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_EccSignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_CRYPTO_Signature::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:

◆ encrypt_message()

enum GNUNET_GenericReturnValue encrypt_message ( struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_PublicKey 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 1206 of file messenger_api_message.c.

1208{
1209 struct GNUNET_CRYPTO_EcdhePublicKey hpke_key;
1211 struct GNUNET_MESSENGER_ShortMessage shortened;
1212 uint16_t length, padded_length, encoded_length;
1213 uint8_t *data;
1214
1215 GNUNET_assert ((message) && (key));
1216
1217 if (GNUNET_YES == is_service_message (message))
1218 return GNUNET_NO;
1219
1220 fold_short_message (message, &shortened);
1221
1222 length = get_short_message_size (&shortened, GNUNET_YES);
1223 padded_length = calc_padded_length (length + encryption_overhead);
1224
1225 GNUNET_assert (padded_length >= length + encryption_overhead);
1226
1228 message->body.privacy.data = GNUNET_malloc (padded_length);
1229 message->body.privacy.length = padded_length;
1230
1232 encoded_length = (padded_length - encryption_overhead);
1233
1234 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1235
1236 result = GNUNET_NO;
1237 data = GNUNET_malloc (encoded_length);
1238
1239 encode_short_message (&shortened, encoded_length, (char *) data);
1240
1242 (uint8_t*) "messenger",
1243 strlen ("messenger"),
1244 NULL, 0,
1245 (uint8_t*) data,
1246 encoded_length,
1247 (uint8_t*) message->body.
1248 privacy.data,
1249 NULL))
1250 {
1251 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1252
1253 unfold_short_message (&shortened, message);
1254 goto cleanup;
1255 }
1256
1257 destroy_message_body (shortened.kind, &(shortened.body));
1259
1260cleanup:
1261 GNUNET_free (data);
1262 return result;
1263}
static char * data
The data to insert into the dht.
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:130
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot(const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:929
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519(const struct GNUNET_CRYPTO_PublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
Definition: crypto_hpke.c:989
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ 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)
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...

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_pk_to_x25519(), 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(), key, 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_PrivateKey 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 1267 of file messenger_api_message.c.

1269{
1270 struct GNUNET_CRYPTO_EcdhePrivateKey hpke_key;
1272 uint16_t padded_length, encoded_length;
1273 uint8_t *data;
1274
1275 GNUNET_assert ((message) && (key));
1276
1277 padded_length = message->body.privacy.length;
1278
1279 if (padded_length < encryption_overhead)
1280 {
1282 "Message length too short to decrypt!\n");
1283
1284 return GNUNET_NO;
1285 }
1286
1288 encoded_length = (padded_length - encryption_overhead);
1289
1290 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1291
1292 result = GNUNET_NO;
1293 data = GNUNET_malloc (encoded_length);
1294
1295 if (GNUNET_OK !=
1297 (uint8_t*) "messenger",
1298 strlen ("messenger"),
1299 NULL, 0,
1300 (uint8_t*) message->body.privacy.data,
1301 padded_length,
1302 (uint8_t*) data,
1303 NULL))
1304 {
1305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1306
1307 goto cleanup;
1308 }
1309
1310 {
1311 struct GNUNET_MESSENGER_ShortMessage shortened;
1312 if (GNUNET_YES != decode_short_message (&shortened,
1313 encoded_length,
1314 (char*) data))
1315 {
1317 "Decoding decrypted message failed!\n");
1318
1319 goto cleanup;
1320 }
1321
1322 unfold_short_message (&shortened, message);
1324 }
1325
1326cleanup:
1327 GNUNET_free (data);
1328 return result;
1329}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open_oneshot(const struct GNUNET_CRYPTO_EcdhePrivateKey *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.
Definition: crypto_hpke.c:958
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519(const struct GNUNET_CRYPTO_PrivateKey *sk, struct GNUNET_CRYPTO_EcdhePrivateKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
Definition: crypto_hpke.c:1013
static enum GNUNET_GenericReturnValue decode_short_message(struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)
Private ECC key encoded for transmission.

References GNUNET_MESSENGER_Message::body, cleanup(), data, GNUNET_MESSENGER_MessagePrivate::data, decode_short_message(), encryption_overhead, GNUNET_assert, GNUNET_CRYPTO_hpke_open_oneshot(), GNUNET_CRYPTO_hpke_sk_to_x25519(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_YES, key, 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_PublicKey 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 1333 of file messenger_api_message.c.

1335{
1336 struct GNUNET_MESSENGER_Message *transcript;
1337
1338 GNUNET_assert ((message) && (key));
1339
1340 if (GNUNET_YES == is_service_message (message))
1341 return NULL;
1342
1344
1345 if (! transcript)
1346 {
1347 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1348 return NULL;
1349 }
1350
1351 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1352 sizeof(transcript->body.transcript.key));
1353
1354 {
1355 struct GNUNET_MESSENGER_ShortMessage shortened;
1356 uint16_t data_length;
1357
1358 fold_short_message (message, &shortened);
1359
1360 data_length = get_short_message_size (&shortened, GNUNET_YES);
1361
1362 transcript->body.transcript.data = GNUNET_malloc (data_length);
1363 transcript->body.transcript.length = data_length;
1364
1365 encode_short_message (&shortened, data_length,
1366 transcript->body.transcript.data);
1367 }
1368
1369 return transcript;
1370}
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_CRYPTO_PublicKey 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:

◆ 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]transcriptMessage transcript
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 1374 of file messenger_api_message.c.

1375{
1376 uint16_t data_length;
1377 struct GNUNET_MESSENGER_ShortMessage shortened;
1378
1379 GNUNET_assert (message);
1380
1382 return GNUNET_NO;
1383
1384 data_length = message->body.transcript.length;
1385
1386 if (GNUNET_YES != decode_short_message (&shortened,
1387 data_length,
1388 message->body.transcript.data))
1389 {
1391 "Decoding decrypted message failed!\n");
1392
1393 return GNUNET_NO;
1394 }
1395
1396 unfold_short_message (&shortened, message);
1397 return GNUNET_YES;
1398}

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:

◆ pack_message()

struct GNUNET_MQ_Envelope * pack_message ( struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash,
const GNUNET_MESSENGER_SignFunction  sign,
enum GNUNET_MESSENGER_PackMode  mode,
const void *  cls 
)

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 and it will be signed if the sign function is not NULL.

Parameters
[out]messageMessage
[out]hashHash of message
[in]signFunction to sign
[in]modeMode of packing
[in,out]clsClosure for signing
Returns
Envelope or NULL

Definition at line 1402 of file messenger_api_message.c.

1407{
1408 struct GNUNET_MessageHeader *header;
1409 uint16_t length, padded_length;
1410 struct GNUNET_MQ_Envelope *env;
1411 char *buffer;
1412
1413 GNUNET_assert (message);
1414
1416 "Packing message kind=%u and sender: %s\n",
1417 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
1418
1419 length = get_message_size (message, GNUNET_YES);
1420 padded_length = calc_padded_length (length);
1421
1423 {
1424 env = GNUNET_MQ_msg_extra (header, padded_length,
1426 buffer = (char*) &(header[1]);
1427 }
1428 else
1429 {
1430 env = NULL;
1431 buffer = GNUNET_malloc (padded_length);
1432 }
1433
1434 encode_message (message, padded_length, buffer, GNUNET_YES);
1435
1436 if (hash)
1437 {
1438 hash_message (message, length, buffer, hash);
1439
1440 if (sign)
1441 sign (cls, message, length, buffer, hash);
1442 }
1443
1445 GNUNET_free (buffer);
1446
1447 return env;
1448}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static enum @44 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.
Definition: gnunet_mq_lib.h:63
#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 maximal 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(), iterate_send_room_message(), and pack_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 1452 of file messenger_api_message.c.

1453{
1454 GNUNET_assert (message);
1455
1456 switch (message->header.kind)
1457 {
1463 return GNUNET_YES;
1464 default:
1465 return GNUNET_NO;
1466 }
1467}
@ 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(), pack_srv_room_message(), process_message_control(), 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 1471 of file messenger_api_message.c.

1472{
1473 GNUNET_assert (message);
1474
1475 if (GNUNET_YES == is_peer_message (message))
1476 return GNUNET_YES;
1477
1478 switch (message->header.kind)
1479 {
1481 return GNUNET_YES; // Reserved for connection handling only!
1483 return GNUNET_YES; // Reserved for member handling only!
1485 return GNUNET_YES; // Reserved for member handling only!
1487 return GNUNET_YES; // Reserved for member name handling only!
1489 return GNUNET_YES; // Reserved for member key handling only!
1491 return GNUNET_YES; // Reserved for connection handling only!
1493 return GNUNET_YES; // Reserved for member id handling only!
1495 return GNUNET_YES; // Reserved for connection handling only!
1497 return GNUNET_YES; // Reserved for peers only!
1499 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
1501 return GNUNET_NO;
1503 return GNUNET_NO;
1505 return GNUNET_NO;
1507 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
1509 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
1511 return GNUNET_YES; // Reserved for connection handling only!
1513 return GNUNET_NO;
1515 return GNUNET_NO;
1517 return GNUNET_NO;
1519 return GNUNET_YES; // Reserved for subscription handling only!
1521 return GNUNET_NO;
1522 default:
1523 return GNUNET_SYSERR;
1524 }
1525}
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBE
The subscribe kind.
@ GNUNET_MESSENGER_KIND_DELETE
The delete 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_CONNECTION, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_FILE, 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_SUBSCRIBE, 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(), and transcribe_message().

Here is the call graph for this function:
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 1529 of file messenger_api_message.c.

1530{
1531 GNUNET_assert (message);
1532
1533 if (GNUNET_YES == is_peer_message (message))
1534 return GNUNET_SYSERR; // Requires signature of peer rather than member!
1535
1536 switch (message->header.kind)
1537 {
1539 return GNUNET_SYSERR; // Reserved for connection handling only!
1541 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
1543 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
1545 return GNUNET_YES;
1547 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
1549 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
1551 return GNUNET_NO; // Reserved for member id handling only!
1553 return GNUNET_SYSERR; // Reserved for connection handling only!
1555 return GNUNET_SYSERR; // Reserved for peers only!
1557 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
1559 return GNUNET_YES;
1561 return GNUNET_YES;
1563 return GNUNET_YES;
1565 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1567 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
1569 return GNUNET_SYSERR; // Reserved for connection handling only!
1571 return GNUNET_YES;
1573 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1575 return GNUNET_YES;
1577 return GNUNET_YES;
1579 return GNUNET_YES;
1580 default:
1581 return GNUNET_SYSERR;
1582 }
1583}

References GNUNET_assert, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_FILE, 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_SUBSCRIBE, 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 1587 of file messenger_api_message.c.

1588{
1589 GNUNET_assert (message);
1590
1591 switch (message->header.kind)
1592 {
1594 return &(message->body.subscribe.discourse);
1596 return &(message->body.talk.discourse);
1597 default:
1598 return NULL;
1599 }
1600}
struct GNUNET_MESSENGER_MessageSubscribe subscribe
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscribe.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to talk.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageSubscribe::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_assert, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageBody::subscribe, 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: