GNUnet 0.27.0
 
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_signature (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
 Encodes the signature of a given message into a buffer of a maximum length in bytes.
 
void encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
 Encodes a given message into a buffer of a maximum length in bytes.
 
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 maximum 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, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
 Signs the hash of a message with a given private key.
 
struct GNUNET_PILS_Operationsign_message_by_peer (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, struct GNUNET_PILS_Handle *pils, const GNUNET_PILS_SignResultCallback sign_cb, void *cls)
 Signs the hash of a message with the peer identity of a given pils service going into a callback with a custom closure on success.
 
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, enum GNUNET_MESSENGER_PackMode mode)
 Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE.
 
enum GNUNET_GenericReturnValue is_peer_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message can be sent by the service without usage of a clients private key.
 
enum GNUNET_GenericReturnValue is_service_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message contains service critical information.
 
enum GNUNET_GenericReturnValue is_epoch_message (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a certain kind of message from storage contains some specific details that might be required for the overall message graph to function as intended.
 
enum GNUNET_GenericReturnValue filter_message_sending (const struct GNUNET_MESSENGER_Message *message)
 Returns whether a specific kind of message should be sent by a client.
 
const struct GNUNET_ShortHashCodeget_message_discourse (const struct GNUNET_MESSENGER_Message *message)
 Returns the discourse hash of a message depending on its kind.
 

Variables

const uint16_t encryption_overhead
 

Macro Definition Documentation

◆ member_size

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

Definition at line 302 of file messenger_api_message.c.

◆ max

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

Definition at line 592 of file messenger_api_message.c.

◆ min

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

Definition at line 621 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 623 of file messenger_api_message.c.

623 { \
624 GNUNET_memcpy (dst + offset, src, size); \
625 offset += size; \
626} 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 628 of file messenger_api_message.c.

628 { \
629 encode_step_ext (dst, offset, src, sizeof(*src)); \
630} 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 632 of file messenger_api_message.c.

632 { \
634 src, dst + offset, length - offset); \
635 if (result < 0) \
636 GNUNET_break (0); \
637 else \
638 offset += result; \
639} 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 641 of file messenger_api_message.c.

641 { \
643 src, dst + offset, length - offset); \
644 if (result < 0) \
645 GNUNET_break (0); \
646 else \
647 offset += result; \
648} 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 650 of file messenger_api_message.c.

650 { \
652 src, dst + offset, length - offset); \
653 if (result < 0) \
654 GNUNET_break (0); \
655 else \
656 offset += result; \
657} 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 936 of file messenger_api_message.c.

936 { \
937 GNUNET_memcpy (dst, src + offset, size); \
938 offset += size; \
939} 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 941 of file messenger_api_message.c.

941 { \
942 decode_step_ext (src, offset, dst, sizeof(*dst)); \
943} 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 945 of file messenger_api_message.c.

945 { \
946 dst = GNUNET_malloc (size + zero); \
947 if (zero) dst[size] = 0; \
948 decode_step_ext (src, offset, dst, size); \
949} 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 951 of file messenger_api_message.c.

951 { \
953 size_t read; \
955 src + offset, length - offset, dst, &read); \
956 if (GNUNET_SYSERR == result) \
957 GNUNET_break (0); \
958 else \
959 offset += read; \
960} 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 962 of file messenger_api_message.c.

962 { \
964 size_t read; \
966 src + offset, length - offset, dst, &read); \
967 if (GNUNET_SYSERR == result) \
968 GNUNET_break (0); \
969 else \
970 offset += read; \
971} while (0)

Typedef Documentation

◆ kind_t

typedef uint32_t kind_t

Definition at line 456 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 50 of file messenger_api_message.c.

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

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

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

Here is the caller graph for this function:

◆ copy_message()

struct GNUNET_MESSENGER_Message * copy_message ( const struct GNUNET_MESSENGER_Message message)

Creates and allocates a copy of a given message.

Parameters
[in]messageMessage
Returns
New message

Definition at line 99 of file messenger_api_message.c.

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

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

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

Here is the caller graph for this function:

◆ copy_message_header()

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

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

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

Definition at line 176 of file messenger_api_message.c.

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

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

Referenced by handle_room_message(), and handle_transcript_message().

Here is the caller graph for this function:

◆ destroy_message_body()

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

Definition at line 193 of file messenger_api_message.c.

