2 This file is part of GNUnet
3 Copyright (C) 2017 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file block/plugin_block_revocation.c
23 * @brief revocation for a block plugin
24 * @author Christian Grothoff
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"
34 #define DEBUG_REVOCATION GNUNET_EXTRA_LOGGING
37 * Number of bits we set per entry in the bloomfilter.
40 #define BLOOMFILTER_K 16
44 * How big is the BF we use for DHT blocks?
46 #define REVOCATION_BF_SIZE 8
50 * Context used inside the plugin.
52 struct InternalContext
55 unsigned int matching_bits;
61 * Create a new block group.
63 * @param ctx block context in which the block group is created
64 * @param type type of the block for which we are creating the group
65 * @param nonce random value used to seed the group creation
66 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
67 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
68 * @param va variable arguments specific to @a type
69 * @return block group handle, NULL if block groups are not supported
70 * by this @a type of block (this is not an error)
72 static struct GNUNET_BLOCK_Group *
73 block_plugin_revocation_create_group (void *cls,
74 enum GNUNET_BLOCK_Type type,
83 guard = va_arg (va, const char *);
84 if (0 == strcmp (guard,
86 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int),
88 else if (0 == strcmp (guard,
90 bf_size = va_arg (va, unsigned int);
94 bf_size = REVOCATION_BF_SIZE;
96 GNUNET_break (NULL == va_arg (va, const char *));
97 return GNUNET_BLOCK_GROUP_bf_create (cls,
108 * Function called to validate a reply or a request. For
109 * request evaluation, simply pass "NULL" for the reply_block.
111 * @param cls our `struct InternalContext`
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
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,
132 const void *reply_block,
133 size_t reply_block_size)
135 struct InternalContext *ic = cls;
136 struct GNUNET_HashCode chash;
137 const struct RevokeMessage *rm = reply_block;
139 if (NULL == reply_block)
140 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
141 if (reply_block_size != sizeof (*rm))
144 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
147 GNUNET_REVOCATION_check_pow (&rm->public_key,
152 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
155 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_REVOCATION,
161 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
163 GNUNET_CRYPTO_hash (&rm->public_key,
164 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
167 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
169 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
170 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
175 * Function called to obtain the key for a block.
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)
186 block_plugin_revocation_get_key (void *cls,
187 enum GNUNET_BLOCK_Type type,
190 struct GNUNET_HashCode *key)
192 const struct RevokeMessage *rm = block;
194 if (block_size != sizeof (*rm))
197 return GNUNET_SYSERR;
199 GNUNET_CRYPTO_hash (&rm->public_key,
200 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
207 * Entry point for the plugin.
209 * @param cls the configuration to use
212 libgnunet_plugin_block_revocation_init (void *cls)
214 static enum GNUNET_BLOCK_Type types[] =
216 GNUNET_BLOCK_TYPE_REVOCATION,
217 GNUNET_BLOCK_TYPE_ANY /* end of list */
219 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
220 struct GNUNET_BLOCK_PluginFunctions *api;
221 struct InternalContext *ic;
222 unsigned long long matching_bits;
225 GNUNET_CONFIGURATION_get_value_number (cfg,
231 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
232 api->evaluate = &block_plugin_revocation_evaluate;
233 api->get_key = &block_plugin_revocation_get_key;
234 api->create_group = &block_plugin_revocation_create_group;
236 ic = GNUNET_new (struct InternalContext);
237 ic->matching_bits = (unsigned int) matching_bits;
244 * Exit point from the plugin.
247 libgnunet_plugin_block_revocation_done (void *cls)
249 struct GNUNET_BLOCK_PluginFunctions *api = cls;
250 struct InternalContext *ic = api->cls;
257 /* end of plugin_block_revocation.c */