aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api_message.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api_message.h')
-rw-r--r--src/messenger/messenger_api_message.h88
1 files changed, 77 insertions, 11 deletions
diff --git a/src/messenger/messenger_api_message.h b/src/messenger/messenger_api_message.h
index 688c72994..3544993f9 100644
--- a/src/messenger/messenger_api_message.h
+++ b/src/messenger/messenger_api_message.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2020--2021 GNUnet e.V. 3 Copyright (C) 2020--2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -33,8 +33,6 @@
33 33
34#include "gnunet_messenger_service.h" 34#include "gnunet_messenger_service.h"
35 35
36#include "messenger_api_ego.h"
37
38#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE - GNUNET_MIN_MESSAGE_SIZE) 36#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE - GNUNET_MIN_MESSAGE_SIZE)
39 37
40#define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char)) 38#define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char))
@@ -166,14 +164,31 @@ hash_message (const struct GNUNET_MESSENGER_Message *message,
166 * @param[in] length Length of buffer 164 * @param[in] length Length of buffer
167 * @param[out] buffer Buffer 165 * @param[out] buffer Buffer
168 * @param[in] hash Hash of message 166 * @param[in] hash Hash of message
169 * @param[in] ego EGO 167 * @param[in] key Private key of EGO
170 */ 168 */
171void 169void
172sign_message (struct GNUNET_MESSENGER_Message *message, 170sign_message (struct GNUNET_MESSENGER_Message *message,
173 uint16_t length, 171 uint16_t length,
174 char *buffer, 172 char *buffer,
175 const struct GNUNET_HashCode *hash, 173 const struct GNUNET_HashCode *hash,
176 const struct GNUNET_MESSENGER_Ego *ego); 174 const struct GNUNET_IDENTITY_PrivateKey *key);
175
176/**
177 * Signs the <i>hash</i> of a <i>message</i> with the peer identity of a given <i>config</i>
178 * and writes the signature into the <i>buffer</i> as well.
179 *
180 * @param[in,out] message Message
181 * @param[in] length Length of buffer
182 * @param[out] buffer Buffer
183 * @param[in] hash Hash of message
184 * @param[in] cfg Peer configuration
185 */
186void
187sign_message_by_peer (struct GNUNET_MESSENGER_Message *message,
188 uint16_t length,
189 char *buffer,
190 const struct GNUNET_HashCode *hash,
191 const struct GNUNET_CONFIGURATION_Handle* cfg);
177 192
178/** 193/**
179 * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific 194 * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific
@@ -191,6 +206,21 @@ verify_message (const struct GNUNET_MESSENGER_Message *message,
191 const struct GNUNET_IDENTITY_PublicKey *key); 206 const struct GNUNET_IDENTITY_PublicKey *key);
192 207
193/** 208/**
209 * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific
210 * peer's <i>identity</i>. The function returns #GNUNET_OK if the signature was valid,
211 * otherwise #GNUNET_SYSERR.
212 *
213 * @param[in] message Message
214 * @param[in] hash Hash of message
215 * @param[in] identity Peer identity
216 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
217 */
218int
219verify_message_by_peer (const struct GNUNET_MESSENGER_Message *message,
220 const struct GNUNET_HashCode *hash,
221 const struct GNUNET_PeerIdentity *identity);
222
223/**
194 * Encrypts a <i>message</i> using a given public <i>key</i> and replaces its body 224 * Encrypts a <i>message</i> using a given public <i>key</i> and replaces its body
195 * and kind with the now private encrypted <i>message</i>. The function returns 225 * and kind with the now private encrypted <i>message</i>. The function returns
196 * #GNUNET_YES if the operation succeeded, otherwise #GNUNET_NO. 226 * #GNUNET_YES if the operation succeeded, otherwise #GNUNET_NO.
@@ -216,33 +246,69 @@ int
216decrypt_message (struct GNUNET_MESSENGER_Message *message, 246decrypt_message (struct GNUNET_MESSENGER_Message *message,
217 const struct GNUNET_IDENTITY_PrivateKey *key); 247 const struct GNUNET_IDENTITY_PrivateKey *key);
218 248
249typedef void (*GNUNET_MESSENGER_SignFunction)(
250 const void *cls,
251 struct GNUNET_MESSENGER_Message *message,
252 uint16_t length,
253 char *buffer,
254 const struct GNUNET_HashCode *hash
255);
256
219#define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1 257#define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1
220#define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0 258#define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0
221 259
222/** 260/**
223 * Encodes the <i>message</i> to pack it into a newly allocated envelope if <i>mode</i> 261 * Encodes the <i>message</i> to pack it into a newly allocated envelope if <i>mode</i>
224 * is equal to #GNUNET_MESSENGER_PACK_MODE_ENVELOPE. Independent of the mode the message 262 * is equal to #GNUNET_MESSENGER_PACK_MODE_ENVELOPE. Independent of the mode the message
225 * will be hashed if <i>hash</i> is not NULL and it will be signed if the <i>ego</i> is 263 * will be hashed if <i>hash</i> is not NULL and it will be signed if the <i>sign</i>
226 * not NULL. 264 * function is not NULL.
227 * 265 *
228 * @param[out] message Message 266 * @param[out] message Message
229 * @param[out] hash Hash of message 267 * @param[out] hash Hash of message
230 * @param[in] ego EGO to sign 268 * @param[in] sign Function to sign
231 * @param[in] mode Mode of packing 269 * @param[in] mode Mode of packing
270 * @param[in,out] cls Closure for signing
232 * @return Envelope or NULL 271 * @return Envelope or NULL
233 */ 272 */
234struct GNUNET_MQ_Envelope* 273struct GNUNET_MQ_Envelope*
235pack_message (struct GNUNET_MESSENGER_Message *message, 274pack_message (struct GNUNET_MESSENGER_Message *message,
236 struct GNUNET_HashCode *hash, 275 struct GNUNET_HashCode *hash,
237 const struct GNUNET_MESSENGER_Ego *ego, 276 const GNUNET_MESSENGER_SignFunction sign,
238 int mode); 277 int mode,
278 const void *cls);
279
280/**
281 * Returns whether a specific kind of message can be sent by the service without usage of a
282 * clients EGO. The function returns #GNUNET_YES if the kind of message can be signed
283 * via a peer's identity, otherwise #GNUNET_NO.
284 *
285 * @param[in] message Message
286 * @return #GNUNET_YES if sending is allowed, #GNUNET_NO otherwise
287 */
288int
289is_peer_message (const struct GNUNET_MESSENGER_Message *message);
290
291/**
292 * Returns whether a specific kind of message contains service critical information. That kind
293 * of information should not be encrypted via private messages for example to guarantee the
294 * service to work properly. The function returns #GNUNET_YES if the kind of message needs to
295 * be transferred accessible to all peers and their running service. It returns #GNUNET_NO
296 * if the message can be encrypted to specific subgroups of members without issues. If the kind
297 * of message is unknown it returns #GNUNET_SYSERR.
298 *
299 * @param[in] message Message
300 * @return #GNUNET_YES if encrypting is disallowed, #GNUNET_NO or #GNUNET_SYSERR otherwise
301 */
302int
303is_service_message (const struct GNUNET_MESSENGER_Message *message);
239 304
240/** 305/**
241 * Returns if a specific kind of message should be sent by a client. The function returns 306 * Returns whether a specific kind of message should be sent by a client. The function returns
242 * #GNUNET_YES or #GNUNET_NO for recommendations and #GNUNET_SYSERR for specific kinds 307 * #GNUNET_YES or #GNUNET_NO for recommendations and #GNUNET_SYSERR for specific kinds
243 * of messages which should not be sent manually at all. 308 * of messages which should not be sent manually at all.
244 * 309 *
245 * @param[in] message Message 310 * @param[in] message Message
311 * @return #GNUNET_YES if sending is allowed, #GNUNET_NO or #GNUNET_SYSERR otherwise
246 */ 312 */
247int 313int
248filter_message_sending (const struct GNUNET_MESSENGER_Message *message); 314filter_message_sending (const struct GNUNET_MESSENGER_Message *message);