GNUnet 0.21.2
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 45 of file messenger_api_message.c.

46{
47 struct GNUNET_MESSENGER_Message *message = GNUNET_new (struct
49
50 message->header.kind = kind;
51
52 switch (message->header.kind)
53 {
55 message->body.name.name = NULL;
56 break;
58 message->body.text.text = NULL;
59 break;
61 message->body.file.uri = NULL;
62 break;
64 message->body.privacy.length = 0;
65 message->body.privacy.data = NULL;
66 break;
68 message->body.ticket.identifier = NULL;
69 break;
71 message->body.transcript.length = 0;
72 message->body.transcript.data = NULL;
73 break;
75 message->body.tag.tag = NULL;
76 break;
78 message->body.talk.length = 0;
79 message->body.talk.data = NULL;
80 break;
81 default:
82 break;
83 }
84
85 return message;
86}
#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 90 of file messenger_api_message.c.

91{
92 GNUNET_assert (message);
93
94 struct GNUNET_MESSENGER_Message *copy = GNUNET_new (struct
96
97 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
98
99 switch (message->header.kind)
100 {
102 copy->body.name.name = message->body.name.name? GNUNET_strdup (
103 message->body.name.name) : NULL;
104 break;
106 copy->body.text.text = message->body.text.text? GNUNET_strdup (
107 message->body.text.text) : NULL;
108 break;
110 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
111 message->body.file.uri) : NULL;
112 break;
115 copy->body.privacy.length) : NULL;
116
117 if (copy->body.privacy.data)
118 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
119 copy->body.privacy.length);
120
121 break;
123 copy->body.ticket.identifier = message->body.ticket.identifier?
125 message->body.ticket.identifier) : NULL;
126 break;
129 copy->body.transcript.length) : NULL;
130
131 if (copy->body.transcript.data)
133 copy->body.transcript.length);
134
135 break;
137 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
138 message->body.tag.tag) : NULL;
139 break;
141 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
142 copy->body.talk.length) : NULL;
143
144 if (copy->body.talk.data)
145 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
146 copy->body.talk.length);
147
148 break;
149 default:
150 break;
151 }
152
153 return copy;
154}
#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 158 of file messenger_api_message.c.

160{
161 GNUNET_assert ((message) && (header));
162
163 enum GNUNET_MESSENGER_MessageKind kind = message->header.kind;
164
165 GNUNET_memcpy (&(message->header), header,
166 sizeof(struct GNUNET_MESSENGER_MessageHeader));
167
168 message->header.kind = kind;
169}
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 217 of file messenger_api_message.c.

218{
219 GNUNET_assert (message);
220
221 destroy_message_body (message->header.kind, &(message->body));
222}
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 226 of file messenger_api_message.c.

227{
228 GNUNET_assert (message);
229
230 destroy_message_body (message->header.kind, &(message->body));
231
232 GNUNET_free (message);
233}
#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 237 of file messenger_api_message.c.

238{
239 GNUNET_assert (message);
240
241 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
243 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
244 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
246 return GNUNET_YES;
247 else
248 return GNUNET_NO;
249}
@ 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 358 of file messenger_api_message.c.

360{
361 uint16_t length = 0;
362
363 if (GNUNET_YES == include_header)
364 {
365 length += member_size (struct GNUNET_MESSENGER_Message, header.timestamp);
366 length += member_size (struct GNUNET_MESSENGER_Message, header.sender_id);
367 length += member_size (struct GNUNET_MESSENGER_Message, header.previous);
368 }
369
370 length += sizeof(kind_t);
371
372 return length + get_message_body_kind_size (kind);
373}
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 424 of file messenger_api_message.c.

426{
427 GNUNET_assert (message);
428
429 uint16_t length = 0;
430
431 if (GNUNET_YES == include_header)
433 &(message->header.signature));
434
435 length += get_message_kind_size (message->header.kind, include_header);
436 length += get_message_body_size (message->header.kind, &(message->body));
437
438 return length;
439}
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:206
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 681 of file messenger_api_message.c.

