aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/plugin_block_revocation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/revocation/plugin_block_revocation.c')
-rw-r--r--src/revocation/plugin_block_revocation.c242
1 files changed, 157 insertions, 85 deletions
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c
index da5882d59..3beae60bb 100644
--- a/src/revocation/plugin_block_revocation.c
+++ b/src/revocation/plugin_block_revocation.c
@@ -34,19 +34,6 @@
34#define DEBUG_REVOCATION GNUNET_EXTRA_LOGGING 34#define DEBUG_REVOCATION GNUNET_EXTRA_LOGGING
35 35
36/** 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. 37 * Context used inside the plugin.
51 */ 38 */
52struct InternalContext 39struct InternalContext
@@ -57,54 +44,6 @@ struct InternalContext
57 44
58 45
59/** 46/**
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 */
71static struct GNUNET_BLOCK_Group *
72block_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 47 * Function called to validate a reply or a request. For
109 * request evaluation, simply pass "NULL" for the reply_block. 48 * request evaluation, simply pass "NULL" for the reply_block.
110 * 49 *
@@ -133,7 +72,6 @@ block_plugin_revocation_evaluate (void *cls,
133 size_t reply_block_size) 72 size_t reply_block_size)
134{ 73{
135 struct InternalContext *ic = cls; 74 struct InternalContext *ic = cls;
136 struct GNUNET_HashCode chash;
137 ssize_t pklen; 75 ssize_t pklen;
138 const struct RevokeMessage *rm = reply_block; 76 const struct RevokeMessage *rm = reply_block;
139 77
@@ -160,14 +98,134 @@ block_plugin_revocation_evaluate (void *cls,
160 GNUNET_break_op (0); 98 GNUNET_break_op (0);
161 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 99 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
162 } 100 }
163 GNUNET_CRYPTO_hash (pk, 101 return GNUNET_BLOCK_EVALUATION_OK_LAST;
164 pklen, 102}
165 &chash); 103
166 if (GNUNET_YES == 104
167 GNUNET_BLOCK_GROUP_bf_test_and_set (group, 105/**
168 &chash)) 106 * Function called to validate a query.
169 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 107 *
170 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 108 * @param cls closure
109 * @param ctx block context
110 * @param type block type
111 * @param query original query (hash)
112 * @param xquery extrended query data (can be NULL, depending on type)
113 * @param xquery_size number of bytes in @a xquery
114 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
115 */
116static enum GNUNET_GenericReturnValue
117block_plugin_revocation_check_query (void *cls,
118 enum GNUNET_BLOCK_Type type,
119 const struct GNUNET_HashCode *query,
120 const void *xquery,
121 size_t xquery_size)
122{
123 (void) cls;
124 (void) query;
125 (void) xquery;
126 if (GNUNET_BLOCK_TYPE_REVOCATION != type)
127 return GNUNET_SYSERR;
128 if (0 != xquery_size)
129 return GNUNET_NO;
130 return GNUNET_OK;
131}
132
133
134/**
135 * Function called to validate a block for storage.
136 *
137 * @param cls closure
138 * @param type block type
139 * @param query key for the block (hash), must match exactly
140 * @param block block data to validate
141 * @param block_size number of bytes in @a block
142 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
143 */
144static enum GNUNET_GenericReturnValue
145block_plugin_revocation_check_block (void *cls,
146 enum GNUNET_BLOCK_Type type,
147 const struct GNUNET_HashCode *query,
148 const void *block,
149 size_t block_size)
150{
151 struct InternalContext *ic = cls;
152 const struct RevokeMessage *rm = block;
153 const struct GNUNET_REVOCATION_PowP *pow
154 = (const struct GNUNET_REVOCATION_PowP *) &rm[1];
155 struct GNUNET_IDENTITY_PublicKey pk;
156 ssize_t pklen;
157 size_t left;
158
159 if (GNUNET_BLOCK_TYPE_REVOCATION != type)
160 return GNUNET_SYSERR;
161 if (block_size < sizeof(*rm) + sizeof(*pow))
162 {
163 GNUNET_break_op (0);
164 return GNUNET_NO;
165 }
166 if (block_size != sizeof(*rm) + ntohl (rm->pow_size))
167 {
168 GNUNET_break_op (0);
169 return GNUNET_NO;
170 }
171 left = block_size - sizeof (*rm) - sizeof (*pow);
172 pklen = GNUNET_IDENTITY_read_key_from_buffer (&pk,
173 &pow[1],
174 left);
175 if (0 > pklen)
176 {
177 GNUNET_break_op (0);
178 return GNUNET_NO;
179 }
180 if (GNUNET_YES !=
181 GNUNET_REVOCATION_check_pow (pow,
182 ic->matching_bits,
183 ic->epoch_duration))
184 {
185 GNUNET_break_op (0);
186 return GNUNET_NO;
187 }
188 return GNUNET_OK;
189}
190
191
192/**
193 * Function called to validate a reply to a request. Note that it is assumed
194 * that the reply has already been matched to the key (and signatures checked)
195 * as it would be done with the GetKeyFunction and the
196 * BlockEvaluationFunction.
197 *
198 * @param cls closure
199 * @param type block type
200 * @param group which block group to use for evaluation
201 * @param query original query (hash)
202 * @param xquery extrended query data (can be NULL, depending on type)
203 * @param xquery_size number of bytes in @a xquery
204 * @param reply_block response to validate
205 * @param reply_block_size number of bytes in @a reply_block
206 * @return characterization of result
207 */
208static enum GNUNET_BLOCK_ReplyEvaluationResult
209block_plugin_revocation_check_reply (
210 void *cls,
211 enum GNUNET_BLOCK_Type type,
212 struct GNUNET_BLOCK_Group *group,
213 const struct GNUNET_HashCode *query,
214 const void *xquery,
215 size_t xquery_size,
216 const void *reply_block,
217 size_t reply_block_size)
218{
219 (void) cls;
220 (void) group;
221 (void) query;
222 (void) xquery;
223 (void) xquery_size;
224 (void) reply_block;
225 (void) reply_block_size;
226 if (GNUNET_BLOCK_TYPE_REVOCATION != type)
227 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
228 return GNUNET_BLOCK_REPLY_OK_LAST;
171} 229}
172 230
173 231
@@ -182,7 +240,7 @@ block_plugin_revocation_evaluate (void *cls,
182 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 240 * @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) 241 * (or if extracting a key from a block of this type does not work)
184 */ 242 */
185static int 243static enum GNUNET_GenericReturnValue
186block_plugin_revocation_get_key (void *cls, 244block_plugin_revocation_get_key (void *cls,
187 enum GNUNET_BLOCK_Type type, 245 enum GNUNET_BLOCK_Type type,
188 const void *block, 246 const void *block,
@@ -190,24 +248,35 @@ block_plugin_revocation_get_key (void *cls,
190 struct GNUNET_HashCode *key) 248 struct GNUNET_HashCode *key)
191{ 249{
192 const struct RevokeMessage *rm = block; 250 const struct RevokeMessage *rm = block;
193 ssize_t ksize; 251 const struct GNUNET_REVOCATION_PowP *pow
252 = (const struct GNUNET_REVOCATION_PowP *) &rm[1];
253 struct GNUNET_IDENTITY_PublicKey pk;
254 ssize_t pklen;
255 size_t left;
194 256
195 if (block_size <= sizeof(*rm)) 257 if (GNUNET_BLOCK_TYPE_REVOCATION != type)
258 return GNUNET_SYSERR;
259 if (block_size < sizeof(*rm) + sizeof(*pow))
196 { 260 {
197 GNUNET_break_op (0); 261 GNUNET_break_op (0);
198 return GNUNET_SYSERR; 262 return GNUNET_NO;
199 } 263 }
200 struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; 264 if (block_size != sizeof(*rm) + ntohl (rm->pow_size))
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 { 265 {
206 GNUNET_break_op (0); 266 GNUNET_break_op (0);
207 return GNUNET_SYSERR; 267 return GNUNET_NO;
208 } 268 }
209 GNUNET_CRYPTO_hash (pk, 269 left = block_size - sizeof (*rm) - sizeof (*pow);
210 ksize, 270 pklen = GNUNET_IDENTITY_read_key_from_buffer (&pk,
271 &pow[1],
272 left);
273 if (0 > pklen)
274 {
275 GNUNET_break_op (0);
276 return GNUNET_NO;
277 }
278 GNUNET_CRYPTO_hash (&pow[1],
279 pklen,
211 key); 280 key);
212 return GNUNET_OK; 281 return GNUNET_OK;
213} 282}
@@ -221,8 +290,8 @@ block_plugin_revocation_get_key (void *cls,
221void * 290void *
222libgnunet_plugin_block_revocation_init (void *cls) 291libgnunet_plugin_block_revocation_init (void *cls)
223{ 292{
224 static enum GNUNET_BLOCK_Type types[] = { 293 static const enum GNUNET_BLOCK_Type types[] = {
225 GNUNET_BLOCK_TYPE_REVOCATION, 294 GNUNET_BLOCK_TYPE_REVOCATION,
226 GNUNET_BLOCK_TYPE_ANY /* end of list */ 295 GNUNET_BLOCK_TYPE_ANY /* end of list */
227 }; 296 };
228 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 297 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
@@ -247,7 +316,10 @@ libgnunet_plugin_block_revocation_init (void *cls)
247 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 316 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
248 api->evaluate = &block_plugin_revocation_evaluate; 317 api->evaluate = &block_plugin_revocation_evaluate;
249 api->get_key = &block_plugin_revocation_get_key; 318 api->get_key = &block_plugin_revocation_get_key;
250 api->create_group = &block_plugin_revocation_create_group; 319 api->check_query = &block_plugin_revocation_check_query;
320 api->check_block = &block_plugin_revocation_check_block;
321 api->check_reply = &block_plugin_revocation_check_reply;
322 api->create_group = NULL;
251 api->types = types; 323 api->types = types;
252 ic = GNUNET_new (struct InternalContext); 324 ic = GNUNET_new (struct InternalContext);
253 ic->matching_bits = (unsigned int) matching_bits; 325 ic->matching_bits = (unsigned int) matching_bits;