GNUnet 0.26.2-44-g5a6b2f9a5
 
Loading...
Searching...
No Matches
messenger_api_message.c File Reference
Include dependency graph for messenger_api_message.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MessageSignature
 
struct  GNUNET_MESSENGER_ShortMessage
 

Macros

#define member_size(type, member)   sizeof(((type*) NULL)->member)
 
#define max(x, y)   (x > y? x : y)
 
#define min(x, y)   (x < y? x : y)
 
#define encode_step_ext(dst, offset, src, size)
 
#define encode_step(dst, offset, src)
 
#define encode_step_key(dst, offset, src, length)
 
#define encode_step_hpke_key(dst, offset, src, length)
 
#define encode_step_signature(dst, offset, src, length)
 
#define decode_step_ext(src, offset, dst, size)
 
#define decode_step(src, offset, dst)
 
#define decode_step_malloc(src, offset, dst, size, zero)
 
#define decode_step_key(src, offset, dst, length)
 
#define decode_step_hpke_key(src, offset, dst, length)
 

Typedefs

typedef uint32_t kind_t
 

Functions

struct GNUNET_MESSENGER_Messagecreate_message (enum GNUNET_MESSENGER_MessageKind kind)
 Creates and allocates a new message with a specific kind.
 
struct GNUNET_MESSENGER_Messagecopy_message (const struct GNUNET_MESSENGER_Message *message)
 Creates and allocates a copy of a given message.
 
void copy_message_header (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_MessageHeader *header)
 Copy message header details from another message to a given message.
 
static void destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
 
void cleanup_message (struct GNUNET_MESSENGER_Message *message)
 Frees the messages body memory.
 
void destroy_message (struct GNUNET_MESSENGER_Message *message)
 Destroys a message and frees its memory fully.
 
enum GNUNET_GenericReturnValue is_message_session_bound (const struct GNUNET_MESSENGER_Message *message)
 Returns if the message should be bound to a member session.
 
static void fold_short_message (const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened)
 
static void unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)
 
static uint16_t get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind)
 
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.
 
static uint16_t get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body)
 
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.
 
static uint16_t get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, enum GNUNET_GenericReturnValue include_body)
 
static uint16_t calc_usual_padding ()
 
static uint16_t calc_padded_length (uint16_t length)
 
static void encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
 
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.
 
static void encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer)
 
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)
 
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.
 
static enum GNUNET_GenericReturnValue decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)
 
void hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
 Calculates a hash of a given buffer with a length in bytes from a message.
 
void sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
 Signs the hash of a message with a given private key and writes the signature into the buffer as well.
 
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.
 
static enum GNUNET_GenericReturnValue calc_message_hmac (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_HashCode *hmac)
 
enum GNUNET_GenericReturnValue sign_message_by_key (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Signs the message body via it's own hmac with a specific shared key.
 
enum GNUNET_GenericReturnValue verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
 Verifies the signature of a given message and its hash with a specific public key.
 
enum GNUNET_GenericReturnValue verify_message_by_peer (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_PeerIdentity *identity)
 Verifies the signature of a given message and its hash with a specific peer's identity.
 
enum GNUNET_GenericReturnValue verify_message_by_key (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Verifies the hmac of a given message body with a specific shared key.
 
enum GNUNET_GenericReturnValue encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
 Encrypts a message using a given public key and replaces its body and kind with the now private encrypted message.
 
enum GNUNET_GenericReturnValue decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key)
 Decrypts a private message using a given private key and replaces its body and kind with the inner encrypted message.
 
struct GNUNET_MESSENGER_Messagetranscribe_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
 Transcribes a message as a new transcript message using a given public key from the recipient of the encrypted message content.
 
enum GNUNET_GenericReturnValue encrypt_secret_message (struct GNUNET_MESSENGER_Message *message, const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Encrypts a message using a given shared key from an announcement of an epoch and replaces its body and kind with the inner encrypted message.
 
enum GNUNET_GenericReturnValue decrypt_secret_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
 Decrypts a secret message using a given shared key and replaces its body and kind with the inner encrypted message.
 
enum GNUNET_GenericReturnValue read_transcript_message (struct GNUNET_MESSENGER_Message *message)
 Read the original message from a transcript message and replaces its body and kind with the inner encrypted message.
 
enum GNUNET_GenericReturnValue extract_access_message_key (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
 Extracts the shared epoch or group key from an access message using the private ephemeral key from an epoch and verifies it via the HMAC from the message body.
 
enum GNUNET_GenericReturnValue extract_authorization_message_key (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
 Extracts the shared epoch or group key from an authorization message using a previously exchanged shared key and verifies it via the HMAC from the message body.
 
struct GNUNET_TIME_Relative get_message_timeout (const struct GNUNET_MESSENGER_Message *message)
 Return the relative timeout of the content from a given message that controls when a delayed handling action of this message needs to be processed at least.
 
struct GNUNET_MQ_Envelopepack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, 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.
 
enum GNUNET_GenericReturnValue is_peer_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message can be sent by the service without usage of a clients private key.
 
enum GNUNET_GenericReturnValue is_service_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message contains service critical information.
 
enum GNUNET_GenericReturnValue is_epoch_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a certain kind of message from storage contains some specific details that might be required for the overall message graph to function as intended.
 
enum GNUNET_GenericReturnValue filter_message_sending (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message should be sent by a client.
 
const struct GNUNET_ShortHashCodeget_message_discourse (const struct GNUNET_MESSENGER_Message *message)
 Returns the discourse hash of a message depending on its kind.
 

Variables

const uint16_t encryption_overhead
 

Macro Definition Documentation

◆ member_size

#define member_size (   type,
  member 
)    sizeof(((type*) NULL)->member)

Definition at line 301 of file messenger_api_message.c.

◆ max

#define max (   x,
 
)    (x > y? x : y)

Definition at line 591 of file messenger_api_message.c.

◆ min

#define min (   x,
 
)    (x < y? x : y)

Definition at line 620 of file messenger_api_message.c.

◆ encode_step_ext

#define encode_step_ext (   dst,
  offset,
  src,
  size 
)
Value:
do { \
GNUNET_memcpy (dst + offset, src, size); \
offset += size; \
} while (0)
static unsigned int size
Size of the "table".
Definition peer.c:68

Definition at line 622 of file messenger_api_message.c.

622 { \
623 GNUNET_memcpy (dst + offset, src, size); \
624 offset += size; \
625} while (0)

◆ encode_step

#define encode_step (   dst,
  offset,
  src 
)
Value:
do { \
encode_step_ext (dst, offset, src, sizeof(*src)); \
} while (0)

Definition at line 627 of file messenger_api_message.c.

627 { \
628 encode_step_ext (dst, offset, src, sizeof(*src)); \
629} while (0)

◆ encode_step_key

#define encode_step_key (   dst,
  offset,
  src,
  length 
)
Value:
do { \
src, dst + offset, length - offset); \
if (result < 0) \
GNUNET_break (0); \
else \
offset += result; \
} while (0)
static int result
Global testing status.
ssize_t GNUNET_CRYPTO_write_blindable_pk_to_buffer(const struct GNUNET_CRYPTO_BlindablePublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_BlindablePublicKey to a compact buffer.

Definition at line 631 of file messenger_api_message.c.

631 { \
633 src, dst + offset, length - offset); \
634 if (result < 0) \
635 GNUNET_break (0); \
636 else \
637 offset += result; \
638} while (0)

◆ encode_step_hpke_key

#define encode_step_hpke_key (   dst,
  offset,
  src,
  length 
)
Value:
do { \
src, dst + offset, length - offset); \
if (result < 0) \
GNUNET_break (0); \
else \
offset += result; \
} while (0)
ssize_t GNUNET_CRYPTO_write_hpke_pk_to_buffer(const struct GNUNET_CRYPTO_HpkePublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_HpkePublicKey to a compact buffer.

Definition at line 640 of file messenger_api_message.c.

640 { \
642 src, dst + offset, length - offset); \
643 if (result < 0) \
644 GNUNET_break (0); \
645 else \
646 offset += result; \
647} while (0)

◆ encode_step_signature

#define encode_step_signature (   dst,
  offset,
  src,
  length 
)
Value:
do { \
src, dst + offset, length - offset); \
if (result < 0) \
GNUNET_break (0); \
else \
offset += result; \
} while (0)
ssize_t GNUNET_CRYPTO_write_blinded_key_signature_to_buffer(const struct GNUNET_CRYPTO_BlindableKeySignature *sig, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_BlindableKeySignature to a compact buffer.

Definition at line 649 of file messenger_api_message.c.

649 { \
651 src, dst + offset, length - offset); \
652 if (result < 0) \
653 GNUNET_break (0); \
654 else \
655 offset += result; \
656} while (0)

◆ decode_step_ext

#define decode_step_ext (   src,
  offset,
  dst,
  size 
)
Value:
do { \
GNUNET_memcpy (dst, src + offset, size); \
offset += size; \
} while (0)

Definition at line 921 of file messenger_api_message.c.

921 { \
922 GNUNET_memcpy (dst, src + offset, size); \
923 offset += size; \
924} while (0)

◆ decode_step

#define decode_step (   src,
  offset,
  dst 
)
Value:
do { \
decode_step_ext (src, offset, dst, sizeof(*dst)); \
} while (0)

Definition at line 926 of file messenger_api_message.c.

926 { \
927 decode_step_ext (src, offset, dst, sizeof(*dst)); \
928} while (0)

