aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/plugin_block_revocation.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 10:19:42 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 10:19:42 +0200
commit4e28833d9ecb6bbd933b770eae2b712fc0d80286 (patch)
treef3501ba172352dcfed9bb7072d969417e852270a /src/revocation/plugin_block_revocation.c
parent3bfe2d52dcac5df09783d82b3a80899ae5b5d69a (diff)
downloadgnunet-4e28833d9ecb6bbd933b770eae2b712fc0d80286.tar.gz
gnunet-4e28833d9ecb6bbd933b770eae2b712fc0d80286.zip
BUILD: Move revocation to service
Diffstat (limited to 'src/revocation/plugin_block_revocation.c')
-rw-r--r--src/revocation/plugin_block_revocation.c308
1 files changed, 0 insertions, 308 deletions
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c
deleted file mode 100644
index 9686f23ff..000000000
--- a/src/revocation/plugin_block_revocation.c
+++ /dev/null
@@ -1,308 +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 */
39struct 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 */
57static enum GNUNET_GenericReturnValue
58block_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 */
87static enum GNUNET_GenericReturnValue
88block_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_CRYPTO_PublicKey pk;
98 size_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 if (GNUNET_SYSERR ==
118 GNUNET_CRYPTO_read_public_key_from_buffer (&pow[1],
119 left,
120 &pk,
121 &pklen))
122 {
123 GNUNET_break_op (0);
124 return GNUNET_NO;
125 }
126 if (0 == pklen)
127 {
128 GNUNET_break_op (0);
129 return GNUNET_NO;
130 }
131 if (GNUNET_YES !=
132 GNUNET_REVOCATION_check_pow (pow,
133 ic->matching_bits,
134 ic->epoch_duration))
135 {
136 GNUNET_break_op (0);
137 return GNUNET_NO;
138 }
139 return GNUNET_OK;
140}
141
142
143/**
144 * Function called to validate a reply to a request. Note that it is assumed
145 * that the reply has already been matched to the key (and signatures checked)
146 * as it would be done with the GetKeyFunction and the
147 * BlockEvaluationFunction.
148 *
149 * @param cls closure
150 * @param type block type
151 * @param group which block group to use for evaluation
152 * @param query original query (hash)
153 * @param xquery extrended query data (can be NULL, depending on type)
154 * @param xquery_size number of bytes in @a xquery
155 * @param reply_block response to validate
156 * @param reply_block_size number of bytes in @a reply_block
157 * @return characterization of result
158 */
159static enum GNUNET_BLOCK_ReplyEvaluationResult
160block_plugin_revocation_check_reply (
161 void *cls,
162 enum GNUNET_BLOCK_Type type,
163 struct GNUNET_BLOCK_Group *group,
164 const struct GNUNET_HashCode *query,
165 const void *xquery,
166 size_t xquery_size,
167 const void *reply_block,
168 size_t reply_block_size)
169{
170 (void) cls;
171 (void) group;
172 (void) query;
173 (void) xquery;
174 (void) xquery_size;
175 (void) reply_block;
176 (void) reply_block_size;
177 if (GNUNET_BLOCK_TYPE_REVOCATION != type)
178 {
179 GNUNET_break (0);
180 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
181 }
182 return GNUNET_BLOCK_REPLY_OK_LAST;
183}
184
185
186/**
187 * Function called to obtain the key for a block.
188 *
189 * @param cls closure
190 * @param type block type
191 * @param block block to get the key for
192 * @param block_size number of bytes in block
193 * @param key set to the key (query) for the given block
194 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
195 * (or if extracting a key from a block of this type does not work)
196 */
197static enum GNUNET_GenericReturnValue
198block_plugin_revocation_get_key (void *cls,
199 enum GNUNET_BLOCK_Type type,
200 const void *block,
201 size_t block_size,
202 struct GNUNET_HashCode *key)
203{
204 const struct RevokeMessage *rm = block;
205 const struct GNUNET_REVOCATION_PowP *pow
206 = (const struct GNUNET_REVOCATION_PowP *) &rm[1];
207 struct GNUNET_CRYPTO_PublicKey pk;
208 size_t pklen;
209 size_t left;
210
211 if (GNUNET_BLOCK_TYPE_REVOCATION != type)
212 {
213 GNUNET_break (0);
214 return GNUNET_SYSERR;
215 }
216 if (block_size < sizeof(*rm) + sizeof(*pow))
217 {
218 GNUNET_break_op (0);
219 return GNUNET_NO;
220 }
221 if (block_size != sizeof(*rm) + ntohl (rm->pow_size))
222 {
223 GNUNET_break_op (0);
224 return GNUNET_NO;
225 }
226 left = block_size - sizeof (*rm) - sizeof (*pow);
227 if (GNUNET_SYSERR == GNUNET_CRYPTO_read_public_key_from_buffer (&pow[1],
228 left,
229 &pk,
230 &pklen))
231 {
232 GNUNET_break_op (0);
233 return GNUNET_NO;
234 }
235 if (0 == pklen)
236 {
237 GNUNET_break_op (0);
238 return GNUNET_NO;
239 }
240 GNUNET_CRYPTO_hash (&pow[1],
241 pklen,
242 key);
243 return GNUNET_OK;
244}
245
246
247/**
248 * Entry point for the plugin.
249 *
250 * @param cls the configuration to use
251 */
252void *
253libgnunet_plugin_block_revocation_init (void *cls)
254{
255 static const enum GNUNET_BLOCK_Type types[] = {
256 GNUNET_BLOCK_TYPE_REVOCATION,
257 GNUNET_BLOCK_TYPE_ANY /* end of list */
258 };
259 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
260 struct GNUNET_BLOCK_PluginFunctions *api;
261 struct InternalContext *ic;
262 unsigned long long matching_bits;
263 struct GNUNET_TIME_Relative epoch_duration;
264
265 if (GNUNET_OK !=
266 GNUNET_CONFIGURATION_get_value_number (cfg,
267 "REVOCATION",
268 "WORKBITS",
269 &matching_bits))
270 return NULL;
271 if (GNUNET_OK !=
272 GNUNET_CONFIGURATION_get_value_time (cfg,
273 "REVOCATION",
274 "EPOCH_DURATION",
275 &epoch_duration))
276 return NULL;
277
278 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
279 api->get_key = &block_plugin_revocation_get_key;
280 api->check_query = &block_plugin_revocation_check_query;
281 api->check_block = &block_plugin_revocation_check_block;
282 api->check_reply = &block_plugin_revocation_check_reply;
283 api->create_group = NULL;
284 api->types = types;
285 ic = GNUNET_new (struct InternalContext);
286 ic->matching_bits = (unsigned int) matching_bits;
287 ic->epoch_duration = epoch_duration;
288 api->cls = ic;
289 return api;
290}
291
292
293/**
294 * Exit point from the plugin.
295 */
296void *
297libgnunet_plugin_block_revocation_done (void *cls)
298{
299 struct GNUNET_BLOCK_PluginFunctions *api = cls;
300 struct InternalContext *ic = api->cls;
301
302 GNUNET_free (ic);
303 GNUNET_free (api);
304 return NULL;
305}
306
307
308/* end of plugin_block_revocation.c */