195{
196 GNUNET_assert (body);
197
198 switch (kind)
199 {
201 if (body->name.name)
202 GNUNET_free (body->name.name);
203 break;
205 if (body->text.text)
206 GNUNET_free (body->text.text);
207 break;
209 if (body->file.uri)
210 GNUNET_free (body->file.uri);
211 break;
213 if (body->privacy.data)
214 GNUNET_free (body->privacy.data);
215 break;
217 if (body->ticket.identifier)
219 break;
221 if (body->transcript.data)
223 break;
225 if (body->tag.tag)
226 GNUNET_free (body->tag.tag);
227 break;
229 if (body->talk.data)
230 GNUNET_free (body->talk.data);
231 break;
233 if (body->secret.data)
234 GNUNET_free (body->secret.data);
235 break;
236 default:
237 break;
238 }
239}
#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 243 of file messenger_api_message.c.

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

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

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

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

◆ destroy_message()

void destroy_message ( struct GNUNET_MESSENGER_Message message)

Destroys a message and frees its memory fully.

Parameters
[in,out]messageMessage

Definition at line 252 of file messenger_api_message.c.

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

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

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

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

◆ is_message_session_bound()

enum GNUNET_GenericReturnValue is_message_session_bound ( const struct GNUNET_MESSENGER_Message message)

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

Parameters
[in]messageMessage
Returns
GNUNET_YES or GNUNET_NO

Definition at line 263 of file messenger_api_message.c.

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

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

Referenced by enqueue_message_to_room(), and update_member_session_history().

Here is the caller graph for this function:

◆ fold_short_message()

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

Definition at line 279 of file messenger_api_message.c.

281{
282 shortened->kind = message->header.kind;
283
284 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
286}
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 290 of file messenger_api_message.c.

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

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

306{
307 uint16_t length;
308
309 length = 0;
310
311 switch (kind)
312 {
314 length += member_size (struct GNUNET_MESSENGER_Message,
315 body.info.messenger_version);
316 break;
318 length += member_size (struct GNUNET_MESSENGER_Message,
319 body.join.epoch);
320 break;
322 length += member_size (struct GNUNET_MESSENGER_Message,
323 body.leave.epoch);
324 break;
326 length += member_size (struct GNUNET_MESSENGER_Message, body.peer.peer);
327 break;
329 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
330 break;
332 length += member_size (struct GNUNET_MESSENGER_Message, body.miss.peer);
333 break;
335 length += member_size (struct GNUNET_MESSENGER_Message,
336 body.merge.epochs[0]);
337 length += member_size (struct GNUNET_MESSENGER_Message,
338 body.merge.epochs[1]);
339 length += member_size (struct GNUNET_MESSENGER_Message,
340 body.merge.previous);
341 break;
343 length += member_size (struct GNUNET_MESSENGER_Message, body.request.hash);
344 break;
346 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door);
347 length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key);
348 break;
350 length += member_size (struct GNUNET_MESSENGER_Message, body.file.key);
351 length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash);
352 length += member_size (struct GNUNET_MESSENGER_Message, body.file.name);
353 break;
355 length += member_size (struct GNUNET_MESSENGER_Message, body.deletion.hash);
356 length += member_size (struct GNUNET_MESSENGER_Message,
357 body.deletion.delay);
358 break;
360 length += member_size (struct GNUNET_MESSENGER_Message,
361 body.connection.amount);
362 length += member_size (struct GNUNET_MESSENGER_Message,
363 body.connection.flags);
364 break;
366 length += member_size (struct GNUNET_MESSENGER_Message,
367 body.transcript.hash);
368 break;
370 length += member_size (struct GNUNET_MESSENGER_Message, body.tag.hash);
371 break;
373 length += member_size (struct GNUNET_MESSENGER_Message,
374 body.subscription.discourse);
375 length += member_size (struct GNUNET_MESSENGER_Message,
376 body.subscription.time);
377 length += member_size (struct GNUNET_MESSENGER_Message,
378 body.subscription.flags);
379 break;
381 length += member_size (struct GNUNET_MESSENGER_Message,
382 body.talk.discourse);
383 break;
385 length += member_size (struct GNUNET_MESSENGER_Message,
386 body.announcement.identifier);
387 length += member_size (struct GNUNET_MESSENGER_Message,
388 body.announcement.key);
389 length += member_size (struct GNUNET_MESSENGER_Message,
390 body.announcement.nonce);
391 length += member_size (struct GNUNET_MESSENGER_Message,
392 body.announcement.timeout);
393 length += member_size (struct GNUNET_MESSENGER_Message,
394 body.announcement.hmac);
395 break;
397 length += member_size (struct GNUNET_MESSENGER_Message,
398 body.secret.identifier);
399 length += member_size (struct GNUNET_MESSENGER_Message,
400 body.secret.iv);
401 length += member_size (struct GNUNET_MESSENGER_Message,
402 body.secret.hmac);
403 break;
405 length += member_size (struct GNUNET_MESSENGER_Message,
406 body.appeal.event);
407 length += member_size (struct GNUNET_MESSENGER_Message,
408 body.appeal.key);
409 length += member_size (struct GNUNET_MESSENGER_Message,
410 body.appeal.timeout);
411 break;
413 length += member_size (struct GNUNET_MESSENGER_Message,
414 body.access.event);
415 length += member_size (struct GNUNET_MESSENGER_Message,
416 body.access.key);
417 length += member_size (struct GNUNET_MESSENGER_Message,
418 body.access.hmac);
419 break;
421 length += member_size (struct GNUNET_MESSENGER_Message,
422 body.revolution.identifier);
423 length += member_size (struct GNUNET_MESSENGER_Message,
424 body.revolution.nonce);
425 length += member_size (struct GNUNET_MESSENGER_Message,
426 body.revolution.hmac);
427 break;
429 length += member_size (struct GNUNET_MESSENGER_Message,
430 body.group.identifier);
431 length += member_size (struct GNUNET_MESSENGER_Message,
432 body.group.initiator);
433 length += member_size (struct GNUNET_MESSENGER_Message,
434 body.group.partner);
435 length += member_size (struct GNUNET_MESSENGER_Message,
436 body.group.timeout);
437 break;
439 length += member_size (struct GNUNET_MESSENGER_Message,
440 body.authorization.identifier);
441 length += member_size (struct GNUNET_MESSENGER_Message,
442 body.authorization.event);
443 length += member_size (struct GNUNET_MESSENGER_Message,
444 body.authorization.key);
445 length += member_size (struct GNUNET_MESSENGER_Message,
446 body.authorization.hmac);
447 break;
448 default:
449 break;
450 }
451
452 return length;
453}
@ 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 459 of file messenger_api_message.c.

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

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