◆ decode_step_malloc

#define decode_step_malloc (   src,
  offset,
  dst,
  size,
  zero 
)
Value:
do { \
dst = GNUNET_malloc (size + zero); \
if (zero) dst[size] = 0; \
decode_step_ext (src, offset, dst, size); \
} while (0)
static const struct GNUNET_CRYPTO_BlindablePrivateKey zero
Public key of all zeros.
#define GNUNET_malloc(size)
Wrapper around malloc.

Definition at line 930 of file messenger_api_message.c.

930 { \
931 dst = GNUNET_malloc (size + zero); \
932 if (zero) dst[size] = 0; \
933 decode_step_ext (src, offset, dst, size); \
934} while (0)

◆ decode_step_key

#define decode_step_key (   src,
  offset,
  dst,
  length 
)
Value:
do { \
size_t read; \
src + offset, length - offset, dst, &read); \
GNUNET_break (0); \
else \
offset += read; \
} while (0)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_blindable_pk_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_BlindablePublicKey *key, size_t *read)
Reads a GNUNET_CRYPTO_BlindablePublicKey from a compact buffer.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SYSERR

Definition at line 936 of file messenger_api_message.c.

936 { \
938 size_t read; \
940 src + offset, length - offset, dst, &read); \
941 if (GNUNET_SYSERR == result) \
942 GNUNET_break (0); \
943 else \
944 offset += read; \
945} while (0)

◆ decode_step_hpke_key

#define decode_step_hpke_key (   src,
  offset,
  dst,
  length 
)
Value:
do { \
size_t read; \
src + offset, length - offset, dst, &read); \
GNUNET_break (0); \
else \
offset += read; \
} while (0)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_hpke_pk_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_HpkePublicKey *key, size_t *read)
Reads a GNUNET_CRYPTO_HpkePublicKey from a compact buffer.

Definition at line 947 of file messenger_api_message.c.

947 { \
949 size_t read; \
951 src + offset, length - offset, dst, &read); \
952 if (GNUNET_SYSERR == result) \
953 GNUNET_break (0); \
954 else \
955 offset += read; \
956} while (0)

Typedef Documentation

◆ kind_t

typedef uint32_t kind_t

Definition at line 455 of file messenger_api_message.c.

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

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

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

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

Here is the caller graph for this function:

◆ copy_message()

struct GNUNET_MESSENGER_Message * copy_message ( const struct GNUNET_MESSENGER_Message message)

Creates and allocates a copy of a given message.

Parameters
[in]messageMessage
Returns
New message

Definition at line 98 of file messenger_api_message.c.

99{
100 struct GNUNET_MESSENGER_Message *copy;
101
102 GNUNET_assert (message);
103
104 copy = GNUNET_new (struct GNUNET_MESSENGER_Message);
105 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
106
107 switch (message->header.kind)
108 {
110 copy->body.name.name = message->body.name.name? GNUNET_strdup (
111 message->body.name.name) : NULL;
112 break;
114 copy->body.text.text = message->body.text.text? GNUNET_strdup (
115 message->body.text.text) : NULL;
116 break;
118 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
119 message->body.file.uri) : NULL;
120 break;
123 copy->body.privacy.length) : NULL;
124
125 if (copy->body.privacy.data)
126 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
127 copy->body.privacy.length);
128
129 break;
131 copy->body.ticket.identifier = message->body.ticket.identifier?
133 message->body.ticket.identifier) : NULL;
134 break;
137 copy->body.transcript.length) : NULL;
138
139 if (copy->body.transcript.data)
141 copy->body.transcript.length);
142
143 break;
145 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
146 message->body.tag.tag) : NULL;
147 break;
149 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
150 copy->body.talk.length) : NULL;
151
152 if (copy->body.talk.data)
153 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
154 copy->body.talk.length);
155
156 break;
158 copy->body.secret.data = copy->body.secret.length ? GNUNET_malloc (
159 copy->body.secret.length) : NULL;
160
161 if (copy->body.secret.data)
162 GNUNET_memcpy (copy->body.secret.data, message->body.secret.data,
163 copy->body.secret.length);
164
165 break;
166 default:
167 break;
168 }
169
170 return copy;
171}
#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_.

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

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

Here is the caller graph for this function:

◆ copy_message_header()

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

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

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

Definition at line 175 of file messenger_api_message.c.

177{
179
180 GNUNET_assert ((message) && (header));
181
182 kind = message->header.kind;
183
184 GNUNET_memcpy (&(message->header), header,
185 sizeof(struct GNUNET_MESSENGER_MessageHeader));
186
187 message->header.kind = kind;
188}
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:

◆ destroy_message_body()

static void destroy_message_body ( enum GNUNET_MESSENGER_MessageKind  kind,
struct GNUNET_MESSENGER_MessageBody body 
)
static

Definition at line 192 of file messenger_api_message.c.

194{
195 GNUNET_assert (body);
196
197 switch (kind)
198 {
200 if (body->name.name)
201 GNUNET_free (body->name.name);
202 break;
204 if (body->text.text)
205 GNUNET_free (body->text.text);
206 break;
208 if (body->file.uri)
209 GNUNET_free (body->file.uri);
210 break;
212 if (body->privacy.data)
213 GNUNET_free (body->privacy.data);
214 break;
216 if (body->ticket.identifier)
218 break;
220 if (body->transcript.data)
222 break;
224 if (body->tag.tag)
225 GNUNET_free (body->tag.tag);
226 break;
228 if (body->talk.data)
229 GNUNET_free (body->talk.data);
230 break;
232 if (body->secret.data)
233 GNUNET_free (body->secret.data);
234 break;
235 default:
236 break;
237 }
238}
#define GNUNET_free(ptr)
Wrapper around free.

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

Referenced by cleanup_message(), destroy_message(), encrypt_message(), encrypt_secret_message(), and unfold_short_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 242 of file messenger_api_message.c.

243{
244 GNUNET_assert (message);
245
246 destroy_message_body (message->header.kind, &(message->body));
247}
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)

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

263{
264 GNUNET_assert (message);
265
266 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
268 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
269 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
271 return GNUNET_YES;
272 else
273 return GNUNET_NO;
274}
@ 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:

◆ fold_short_message()

static void fold_short_message ( const struct GNUNET_MESSENGER_Message message,
struct GNUNET_MESSENGER_ShortMessage shortened 
)
static

Definition at line 278 of file messenger_api_message.c.

280{
281 shortened->kind = message->header.kind;
282
283 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
285}
The unified body of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessageBody body
enum GNUNET_MESSENGER_MessageKind kind

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_ShortMessage::body, GNUNET_memcpy, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, and GNUNET_MESSENGER_ShortMessage::kind.

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

Here is the caller graph for this function:

◆ unfold_short_message()

static void unfold_short_message ( struct GNUNET_MESSENGER_ShortMessage shortened,
struct GNUNET_MESSENGER_Message message 
)
static

Definition at line 289 of file messenger_api_message.c.

291{
292 destroy_message_body (message->header.kind, &(message->body));
293
294 message->header.kind = shortened->kind;
295
296 GNUNET_memcpy (&(message->body), &(shortened->body),
297 sizeof(struct GNUNET_MESSENGER_MessageBody));
298}

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

Referenced by decrypt_message(), decrypt_secret_message(), encrypt_message(), encrypt_secret_message(), and read_transcript_message().

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

◆ get_message_body_kind_size()

static uint16_t get_message_body_kind_size ( enum GNUNET_MESSENGER_MessageKind  kind)
static

Definition at line 304 of file messenger_api_message.c.