685{
686 GNUNET_assert ((message) && (buffer));
687
688 uint16_t offset = 0;
689
690 if (GNUNET_YES == include_header)
691 encode_step_signature (buffer, offset, &(message->header.signature),
692 length);
693
694 const kind_t kind = GNUNET_htobe32 ((kind_t) message->header.kind);
695
696 if (GNUNET_YES == include_header)
697 {
698 encode_step (buffer, offset, &(message->header.timestamp));
699 encode_step (buffer, offset, &(message->header.sender_id));
700 encode_step (buffer, offset, &(message->header.previous));
701 }
702
703 encode_step (buffer, offset, &kind);
704
705 encode_message_body (message->header.kind, &(message->body),
706 length, buffer, offset);
707}
#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 928 of file messenger_api_message.c.

933{
935 (message) &&
936 (buffer) &&
938 include_header))
939 );
940
941 uint16_t offset = 0;
942
943 if (GNUNET_YES == include_header)
944 {
946 &(message->header.signature), buffer, length - offset
947 );
948
949 if (result < 0)
950 return GNUNET_NO;
951 else
952 offset += result;
953 }
954
955 const uint16_t count = length - offset;
956
958 include_header))
959 return GNUNET_NO;
960
961 kind_t kind;
962
963 if (GNUNET_YES == include_header)
964 {
965 decode_step (buffer, offset, &(message->header.timestamp));
966 decode_step (buffer, offset, &(message->header.sender_id));
967 decode_step (buffer, offset, &(message->header.previous));
968 }
969
970 decode_step (buffer, offset, &kind);
971
973 kind);
974
975 if (count < get_message_kind_size (message->header.kind, include_header))
976 return GNUNET_NO;
977
978 const uint16_t result = decode_message_body (&(message->header.kind),
979 &(message->body), length, buffer,
980 offset);
981
982 if (padding)
983 *padding = result;
984
985 return GNUNET_YES;
986}
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:243
#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 1031 of file messenger_api_message.c.

1035{
1036 GNUNET_assert ((message) && (buffer) && (hash));
1037
1038 const ssize_t offset = GNUNET_CRYPTO_signature_get_length (
1039 &(message->header.signature)
1040 );
1041
1042 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1043}
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 1047 of file messenger_api_message.c.

1052{
1053 GNUNET_assert ((message) && (buffer) && (hash) && (key));
1054
1055 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1056 GNUNET_h2s (hash));
1057
1058 struct GNUNET_MESSENGER_MessageSignature signature;
1059
1061 signature.purpose.size = htonl (sizeof(signature));
1062
1063 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1064 GNUNET_CRYPTO_sign (key, &signature, &(message->header.signature));
1065
1066 message->header.signature.type = key->type;
1067
1068 uint16_t offset = 0;
1069 encode_step_signature (buffer, offset, &(message->header.signature), length);
1070}
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 1074 of file messenger_api_message.c.

1079{
1080 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
1081
1082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1083 GNUNET_h2s (hash));
1084
1085 struct GNUNET_MESSENGER_MessageSignature signature;
1086
1088 signature.purpose.size = htonl (sizeof(signature));
1089
1090 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1091 GNUNET_CRYPTO_sign_by_peer_identity (cfg, &(signature.purpose),
1092 &(message->header.signature.
1093 eddsa_signature));
1094
1096
1097 uint16_t offset = 0;
1098 encode_step_signature (buffer, offset, &(message->header.signature), length);
1099}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
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 1103 of file messenger_api_message.c.

1106{
1107 GNUNET_assert ((message) && (hash) && (key));
1108
1109 if (key->type != message->header.signature.type)
1110 return GNUNET_SYSERR;
1111
1112 struct GNUNET_MESSENGER_MessageSignature signature;
1113
1115 signature.purpose.size = htonl (sizeof(signature));
1116
1117 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1118
1121 &(message->header.signature), key);
1122}
#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 1126 of file messenger_api_message.c.

1129{
1130 GNUNET_assert ((message) && (hash) && (identity));
1131
1132 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1133 return GNUNET_SYSERR;
1134
1135 struct GNUNET_MESSENGER_MessageSignature signature;
1136
1138 signature.purpose.size = htonl (sizeof(signature));
1139
1140 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1141
1143 GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &(signature.purpose),
1144 &(message->header.signature.
1145 eddsa_signature), identity);
1146}
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 1150 of file messenger_api_message.c.