482{
483 uint16_t length;
484
485 length = 0;
486
487 switch (kind)
488 {
492 break;
494 length += (body->name.name ? strlen (body->name.name) : 0);
495 break;
497 length += GNUNET_CRYPTO_blindable_pk_get_length (&(body->key.key));
498 length += GNUNET_CRYPTO_hpke_pk_get_length (&(body->key.hpke_key));
499 break;
501 length += (body->text.text ? strlen (body->text.text) : 0);
502 break;
504 length += (body->file.uri ? strlen (body->file.uri) : 0);
505 break;
507 length += body->privacy.length;
508 break;
510 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
511 break;
514 length += body->transcript.length;
515 break;
517 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
518 break;
520 length += body->talk.length;
521 break;
523 length += body->secret.length;
524 break;
525 default:
526 break;
527 }
528
529 return length;
530}
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 534 of file messenger_api_message.c.

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

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

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

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

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

557{
558 uint16_t minimum_size;
559
560 minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
561
562 if (message)
563 return minimum_size + get_message_body_kind_size (message->kind)
564 + (include_body == GNUNET_YES?
565 get_message_body_size (message->kind, &(message->body)) : 0);
566 else
567 return minimum_size;
568}
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 572 of file messenger_api_message.c.

573{
574 uint16_t padding;
575 uint16_t kind_size;
576
577 padding = 0;
578
579 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
580 {
582 GNUNET_YES);
583
584 if (kind_size > padding)
585 padding = kind_size;
586 }
587
588 return padding + GNUNET_MESSENGER_PADDING_MIN;
589}
#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 595 of file messenger_api_message.c.

596{
597 static uint16_t usual_padding = 0;
598 uint16_t padded_length;
599
600 if (! usual_padding)
601 usual_padding = calc_usual_padding ();
602
603 padded_length = max (
605 usual_padding);
606
607 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
609
610 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
612
613 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
615
617
618}
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 660 of file messenger_api_message.c.