305{
306 uint16_t length;
307
308 length = 0;
309
310 switch (kind)
311 {
313 length += member_size (struct GNUNET_MESSENGER_Message,
314 body.info.messenger_version);
315 break;
317 length += member_size (struct GNUNET_MESSENGER_Message,
318 body.join.epoch);
319 break;
321 length += member_size (struct GNUNET_MESSENGER_Message,
322 body.leave.epoch);
323 break;
325 length += member_size (struct GNUNET_MESSENGER_Message, body.peer.peer);
326 break;
328 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
329 break;
331 length += member_size (struct GNUNET_MESSENGER_Message, body.miss.peer);
332 break;
334 length += member_size (struct GNUNET_MESSENGER_Message,
335 body.merge.epochs[0]);
336 length += member_size (struct GNUNET_MESSENGER_Message,
337 body.merge.epochs[1]);
338 length += member_size (struct GNUNET_MESSENGER_Message,
339 body.merge.previous);
340 break;
342 length += member_size (struct GNUNET_MESSENGER_Message, body.request.hash);
343 break;
345 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door);
346 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key);
347 break;
349 length += member_size (struct GNUNET_MESSENGER_Message, body.file.key);
350 length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash);
351 length += member_size (struct GNUNET_MESSENGER_Message, body.file.name);
352 break;
354 length += member_size (struct GNUNET_MESSENGER_Message, body.deletion.hash);
355 length += member_size (struct GNUNET_MESSENGER_Message,
356 body.deletion.delay);
357 break;
359 length += member_size (struct GNUNET_MESSENGER_Message,
360 body.connection.amount);
361 length += member_size (struct GNUNET_MESSENGER_Message,
362 body.connection.flags);
363 break;
365 length += member_size (struct GNUNET_MESSENGER_Message,
366 body.transcript.hash);
367 break;
369 length += member_size (struct GNUNET_MESSENGER_Message, body.tag.hash);
370 break;
372 length += member_size (struct GNUNET_MESSENGER_Message,
373 body.subscription.discourse);
374 length += member_size (struct GNUNET_MESSENGER_Message,
375 body.subscription.time);
376 length += member_size (struct GNUNET_MESSENGER_Message,
377 body.subscription.flags);
378 break;
380 length += member_size (struct GNUNET_MESSENGER_Message,
381 body.talk.discourse);
382 break;
384 length += member_size (struct GNUNET_MESSENGER_Message,
385 body.announcement.identifier);
386 length += member_size (struct GNUNET_MESSENGER_Message,
387 body.announcement.key);
388 length += member_size (struct GNUNET_MESSENGER_Message,
389 body.announcement.nonce);
390 length += member_size (struct GNUNET_MESSENGER_Message,
391 body.announcement.timeout);
392 length += member_size (struct GNUNET_MESSENGER_Message,
393 body.announcement.hmac);
394 break;
396 length += member_size (struct GNUNET_MESSENGER_Message,
397 body.secret.identifier);
398 length += member_size (struct GNUNET_MESSENGER_Message,
399 body.secret.iv);
400 length += member_size (struct GNUNET_MESSENGER_Message,
401 body.secret.hmac);
402 break;
404 length += member_size (struct GNUNET_MESSENGER_Message,
405 body.appeal.event);
406 length += member_size (struct GNUNET_MESSENGER_Message,
407 body.appeal.key);
408 length += member_size (struct GNUNET_MESSENGER_Message,
409 body.appeal.timeout);
410 break;
412 length += member_size (struct GNUNET_MESSENGER_Message,
413 body.access.event);
414 length += member_size (struct GNUNET_MESSENGER_Message,
415 body.access.key);
416 length += member_size (struct GNUNET_MESSENGER_Message,
417 body.access.hmac);
418 break;
420 length += member_size (struct GNUNET_MESSENGER_Message,
421 body.revolution.identifier);
422 length += member_size (struct GNUNET_MESSENGER_Message,
423 body.revolution.nonce);
424 length += member_size (struct GNUNET_MESSENGER_Message,
425 body.revolution.hmac);
426 break;
428 length += member_size (struct GNUNET_MESSENGER_Message,
429 body.group.identifier);
430 length += member_size (struct GNUNET_MESSENGER_Message,
431 body.group.initiator);
432 length += member_size (struct GNUNET_MESSENGER_Message,
433 body.group.partner);
434 length += member_size (struct GNUNET_MESSENGER_Message,
435 body.group.timeout);
436 break;
438 length += member_size (struct GNUNET_MESSENGER_Message,
439 body.authorization.identifier);
440 length += member_size (struct GNUNET_MESSENGER_Message,
441 body.authorization.event);
442 length += member_size (struct GNUNET_MESSENGER_Message,
443 body.authorization.key);
444 length += member_size (struct GNUNET_MESSENGER_Message,
445 body.authorization.hmac);
446 break;
447 default:
448 break;
449 }
450
451 return length;
452}
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_AUTHORIZATION
The authorization kind.
@ GNUNET_MESSENGER_KIND_ANNOUNCEMENT
The announcement kind.
@ GNUNET_MESSENGER_KIND_APPEAL
The appeal kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_ACCESS
The access kind.
@ GNUNET_MESSENGER_KIND_REVOLUTION
The revolution kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBTION
The subscription kind.
@ GNUNET_MESSENGER_KIND_DELETION
The deletion kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_KIND_GROUP
The group kind.
#define member_size(type, member)

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::appeal, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessageDeletion::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribtion::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageJoin::epoch, GNUNET_MESSENGER_MessageLeave::epoch, GNUNET_MESSENGER_MessageMerge::epochs, GNUNET_MESSENGER_MessageAppeal::event, GNUNET_MESSENGER_MessageAccess::event, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_MESSENGER_MessageSubscribtion::flags, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageBody::group, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageDeletion::hash, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageSecret::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageAnnouncement::identifier, GNUNET_MESSENGER_MessageSecret::identifier, GNUNET_MESSENGER_MessageRevolution::identifier, GNUNET_MESSENGER_MessageGroup::identifier, GNUNET_MESSENGER_MessageAuthorization::identifier, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageGroup::initiator, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageSecret::iv, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageFile::key, GNUNET_MESSENGER_MessageAnnouncement::key, GNUNET_MESSENGER_MessageAppeal::key, GNUNET_MESSENGER_MessageAccess::key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageBody::leave, member_size, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageInfo::messenger_version, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageAnnouncement::nonce, GNUNET_MESSENGER_MessageRevolution::nonce, GNUNET_MESSENGER_MessageGroup::partner, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageBody::revolution, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageBody::subscription, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageSubscribtion::time, GNUNET_MESSENGER_MessageAnnouncement::timeout, GNUNET_MESSENGER_MessageAppeal::timeout, GNUNET_MESSENGER_MessageGroup::timeout, and GNUNET_MESSENGER_MessageBody::transcript.

Referenced by get_message_kind_size(), and get_short_message_size().

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

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

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_body_size()

static uint16_t get_message_body_size ( enum GNUNET_MESSENGER_MessageKind  kind,
const struct GNUNET_MESSENGER_MessageBody body 
)
static

Definition at line 479 of file messenger_api_message.c.

