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.c128
1 files changed, 24 insertions, 104 deletions
diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c
index d3eb7d2b9..a596beb28 100644
--- a/src/dns/plugin_block_dns.c
+++ b/src/dns/plugin_block_dns.c
@@ -90,93 +90,6 @@ block_plugin_dns_create_group (void *cls,
90 90
91 91
92/** 92/**
93 * Function called to validate a reply or a request. For
94 * request evaluation, simply pass "NULL" for the reply_block.
95 *
96 * @param cls closure
97 * @param ctx block context
98 * @param type block type
99 * @param bg group to evaluate against
100 * @param eo control flags
101 * @param query original query (hash)
102 * @param xquery extended query data (can be NULL, depending on type)
103 * @param xquery_size number of bytes in @a xquery
104 * @param reply_block response to validate
105 * @param reply_block_size number of bytes in @a reply_block
106 * @return characterization of result
107 */
108static enum GNUNET_BLOCK_EvaluationResult
109block_plugin_dns_evaluate (void *cls,
110 struct GNUNET_BLOCK_Context *ctx,
111 enum GNUNET_BLOCK_Type type,
112 struct GNUNET_BLOCK_Group *bg,
113 enum GNUNET_BLOCK_EvaluationOptions eo,
114 const struct GNUNET_HashCode *query,
115 const void *xquery,
116 size_t xquery_size,
117 const void *reply_block,
118 size_t reply_block_size)
119{
120 const struct GNUNET_DNS_Advertisement *ad;
121 struct GNUNET_HashCode phash;
122
123 switch (type)
124 {
125 case GNUNET_BLOCK_TYPE_DNS:
126 if (0 != xquery_size)
127 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
128
129 if (NULL == reply_block)
130 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
131
132 if (sizeof(struct GNUNET_DNS_Advertisement) != reply_block_size)
133 {
134 GNUNET_break_op (0);
135 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
136 }
137 ad = reply_block;
138
139 if (ntohl (ad->purpose.size) !=
140 sizeof(struct GNUNET_DNS_Advertisement)
141 - sizeof(struct GNUNET_CRYPTO_EddsaSignature))
142 {
143 GNUNET_break_op (0);
144 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
145 }
146 if (0 ==
147 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh
148 (ad->expiration_time)).
149 rel_value_us)
150 {
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
152 "DNS advertisement has expired\n");
153 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
154 }
155 if (GNUNET_OK !=
156 GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD,
157 &ad->purpose,
158 &ad->signature,
159 &ad->peer.public_key))
160 {
161 GNUNET_break_op (0);
162 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
163 }
164 GNUNET_CRYPTO_hash (reply_block,
165 reply_block_size,
166 &phash);
167 if (GNUNET_YES ==
168 GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
169 &phash))
170 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
171 return GNUNET_BLOCK_EVALUATION_OK_MORE;
172
173 default:
174 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
175 }
176}
177
178
179/**
180 * Function called to validate a query. 93 * Function called to validate a query.
181 * 94 *
182 * @param cls closure 95 * @param cls closure
@@ -198,9 +111,13 @@ block_plugin_dns_check_query (void *cls,
198 { 111 {
199 case GNUNET_BLOCK_TYPE_DNS: 112 case GNUNET_BLOCK_TYPE_DNS:
200 if (0 != xquery_size) 113 if (0 != xquery_size)
201 return GNUNET_NO; 114 {
115 GNUNET_break_op (0);
116 return GNUNET_NO;
117 }
202 return GNUNET_OK; 118 return GNUNET_OK;
203 default: 119 default:
120 GNUNET_break (0);
204 return GNUNET_SYSERR; 121 return GNUNET_SYSERR;
205 } 122 }
206} 123}
@@ -211,17 +128,15 @@ block_plugin_dns_check_query (void *cls,
211 * 128 *
212 * @param cls closure 129 * @param cls closure
213 * @param type block type 130 * @param type block type
214 * @param query key for the block (hash), must match exactly
215 * @param block block data to validate 131 * @param block block data to validate
216 * @param block_size number of bytes in @a block 132 * @param block_size number of bytes in @a block
217 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not 133 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
218 */ 134 */
219static enum GNUNET_GenericReturnValue 135static enum GNUNET_GenericReturnValue
220block_plugin_dns_check_block (void *cls, 136block_plugin_dns_check_block (void *cls,
221 enum GNUNET_BLOCK_Type type, 137 enum GNUNET_BLOCK_Type type,
222 const struct GNUNET_HashCode *query, 138 const void *block,
223 const void *block, 139 size_t block_size)
224 size_t block_size)
225{ 140{
226 const struct GNUNET_DNS_Advertisement *ad; 141 const struct GNUNET_DNS_Advertisement *ad;
227 142
@@ -260,6 +175,7 @@ block_plugin_dns_check_block (void *cls,
260 } 175 }
261 return GNUNET_OK; 176 return GNUNET_OK;
262 default: 177 default:
178 GNUNET_break (0);
263 return GNUNET_SYSERR; 179 return GNUNET_SYSERR;
264 } 180 }
265} 181}
@@ -283,14 +199,14 @@ block_plugin_dns_check_block (void *cls,
283 */ 199 */
284static enum GNUNET_BLOCK_ReplyEvaluationResult 200static enum GNUNET_BLOCK_ReplyEvaluationResult
285block_plugin_dns_check_reply ( 201block_plugin_dns_check_reply (
286 void *cls, 202 void *cls,
287 enum GNUNET_BLOCK_Type type, 203 enum GNUNET_BLOCK_Type type,
288 struct GNUNET_BLOCK_Group *group, 204 struct GNUNET_BLOCK_Group *group,
289 const struct GNUNET_HashCode *query, 205 const struct GNUNET_HashCode *query,
290 const void *xquery, 206 const void *xquery,
291 size_t xquery_size, 207 size_t xquery_size,
292 const void *reply_block, 208 const void *reply_block,
293 size_t reply_block_size) 209 size_t reply_block_size)
294{ 210{
295 struct GNUNET_HashCode phash; 211 struct GNUNET_HashCode phash;
296 212
@@ -306,6 +222,7 @@ block_plugin_dns_check_reply (
306 return GNUNET_BLOCK_REPLY_OK_DUPLICATE; 222 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
307 return GNUNET_BLOCK_REPLY_OK_MORE; 223 return GNUNET_BLOCK_REPLY_OK_MORE;
308 default: 224 default:
225 GNUNET_break (0);
309 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; 226 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
310 } 227 }
311} 228}
@@ -329,8 +246,12 @@ block_plugin_dns_get_key (void *cls,
329 size_t block_size, 246 size_t block_size,
330 struct GNUNET_HashCode *key) 247 struct GNUNET_HashCode *key)
331{ 248{
332 /* we cannot extract a key from a block of this type */ 249 if (GNUNET_BLOCK_TYPE_DNS != type)
333 return GNUNET_SYSERR; 250 {
251 GNUNET_break (0);
252 return GNUNET_SYSERR;
253 }
254 return GNUNET_NO;
334} 255}
335 256
336 257
@@ -347,7 +268,6 @@ libgnunet_plugin_block_dns_init (void *cls)
347 struct GNUNET_BLOCK_PluginFunctions *api; 268 struct GNUNET_BLOCK_PluginFunctions *api;
348 269
349 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 270 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
350 api->evaluate = &block_plugin_dns_evaluate;
351 api->get_key = &block_plugin_dns_get_key; 271 api->get_key = &block_plugin_dns_get_key;
352 api->check_query = &block_plugin_dns_check_query; 272 api->check_query = &block_plugin_dns_check_query;
353 api->check_block = &block_plugin_dns_check_block; 273 api->check_block = &block_plugin_dns_check_block;