665{
666 uint32_t value0, value1;
667
668 GNUNET_assert ((body) && (buffer));
669
670 switch (kind)
671 {
673 value0 = GNUNET_htobe32 (body->info.messenger_version);
674
675 encode_step (buffer, offset, &value0);
676 break;
678 encode_step (buffer, offset, &(body->join.epoch));
679 encode_step_key (buffer, offset, &(body->join.key), length);
680 encode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
681 break;
683 encode_step (buffer, offset, &(body->leave.epoch));
684 break;
686 if (body->name.name)
688 buffer,
689 offset,
690 body->name.name,
691 min (length - offset, strlen (body->name.name)));
692 break;
694 encode_step_key (buffer, offset, &(body->key.key), length);
695 encode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
696 break;
698 encode_step (buffer, offset, &(body->peer.peer));
699 break;
701 encode_step (buffer, offset, &(body->id.id));
702 break;
704 encode_step (buffer, offset, &(body->miss.peer));
705 break;
707 encode_step (buffer, offset, &(body->merge.epochs[0]));
708 encode_step (buffer, offset, &(body->merge.epochs[1]));
709 encode_step (buffer, offset, &(body->merge.previous));
710 break;
712 encode_step (buffer, offset, &(body->request.hash));
713 break;
715 encode_step (buffer, offset, &(body->invite.door));
716 encode_step (buffer, offset, &(body->invite.key));
717 break;
719 if (body->text.text)
721 buffer,
722 offset,
723 body->text.text,
724 min (length - offset, strlen (body->text.text)));
725 break;
727 encode_step (buffer, offset, &(body->file.key));
728 encode_step (buffer, offset, &(body->file.hash));
729 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
730 if (body->file.uri)
731 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
732 strlen (
733 body->file.uri)));
734 break;
736 if (body->privacy.data)
737 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
738 body->privacy.
739 length));
740 break;
742 encode_step (buffer, offset, &(body->deletion.hash));
743 encode_step (buffer, offset, &(body->deletion.delay));
744 break;
746 value0 = GNUNET_htobe32 (body->connection.amount);
747 value1 = GNUNET_htobe32 (body->connection.flags);
748
749 encode_step (buffer, offset, &value0);
750 encode_step (buffer, offset, &value1);
751 break;
753 encode_step_ext (buffer, offset, body->ticket.identifier,
754 min (length - offset, strlen (body->ticket.identifier)));
755 break;
757 encode_step (buffer, offset, &(body->transcript.hash));
758 encode_step_key (buffer, offset, &(body->transcript.key), length);
759
760 if (body->transcript.data)
761 encode_step_ext (buffer, offset, body->transcript.data, min (length
762 - offset,
763 body->
764 transcript.
765 length));
766 break;
768 encode_step (buffer, offset, &(body->tag.hash));
769
770 if (body->tag.tag)
771 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
772 strlen (
773 body->tag.tag)));
774 break;
776 value0 = GNUNET_htobe32 (body->subscription.flags);
777
778 encode_step (buffer, offset, &(body->subscription.discourse));
779 encode_step (buffer, offset, &(body->subscription.time));
780 encode_step (buffer, offset, &value0);
781 break;
783 encode_step (buffer, offset, &(body->talk.discourse));
784
785 if (body->talk.data)
786 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
787 body->talk.
788 length));
789 break;
791 encode_step (buffer, offset, &(body->announcement.identifier));
792 encode_step (buffer, offset, &(body->announcement.key));
793 encode_step (buffer, offset, &(body->announcement.nonce));
794 encode_step (buffer, offset, &(body->announcement.timeout));
795 encode_step (buffer, offset, &(body->announcement.hmac));
796 break;
798 encode_step (buffer, offset, &(body->secret.identifier));
799 encode_step (buffer, offset, &(body->secret.iv));
800 encode_step (buffer, offset, &(body->secret.hmac));
801
802 if (body->secret.data)
803 encode_step_ext (buffer, offset, body->secret.data, min (length - offset,
804 body->secret.
805 length));
806 break;
808 encode_step (buffer, offset, &(body->appeal.event));
809 encode_step (buffer, offset, &(body->appeal.key));
810 encode_step (buffer, offset, &(body->appeal.timeout));
811 break;
813 encode_step (buffer, offset, &(body->access.event));
814 encode_step (buffer, offset, &(body->access.key));
815 encode_step (buffer, offset, &(body->access.hmac));
816 break;
818 encode_step (buffer, offset, &(body->revolution.identifier));
819 encode_step (buffer, offset, &(body->revolution.nonce));
820 encode_step (buffer, offset, &(body->revolution.hmac));
821 break;
823 encode_step (buffer, offset, &(body->group.identifier));
824 encode_step (buffer, offset, &(body->group.initiator));
825 encode_step (buffer, offset, &(body->group.partner));
826 encode_step (buffer, offset, &(body->group.timeout));
827 break;
829 encode_step (buffer, offset, &(body->authorization.identifier));
830 encode_step (buffer, offset, &(body->authorization.event));
831 encode_step (buffer, offset, &(body->authorization.key));
832 encode_step (buffer, offset, &(body->authorization.hmac));
833 break;
834 default:
835 break;
836 }
837
838 if (offset >= length)
839 return;
840
841 {
842 uint16_t padding;
843 uint16_t used_padding;
844
845 padding = length - offset;
846 used_padding = sizeof(padding) + sizeof(char);
847
848 GNUNET_assert (padding >= used_padding);
849
850 buffer[offset++] = '\0';
851
852 if (padding > used_padding)
854 padding - used_padding);
855
856 GNUNET_memcpy (buffer + length - sizeof(padding), &padding,
857 sizeof(padding));
858 }
859}
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_signature()

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

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

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