481{
482 uint16_t length;
483
484 length = 0;
485
486 switch (kind)
487 {
491 break;
493 length += (body->name.name ? strlen (body->name.name) : 0);
494 break;
496 length += GNUNET_CRYPTO_blindable_pk_get_length (&(body->key.key));
497 length += GNUNET_CRYPTO_hpke_pk_get_length (&(body->key.hpke_key));
498 break;
500 length += (body->text.text ? strlen (body->text.text) : 0);
501 break;
503 length += (body->file.uri ? strlen (body->file.uri) : 0);
504 break;
506 length += body->privacy.length;
507 break;
509 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
510 break;
513 length += body->transcript.length;
514 break;
516 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
517 break;
519 length += body->talk.length;
520 break;
522 length += body->secret.length;
523 break;
524 default:
525 break;
526 }
527
528 return length;
529}
ssize_t GNUNET_CRYPTO_hpke_pk_get_length(const struct GNUNET_CRYPTO_HpkePublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_HpkePublicKey.
ssize_t GNUNET_CRYPTO_blindable_pk_get_length(const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_BlindablePublicKey.
Definition crypto_pkey.c:85
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_CRYPTO_BlindablePublicKey key
The senders blindable public key to verify its signatures.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The senders HPKE public key to encrypt private messages with.
struct GNUNET_CRYPTO_BlindablePublicKey key
The new blindable public key which replaces the current senders public key.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The new HPKE public key which replaces the current senders HPKE public key.
struct GNUNET_CRYPTO_BlindablePublicKey key
The key from the recipient of the original message.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageBody::file, GNUNET_CRYPTO_blindable_pk_get_length(), GNUNET_CRYPTO_hpke_pk_get_length(), GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageJoin::hpke_key, GNUNET_MESSENGER_MessageKey::hpke_key, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageTag::tag, GNUNET_MESSENGER_MessageBody::tag, GNUNET_MESSENGER_MessageBody::talk, GNUNET_MESSENGER_MessageText::text, GNUNET_MESSENGER_MessageBody::text, GNUNET_MESSENGER_MessageBody::ticket, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by get_message_size(), and get_short_message_size().

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

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

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

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

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

◆ get_short_message_size()

static uint16_t get_short_message_size ( const struct GNUNET_MESSENGER_ShortMessage message,
enum GNUNET_GenericReturnValue  include_body 
)
static

Definition at line 554 of file messenger_api_message.c.

556{
557 uint16_t minimum_size;
558
559 minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
560
561 if (message)
562 return minimum_size + get_message_body_kind_size (message->kind)
563 + (include_body == GNUNET_YES?
564 get_message_body_size (message->kind, &(message->body)) : 0);
565 else
566 return minimum_size;
567}
A 512-bit hashcode.

References GNUNET_MESSENGER_ShortMessage::body, get_message_body_kind_size(), get_message_body_size(), GNUNET_YES, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by decode_short_message(), encrypt_message(), encrypt_secret_message(), and transcribe_message().

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

◆ calc_usual_padding()

static uint16_t calc_usual_padding ( )
static

Definition at line 571 of file messenger_api_message.c.

572{
573 uint16_t padding;
574 uint16_t kind_size;
575
576 padding = 0;
577
578 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
579 {
581 GNUNET_YES);
582
583 if (kind_size > padding)
584 padding = kind_size;
585 }
586
587 return padding + GNUNET_MESSENGER_PADDING_MIN;
588}
#define GNUNET_MESSENGER_KIND_MAX
#define GNUNET_MESSENGER_PADDING_MIN

References get_message_kind_size(), GNUNET_MESSENGER_KIND_MAX, GNUNET_MESSENGER_PADDING_MIN, and GNUNET_YES.

Referenced by calc_padded_length().

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

◆ calc_padded_length()

static uint16_t calc_padded_length ( uint16_t  length)
static

Definition at line 594 of file messenger_api_message.c.

595{
596 static uint16_t usual_padding = 0;
597 uint16_t padded_length;
598
599 if (! usual_padding)
600 usual_padding = calc_usual_padding ();
601
602 padded_length = max (
604 usual_padding);
605
606 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
608
609 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
611
612 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
614
616
617}
static uint16_t calc_usual_padding()
#define max(x, y)
#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE
#define GNUNET_MESSENGER_PADDING_LEVEL0
#define GNUNET_MESSENGER_PADDING_LEVEL2
#define GNUNET_MESSENGER_PADDING_LEVEL1

References calc_usual_padding(), GNUNET_MESSENGER_MAX_MESSAGE_SIZE, GNUNET_MESSENGER_PADDING_LEVEL0, GNUNET_MESSENGER_PADDING_LEVEL1, GNUNET_MESSENGER_PADDING_LEVEL2, GNUNET_MESSENGER_PADDING_MIN, and max.

Referenced by encrypt_message(), encrypt_secret_message(), and pack_message().

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

◆ encode_message_body()

static void encode_message_body ( enum GNUNET_MESSENGER_MessageKind  kind,
const struct GNUNET_MESSENGER_MessageBody body,
uint16_t  length,
char *  buffer,
uint16_t  offset 
)
static

Definition at line 659 of file messenger_api_message.c.

664{
665 uint32_t value0, value1;
666
667 GNUNET_assert ((body) && (buffer));
668
669 switch (kind)
670 {
672 value0 = GNUNET_htobe32 (body->info.messenger_version);
673
674 encode_step (buffer, offset, &value0);
675 break;
677 encode_step (buffer, offset, &(body->join.epoch));
678 encode_step_key (buffer, offset, &(body->join.key), length);
679 encode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
680 break;
682 encode_step (buffer, offset, &(body->leave.epoch));
683 break;
685 if (body->name.name)
687 buffer,
688 offset,
689 body->name.name,
690 min (length - offset, strlen (body->name.name)));
691 break;
693 encode_step_key (buffer, offset, &(body->key.key), length);
694 encode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
695 break;
697 encode_step (buffer, offset, &(body->peer.peer));
698 break;
700 encode_step (buffer, offset, &(body->id.id));
701 break;
703 encode_step (buffer, offset, &(body->miss.peer));
704 break;
706 encode_step (buffer, offset, &(body->merge.epochs[0]));
707 encode_step (buffer, offset, &(body->merge.epochs[1]));
708 encode_step (buffer, offset, &(body->merge.previous));
709 break;
711 encode_step (buffer, offset, &(body->request.hash));
712 break;
714 encode_step (buffer, offset, &(body->invite.door));
715 encode_step (buffer, offset, &(body->invite.key));
716 break;
718 if (body->text.text)
720 buffer,
721 offset,
722 body->text.text,
723 min (length - offset, strlen (body->text.text)));
724 break;
726 encode_step (buffer, offset, &(body->file.key));
727 encode_step (buffer, offset, &(body->file.hash));
728 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
729 if (body->file.uri)
730 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
731 strlen (
732 body->file.uri)));
733 break;
735 if (body->privacy.data)
736 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
737 body->privacy.
738 length));
739 break;
741 encode_step (buffer, offset, &(body->deletion.hash));
742 encode_step (buffer, offset, &(body->deletion.delay));
743 break;
745 value0 = GNUNET_htobe32 (body->connection.amount);
746 value1 = GNUNET_htobe32 (body->connection.flags);
747
748 encode_step (buffer, offset, &value0);
749 encode_step (buffer, offset, &value1);
750 break;
752 encode_step_ext (buffer, offset, body->ticket.identifier,
753 min (length - offset, strlen (body->ticket.identifier)));
754 break;
756 encode_step (buffer, offset, &(body->transcript.hash));
757 encode_step_key (buffer, offset, &(body->transcript.key), length);
758
759 if (body->transcript.data)
760 encode_step_ext (buffer, offset, body->transcript.data, min (length
761 - offset,
762 body->
763 transcript.
764 length));
765 break;
767 encode_step (buffer, offset, &(body->tag.hash));
768
769 if (body->tag.tag)
770 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
771 strlen (
772 body->tag.tag)));
773 break;
775 value0 = GNUNET_htobe32 (body->subscription.flags);
776
777 encode_step (buffer, offset, &(body->subscription.discourse));
778 encode_step (buffer, offset, &(body->subscription.time));
779 encode_step (buffer, offset, &value0);
780 break;
782 encode_step (buffer, offset, &(body->talk.discourse));
783
784 if (body->talk.data)
785 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
786 body->talk.
787 length));
788 break;
790 encode_step (buffer, offset, &(body->announcement.identifier));
791 encode_step (buffer, offset, &(body->announcement.key));
792 encode_step (buffer, offset, &(body->announcement.nonce));
793 encode_step (buffer, offset, &(body->announcement.timeout));
794 encode_step (buffer, offset, &(body->announcement.hmac));
795 break;
797 encode_step (buffer, offset, &(body->secret.identifier));
798 encode_step (buffer, offset, &(body->secret.iv));
799 encode_step (buffer, offset, &(body->secret.hmac));
800
801 if (body->secret.data)
802 encode_step_ext (buffer, offset, body->secret.data, min (length - offset,
803 body->secret.
804 length));
805 break;
807 encode_step (buffer, offset, &(body->appeal.event));
808 encode_step (buffer, offset, &(body->appeal.key));
809 encode_step (buffer, offset, &(body->appeal.timeout));
810 break;
812 encode_step (buffer, offset, &(body->access.event));
813 encode_step (buffer, offset, &(body->access.key));
814 encode_step (buffer, offset, &(body->access.hmac));
815 break;
817 encode_step (buffer, offset, &(body->revolution.identifier));
818 encode_step (buffer, offset, &(body->revolution.nonce));
819 encode_step (buffer, offset, &(body->revolution.hmac));
820 break;
822 encode_step (buffer, offset, &(body->group.identifier));
823 encode_step (buffer, offset, &(body->group.initiator));
824 encode_step (buffer, offset, &(body->group.partner));
825 encode_step (buffer, offset, &(body->group.timeout));
826 break;
828 encode_step (buffer, offset, &(body->authorization.identifier));
829 encode_step (buffer, offset, &(body->authorization.event));
830 encode_step (buffer, offset, &(body->authorization.key));
831 encode_step (buffer, offset, &(body->authorization.hmac));
832 break;
833 default:
834 break;
835 }
836
837 if (offset >= length)
838 return;
839
840 {
841 uint16_t padding;
842 uint16_t used_padding;
843
844 padding = length - offset;
845 used_padding = sizeof(padding) + sizeof(char);
846
847 GNUNET_assert (padding >= used_padding);
848
849 buffer[offset++] = '\0';
850
851 if (padding > used_padding)
853 padding - used_padding);
854
855 GNUNET_memcpy (buffer + length - sizeof(padding), &padding,
856 sizeof(padding));
857 }
858}
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_htobe32(x)
#define encode_step_ext(dst, offset, src, size)
#define encode_step(dst, offset, src)
#define encode_step_hpke_key(dst, offset, src, length)
#define min(x, y)
#define encode_step_key(dst, offset, src, length)
struct GNUNET_HashCode hmac
The hmac of the access.
struct GNUNET_HashCode event
The hash of the linked announcement or group message event.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)+16+sizeof(struct GNUNET_CRYPTO_HpkeEncapsulation)]
The encrypted group or epoch key.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the announcement.
struct GNUNET_HashCode hmac
The hmac of the announcement.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to appeal access.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to receive access.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the appeal.
struct GNUNET_HashCode event
The hash of the linked announcement message event.
struct GNUNET_HashCode event
The hash of the linked group message event.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode hmac
The hmac of the authorization.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)]
The encrypted group or epoch key.
struct GNUNET_MESSENGER_MessageAnnouncement announcement
struct GNUNET_MESSENGER_MessageGroup group
struct GNUNET_MESSENGER_MessageDeletion deletion
struct GNUNET_MESSENGER_MessageConnection connection
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageLeave leave
struct GNUNET_MESSENGER_MessageRevolution revolution
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_MESSENGER_MessageAccess access
struct GNUNET_MESSENGER_MessageSubscribtion subscription
struct GNUNET_MESSENGER_MessageAuthorization authorization
struct GNUNET_MESSENGER_MessageAppeal appeal
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessageInfo info
uint32_t amount
The amount of connections of a peer.
uint32_t flags
The flags about the connections of a peer.
struct GNUNET_HashCode hash
The hash of the message to delete.
struct GNUNET_TIME_RelativeNBO delay
The delay of the delete operation to get processed.
struct GNUNET_HashCode hash
The hash of the original file.
struct GNUNET_CRYPTO_SymmetricSessionKey key
The symmetric key to decrypt the file.
char name[NAME_MAX]
The name of the original file.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the group formation.
struct GNUNET_HashCode initiator
The hash of the initiator group announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode partner
The hash of the partner group announcement.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
uint32_t messenger_version
The version of GNUnet Messenger API.
union GNUNET_MESSENGER_RoomKey key
The hash identifying the port of the room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_HashCode epoch
The previous epoch the message was sent from.
struct GNUNET_HashCode epoch
The previous epoch the message was sent from.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_HashCode epochs[2]
The previous epochs the message was sent from.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_HashCode hash
The hash of the requested message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the revolution.
struct GNUNET_HashCode hmac
The hmac of the revolution.
uint8_t iv[sizeof(struct GNUNET_CRYPTO_SymmetricInitializationVector)]
The IV of the secret message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_HashCode hmac
The hmac of the encrypted message.
uint32_t flags
The flags about the subscription to a discourse.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscription.
struct GNUNET_HashCode hash
The hash of the message to tag.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to talk.
struct GNUNET_HashCode hash
The hash of the original message.

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::appeal, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageSecret::data, GNUNET_MESSENGER_MessageDeletion::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribtion::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, encode_step, encode_step_ext, encode_step_hpke_key, encode_step_key, GNUNET_MESSENGER_MessageJoin::epoch, GNUNET_MESSENGER_MessageLeave::epoch, GNUNET_MESSENGER_MessageMerge::epochs, GNUNET_MESSENGER_MessageAppeal::event, GNUNET_MESSENGER_MessageAccess::event, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_MESSENGER_MessageSubscribtion::flags, GNUNET_assert, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block(), GNUNET_htobe32, GNUNET_memcpy, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_MessageBody::group, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageDeletion::hash, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageSecret::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, GNUNET_MESSENGER_MessageJoin::hpke_key, GNUNET_MESSENGER_MessageKey::hpke_key, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageAnnouncement::identifier, GNUNET_MESSENGER_MessageSecret::identifier, GNUNET_MESSENGER_MessageRevolution::identifier, GNUNET_MESSENGER_MessageGroup::identifier, GNUNET_MESSENGER_MessageAuthorization::identifier, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageGroup::initiator, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageSecret::iv, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageFile::key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageAnnouncement::key, GNUNET_MESSENGER_MessageAppeal::key, GNUNET_MESSENGER_MessageAccess::key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageBody::leave, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageInfo::messenger_version, min, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageAnnouncement::nonce, GNUNET_MESSENGER_MessageRevolution::nonce, GNUNET_MESSENGER_MessageGroup::partner, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageBody::revolution, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageBody::subscription, 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_MessageSubscribtion::time, GNUNET_MESSENGER_MessageAnnouncement::timeout, GNUNET_MESSENGER_MessageAppeal::timeout, GNUNET_MESSENGER_MessageGroup::timeout, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by encode_message(), and encode_short_message().

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

