diff options
Diffstat (limited to 'src/revocation/plugin_block_revocation.c')
-rw-r--r-- | src/revocation/plugin_block_revocation.c | 297 |
1 files changed, 0 insertions, 297 deletions
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c deleted file mode 100644 index 12ec555e4..000000000 --- a/src/revocation/plugin_block_revocation.c +++ /dev/null | |||
@@ -1,297 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2017 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 | /** | ||
22 | * @file block/plugin_block_revocation.c | ||
23 | * @brief revocation for a block plugin | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_signatures.h" | ||
29 | #include "gnunet_block_plugin.h" | ||
30 | #include "gnunet_block_group_lib.h" | ||
31 | #include "revocation.h" | ||
32 | #include "gnunet_revocation_service.h" | ||
33 | |||
34 | #define DEBUG_REVOCATION GNUNET_EXTRA_LOGGING | ||
35 | |||
36 | /** | ||
37 | * Context used inside the plugin. | ||
38 | */ | ||
39 | struct InternalContext | ||
40 | { | ||
41 | unsigned int matching_bits; | ||
42 | struct GNUNET_TIME_Relative epoch_duration; | ||
43 | }; | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Function called to validate a query. | ||
48 | * | ||
49 | * @param cls closure | ||
50 | * @param ctx block context | ||
51 | * @param type block type | ||
52 | * @param query original query (hash) | ||
53 | * @param xquery extrended query data (can be NULL, depending on type) | ||
54 | * @param xquery_size number of bytes in @a xquery | ||
55 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
56 | */ | ||
57 | static enum GNUNET_GenericReturnValue | ||
58 | block_plugin_revocation_check_query (void *cls, | ||
59 | enum GNUNET_BLOCK_Type type, | ||
60 | const struct GNUNET_HashCode *query, | ||
61 | const void *xquery, | ||
62 | size_t xquery_size) | ||
63 | { | ||
64 | (void) cls; | ||
65 | (void) query; | ||
66 | (void) xquery; | ||
67 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | ||
68 | { | ||
69 | GNUNET_break (0); | ||
70 | return GNUNET_SYSERR; | ||
71 | } | ||
72 | if (0 != xquery_size) | ||
73 | return GNUNET_NO; | ||
74 | return GNUNET_OK; | ||
75 | } | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Function called to validate a block for storage. | ||
80 | * | ||
81 | * @param cls closure | ||
82 | * @param type block type | ||
83 | * @param block block data to validate | ||
84 | * @param block_size number of bytes in @a block | ||
85 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
86 | */ | ||
87 | static enum GNUNET_GenericReturnValue | ||
88 | block_plugin_revocation_check_block (void *cls, | ||
89 | enum GNUNET_BLOCK_Type type, | ||
90 | const void *block, | ||
91 | size_t block_size) | ||
92 | { | ||
93 | struct InternalContext *ic = cls; | ||
94 | const struct RevokeMessage *rm = block; | ||
95 | const struct GNUNET_REVOCATION_PowP *pow | ||
96 | = (const struct GNUNET_REVOCATION_PowP *) &rm[1]; | ||
97 | struct GNUNET_IDENTITY_PublicKey pk; | ||
98 | ssize_t pklen; | ||
99 | size_t left; | ||
100 | |||
101 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | ||
102 | { | ||
103 | GNUNET_break (0); | ||
104 | return GNUNET_SYSERR; | ||
105 | } | ||
106 | if (block_size < sizeof(*rm) + sizeof(*pow)) | ||
107 | { | ||
108 | GNUNET_break_op (0); | ||
109 | return GNUNET_NO; | ||
110 | } | ||
111 | if (block_size != sizeof(*rm) + ntohl (rm->pow_size)) | ||
112 | { | ||
113 | GNUNET_break_op (0); | ||
114 | return GNUNET_NO; | ||
115 | } | ||
116 | left = block_size - sizeof (*rm) - sizeof (*pow); | ||
117 | pklen = GNUNET_IDENTITY_read_key_from_buffer (&pk, | ||
118 | &pow[1], | ||
119 | left); | ||
120 | if (0 > pklen) | ||
121 | { | ||
122 | GNUNET_break_op (0); | ||
123 | return GNUNET_NO; | ||
124 | } | ||
125 | if (GNUNET_YES != | ||
126 | GNUNET_REVOCATION_check_pow (pow, | ||
127 | ic->matching_bits, | ||
128 | ic->epoch_duration)) | ||
129 | { | ||
130 | GNUNET_break_op (0); | ||
131 | return GNUNET_NO; | ||
132 | } | ||
133 | return GNUNET_OK; | ||
134 | } | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Function called to validate a reply to a request. Note that it is assumed | ||
139 | * that the reply has already been matched to the key (and signatures checked) | ||
140 | * as it would be done with the GetKeyFunction and the | ||
141 | * BlockEvaluationFunction. | ||
142 | * | ||
143 | * @param cls closure | ||
144 | * @param type block type | ||
145 | * @param group which block group to use for evaluation | ||
146 | * @param query original query (hash) | ||
147 | * @param xquery extrended query data (can be NULL, depending on type) | ||
148 | * @param xquery_size number of bytes in @a xquery | ||
149 | * @param reply_block response to validate | ||
150 | * @param reply_block_size number of bytes in @a reply_block | ||
151 | * @return characterization of result | ||
152 | */ | ||
153 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
154 | block_plugin_revocation_check_reply ( | ||
155 | void *cls, | ||
156 | enum GNUNET_BLOCK_Type type, | ||
157 | struct GNUNET_BLOCK_Group *group, | ||
158 | const struct GNUNET_HashCode *query, | ||
159 | const void *xquery, | ||
160 | size_t xquery_size, | ||
161 | const void *reply_block, | ||
162 | size_t reply_block_size) | ||
163 | { | ||
164 | (void) cls; | ||
165 | (void) group; | ||
166 | (void) query; | ||
167 | (void) xquery; | ||
168 | (void) xquery_size; | ||
169 | (void) reply_block; | ||
170 | (void) reply_block_size; | ||
171 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | ||
172 | { | ||
173 | GNUNET_break (0); | ||
174 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
175 | } | ||
176 | return GNUNET_BLOCK_REPLY_OK_LAST; | ||
177 | } | ||
178 | |||
179 | |||
180 | /** | ||
181 | * Function called to obtain the key for a block. | ||
182 | * | ||
183 | * @param cls closure | ||
184 | * @param type block type | ||
185 | * @param block block to get the key for | ||
186 | * @param block_size number of bytes in block | ||
187 | * @param key set to the key (query) for the given block | ||
188 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | ||
189 | * (or if extracting a key from a block of this type does not work) | ||
190 | */ | ||
191 | static enum GNUNET_GenericReturnValue | ||
192 | block_plugin_revocation_get_key (void *cls, | ||
193 | enum GNUNET_BLOCK_Type type, | ||
194 | const void *block, | ||
195 | size_t block_size, | ||
196 | struct GNUNET_HashCode *key) | ||
197 | { | ||
198 | const struct RevokeMessage *rm = block; | ||
199 | const struct GNUNET_REVOCATION_PowP *pow | ||
200 | = (const struct GNUNET_REVOCATION_PowP *) &rm[1]; | ||
201 | struct GNUNET_IDENTITY_PublicKey pk; | ||
202 | ssize_t pklen; | ||
203 | size_t left; | ||
204 | |||
205 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | ||
206 | { | ||
207 | GNUNET_break (0); | ||
208 | return GNUNET_SYSERR; | ||
209 | } | ||
210 | if (block_size < sizeof(*rm) + sizeof(*pow)) | ||
211 | { | ||
212 | GNUNET_break_op (0); | ||
213 | return GNUNET_NO; | ||
214 | } | ||
215 | if (block_size != sizeof(*rm) + ntohl (rm->pow_size)) | ||
216 | { | ||
217 | GNUNET_break_op (0); | ||
218 | return GNUNET_NO; | ||
219 | } | ||
220 | left = block_size - sizeof (*rm) - sizeof (*pow); | ||
221 | pklen = GNUNET_IDENTITY_read_key_from_buffer (&pk, | ||
222 | &pow[1], | ||
223 | left); | ||
224 | if (0 > pklen) | ||
225 | { | ||
226 | GNUNET_break_op (0); | ||
227 | return GNUNET_NO; | ||
228 | } | ||
229 | GNUNET_CRYPTO_hash (&pow[1], | ||
230 | pklen, | ||
231 | key); | ||
232 | return GNUNET_OK; | ||
233 | } | ||
234 | |||
235 | |||
236 | /** | ||
237 | * Entry point for the plugin. | ||
238 | * | ||
239 | * @param cls the configuration to use | ||
240 | */ | ||
241 | void * | ||
242 | libgnunet_plugin_block_revocation_init (void *cls) | ||
243 | { | ||
244 | static const enum GNUNET_BLOCK_Type types[] = { | ||
245 | GNUNET_BLOCK_TYPE_REVOCATION, | ||
246 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | ||
247 | }; | ||
248 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
249 | struct GNUNET_BLOCK_PluginFunctions *api; | ||
250 | struct InternalContext *ic; | ||
251 | unsigned long long matching_bits; | ||
252 | struct GNUNET_TIME_Relative epoch_duration; | ||
253 | |||
254 | if (GNUNET_OK != | ||
255 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
256 | "REVOCATION", | ||
257 | "WORKBITS", | ||
258 | &matching_bits)) | ||
259 | return NULL; | ||
260 | if (GNUNET_OK != | ||
261 | GNUNET_CONFIGURATION_get_value_time (cfg, | ||
262 | "REVOCATION", | ||
263 | "EPOCH_DURATION", | ||
264 | &epoch_duration)) | ||
265 | return NULL; | ||
266 | |||
267 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | ||
268 | api->get_key = &block_plugin_revocation_get_key; | ||
269 | api->check_query = &block_plugin_revocation_check_query; | ||
270 | api->check_block = &block_plugin_revocation_check_block; | ||
271 | api->check_reply = &block_plugin_revocation_check_reply; | ||
272 | api->create_group = NULL; | ||
273 | api->types = types; | ||
274 | ic = GNUNET_new (struct InternalContext); | ||
275 | ic->matching_bits = (unsigned int) matching_bits; | ||
276 | ic->epoch_duration = epoch_duration; | ||
277 | api->cls = ic; | ||
278 | return api; | ||
279 | } | ||
280 | |||
281 | |||
282 | /** | ||
283 | * Exit point from the plugin. | ||
284 | */ | ||
285 | void * | ||
286 | libgnunet_plugin_block_revocation_done (void *cls) | ||
287 | { | ||
288 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | ||
289 | struct InternalContext *ic = api->cls; | ||
290 | |||
291 | GNUNET_free (ic); | ||
292 | GNUNET_free (api); | ||
293 | return NULL; | ||
294 | } | ||
295 | |||
296 | |||
297 | /* end of plugin_block_revocation.c */ | ||