Definition at line 863 of file messenger_api_message.c.

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

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

Referenced by callback_srv_room_sign_result(), and send_message_to_room().

Here is the caller graph for this function:

◆ encode_message()

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

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

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

Definition at line 877 of file messenger_api_message.c.

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

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

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

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

◆ encode_short_message()

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

Definition at line 910 of file messenger_api_message.c.

913{
914 struct GNUNET_HashCode hash;
915 uint16_t offset;
916 kind_t kind;
917
918 GNUNET_assert ((message) && (buffer));
919
920 offset = sizeof(hash);
921 kind = GNUNET_htobe32 ((kind_t) message->kind);
922
923 encode_step (buffer, offset, &kind);
924
925 encode_message_body (message->kind, &(message->body), length, buffer, offset);
926
928 buffer + sizeof(hash),
929 length - sizeof(hash),
930 &hash);
931
932 GNUNET_memcpy (buffer, &hash, sizeof(hash));
933}
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 974 of file messenger_api_message.c.

979{
980 uint16_t padding;
981 uint32_t value0, value1;
982
983 GNUNET_assert ((kind) && (body) && (buffer));
984
985 padding = 0;
986
987 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
988
989 if (padding > length - offset)
990 padding = 0;
991
992 {
993 uint16_t end_zero;
994 end_zero = length - padding;
995
996 if ((padding) && (buffer[end_zero] != '\0'))
997 padding = 0;
998 }
999
1000 length -= padding;
1001
1002 switch (*kind)
1003 {
1005 decode_step (buffer, offset, &value0);
1006
1007 body->info.messenger_version = GNUNET_be32toh (value0);
1008 break;
1010 decode_step (buffer, offset, &(body->join.epoch));
1011 decode_step_key (buffer, offset, &(body->join.key), length);
1012 decode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
1013 break;
1015 decode_step (buffer, offset, &(body->leave.epoch));
1016 break;
1018 if (length > offset)
1019 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
1020 else
1021 body->name.name = NULL;
1022 break;
1024 decode_step_key (buffer, offset, &(body->key.key), length);
1025 decode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
1026 break;
1028 decode_step (buffer, offset, &(body->peer.peer));
1029 break;
1031 decode_step (buffer, offset, &(body->id.id));
1032 break;
1034 decode_step (buffer, offset, &(body->miss.peer));
1035 break;
1037 decode_step (buffer, offset, &(body->merge.epochs[0]));
1038 decode_step (buffer, offset, &(body->merge.epochs[1]));
1039 decode_step (buffer, offset, &(body->merge.previous));
1040 break;
1042 decode_step (buffer, offset, &(body->request.hash));
1043 break;
1045 decode_step (buffer, offset, &(body->invite.door));
1046 decode_step (buffer, offset, &(body->invite.key));
1047 break;
1049 if (length > offset)
1050 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
1051 else
1052 body->text.text = NULL;
1053 break;
1055 decode_step (buffer, offset, &(body->file.key));
1056 decode_step (buffer, offset, &(body->file.hash));
1057 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
1058 if (length > offset)
1059 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
1060 else
1061 body->file.uri = NULL;
1062 break;
1064 if (length > offset)
1065 {
1066 body->privacy.length = (length - offset);
1067 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
1068 0);
1069 }
1070 else
1071 {
1072 body->privacy.length = 0;
1073 body->privacy.data = NULL;
1074 }
1075
1076 break;
1078 decode_step (buffer, offset, &(body->deletion.hash));
1079 decode_step (buffer, offset, &(body->deletion.delay));
1080 break;
1082 decode_step (buffer, offset, &value0);
1083 decode_step (buffer, offset, &value1);
1084
1085 body->connection.amount = GNUNET_be32toh (value0);
1086 body->connection.flags = GNUNET_be32toh (value1);
1087 break;
1089 if (length > offset)
1090 decode_step_malloc (buffer, offset, body->ticket.identifier, length
1091 - offset, 1);
1092 else
1093 body->ticket.identifier = NULL;
1094 break;
1096 decode_step (buffer, offset, &(body->transcript.hash));
1097 decode_step_key (buffer, offset, &(body->transcript.key), length);
1098
1099 if (length > offset)
1100 {
1101 body->transcript.length = (length - offset);
1102 decode_step_malloc (buffer, offset, body->transcript.data,
1103 length - offset, 0);
1104 }
1105 else
1106 {
1107 body->transcript.length = 0;
1108 body->transcript.data = NULL;
1109 }
1110
1111 break;
1113 decode_step (buffer, offset, &(body->tag.hash));
1114 if (length > offset)
1115 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
1116 else
1117 body->tag.tag = NULL;
1118 break;
1120 decode_step (buffer, offset, &(body->subscription.discourse));
1121 decode_step (buffer, offset, &(body->subscription.time));
1122 decode_step (buffer, offset, &value0);
1123
1124 body->subscription.flags = GNUNET_be32toh (value0);
1125 break;
1127 decode_step (buffer, offset, &(body->talk.discourse));
1128
1129 if (length > offset)
1130 {
1131 body->talk.length = (length - offset);
1132 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
1133 0);
1134 }
1135 else
1136 {
1137 body->talk.length = 0;
1138 body->talk.data = NULL;
1139 }
1140
1141 break;
1143 decode_step (buffer, offset, &(body->announcement.identifier));
1144 decode_step (buffer, offset, &(body->announcement.key));
1145 decode_step (buffer, offset, &(body->announcement.nonce));
1146 decode_step (buffer, offset, &(body->announcement.timeout));
1147 decode_step (buffer, offset, &(body->announcement.hmac));
1148 break;
1150 decode_step (buffer, offset, &(body->secret.identifier));
1151 decode_step (buffer, offset, &(body->secret.iv));
1152 decode_step (buffer, offset, &(body->secret.hmac));
1153
1154 if (length > offset)
1155 {
1156 body->secret.length = (length - offset);
1157 decode_step_malloc (buffer, offset, body->secret.data, length - offset,
1158 0);
1159 }
1160 else
1161 {
1162 body->secret.length = 0;
1163 body->secret.data = NULL;
1164 }
1165
1166 break;
1168 decode_step (buffer, offset, &(body->appeal.event));
1169 decode_step (buffer, offset, &(body->appeal.key));
1170 decode_step (buffer, offset, &(body->appeal.timeout));
1171 break;
1173 decode_step (buffer, offset, &(body->access.event));
1174 decode_step (buffer, offset, &(body->access.key));
1175 decode_step (buffer, offset, &(body->access.hmac));
1176 break;
1178 decode_step (buffer, offset, &(body->revolution.identifier));
1179 decode_step (buffer, offset, &(body->revolution.nonce));
1180 decode_step (buffer, offset, &(body->revolution.hmac));
1181 break;
1183 decode_step (buffer, offset, &(body->group.identifier));
1184 decode_step (buffer, offset, &(body->group.initiator));
1185 decode_step (buffer, offset, &(body->group.partner));
1186 decode_step (buffer, offset, &(body->group.timeout));
1187 break;
1189 decode_step (buffer, offset, &(body->authorization.identifier));
1190 decode_step (buffer, offset, &(body->authorization.event));
1191 decode_step (buffer, offset, &(body->authorization.key));
1192 decode_step (buffer, offset, &(body->authorization.hmac));
1193 break;
1194 default:
1196 break;
1197 }
1198
1199 return padding;
1200}
#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 maximum length in bytes.

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