866{
867 uint16_t offset;
868 kind_t kind;
869
870 GNUNET_assert ((message) && (buffer));
871
872 offset = 0;
873
874 if (GNUNET_YES == include_header)
875 encode_step_signature (buffer, offset, &(message->header.signature),
876 length);
877
878 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
879
880 if (GNUNET_YES == include_header)
881 {
882 encode_step (buffer, offset, &(message->header.timestamp));
883 encode_step (buffer, offset, &(message->header.sender_id));
884 encode_step (buffer, offset, &(message->header.previous));
885 }
886
887 encode_step (buffer, offset, &kind);
888
889 encode_message_body (message->header.kind, &(message->body),
890 length, buffer, offset);
891}
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:

◆ encode_short_message()

static void encode_short_message ( const struct GNUNET_MESSENGER_ShortMessage message,
uint16_t  length,
char *  buffer 
)
static

Definition at line 895 of file messenger_api_message.c.

898{
899 struct GNUNET_HashCode hash;
900 uint16_t offset;
901 kind_t kind;
902
903 GNUNET_assert ((message) && (buffer));
904
905 offset = sizeof(hash);
906 kind = GNUNET_htobe32 ((kind_t) message->kind);
907
908 encode_step (buffer, offset, &kind);
909
910 encode_message_body (message->kind, &(message->body), length, buffer, offset);
911
913 buffer + sizeof(hash),
914 length - sizeof(hash),
915 &hash);
916
917 GNUNET_memcpy (buffer, &hash, sizeof(hash));
918}
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_MESSENGER_ShortMessage::body, encode_message_body(), encode_step, GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_htobe32, GNUNET_memcpy, and GNUNET_MESSENGER_ShortMessage::kind.

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

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

◆ decode_message_body()

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 
)
static

Definition at line 959 of file messenger_api_message.c.

964{
965 uint16_t padding;
966 uint32_t value0, value1;
967
968 GNUNET_assert ((kind) && (body) && (buffer));
969
970 padding = 0;
971
972 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
973
974 if (padding > length - offset)
975 padding = 0;
976
977 {
978 uint16_t end_zero;
979 end_zero = length - padding;
980
981 if ((padding) && (buffer[end_zero] != '\0'))
982 padding = 0;
983 }
984
985 length -= padding;
986
987 switch (*kind)
988 {
990 decode_step (buffer, offset, &value0);
991
992 body->info.messenger_version = GNUNET_be32toh (value0);
993 break;
995 decode_step (buffer, offset, &(body->join.epoch));
996 decode_step_key (buffer, offset, &(body->join.key), length);
997 decode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
998 break;
1000 decode_step (buffer, offset, &(body->leave.epoch));
1001 break;
1003 if (length > offset)
1004 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
1005 else
1006 body->name.name = NULL;
1007 break;
1009 decode_step_key (buffer, offset, &(body->key.key), length);
1010 decode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
1011 break;
1013 decode_step (buffer, offset, &(body->peer.peer));
1014 break;
1016 decode_step (buffer, offset, &(body->id.id));
1017 break;
1019 decode_step (buffer, offset, &(body->miss.peer));
1020 break;
1022 decode_step (buffer, offset, &(body->merge.epochs[0]));
1023 decode_step (buffer, offset, &(body->merge.epochs[1]));
1024 decode_step (buffer, offset, &(body->merge.previous));
1025 break;
1027 decode_step (buffer, offset, &(body->request.hash));
1028 break;
1030 decode_step (buffer, offset, &(body->invite.door));
1031 decode_step (buffer, offset, &(body->invite.key));
1032 break;
1034 if (length > offset)
1035 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
1036 else
1037 body->text.text = NULL;
1038 break;
1040 decode_step (buffer, offset, &(body->file.key));
1041 decode_step (buffer, offset, &(body->file.hash));
1042 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
1043 if (length > offset)
1044 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
1045 else
1046 body->file.uri = NULL;
1047 break;
1049 if (length > offset)
1050 {
1051 body->privacy.length = (length - offset);
1052 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
1053 0);
1054 }
1055 else
1056 {
1057 body->privacy.length = 0;
1058 body->privacy.data = NULL;
1059 }
1060
1061 break;
1063 decode_step (buffer, offset, &(body->deletion.hash));
1064 decode_step (buffer, offset, &(body->deletion.delay));
1065 break;
1067 decode_step (buffer, offset, &value0);
1068 decode_step (buffer, offset, &value1);
1069
1070 body->connection.amount = GNUNET_be32toh (value0);
1071 body->connection.flags = GNUNET_be32toh (value1);
1072 break;
1074 if (length > offset)
1075 decode_step_malloc (buffer, offset, body->ticket.identifier, length
1076 - offset, 1);
1077 else
1078 body->ticket.identifier = NULL;
1079 break;
1081 decode_step (buffer, offset, &(body->transcript.hash));
1082 decode_step_key (buffer, offset, &(body->transcript.key), length);
1083
1084 if (length > offset)
1085 {
1086 body->transcript.length = (length - offset);
1087 decode_step_malloc (buffer, offset, body->transcript.data,
1088 length - offset, 0);
1089 }
1090 else
1091 {
1092 body->transcript.length = 0;
1093 body->transcript.data = NULL;
1094 }
1095
1096 break;
1098 decode_step (buffer, offset, &(body->tag.hash));
1099 if (length > offset)
1100 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
1101 else
1102 body->tag.tag = NULL;
1103 break;
1105 decode_step (buffer, offset, &(body->subscription.discourse));
1106 decode_step (buffer, offset, &(body->subscription.time));
1107 decode_step (buffer, offset, &value0);
1108
1109 body->subscription.flags = GNUNET_be32toh (value0);
1110 break;
1112 decode_step (buffer, offset, &(body->talk.discourse));
1113
1114 if (length > offset)
1115 {
1116 body->talk.length = (length - offset);
1117 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
1118 0);
1119 }
1120 else
1121 {
1122 body->talk.length = 0;
1123 body->talk.data = NULL;
1124 }
1125
1126 break;
1128 decode_step (buffer, offset, &(body->announcement.identifier));
1129 decode_step (buffer, offset, &(body->announcement.key));
1130 decode_step (buffer, offset, &(body->announcement.nonce));
1131 decode_step (buffer, offset, &(body->announcement.timeout));
1132 decode_step (buffer, offset, &(body->announcement.hmac));
1133 break;
1135 decode_step (buffer, offset, &(body->secret.identifier));
1136 decode_step (buffer, offset, &(body->secret.iv));
1137 decode_step (buffer, offset, &(body->secret.hmac));
1138
1139 if (length > offset)
1140 {
1141 body->secret.length = (length - offset);
1142 decode_step_malloc (buffer, offset, body->secret.data, length - offset,
1143 0);
1144 }
1145 else
1146 {
1147 body->secret.length = 0;
1148 body->secret.data = NULL;
1149 }
1150
1151 break;
1153 decode_step (buffer, offset, &(body->appeal.event));
1154 decode_step (buffer, offset, &(body->appeal.key));
1155 decode_step (buffer, offset, &(body->appeal.timeout));
1156 break;
1158 decode_step (buffer, offset, &(body->access.event));
1159 decode_step (buffer, offset, &(body->access.key));
1160 decode_step (buffer, offset, &(body->access.hmac));
1161 break;
1163 decode_step (buffer, offset, &(body->revolution.identifier));
1164 decode_step (buffer, offset, &(body->revolution.nonce));
1165 decode_step (buffer, offset, &(body->revolution.hmac));
1166 break;
1168 decode_step (buffer, offset, &(body->group.identifier));
1169 decode_step (buffer, offset, &(body->group.initiator));
1170 decode_step (buffer, offset, &(body->group.partner));
1171 decode_step (buffer, offset, &(body->group.timeout));
1172 break;
1174 decode_step (buffer, offset, &(body->authorization.identifier));
1175 decode_step (buffer, offset, &(body->authorization.event));
1176 decode_step (buffer, offset, &(body->authorization.key));
1177 decode_step (buffer, offset, &(body->authorization.hmac));
1178 break;
1179 default:
1181 break;
1182 }
1183
1184 return padding;
1185}
#define GNUNET_be32toh(x)
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
#define decode_step(src, offset, dst)
#define decode_step_key(src, offset, dst, length)
#define decode_step_hpke_key(src, offset, dst, length)
#define decode_step_malloc(src, offset, dst, size, zero)
#define decode_step_ext(src, offset, dst, size)

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageConnection::amount, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::appeal, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_MessageBody::connection, GNUNET_MESSENGER_MessagePrivate::data, GNUNET_MESSENGER_MessageTranscript::data, GNUNET_MESSENGER_MessageTalk::data, GNUNET_MESSENGER_MessageSecret::data, decode_step, decode_step_ext, decode_step_hpke_key, decode_step_key, decode_step_malloc, GNUNET_MESSENGER_MessageDeletion::delay, GNUNET_MESSENGER_MessageBody::deletion, GNUNET_MESSENGER_MessageSubscribtion::discourse, GNUNET_MESSENGER_MessageTalk::discourse, GNUNET_MESSENGER_MessageInvite::door, GNUNET_MESSENGER_MessageJoin::epoch, GNUNET_MESSENGER_MessageLeave::epoch, GNUNET_MESSENGER_MessageMerge::epochs, GNUNET_MESSENGER_MessageAppeal::event, GNUNET_MESSENGER_MessageAccess::event, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_MESSENGER_MessageBody::file, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_MESSENGER_MessageSubscribtion::flags, GNUNET_assert, GNUNET_be32toh, GNUNET_memcpy, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_APPEAL, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_GROUP, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_KIND_SECRET, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_MESSENGER_KIND_TAG, GNUNET_MESSENGER_KIND_TALK, GNUNET_MESSENGER_KIND_TEXT, GNUNET_MESSENGER_KIND_TICKET, GNUNET_MESSENGER_KIND_TRANSCRIPT, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_MESSENGER_MessageBody::group, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MessageFile::hash, GNUNET_MESSENGER_MessageDeletion::hash, GNUNET_MESSENGER_MessageTranscript::hash, GNUNET_MESSENGER_MessageTag::hash, GNUNET_MESSENGER_MessageAnnouncement::hmac, GNUNET_MESSENGER_MessageSecret::hmac, GNUNET_MESSENGER_MessageAccess::hmac, GNUNET_MESSENGER_MessageRevolution::hmac, GNUNET_MESSENGER_MessageAuthorization::hmac, GNUNET_MESSENGER_MessageJoin::hpke_key, GNUNET_MESSENGER_MessageKey::hpke_key, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_MessageTicket::identifier, GNUNET_MESSENGER_MessageAnnouncement::identifier, GNUNET_MESSENGER_MessageSecret::identifier, GNUNET_MESSENGER_MessageRevolution::identifier, GNUNET_MESSENGER_MessageGroup::identifier, GNUNET_MESSENGER_MessageAuthorization::identifier, GNUNET_MESSENGER_MessageBody::info, GNUNET_MESSENGER_MessageGroup::initiator, GNUNET_MESSENGER_MessageBody::invite, GNUNET_MESSENGER_MessageSecret::iv, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageInvite::key, GNUNET_MESSENGER_MessageFile::key, GNUNET_MESSENGER_MessageTranscript::key, GNUNET_MESSENGER_MessageAnnouncement::key, GNUNET_MESSENGER_MessageAppeal::key, GNUNET_MESSENGER_MessageAccess::key, GNUNET_MESSENGER_MessageAuthorization::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageBody::leave, GNUNET_MESSENGER_MessagePrivate::length, GNUNET_MESSENGER_MessageTranscript::length, GNUNET_MESSENGER_MessageTalk::length, GNUNET_MESSENGER_MessageSecret::length, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageInfo::messenger_version, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageFile::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageAnnouncement::nonce, GNUNET_MESSENGER_MessageRevolution::nonce, GNUNET_MESSENGER_MessageGroup::partner, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageMiss::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageBody::privacy, GNUNET_MESSENGER_MessageBody::request, GNUNET_MESSENGER_MessageBody::revolution, GNUNET_MESSENGER_MessageBody::secret, GNUNET_MESSENGER_MessageBody::subscription, 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_MessageSubscribtion::time, GNUNET_MESSENGER_MessageAnnouncement::timeout, GNUNET_MESSENGER_MessageAppeal::timeout, GNUNET_MESSENGER_MessageGroup::timeout, GNUNET_MESSENGER_MessageBody::transcript, and GNUNET_MESSENGER_MessageFile::uri.