1152{
1153 GNUNET_assert ((message) && (key));
1154
1155 if (GNUNET_YES == is_service_message (message))
1156 return GNUNET_NO;
1157
1158 struct GNUNET_MESSENGER_ShortMessage shortened;
1159
1160 fold_short_message (message, &shortened);
1161
1162 const uint16_t length = get_short_message_size (&shortened, GNUNET_YES);
1163 const uint16_t padded_length = calc_padded_length (
1165 );
1166
1168 message->body.privacy.data = GNUNET_malloc (padded_length);
1169 message->body.privacy.length = padded_length;
1170
1171 const uint16_t encoded_length = (
1173 );
1174
1175 encode_short_message (&shortened, encoded_length, message->body.privacy.data);
1176
1178 encoded_length,
1179 key,
1180 message->body.privacy.data,
1181 padded_length))
1182 {
1183 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1184
1185 unfold_short_message (&shortened, message);
1186 return GNUNET_NO;
1187 }
1188
1189 destroy_message_body (shortened.kind, &(shortened.body));
1190 return GNUNET_YES;
1191}
#define GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_PublicKey *pub, void *result, size_t result_size)
Encrypt a block with GNUNET_CRYPTO_PublicKey and derives a GNUNET_CRYPTO_EcdhePublicKey which is requ...
Definition: crypto_pkey.c:433
@ 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)
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(), GNUNET_MESSENGER_MessagePrivate::data, destroy_message_body(), encode_short_message(), fold_short_message(), get_short_message_size(), GNUNET_assert, GNUNET_CRYPTO_encrypt(), GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES, GNUNET_ERROR_TYPE_WARNING, 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, 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 1195 of file messenger_api_message.c.

1197{
1198 GNUNET_assert ((message) && (key));
1199
1200 const uint16_t padded_length = message->body.privacy.length;
1201
1202 if (padded_length < GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES)
1203 {
1205 "Message length too short to decrypt!\n");
1206
1207 return GNUNET_NO;
1208 }
1209
1210 const uint16_t encoded_length = (
1212 );
1213
1215 padded_length,
1216 key,
1217 message->body.privacy.data,
1218 encoded_length))
1219 {
1220 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Decrypting message failed!\n");
1221
1222 return GNUNET_NO;
1223 }
1224
1225 struct GNUNET_MESSENGER_ShortMessage shortened;
1226
1227 if (GNUNET_YES != decode_short_message (&shortened,
1228 encoded_length,
1229 message->body.privacy.data))
1230 {
1232 "Decoding decrypted message failed!\n");
1233
1234 return GNUNET_NO;
1235 }
1236
1237 unfold_short_message (&shortened, message);
1238 return GNUNET_YES;
1239}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_PrivateKey *priv, void *result, size_t result_size)
Decrypt a given block with GNUNET_CRYPTO_PrivateKey and a given GNUNET_CRYPTO_EcdhePublicKey using ec...
Definition: crypto_pkey.c:484
@ GNUNET_ERROR_TYPE_INFO
static enum GNUNET_GenericReturnValue decode_short_message(struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessagePrivate::data, decode_short_message(), GNUNET_assert, GNUNET_CRYPTO_decrypt(), GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_YES, key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageBody::privacy, 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 1243 of file messenger_api_message.c.

1245{
1246 GNUNET_assert ((message) && (key));
1247
1248 if (GNUNET_YES == is_service_message (message))
1249 return NULL;
1250
1251 struct GNUNET_MESSENGER_Message *transcript = create_message (
1253
1254 if (! transcript)
1255 {
1256 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1257 return NULL;
1258 }
1259
1260 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1261 sizeof(transcript->body.transcript.key));
1262
1263 struct GNUNET_MESSENGER_ShortMessage shortened;
1264
1265 fold_short_message (message, &shortened);
1266
1267 const uint16_t data_length = get_short_message_size (
1268 &shortened, GNUNET_YES);
1269
1270 transcript->body.transcript.data = GNUNET_malloc (data_length);
1271 transcript->body.transcript.length = data_length;
1272
1273 encode_short_message (&shortened, data_length,
1274 transcript->body.transcript.data);
1275
1276 return transcript;
1277}
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 1281 of file messenger_api_message.c.

1282{
1283 GNUNET_assert (message);
1284
1286 return GNUNET_NO;
1287
1288 const uint16_t data_length = message->body.transcript.length;
1289
1290 struct GNUNET_MESSENGER_ShortMessage shortened;
1291 if (GNUNET_YES != decode_short_message (&shortened,
1292 data_length,
1293 message->body.transcript.data))
1294 {
1296 "Decoding decrypted message failed!\n");
1297
1298 return GNUNET_NO;
1299 }
1300
1301 unfold_short_message (&shortened, message);
1302 return GNUNET_YES;
1303}

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

