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.h225
1 files changed, 0 insertions, 225 deletions
diff --git a/src/messenger/messenger_api_message.h b/src/messenger/messenger_api_message.h
deleted file mode 100644
index 7ce30dc92..000000000
--- a/src/messenger/messenger_api_message.h
+++ /dev/null
@@ -1,225 +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 * Destroys a message and frees its memory fully.
66 *
67 * @param[in/out] message Message
68 */
69void
70destroy_message (struct GNUNET_MESSENGER_Message *message);
71
72/**
73 * Returns if the message should be bound to a member session.
74 *
75 * @param[in] message Message
76 * @return #GNUNET_YES or #GNUNET_NO
77 */
78int
79is_message_session_bound (const struct GNUNET_MESSENGER_Message *message);
80
81/**
82 * Returns the minimal size in bytes to encode a message of a specific <i>kind</i>.
83 *
84 * @param[in] kind Kind of message
85 * @return Minimal size to encode
86 */
87uint16_t
88get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind);
89
90/**
91 * Returns the exact size in bytes to encode a given <i>message</i>.
92 *
93 * @param[in] message Message
94 * @param[in] encode_signature Flag to include signature
95 * @return Size to encode
96 */
97uint16_t
98get_message_size (const struct GNUNET_MESSENGER_Message *message,
99 int include_signature);
100
101/**
102 * Encodes a given <i>message</i> into a <i>buffer</i> of a maximal <i>length</i> in bytes.
103 *
104 * @param[in] message Message
105 * @param[in] length Maximal length to encode
106 * @param[out] buffer Buffer
107 * @param[in] encode_signature Flag to include signature
108 */
109void
110encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer,
111 int include_signature);
112
113/**
114 * Decodes a <i>message</i> from a given <i>buffer</i> of a maximal <i>length</i> in bytes.
115 *
116 * If the buffer is too small for a message of its decoded kind the function fails with
117 * resulting #GNUNET_NO after decoding only the messages header.
118 *
119 * On success the function returns #GNUNET_YES.
120 *
121 * @param[out] message Message
122 * @param[in] length Maximal length to decode
123 * @param[in] buffer Buffer
124 * @param[out] padding Padding
125 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
126 */
127int
128decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer,
129 int include_signature, uint16_t *padding);
130
131/**
132 * Calculates a <i>hash</i> of a given <i>buffer</i> with a <i>length</i> in bytes
133 * from a <i>message</i>.
134 *
135 * @param[in] message Message
136 * @param[in] length Length of buffer
137 * @param[in] buffer Buffer
138 * @param[out] hash Hash
139 */
140void
141hash_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer,
142 struct GNUNET_HashCode *hash);
143
144/**
145 * Signs the <i>hash</i> of a <i>message</i> with a given <i>ego</i> and writes the signature
146 * into the <i>buffer</i> as well.
147 *
148 * @param[in/out] message Message
149 * @param[in] length Length of buffer
150 * @param[out] buffer Buffer
151 * @param[in] hash Hash of message
152 * @param[in] ego EGO
153 */
154void
155sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer,
156 const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego);
157
158/**
159 * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific
160 * public key. The function returns #GNUNET_OK if the signature was valid, otherwise
161 * #GNUNET_SYSERR.
162 *
163 * @param[in] message Message
164 * @param[in] hash Hash of message
165 * @param[in] key Public key of EGO
166 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
167 */
168int
169verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash,
170 const struct GNUNET_IDENTITY_PublicKey *key);
171
172/**
173 * Encrypts a <i>message</i> using a given public <i>key</i> and replaces its body
174 * and kind with the now private encrypted <i>message</i>. The function returns
175 * #GNUNET_YES if the operation succeeded, otherwise #GNUNET_NO.
176 *
177 * @param[in/out] message Message
178 * @param[in] key Public key of EGO
179 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
180 */
181int
182encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key);
183
184/**
185 * Decrypts a private <i>message</i> using a given private <i>key</i> and replaces its body
186 * and kind with the inner encrypted message. The function returns #GNUNET_YES if the
187 * operation succeeded, otherwise #GNUNET_NO.
188 *
189 * @param[in/out] message Message
190 * @param[in] key Private key of EGO
191 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
192 */
193int
194decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key);
195
196#define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1
197#define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0
198
199/**
200 * Encodes the <i>message</i> to pack it into a newly allocated envelope if <i>mode</i>
201 * is equal to #GNUNET_MESSENGER_PACK_MODE_ENVELOPE. Independent of the mode the message
202 * will be hashed if <i>hash</i> is not NULL and it will be signed if the <i>ego</i> is
203 * not NULL.
204 *
205 * @param[out] message Message
206 * @param[out] hash Hash of message
207 * @param[in] ego EGO to sign
208 * @param[in] mode Mode of packing
209 * @return Envelope or NULL
210 */
211struct GNUNET_MQ_Envelope*
212pack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash,
213 const struct GNUNET_MESSENGER_Ego *ego, int mode);
214
215/**
216 * Returns if a specific kind of message should be sent by a client. The function returns
217 * #GNUNET_YES or #GNUNET_NO for recommendations and #GNUNET_SYSERR for specific kinds
218 * of messages which should not be sent manually at all.
219 *
220 * @param[in] message Message
221 */
222int
223filter_message_sending (const struct GNUNET_MESSENGER_Message *message);
224
225#endif //GNUNET_MESSENGER_API_MESSAGE_H