Referenced by decode_message(), and decode_short_message().

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

1194{
1195 uint16_t offset;
1196 uint16_t count;
1197 kind_t kind;
1198
1200 (message) &&
1201 (buffer) &&
1203 include_header)));
1204
1205 offset = 0;
1206
1207 if (GNUNET_YES == include_header)
1208 {
1209 ssize_t result;
1210
1212 &(message->header.signature), buffer, length - offset);
1213
1214 if (result < 0)
1215 return GNUNET_NO;
1216 else
1217 offset += result;
1218 }
1219
1220 count = length - offset;
1222 include_header))
1223 return GNUNET_NO;
1224
1225 if (GNUNET_YES == include_header)
1226 {
1227 decode_step (buffer, offset, &(message->header.timestamp));
1228 decode_step (buffer, offset, &(message->header.sender_id));
1229 decode_step (buffer, offset, &(message->header.previous));
1230 }
1231
1232 decode_step (buffer, offset, &kind);
1233 kind = GNUNET_be32toh (kind);
1234
1235 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1236
1237 if (count < get_message_kind_size (message->header.kind, include_header))
1238 return GNUNET_NO;
1239
1240 {
1241 uint16_t result;
1242 result = decode_message_body (&(message->header.kind),
1243 &(message->body), length, buffer, offset);
1244
1245 if (padding)
1246 *padding = result;
1247 }
1248
1249 return GNUNET_YES;
1250}
ssize_t GNUNET_CRYPTO_read_blinded_key_signature_from_buffer(struct GNUNET_CRYPTO_BlindableKeySignature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_BlindableKeySignature from a compact buffer.
static uint16_t decode_message_body(enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)

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

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

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

◆ decode_short_message()

static enum GNUNET_GenericReturnValue decode_short_message ( struct GNUNET_MESSENGER_ShortMessage message,
uint16_t  length,
const char *  buffer 
)
static

Definition at line 1254 of file messenger_api_message.c.

1257{
1258 struct GNUNET_HashCode expected, hash;
1259 uint16_t offset;
1260 kind_t kind;
1261
1262 GNUNET_assert ((message) && (buffer));
1263
1264 offset = sizeof(hash);
1265
1266 if (length < get_short_message_size (NULL, GNUNET_NO))
1267 return GNUNET_NO;
1268
1269 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1270
1272 buffer + sizeof(hash),
1273 length - sizeof(hash),
1274 &expected);
1275
1276 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1277 return GNUNET_NO;
1278
1279 decode_step (buffer, offset, &kind);
1280 kind = GNUNET_be32toh (kind);
1281
1282 message->kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1283
1284 if (length < get_short_message_size (message, GNUNET_NO))
1285 return GNUNET_NO;
1286
1287 decode_message_body (&(message->kind), &(message->body), length, buffer,
1288 offset);
1289
1290 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1291 return GNUNET_NO;
1292
1293 return GNUNET_YES;
1294}
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
static uint16_t get_short_message_size(const struct GNUNET_MESSENGER_ShortMessage *message, enum GNUNET_GenericReturnValue include_body)

References GNUNET_MESSENGER_ShortMessage::body, decode_message_body(), decode_step, get_short_message_size(), GNUNET_assert, GNUNET_be32toh, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_cmp(), GNUNET_memcpy, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_NO, GNUNET_YES, and GNUNET_MESSENGER_ShortMessage::kind.

Referenced by decrypt_message(), decrypt_secret_message(), and read_transcript_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 1298 of file messenger_api_message.c.

1302{
1303 ssize_t offset;
1304
1305 GNUNET_assert ((message) && (buffer) && (hash));
1306
1308 signature));
1309
1310 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1311}

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

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

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

◆ sign_message()

void sign_message ( struct GNUNET_MESSENGER_Message message,
uint16_t  length,
char *  buffer,
const struct GNUNET_HashCode hash,
const struct GNUNET_CRYPTO_BlindablePrivateKey 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 1315 of file messenger_api_message.c.

1320{
1321 GNUNET_assert ((message) && (buffer) && (hash) && (key));
1322
1323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1324 GNUNET_h2s (hash));
1325
1326 {
1327 struct GNUNET_MESSENGER_MessageSignature signature;
1328
1330 signature.purpose.size = htonl (sizeof(signature));
1331
1332 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1333 GNUNET_CRYPTO_blinded_key_sign (key, &signature, &(message->header.signature
1334 ));
1335 }
1336
1337 message->header.signature.type = key->type;
1338
1339 {
1340 uint16_t offset = 0;
1342 buffer,
1343 offset,
1344 &(message->header.signature),
1345 length);
1346 }
1347}
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
#define GNUNET_log(kind,...)
#define GNUNET_CRYPTO_blinded_key_sign(priv, ps, sig)
Sign a given block with GNUNET_CRYPTO_BlindablePrivateKey.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
struct GNUNET_CRYPTO_SignaturePurpose purpose

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

Referenced by send_message_to_room().

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

◆ sign_message_by_peer()

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

1356{
1357 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
1358
1359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1360 GNUNET_h2s (hash));
1361
1362 {
1363 struct GNUNET_MESSENGER_MessageSignature signature;
1365 signature.purpose.size = htonl (sizeof (signature));
1366
1367 GNUNET_memcpy (&(signature.hash), hash, sizeof (signature.hash));
1369 &(message->header.signature
1370 .
1371 eddsa_signature));
1372 }
1373
1375
1376 {
1377 uint16_t offset = 0;
1379 buffer,
1380 offset,
1381 &(message->header.signature),
1382 length);
1383 }
1384}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blinded_key_sign_by_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_SignaturePurpose *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_blinded_key_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_SignaturePurpose::purpose, GNUNET_MESSENGER_MessageSignature::purpose, GNUNET_MESSENGER_MessageHeader::signature, GNUNET_CRYPTO_SignaturePurpose::size, and GNUNET_CRYPTO_BlindableKeySignature::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:

◆ calc_message_hmac()

static enum GNUNET_GenericReturnValue calc_message_hmac ( const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_CRYPTO_SymmetricSessionKey key,
struct GNUNET_HashCode hmac 
)
static

Definition at line 1388 of file messenger_api_message.c.

1391{
1392 struct GNUNET_CRYPTO_AuthKey auth_key;
1393
1394 GNUNET_assert ((message) && (key) && (hmac));
1395
1396 switch (message->header.kind)
1397 {
1400 &auth_key, sizeof (auth_key),
1403 key, sizeof (*key),
1406 return GNUNET_NO;
1407
1408 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.announcement),
1409 sizeof (message->body.announcement)
1410 - sizeof (*hmac),
1411 hmac);
1412 return GNUNET_YES;
1415 &auth_key, sizeof (auth_key),
1418 key, sizeof (*key),
1420 return GNUNET_NO;
1421
1422 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.access),
1423 sizeof (message->body.access)
1424 - sizeof (*hmac),
1425 hmac);
1426 return GNUNET_YES;
1429 &auth_key, sizeof (auth_key),
1432 key, sizeof (*key),
1435 return GNUNET_NO;
1436
1437 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.revolution),
1438 sizeof (message->body.revolution)
1439 - sizeof (*hmac),
1440 hmac);
1441 return GNUNET_YES;
1444 &auth_key, sizeof (auth_key),
1447 key, sizeof (*key),
1450 return GNUNET_NO;
1451
1452 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.authorization),
1453 sizeof (message->body.authorization)
1454 - sizeof (*hmac),
1455 hmac);
1456 return GNUNET_YES;
1457 default:
1458 return GNUNET_SYSERR;
1459 }
1460}
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
#define GNUNET_CRYPTO_kdf_arg_auto(d)
#define GNUNET_CRYPTO_kdf_arg(d, s)
#define GNUNET_MESSENGER_EPOCH_NONCE_BYTES
#define GNUNET_MESSENGER_SALT_EPOCH_KEY
#define GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY
#define GNUNET_MESSENGER_SALT_GROUP_KEY
type for (message) authentication keys

References GNUNET_MESSENGER_MessageBody::access, GNUNET_MESSENGER_MessageBody::announcement, GNUNET_MESSENGER_MessageBody::authorization, GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageAccess::event, GNUNET_MESSENGER_MessageAuthorization::event, GNUNET_assert, GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_hmac(), GNUNET_CRYPTO_kdf_arg, GNUNET_CRYPTO_kdf_arg_auto, GNUNET_MESSENGER_EPOCH_NONCE_BYTES, GNUNET_MESSENGER_KIND_ACCESS, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_MESSENGER_KIND_AUTHORIZATION, GNUNET_MESSENGER_KIND_REVOLUTION, GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY, GNUNET_MESSENGER_SALT_EPOCH_KEY, GNUNET_MESSENGER_SALT_GROUP_KEY, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageAnnouncement::identifier, GNUNET_MESSENGER_MessageRevolution::identifier, GNUNET_MESSENGER_MessageAuthorization::identifier, key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageAnnouncement::nonce, GNUNET_MESSENGER_MessageRevolution::nonce, and GNUNET_MESSENGER_MessageBody::revolution.

Referenced by sign_message_by_key(), and verify_message_by_key().

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

◆ sign_message_by_key()

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

Signs the message body via it's own hmac with a specific shared key.

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

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

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

Definition at line 1464 of file messenger_api_message.c.

1466{
1467 struct GNUNET_HashCode *hmac;
1468
1469 GNUNET_assert ((message) && (key));
1470
1471 switch (message->header.kind)
1472 {
1474 hmac = &(message->body.announcement.hmac);
1475 break;
1477 hmac = &(message->body.access.hmac);
1478 break;
1480 hmac = &(message->body.revolution.hmac);
1481 break;
1483 hmac = &(message->body.authorization.hmac);
1484 break;
1485 default:
1486 hmac = NULL;
1487 break;
1488 }
1489
1490 if (! hmac)
1491 return GNUNET_SYSERR;
1492
1493 return calc_message_hmac (message, key, hmac);
1494}
static enum GNUNET_GenericReturnValue calc_message_hmac(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_HashCode *hmac)

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

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

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

◆ verify_message()

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

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

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

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

Definition at line 1498 of file messenger_api_message.c.

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

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

Referenced by verify_member_session_as_sender().

Here is the caller graph for this function:

◆ verify_message_by_peer()

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

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

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

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

Definition at line 1521 of file messenger_api_message.c.

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

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

Referenced by get_store_peer_of(), and verify_store_peer().

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

◆ verify_message_by_key()

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

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

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

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

Definition at line 1545 of file messenger_api_message.c.

1547{
1548 const struct GNUNET_HashCode *msg_hmac;
1549 struct GNUNET_HashCode hmac;
1550
1551 GNUNET_assert ((message) && (key));
1552
1553 switch (message->header.kind)
1554 {
1556 msg_hmac = &(message->body.announcement.hmac);
1557 break;
1559 msg_hmac = &(message->body.access.hmac);
1560 break;
1562 msg_hmac = &(message->body.revolution.hmac);
1563 break;
1565 msg_hmac = &(message->body.authorization.hmac);
1566 break;
1567 default:
1568 msg_hmac = NULL;
1569 break;
1570 }
1571
1572 if (! msg_hmac)
1573 return GNUNET_SYSERR;
1574
1575 if (GNUNET_YES != calc_message_hmac (message, key, &hmac))
1576 return GNUNET_SYSERR;
1577
1578 if (0 == GNUNET_CRYPTO_hash_cmp (&hmac, msg_hmac))
1579 return GNUNET_OK;
1580
1581 return GNUNET_SYSERR;
1582}
@ GNUNET_OK

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

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

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

◆ encrypt_message()

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

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

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

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

Definition at line 1586 of file messenger_api_message.c.

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

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

Referenced by dequeue_message_from_room(), and send_message_to_room_with_key().

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

◆ decrypt_message()

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

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

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

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

Definition at line 1646 of file messenger_api_message.c.

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

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

Referenced by handle_private_message().

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

◆ transcribe_message()

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

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

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

Definition at line 1711 of file messenger_api_message.c.

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

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

Referenced by send_message_to_room_with_key().

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

◆ encrypt_secret_message()

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

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

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

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

Definition at line 1752 of file messenger_api_message.c.

1756{
1758 struct GNUNET_MESSENGER_ShortMessage shortened;
1759 uint16_t length, padded_length;
1760 uint8_t *data;
1761
1762 GNUNET_assert ((message) && (identifier) && (key));
1763
1764 fold_short_message (message, &shortened);
1765
1766 length = get_short_message_size (&shortened, GNUNET_YES);
1767 padded_length = calc_padded_length (length + 0);
1768
1769 GNUNET_assert (padded_length >= length + 0);
1770
1772
1773 GNUNET_memcpy (&(message->body.secret.identifier), identifier,
1774 sizeof (message->body.secret.identifier));
1775
1777 &(message->body.secret.iv),
1779
1780 message->body.secret.data = GNUNET_malloc (padded_length);
1781 message->body.secret.length = padded_length;
1782
1783 result = GNUNET_NO;
1784 data = GNUNET_malloc (padded_length);
1785
1786 encode_short_message (&shortened, padded_length, (char *) data);
1787
1788 {
1790
1792 &iv, sizeof (iv),
1795 key, sizeof (*key),
1797 {
1798 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving initialization vector failed!\n");
1799 unfold_short_message (&shortened, message);
1800 goto cleanup;
1801 }
1802
1803 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (data, padded_length, key,
1804 &iv, message->body.secret.data))
1805 {
1806 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1807 unfold_short_message (&shortened, message);
1808 goto cleanup;
1809 }
1810 }
1811
1812 {
1813 struct GNUNET_CRYPTO_AuthKey auth_key;
1814
1816 &auth_key, sizeof (auth_key),
1819 key, sizeof (*key),
1821 {
1822 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving authentication key failed!\n");
1823 unfold_short_message (&shortened, message);
1824 goto cleanup;
1825 }
1826
1827 GNUNET_CRYPTO_hmac (&auth_key, message->body.secret.data, padded_length,
1828 &(message->body.secret.hmac));
1829 }
1830
1831 destroy_message_body (shortened.kind, &(shortened.body));
1833
1834cleanup:
1835 GNUNET_free (data);
1836 return result;
1837}
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#define GNUNET_MESSENGER_SECRET_IV_BYTES
#define GNUNET_MESSENGER_SALT_SECRET_KEY
#define GNUNET_MESSENGER_SALT_SECRET_IV

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