1312{
1313 GNUNET_assert (message);
1314
1316 "Packing message kind=%u and sender: %s\n",
1317 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
1318
1319 struct GNUNET_MessageHeader *header;
1320
1321 const uint16_t length = get_message_size (message, GNUNET_YES);
1322 const uint16_t padded_length = calc_padded_length (length);
1323
1324 struct GNUNET_MQ_Envelope *env;
1325 char *buffer;
1326
1328 {
1329 env = GNUNET_MQ_msg_extra (header, padded_length,
1331
1332 buffer = (char*) &(header[1]);
1333 }
1334 else
1335 {
1336 env = NULL;
1337
1338 buffer = GNUNET_malloc (padded_length);
1339 }
1340
1341 encode_message (message, padded_length, buffer, GNUNET_YES);
1342
1343 if (hash)
1344 {
1345 hash_message (message, length, buffer, hash);
1346
1347 if (sign)
1348 sign (cls, message, length, buffer, hash);
1349 }
1350
1352 GNUNET_free (buffer);
1353
1354 return env;
1355}
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_INFO, 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 1359 of file messenger_api_message.c.

1360{
1361 GNUNET_assert (message);
1362
1363 switch (message->header.kind)
1364 {
1370 return GNUNET_YES;
1371 default:
1372 return GNUNET_NO;
1373 }
1374}
@ 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 1378 of file messenger_api_message.c.

1379{
1380 GNUNET_assert (message);
1381
1382 if (GNUNET_YES == is_peer_message (message))
1383 return GNUNET_YES;
1384
1385 switch (message->header.kind)
1386 {
1388 return GNUNET_YES; // Reserved for connection handling only!
1390 return GNUNET_YES; // Reserved for member handling only!
1392 return GNUNET_YES; // Reserved for member handling only!
1394 return GNUNET_YES; // Reserved for member name handling only!
1396 return GNUNET_YES; // Reserved for member key handling only!
1398 return GNUNET_YES; // Reserved for connection handling only!
1400 return GNUNET_YES; // Reserved for member id handling only!
1402 return GNUNET_YES; // Reserved for connection handling only!
1404 return GNUNET_YES; // Reserved for peers only!
1406 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
1408 return GNUNET_NO;
1410 return GNUNET_NO;
1412 return GNUNET_NO;
1414 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
1416 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
1418 return GNUNET_YES; // Reserved for connection handling only!
1420 return GNUNET_NO;
1422 return GNUNET_NO;
1424 return GNUNET_NO;
1426 return GNUNET_YES; // Reserved for subscription handling only!
1428 return GNUNET_NO;
1429 default:
1430 return GNUNET_SYSERR;
1431 }
1432}
@ 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 1436 of file messenger_api_message.c.

1437{
1438 GNUNET_assert (message);
1439
1440 if (GNUNET_YES == is_peer_message (message))
1441 return GNUNET_SYSERR; // Requires signature of peer rather than member!
1442
1443 switch (message->header.kind)
1444 {
1446 return GNUNET_SYSERR; // Reserved for connection handling only!
1448 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
1450 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
1452 return GNUNET_YES;
1454 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
1456 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
1458 return GNUNET_NO; // Reserved for member id handling only!
1460 return GNUNET_SYSERR; // Reserved for connection handling only!
1462 return GNUNET_SYSERR; // Reserved for peers only!
1464 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
1466 return GNUNET_YES;
1468 return GNUNET_YES;
1470 return GNUNET_YES;
1472 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1474 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
1476 return GNUNET_SYSERR; // Reserved for connection handling only!
1478 return GNUNET_YES;
1480 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1482 return GNUNET_YES;
1484 return GNUNET_YES;
1486 return GNUNET_YES;
1487 default:
1488 return GNUNET_SYSERR;
1489 }
1490}

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

1495{
1496 GNUNET_assert (message);
1497
1498 switch (message->header.kind)
1499 {
1501 return &(message->body.subscribe.discourse);
1503 return &(message->body.talk.discourse);
1504 default:
1505 return NULL;
1506 }
1507}
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 iterate_flag_for_cleanup_discourse_message(), and put_store_message().

Here is the caller graph for this function: