diff options
Diffstat (limited to 'src/revocation/plugin_block_revocation.c')
-rw-r--r-- | src/revocation/plugin_block_revocation.c | 275 |
1 files changed, 0 insertions, 275 deletions
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c deleted file mode 100644 index da5882d59..000000000 --- a/src/revocation/plugin_block_revocation.c +++ /dev/null | |||
@@ -1,275 +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 | * Number of bits we set per entry in the bloomfilter. | ||
38 | * Do not change! | ||
39 | */ | ||
40 | #define BLOOMFILTER_K 16 | ||
41 | |||
42 | |||
43 | /** | ||
44 | * How big is the BF we use for DHT blocks? | ||
45 | */ | ||
46 | #define REVOCATION_BF_SIZE 8 | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Context used inside the plugin. | ||
51 | */ | ||
52 | struct InternalContext | ||
53 | { | ||
54 | unsigned int matching_bits; | ||
55 | struct GNUNET_TIME_Relative epoch_duration; | ||
56 | }; | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Create a new block group. | ||
61 | * | ||
62 | * @param ctx block context in which the block group is created | ||
63 | * @param type type of the block for which we are creating the group | ||
64 | * @param nonce random value used to seed the group creation | ||
65 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
66 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
67 | * @param va variable arguments specific to @a type | ||
68 | * @return block group handle, NULL if block groups are not supported | ||
69 | * by this @a type of block (this is not an error) | ||
70 | */ | ||
71 | static struct GNUNET_BLOCK_Group * | ||
72 | block_plugin_revocation_create_group (void *cls, | ||
73 | enum GNUNET_BLOCK_Type type, | ||
74 | uint32_t nonce, | ||
75 | const void *raw_data, | ||
76 | size_t raw_data_size, | ||
77 | va_list va) | ||
78 | { | ||
79 | unsigned int bf_size; | ||
80 | const char *guard; | ||
81 | |||
82 | guard = va_arg (va, const char *); | ||
83 | if (0 == strcmp (guard, | ||
84 | "seen-set-size")) | ||
85 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned | ||
86 | int), | ||
87 | BLOOMFILTER_K); | ||
88 | else if (0 == strcmp (guard, | ||
89 | "filter-size")) | ||
90 | bf_size = va_arg (va, unsigned int); | ||
91 | else | ||
92 | { | ||
93 | GNUNET_break (0); | ||
94 | bf_size = REVOCATION_BF_SIZE; | ||
95 | } | ||
96 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
97 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
98 | bf_size, | ||
99 | BLOOMFILTER_K, | ||
100 | type, | ||
101 | nonce, | ||
102 | raw_data, | ||
103 | raw_data_size); | ||
104 | } | ||
105 | |||
106 | |||
107 | /** | ||
108 | * Function called to validate a reply or a request. For | ||
109 | * request evaluation, simply pass "NULL" for the reply_block. | ||
110 | * | ||
111 | * @param cls our `struct InternalContext` | ||
112 | * @param ctx context | ||
113 | * @param type block type | ||
114 | * @param group block group to use | ||
115 | * @param eo control flags | ||
116 | * @param query original query (hash) | ||
117 | * @param xquery extrended query data (can be NULL, depending on type) | ||
118 | * @param xquery_size number of bytes in xquery | ||
119 | * @param reply_block response to validate | ||
120 | * @param reply_block_size number of bytes in reply block | ||
121 | * @return characterization of result | ||
122 | */ | ||
123 | static enum GNUNET_BLOCK_EvaluationResult | ||
124 | block_plugin_revocation_evaluate (void *cls, | ||
125 | struct GNUNET_BLOCK_Context *ctx, | ||
126 | enum GNUNET_BLOCK_Type type, | ||
127 | struct GNUNET_BLOCK_Group *group, | ||
128 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
129 | const struct GNUNET_HashCode *query, | ||
130 | const void *xquery, | ||
131 | size_t xquery_size, | ||
132 | const void *reply_block, | ||
133 | size_t reply_block_size) | ||
134 | { | ||
135 | struct InternalContext *ic = cls; | ||
136 | struct GNUNET_HashCode chash; | ||
137 | ssize_t pklen; | ||
138 | const struct RevokeMessage *rm = reply_block; | ||
139 | |||
140 | if (NULL == reply_block) | ||
141 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
142 | if (reply_block_size != sizeof(*rm)) | ||
143 | { | ||
144 | GNUNET_break_op (0); | ||
145 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
146 | } | ||
147 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; | ||
148 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
149 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
150 | if (GNUNET_YES != GNUNET_REVOCATION_check_pow (pow, | ||
151 | ic->matching_bits, | ||
152 | ic->epoch_duration)) | ||
153 | { | ||
154 | GNUNET_break_op (0); | ||
155 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
156 | } | ||
157 | pklen = GNUNET_IDENTITY_key_get_length (pk); | ||
158 | if (0 > pklen) | ||
159 | { | ||
160 | GNUNET_break_op (0); | ||
161 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
162 | } | ||
163 | GNUNET_CRYPTO_hash (pk, | ||
164 | pklen, | ||
165 | &chash); | ||
166 | if (GNUNET_YES == | ||
167 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
168 | &chash)) | ||
169 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
170 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
171 | } | ||
172 | |||
173 | |||
174 | /** | ||
175 | * Function called to obtain the key for a block. | ||
176 | * | ||
177 | * @param cls closure | ||
178 | * @param type block type | ||
179 | * @param block block to get the key for | ||
180 | * @param block_size number of bytes in block | ||
181 | * @param key set to the key (query) for the given block | ||
182 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | ||
183 | * (or if extracting a key from a block of this type does not work) | ||
184 | */ | ||
185 | static int | ||
186 | block_plugin_revocation_get_key (void *cls, | ||
187 | enum GNUNET_BLOCK_Type type, | ||
188 | const void *block, | ||
189 | size_t block_size, | ||
190 | struct GNUNET_HashCode *key) | ||
191 | { | ||
192 | const struct RevokeMessage *rm = block; | ||
193 | ssize_t ksize; | ||
194 | |||
195 | if (block_size <= sizeof(*rm)) | ||
196 | { | ||
197 | GNUNET_break_op (0); | ||
198 | return GNUNET_SYSERR; | ||
199 | } | ||
200 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; | ||
201 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
202 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
203 | ksize = GNUNET_IDENTITY_key_get_length (pk); | ||
204 | if (0 > ksize) | ||
205 | { | ||
206 | GNUNET_break_op (0); | ||
207 | return GNUNET_SYSERR; | ||
208 | } | ||
209 | GNUNET_CRYPTO_hash (pk, | ||
210 | ksize, | ||
211 | key); | ||
212 | return GNUNET_OK; | ||
213 | } | ||
214 | |||
215 | |||
216 | /** | ||
217 | * Entry point for the plugin. | ||
218 | * | ||
219 | * @param cls the configuration to use | ||
220 | */ | ||
221 | void * | ||
222 | libgnunet_plugin_block_revocation_init (void *cls) | ||
223 | { | ||
224 | static enum GNUNET_BLOCK_Type types[] = { | ||
225 | GNUNET_BLOCK_TYPE_REVOCATION, | ||
226 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | ||
227 | }; | ||
228 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
229 | struct GNUNET_BLOCK_PluginFunctions *api; | ||
230 | struct InternalContext *ic; | ||
231 | unsigned long long matching_bits; | ||
232 | struct GNUNET_TIME_Relative epoch_duration; | ||
233 | |||
234 | if (GNUNET_OK != | ||
235 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
236 | "REVOCATION", | ||
237 | "WORKBITS", | ||
238 | &matching_bits)) | ||
239 | return NULL; | ||
240 | if (GNUNET_OK != | ||
241 | GNUNET_CONFIGURATION_get_value_time (cfg, | ||
242 | "REVOCATION", | ||
243 | "EPOCH_DURATION", | ||
244 | &epoch_duration)) | ||
245 | return NULL; | ||
246 | |||
247 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | ||
248 | api->evaluate = &block_plugin_revocation_evaluate; | ||
249 | api->get_key = &block_plugin_revocation_get_key; | ||
250 | api->create_group = &block_plugin_revocation_create_group; | ||
251 | api->types = types; | ||
252 | ic = GNUNET_new (struct InternalContext); | ||
253 | ic->matching_bits = (unsigned int) matching_bits; | ||
254 | ic->epoch_duration = epoch_duration; | ||
255 | api->cls = ic; | ||
256 | return api; | ||
257 | } | ||
258 | |||
259 | |||
260 | /** | ||
261 | * Exit point from the plugin. | ||
262 | */ | ||
263 | void * | ||
264 | libgnunet_plugin_block_revocation_done (void *cls) | ||
265 | { | ||
266 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | ||
267 | struct InternalContext *ic = api->cls; | ||
268 | |||
269 | GNUNET_free (ic); | ||
270 | GNUNET_free (api); | ||
271 | return NULL; | ||
272 | } | ||
273 | |||
274 | |||
275 | /* end of plugin_block_revocation.c */ | ||