Referenced by send_message_to_room().

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

◆ decrypt_secret_message()

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

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

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

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

Definition at line 1841 of file messenger_api_message.c.

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

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

Referenced by update_room_secret_message().

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

◆ read_transcript_message()

enum GNUNET_GenericReturnValue read_transcript_message ( struct GNUNET_MESSENGER_Message message)

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

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

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

Definition at line 1929 of file messenger_api_message.c.

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

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

Referenced by handle_transcript_message().

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

◆ extract_access_message_key()

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

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

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

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

Definition at line 1955 of file messenger_api_message.c.

1959{
1960 GNUNET_assert ((message) && (key) && (shared_key) &&
1962
1963 if (GNUNET_OK !=
1965 (uint8_t*) "messenger",
1966 strlen ("messenger"),
1967 NULL, 0,
1968 (uint8_t*) message->body.access.key,
1970 (uint8_t*) shared_key,
1971 NULL))
1972 {
1973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1974 return GNUNET_NO;
1975 }
1976
1977 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1978 {
1979 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1980 return GNUNET_NO;
1981 }
1982
1983 return GNUNET_YES;
1984}
#define GNUNET_MESSENGER_ACCESS_KEY_BYTES
enum GNUNET_GenericReturnValue verify_message_by_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Verifies the hmac of a given message body with a specific shared key.

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

Referenced by handle_epoch_announcement_access(), and handle_epoch_group_access().

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

◆ extract_authorization_message_key()

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

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

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

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

Definition at line 1988 of file messenger_api_message.c.

1993{
1995
1996 GNUNET_assert ((message) && (key) && (shared_key) &&
1998
2000 &iv, sizeof (iv),
2003 key,
2004 sizeof (*key),
2007 {
2008 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving initialization vector failed!\n");
2009 return GNUNET_NO;
2010 }
2011
2014 key,
2015 &iv,
2016 shared_key))
2017 {
2018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
2019 return GNUNET_NO;
2020 }
2021
2022 if (GNUNET_OK != verify_message_by_key (message, shared_key))
2023 {
2024 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
2025 return GNUNET_NO;
2026 }
2027
2028 return GNUNET_YES;
2029}
#define GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES

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

Referenced by handle_authorization_message().

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

◆ get_message_timeout()

struct GNUNET_TIME_Relative get_message_timeout ( const struct GNUNET_MESSENGER_Message message)

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

Parameters
[in]messageMessage
Returns
Relative timeout of message

Definition at line 2033 of file messenger_api_message.c.

2034{
2037
2038 GNUNET_assert (message);
2039
2041
2042 switch (message->header.kind)
2043 {
2046 break;
2049 break;
2052 break;
2055 break;
2056 default:
2058 break;
2059 }
2060
2062
2066
2067 return timeout;
2068}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition gnunet-arm.c:118
static uint64_t timestamp(void)
Get current timestamp.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition time.c:344
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition time.c:133
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition time.c:626
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_(void)
Return relative time of 1 minute.
Definition time.c:178
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition time.c:452
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.

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

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

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

◆ pack_message()

struct GNUNET_MQ_Envelope * pack_message ( struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash,
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 2072 of file messenger_api_message.c.

2077{
2078 struct GNUNET_MessageHeader *header;
2079 uint16_t length, padded_length;
2080 struct GNUNET_MQ_Envelope *env;
2081 char *buffer;
2082
2083 GNUNET_assert (message);
2084
2086 "Packing message kind=%u and sender: %s\n",
2087 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
2088
2089 length = get_message_size (message, GNUNET_YES);
2090 padded_length = calc_padded_length (length);
2091
2093 {
2094 env = GNUNET_MQ_msg_extra (header, padded_length,
2096 buffer = (char*) &(header[1]);
2097 }
2098 else
2099 {
2100 env = NULL;
2101 buffer = GNUNET_malloc (padded_length);
2102 }
2103
2104 encode_message (message, padded_length, buffer, GNUNET_YES);
2105
2106 if (hash)
2107 {
2108 hash_message (message, length, buffer, hash);
2109
2110 if (sign)
2111 sign (cls, message, length, buffer, hash);
2112 }
2113
2115 GNUNET_free (buffer);
2116
2117 return env;
2118}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static enum @52 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a 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.
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE
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 2122 of file messenger_api_message.c.

2123{
2124 GNUNET_assert (message);
2125
2126 switch (message->header.kind)
2127 {
2133 return GNUNET_YES;
2134 default:
2135 return GNUNET_NO;
2136 }
2137}

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

2142{
2143 GNUNET_assert (message);
2144
2145 if (GNUNET_YES == is_peer_message (message))
2146 return GNUNET_YES;
2147
2148 switch (message->header.kind)
2149 {
2151 return GNUNET_YES; // Reserved for connection handling only!
2153 return GNUNET_YES; // Reserved for member handling only!
2155 return GNUNET_YES; // Reserved for member handling only!
2157 return GNUNET_YES; // Reserved for member name handling only!
2159 return GNUNET_YES; // Reserved for member key handling only!
2161 return GNUNET_YES; // Reserved for connection handling only!
2163 return GNUNET_YES; // Reserved for member id handling only!
2165 return GNUNET_YES; // Reserved for connection handling only!
2167 return GNUNET_YES; // Reserved for peers only!
2169 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
2171 return GNUNET_NO;
2173 return GNUNET_NO;
2175 return GNUNET_NO;
2177 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2179 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
2181 return GNUNET_YES; // Reserved for connection handling only!
2183 return GNUNET_NO;
2185 return GNUNET_NO;
2187 return GNUNET_NO;
2189 return GNUNET_YES; // Reserved for subscription handling only!
2191 return GNUNET_NO;
2193 return GNUNET_YES; // Reserved for epoch and group key exchange!
2195 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2197 return GNUNET_YES; // Reserved for epoch key exchange!
2199 return GNUNET_YES; // Reserved for epoch and group key exchange!
2201 return GNUNET_YES; // Reserved for epoch and group key revoking!
2203 return GNUNET_YES; // Reserved for group key exchange!
2205 return GNUNET_YES; // Reserved for epoch and group key exchange!
2206 default:
2207 return GNUNET_SYSERR;
2208 }
2209}
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...

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

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

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

◆ is_epoch_message()

enum GNUNET_GenericReturnValue is_epoch_message ( const struct GNUNET_MESSENGER_Message message)

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

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

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

Definition at line 2213 of file messenger_api_message.c.

2214{
2215 GNUNET_assert (message);
2216
2217 switch (message->header.kind)
2218 {
2220 return GNUNET_YES;
2222 return GNUNET_YES;
2224 return GNUNET_YES;
2225 default:
2226 return GNUNET_NO;
2227 }
2228}

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

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

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

2233{
2234 GNUNET_assert (message);
2235
2236 if (GNUNET_YES == is_peer_message (message))
2237 return GNUNET_SYSERR; // Requires signature of peer rather than member!
2238
2239 switch (message->header.kind)
2240 {
2242 return GNUNET_SYSERR; // Reserved for connection handling only!
2244 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
2246 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
2248 return GNUNET_YES;
2250 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
2252 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
2254 return GNUNET_NO; // Reserved for member id handling only!
2256 return GNUNET_SYSERR; // Reserved for connection handling only!
2258 return GNUNET_SYSERR; // Reserved for peers only!
2260 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
2262 return GNUNET_YES;
2264 return GNUNET_YES;
2266 return GNUNET_YES;
2268 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2270 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
2272 return GNUNET_SYSERR; // Reserved for connection handling only!
2274 return GNUNET_YES;
2276 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2278 return GNUNET_YES;
2280 return GNUNET_YES;
2282 return GNUNET_YES;
2284 return GNUNET_NO; // Should only be used for implicit key exchange!
2286 return GNUNET_NO; // Should only be used for implicit forward secrecy!
2288 return GNUNET_NO; // Should only be used for implicit key exchange!
2290 return GNUNET_NO; // Should only be used for implicit key exchange!
2292 return GNUNET_NO; // Should only be used for implicit key exchange!
2294 return GNUNET_NO; // Should only be used for implicit key exchange!
2296 return GNUNET_NO; // Should only be used for implicit key exchange!
2297 default:
2298 return GNUNET_SYSERR;
2299 }
2300}

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

Referenced by check_send_message(), and GNUNET_MESSENGER_send_message().

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

◆ get_message_discourse()

const struct GNUNET_ShortHashCode * get_message_discourse ( const struct GNUNET_MESSENGER_Message message)

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

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

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

Definition at line 2304 of file messenger_api_message.c.

2305{
2306 GNUNET_assert (message);
2307
2308 switch (message->header.kind)
2309 {
2311 return &(message->body.subscription.discourse);
2313 return &(message->body.talk.discourse);
2314 default:
2315 return NULL;
2316 }
2317}

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

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

Here is the caller graph for this function:

Variable Documentation

◆ encryption_overhead

const uint16_t encryption_overhead
Initial value:

Definition at line 33 of file messenger_api_message.c.

Referenced by decrypt_message(), and encrypt_message().