On success the function returns GNUNET_YES.

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

Definition at line 1204 of file messenger_api_message.c.

1209{
1210 uint16_t offset;
1211 uint16_t count;
1212 kind_t kind;
1213
1215 (message) &&
1216 (buffer) &&
1218 include_header)));
1219
1220 offset = 0;
1221
1222 if (GNUNET_YES == include_header)
1223 {
1224 ssize_t result;
1225
1227 &(message->header.signature), buffer, length - offset);
1228
1229 if (result < 0)
1230 return GNUNET_NO;
1231 else
1232 offset += result;
1233 }
1234
1235 count = length - offset;
1237 include_header))
1238 return GNUNET_NO;
1239
1240 if (GNUNET_YES == include_header)
1241 {
1242 decode_step (buffer, offset, &(message->header.timestamp));
1243 decode_step (buffer, offset, &(message->header.sender_id));
1244 decode_step (buffer, offset, &(message->header.previous));
1245 }
1246
1247 decode_step (buffer, offset, &kind);
1248 kind = GNUNET_be32toh (kind);
1249
1250 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1251
1252 if (count < get_message_kind_size (message->header.kind, include_header))
1253 return GNUNET_NO;
1254
1255 {
1256 uint16_t result;
1257 result = decode_message_body (&(message->header.kind),
1258 &(message->body), length, buffer, offset);
1259
1260 if (padding)
1261 *padding = result;
1262 }
1263
1264 return GNUNET_YES;
1265}
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 1269 of file messenger_api_message.c.

