aboutsummaryrefslogtreecommitdiff
path: root/src/dns/plugin_block_dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dns/plugin_block_dns.c')
-rw-r--r--src/dns/plugin_block_dns.c140
1 files changed, 139 insertions, 1 deletions
diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c
index e0beccb52..d3eb7d2b9 100644
--- a/src/dns/plugin_block_dns.c
+++ b/src/dns/plugin_block_dns.c
@@ -177,6 +177,141 @@ block_plugin_dns_evaluate (void *cls,
177 177
178 178
179/** 179/**
180 * Function called to validate a query.
181 *
182 * @param cls closure
183 * @param ctx block context
184 * @param type block type
185 * @param query original query (hash)
186 * @param xquery extrended query data (can be NULL, depending on type)
187 * @param xquery_size number of bytes in @a xquery
188 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
189 */
190static enum GNUNET_GenericReturnValue
191block_plugin_dns_check_query (void *cls,
192 enum GNUNET_BLOCK_Type type,
193 const struct GNUNET_HashCode *query,
194 const void *xquery,
195 size_t xquery_size)
196{
197 switch (type)
198 {
199 case GNUNET_BLOCK_TYPE_DNS:
200 if (0 != xquery_size)
201 return GNUNET_NO;
202 return GNUNET_OK;
203 default:
204 return GNUNET_SYSERR;
205 }
206}
207
208
209/**
210 * Function called to validate a block for storage.
211 *
212 * @param cls closure
213 * @param type block type
214 * @param query key for the block (hash), must match exactly
215 * @param block block data to validate
216 * @param block_size number of bytes in @a block
217 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
218 */
219static enum GNUNET_GenericReturnValue
220block_plugin_dns_check_block (void *cls,
221 enum GNUNET_BLOCK_Type type,
222 const struct GNUNET_HashCode *query,
223 const void *block,
224 size_t block_size)
225{
226 const struct GNUNET_DNS_Advertisement *ad;
227
228 switch (type)
229 {
230 case GNUNET_BLOCK_TYPE_DNS:
231 if (sizeof(struct GNUNET_DNS_Advertisement) != block_size)
232 {
233 GNUNET_break_op (0);
234 return GNUNET_NO;
235 }
236 ad = block;
237
238 if (ntohl (ad->purpose.size) !=
239 sizeof(struct GNUNET_DNS_Advertisement)
240 - sizeof(struct GNUNET_CRYPTO_EddsaSignature))
241 {
242 GNUNET_break_op (0);
243 return GNUNET_NO;
244 }
245 if (GNUNET_TIME_absolute_is_past (
246 GNUNET_TIME_absolute_ntoh (ad->expiration_time)))
247 {
248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
249 "DNS advertisement has expired\n");
250 return GNUNET_NO;
251 }
252 if (GNUNET_OK !=
253 GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD,
254 &ad->purpose,
255 &ad->signature,
256 &ad->peer.public_key))
257 {
258 GNUNET_break_op (0);
259 return GNUNET_NO;
260 }
261 return GNUNET_OK;
262 default:
263 return GNUNET_SYSERR;
264 }
265}
266
267
268/**
269 * Function called to validate a reply to a request. Note that it is assumed
270 * that the reply has already been matched to the key (and signatures checked)
271 * as it would be done with the GetKeyFunction and the
272 * BlockEvaluationFunction.
273 *
274 * @param cls closure
275 * @param type block type
276 * @param group which block group to use for evaluation
277 * @param query original query (hash)
278 * @param xquery extrended query data (can be NULL, depending on type)
279 * @param xquery_size number of bytes in @a xquery
280 * @param reply_block response to validate
281 * @param reply_block_size number of bytes in @a reply_block
282 * @return characterization of result
283 */
284static enum GNUNET_BLOCK_ReplyEvaluationResult
285block_plugin_dns_check_reply (
286 void *cls,
287 enum GNUNET_BLOCK_Type type,
288 struct GNUNET_BLOCK_Group *group,
289 const struct GNUNET_HashCode *query,
290 const void *xquery,
291 size_t xquery_size,
292 const void *reply_block,
293 size_t reply_block_size)
294{
295 struct GNUNET_HashCode phash;
296
297 switch (type)
298 {
299 case GNUNET_BLOCK_TYPE_DNS:
300 GNUNET_CRYPTO_hash (reply_block,
301 reply_block_size,
302 &phash);
303 if (GNUNET_YES ==
304 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
305 &phash))
306 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
307 return GNUNET_BLOCK_REPLY_OK_MORE;
308 default:
309 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
310 }
311}
312
313
314/**
180 * Function called to obtain the key for a block. 315 * Function called to obtain the key for a block.
181 * 316 *
182 * @param cls closure 317 * @param cls closure
@@ -187,7 +322,7 @@ block_plugin_dns_evaluate (void *cls,
187 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 322 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
188 * (or if extracting a key from a block of this type does not work) 323 * (or if extracting a key from a block of this type does not work)
189 */ 324 */
190static int 325static enum GNUNET_GenericReturnValue
191block_plugin_dns_get_key (void *cls, 326block_plugin_dns_get_key (void *cls,
192 enum GNUNET_BLOCK_Type type, 327 enum GNUNET_BLOCK_Type type,
193 const void *block, 328 const void *block,
@@ -214,6 +349,9 @@ libgnunet_plugin_block_dns_init (void *cls)
214 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 349 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
215 api->evaluate = &block_plugin_dns_evaluate; 350 api->evaluate = &block_plugin_dns_evaluate;
216 api->get_key = &block_plugin_dns_get_key; 351 api->get_key = &block_plugin_dns_get_key;
352 api->check_query = &block_plugin_dns_check_query;
353 api->check_block = &block_plugin_dns_check_block;
354 api->check_reply = &block_plugin_dns_check_reply;
217 api->create_group = &block_plugin_dns_create_group; 355 api->create_group = &block_plugin_dns_create_group;
218 api->types = types; 356 api->types = types;
219 return api; 357 return api;