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.h251
1 files changed, 0 insertions, 251 deletions
diff --git a/src/messenger/messenger_api_message.h b/src/messenger/messenger_api_message.h
deleted file mode 100644
index 46c5cb024..000000000
--- a/src/messenger/messenger_api_message.h
+++ /dev/null
@@ -1,251 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2021 GNUnet e.V.
4
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
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Tobias Frisch
22 * @file src/messenger/messenger_api_message.h
23 * @brief messenger api: client and service implementation of GNUnet MESSENGER service
24 */
25
26#ifndef GNUNET_MESSENGER_API_MESSAGE_H
27#define GNUNET_MESSENGER_API_MESSAGE_H
28
29#include "platform.h"
30#include "gnunet_crypto_lib.h"
31#include "gnunet_identity_service.h"
32#include "gnunet_mq_lib.h"
33#include "gnunet_signatures.h"
34
35#include "gnunet_messenger_service.h"
36
37#include "messenger_api_ego.h"
38
39#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE - GNUNET_MIN_MESSAGE_SIZE)
40
41#define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char))
42#define GNUNET_MESSENGER_PADDING_LEVEL0 (512)
43#define GNUNET_MESSENGER_PADDING_LEVEL1 (4096)
44#define GNUNET_MESSENGER_PADDING_LEVEL2 (32768)
45
46/**
47 * Creates and allocates a new message with a specific <i>kind</i>.
48 *
49 * @param[in] kind Kind of message
50 * @return New message
51 */
52struct GNUNET_MESSENGER_Message*
53create_message (enum GNUNET_MESSENGER_MessageKind kind);
54
55/**
56 * Creates and allocates a copy of a given <i>message</i>.
57 *
58 * @param[in] message Message
59 * @return New message
60 */
61struct GNUNET_MESSENGER_Message*
62copy_message (const struct GNUNET_MESSENGER_Message *message);
63
64/**
65 * Frees the messages body memory.
66 *
67 * @param[in/out] message Message
68 */
69void
70cleanup_message (struct GNUNET_MESSENGER_Message *message);
71
72/**
73 * Destroys a message and frees its memory fully.
74 *
75 * @param[in/out] message Message
76 */
77void
78destroy_message (struct GNUNET_MESSENGER_Message *message);
79
80/**
81 * Returns if the message should be bound to a member session.
82 *
83 * @param[in] message Message
84 * @return #GNUNET_YES or #GNUNET_NO
85 */
86int
87is_message_session_bound (const struct GNUNET_MESSENGER_Message *message);
88
89/**
90 * Returns the minimal size in bytes to encode a message of a specific <i>kind</i>.
91 *
92 * @param[in] kind Kind of message
93 * @param[in] include_header Flag to include header
94 * @return Minimal size to encode
95 */
96uint16_t
97get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind,
98 int include_header);
99
100/**
101 * Returns the exact size in bytes to encode a given <i>message</i>.
102 *
103 * @param[in] message Message
104 * @param[in] include_header Flag to include header
105 * @return Size to encode
106 */
107uint16_t
108get_message_size (const struct GNUNET_MESSENGER_Message *message,
109 int include_header);
110
111/**
112 * Encodes a given <i>message</i> into a <i>buffer</i> of a maximal <i>length</i> in bytes.
113 *
114 * @param[in] message Message
115 * @param[in] length Maximal length to encode
116 * @param[out] buffer Buffer
117 * @param[in] include_header Flag to include header
118 */
119void
120encode_message (const struct GNUNET_MESSENGER_Message *message,
121 uint16_t length,
122 char *buffer,
123 int include_header);
124
125/**
126 * Decodes a <i>message</i> from a given <i>buffer</i> of a maximal <i>length</i> in bytes.
127 *
128 * If the buffer is too small for a message of its decoded kind the function fails with
129 * resulting #GNUNET_NO after decoding only the messages header.
130 *
131 * On success the function returns #GNUNET_YES.
132 *
133 * @param[out] message Message
134 * @param[in] length Maximal length to decode
135 * @param[in] buffer Buffer
136 * @param[in] include_header Flag to include header
137 * @param[out] padding Padding
138 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
139 */
140int
141decode_message (struct GNUNET_MESSENGER_Message *message,
142 uint16_t length,
143 const char *buffer,
144 int include_header,
145 uint16_t *padding);
146
147/**
148 * Calculates a <i>hash</i> of a given <i>buffer</i> with a <i>length</i> in bytes
149 * from a <i>message</i>.
150 *
151 * @param[in] message Message
152 * @param[in] length Length of buffer
153 * @param[in] buffer Buffer
154 * @param[out] hash Hash
155 */
156void
157hash_message (const struct GNUNET_MESSENGER_Message *message,
158 uint16_t length,
159 const char *buffer,
160 struct GNUNET_HashCode *hash);
161
162/**
163 * Signs the <i>hash</i> of a <i>message</i> with a given <i>ego</i> and writes the signature
164 * into the <i>buffer</i> as well.
165 *
166 * @param[in/out] message Message
167 * @param[in] length Length of buffer
168 * @param[out] buffer Buffer
169 * @param[in] hash Hash of message
170 * @param[in] ego EGO
171 */
172void
173sign_message (struct GNUNET_MESSENGER_Message *message,
174 uint16_t length,
175 char *buffer,
176 const struct GNUNET_HashCode *hash,
177 const struct GNUNET_MESSENGER_Ego *ego);
178
179/**
180 * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific
181 * public key. The function returns #GNUNET_OK if the signature was valid, otherwise
182 * #GNUNET_SYSERR.
183 *
184 * @param[in] message Message
185 * @param[in] hash Hash of message
186 * @param[in] key Public key of EGO
187 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
188 */
189int
190verify_message (const struct GNUNET_MESSENGER_Message *message,
191 const struct GNUNET_HashCode *hash,
192 const struct GNUNET_IDENTITY_PublicKey *key);
193
194/**
195 * Encrypts a <i>message</i> using a given public <i>key</i> and replaces its body
196 * and kind with the now private encrypted <i>message</i>. The function returns
197 * #GNUNET_YES if the operation succeeded, otherwise #GNUNET_NO.
198 *
199 * @param[in/out] message Message
200 * @param[in] key Public key of EGO
201 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
202 */
203int
204encrypt_message (struct GNUNET_MESSENGER_Message *message,
205 const struct GNUNET_IDENTITY_PublicKey *key);
206
207/**
208 * Decrypts a private <i>message</i> using a given private <i>key</i> and replaces its body
209 * and kind with the inner encrypted message. The function returns #GNUNET_YES if the
210 * operation succeeded, otherwise #GNUNET_NO.
211 *
212 * @param[in/out] message Message
213 * @param[in] key Private key of EGO
214 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
215 */
216int
217decrypt_message (struct GNUNET_MESSENGER_Message *message,
218 const struct GNUNET_IDENTITY_PrivateKey *key);
219
220#define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1
221#define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0
222
223/**
224 * Encodes the <i>message</i> to pack it into a newly allocated envelope if <i>mode</i>
225 * is equal to #GNUNET_MESSENGER_PACK_MODE_ENVELOPE. Independent of the mode the message
226 * will be hashed if <i>hash</i> is not NULL and it will be signed if the <i>ego</i> is
227 * not NULL.
228 *
229 * @param[out] message Message
230 * @param[out] hash Hash of message
231 * @param[in] ego EGO to sign
232 * @param[in] mode Mode of packing
233 * @return Envelope or NULL
234 */
235struct GNUNET_MQ_Envelope*
236pack_message (struct GNUNET_MESSENGER_Message *message,
237 struct GNUNET_HashCode *hash,
238 const struct GNUNET_MESSENGER_Ego *ego,
239 int mode);
240
241/**
242 * Returns if a specific kind of message should be sent by a client. The function returns
243 * #GNUNET_YES or #GNUNET_NO for recommendations and #GNUNET_SYSERR for specific kinds
244 * of messages which should not be sent manually at all.
245 *
246 * @param[in] message Message
247 */
248int
249filter_message_sending (const struct GNUNET_MESSENGER_Message *message);
250
251#endif //GNUNET_MESSENGER_API_MESSAGE_H