1272{
1273 struct GNUNET_HashCode expected, hash;
1274 uint16_t offset;
1275 kind_t kind;
1276
1277 GNUNET_assert ((message) && (buffer));
1278
1279 offset = sizeof(hash);
1280
1281 if (length < get_short_message_size (NULL, GNUNET_NO))
1282 return GNUNET_NO;
1283
1284 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1285
1287 buffer + sizeof(hash),
1288 length - sizeof(hash),
1289 &expected);
1290
1291 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1292 return GNUNET_NO;
1293
1294 decode_step (buffer, offset, &kind);
1295 kind = GNUNET_be32toh (kind);
1296
1297 message->kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1298
1299 if (length < get_short_message_size (message, GNUNET_NO))
1300 return GNUNET_NO;
1301
1302 decode_message_body (&(message->kind), &(message->body), length, buffer,
1303 offset);
1304
1305 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1306 return GNUNET_NO;
1307
1308 return GNUNET_YES;
1309}
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 1313 of file messenger_api_message.c.

1317{
1318 ssize_t offset;
1319
1320 GNUNET_assert ((message) && (buffer) && (hash));
1321
1323 signature));
1324
1325 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1326}

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

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

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

◆ sign_message()

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

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

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

Definition at line 1330 of file messenger_api_message.c.

1333{
1334 struct GNUNET_MESSENGER_MessageSignature signature;
1335
1336 GNUNET_assert ((message) && (hash) && (key));
1337
1338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1339 GNUNET_h2s (hash));
1340
1341 signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
1342 signature.purpose.size = htonl (sizeof(signature));
1343
1344 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1345
1347 &(message->header.signature));
1348 message->header.signature.type = key->type;
1349}
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

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

Referenced by send_message_to_room().

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

◆ sign_message_by_peer()

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

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

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

Definition at line 1353 of file messenger_api_message.c.

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

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

Referenced by sign_srv_room_message().

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

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

1387{
1388 struct GNUNET_CRYPTO_AuthKey auth_key;
1389
1390 GNUNET_assert ((message) && (key) && (hmac));
1391
1392 switch (message->header.kind)
1393 {
1396 &auth_key, sizeof (auth_key),
1399 key, sizeof (*key),
1402 return GNUNET_NO;
1403
1404 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.announcement),
1405 sizeof (message->body.announcement)
1406 - sizeof (*hmac),
1407 hmac);
1408 return GNUNET_YES;
1411 &auth_key, sizeof (auth_key),
1414 key, sizeof (*key),
1416 return GNUNET_NO;
1417
1418 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.access),
1419 sizeof (message->body.access)
1420 - sizeof (*hmac),
1421 hmac);
1422 return GNUNET_YES;
1425 &auth_key, sizeof (auth_key),
1428 key, sizeof (*key),
1431 return GNUNET_NO;
1432
1433 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.revolution),
1434 sizeof (message->body.revolution)
1435 - sizeof (*hmac),
1436 hmac);
1437 return GNUNET_YES;
1440 &auth_key, sizeof (auth_key),
1443 key, sizeof (*key),
1446 return GNUNET_NO;
1447
1448 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.authorization),
1449 sizeof (message->body.authorization)
1450 - sizeof (*hmac),
1451 hmac);
1452 return GNUNET_YES;
1453 default:
1454 return GNUNET_SYSERR;
1455 }
1456}
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 1460 of file messenger_api_message.c.

1462{
1463 struct GNUNET_HashCode *hmac;
1464
1465 GNUNET_assert ((message) && (key));
1466
1467 switch (message->header.kind)
1468 {
1470 hmac = &(message->body.announcement.hmac);
1471 break;
1473 hmac = &(message->body.access.hmac);
1474 break;
1476 hmac = &(message->body.revolution.hmac);
1477 break;
1479 hmac = &(message->body.authorization.hmac);
1480 break;
1481 default:
1482 hmac = NULL;
1483 break;
1484 }
1485
1486 if (! hmac)
1487 return GNUNET_SYSERR;
1488
1489 return calc_message_hmac (message, key, hmac);
1490}
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 1494 of file messenger_api_message.c.

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

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

Referenced by verify_member_session_as_sender().

Here is the caller graph for this function:

◆ verify_message_by_peer()

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

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

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

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

Definition at line 1517 of file messenger_api_message.c.

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

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

Referenced by get_store_peer_of(), and verify_store_peer().

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

◆ verify_message_by_key()

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

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

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

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

Definition at line 1541 of file messenger_api_message.c.

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

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

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

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

◆ encrypt_message()

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

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

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

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

Definition at line 1582 of file messenger_api_message.c.

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

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

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

Referenced by handle_private_message().

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

◆ transcribe_message()

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

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

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

Definition at line 1707 of file messenger_api_message.c.

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

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

Referenced by send_message_to_room_with_key().

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

◆ encrypt_secret_message()

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

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

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

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

Definition at line 1748 of file messenger_api_message.c.

1752{
1754 struct GNUNET_MESSENGER_ShortMessage shortened;
1755 uint16_t length, padded_length;
1756 uint8_t *data;
1757
1758 GNUNET_assert ((message) && (identifier) && (key));
1759
1760 fold_short_message (message, &shortened);
1761
1762 length = get_short_message_size (&shortened, GNUNET_YES);
1763 padded_length = calc_padded_length (length + 0);
1764
1765 GNUNET_assert (padded_length >= length + 0);
1766
1768
1769 GNUNET_memcpy (&(message->body.secret.identifier), identifier,
1770 sizeof (message->body.secret.identifier));
1771
1773 &(message->body.secret.iv),
1775
1776 message->body.secret.data = GNUNET_malloc (padded_length);
1777 message->body.secret.length = padded_length;
1778
1779 result = GNUNET_NO;
1780 data = GNUNET_malloc (padded_length);
1781
1782 encode_short_message (&shortened, padded_length, (char *) data);
1783
1784 {
1786
1788 &iv, sizeof (iv),
1791 key, sizeof (*key),
1793 {
1794 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving initialization vector failed!\n");
1795 unfold_short_message (&shortened, message);
1796 goto cleanup;
1797 }
1798
1799 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (data, padded_length, key,
1800 &iv, message->body.secret.data))
1801 {
1802 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1803 unfold_short_message (&shortened, message);
1804 goto cleanup;
1805 }
1806 }
1807
1808 {
1809 struct GNUNET_CRYPTO_AuthKey auth_key;
1810
1812 &auth_key, sizeof (auth_key),
1815 key, sizeof (*key),
1817 {
1818 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving authentication key failed!\n");
1819 unfold_short_message (&shortened, message);
1820 goto cleanup;
1821 }
1822
1823 GNUNET_CRYPTO_hmac (&auth_key, message->body.secret.data, padded_length,
1824 &(message->body.secret.hmac));
1825 }
1826
1827 destroy_message_body (shortened.kind, &(shortened.body));
1829
1830cleanup:
1831 GNUNET_free (data);
1832 return result;
1833}
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 1837 of file messenger_api_message.c.

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

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

Referenced by update_room_secret_message().

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

◆ read_transcript_message()

enum GNUNET_GenericReturnValue read_transcript_message ( struct GNUNET_MESSENGER_Message message)

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

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

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

Definition at line 1925 of file messenger_api_message.c.

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

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

Referenced by handle_transcript_message().

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

◆ extract_access_message_key()

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

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

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

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

Definition at line 1951 of file messenger_api_message.c.

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

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

Referenced by handle_epoch_announcement_access(), and handle_epoch_group_access().

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

◆ extract_authorization_message_key()

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

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

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

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

Definition at line 1984 of file messenger_api_message.c.

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

2030{
2033
2034 GNUNET_assert (message);
2035
2037
2038 switch (message->header.kind)
2039 {
2042 break;
2045 break;
2048 break;
2051 break;
2052 default:
2054 break;
2055 }
2056
2058
2062
2063 return timeout;
2064}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition gnunet-arm.c:118
static uint64_t timestamp(void)
Get current timestamp.
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,
enum GNUNET_MESSENGER_PackMode  mode 
)

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

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

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

Definition at line 2068 of file messenger_api_message.c.

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

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

◆ is_peer_message()

enum GNUNET_GenericReturnValue is_peer_message ( const struct GNUNET_MESSENGER_Message message)

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

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

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

Definition at line 2111 of file messenger_api_message.c.

2112{
2113 GNUNET_assert (message);
2114
2115 switch (message->header.kind)
2116 {
2122 return GNUNET_YES;
2123 default:
2124 return GNUNET_NO;
2125 }
2126}

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

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

Here is the caller graph for this function:

◆ is_service_message()

enum GNUNET_GenericReturnValue is_service_message ( const struct GNUNET_MESSENGER_Message message)

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

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

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

Definition at line 2130 of file messenger_api_message.c.

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

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

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

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

◆ is_epoch_message()

enum GNUNET_GenericReturnValue is_epoch_message ( const struct GNUNET_MESSENGER_Message message)

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

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

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

Definition at line 2202 of file messenger_api_message.c.

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

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

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

Here is the caller graph for this function:

◆ filter_message_sending()

enum GNUNET_GenericReturnValue filter_message_sending ( const struct GNUNET_MESSENGER_Message message)

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

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

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

Definition at line 2221 of file messenger_api_message.c.

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

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

Referenced by check_send_message(), and GNUNET_MESSENGER_send_message().

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

◆ get_message_discourse()

const struct GNUNET_ShortHashCode * get_message_discourse ( const struct GNUNET_MESSENGER_Message message)

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

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

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

Definition at line 2293 of file messenger_api_message.c.

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

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

Referenced by decrypt_message(), and encrypt_message().