diff options
Diffstat (limited to 'src/dns/plugin_block_dns.c')
-rw-r--r-- | src/dns/plugin_block_dns.c | 191 |
1 files changed, 96 insertions, 95 deletions
diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c index ed75ce2f3..fd4d844c5 100644 --- a/src/dns/plugin_block_dns.c +++ b/src/dns/plugin_block_dns.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file dns/plugin_block_dns.c | 22 | * @file dns/plugin_block_dns.c |
@@ -54,37 +54,37 @@ | |||
54 | * by this @a type of block (this is not an error) | 54 | * by this @a type of block (this is not an error) |
55 | */ | 55 | */ |
56 | static struct GNUNET_BLOCK_Group * | 56 | static struct GNUNET_BLOCK_Group * |
57 | block_plugin_dns_create_group (void *cls, | 57 | block_plugin_dns_create_group(void *cls, |
58 | enum GNUNET_BLOCK_Type type, | 58 | enum GNUNET_BLOCK_Type type, |
59 | uint32_t nonce, | 59 | uint32_t nonce, |
60 | const void *raw_data, | 60 | const void *raw_data, |
61 | size_t raw_data_size, | 61 | size_t raw_data_size, |
62 | va_list va) | 62 | va_list va) |
63 | { | 63 | { |
64 | unsigned int bf_size; | 64 | unsigned int bf_size; |
65 | const char *guard; | 65 | const char *guard; |
66 | 66 | ||
67 | guard = va_arg (va, const char *); | 67 | guard = va_arg(va, const char *); |
68 | if (0 == strcmp (guard, | 68 | if (0 == strcmp(guard, |
69 | "seen-set-size")) | 69 | "seen-set-size")) |
70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), | 70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), |
71 | BLOOMFILTER_K); | 71 | BLOOMFILTER_K); |
72 | else if (0 == strcmp (guard, | 72 | else if (0 == strcmp(guard, |
73 | "filter-size")) | 73 | "filter-size")) |
74 | bf_size = va_arg (va, unsigned int); | 74 | bf_size = va_arg(va, unsigned int); |
75 | else | 75 | else |
76 | { | 76 | { |
77 | GNUNET_break (0); | 77 | GNUNET_break(0); |
78 | bf_size = 8; | 78 | bf_size = 8; |
79 | } | 79 | } |
80 | GNUNET_break (NULL == va_arg (va, const char *)); | 80 | GNUNET_break(NULL == va_arg(va, const char *)); |
81 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 81 | return GNUNET_BLOCK_GROUP_bf_create(cls, |
82 | bf_size, | 82 | bf_size, |
83 | BLOOMFILTER_K, | 83 | BLOOMFILTER_K, |
84 | type, | 84 | type, |
85 | nonce, | 85 | nonce, |
86 | raw_data, | 86 | raw_data, |
87 | raw_data_size); | 87 | raw_data_size); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
@@ -105,71 +105,72 @@ block_plugin_dns_create_group (void *cls, | |||
105 | * @return characterization of result | 105 | * @return characterization of result |
106 | */ | 106 | */ |
107 | static enum GNUNET_BLOCK_EvaluationResult | 107 | static enum GNUNET_BLOCK_EvaluationResult |
108 | block_plugin_dns_evaluate (void *cls, | 108 | block_plugin_dns_evaluate(void *cls, |
109 | struct GNUNET_BLOCK_Context *ctx, | 109 | struct GNUNET_BLOCK_Context *ctx, |
110 | enum GNUNET_BLOCK_Type type, | 110 | enum GNUNET_BLOCK_Type type, |
111 | struct GNUNET_BLOCK_Group *bg, | 111 | struct GNUNET_BLOCK_Group *bg, |
112 | enum GNUNET_BLOCK_EvaluationOptions eo, | 112 | enum GNUNET_BLOCK_EvaluationOptions eo, |
113 | const struct GNUNET_HashCode * query, | 113 | const struct GNUNET_HashCode * query, |
114 | const void *xquery, | 114 | const void *xquery, |
115 | size_t xquery_size, | 115 | size_t xquery_size, |
116 | const void *reply_block, | 116 | const void *reply_block, |
117 | size_t reply_block_size) | 117 | size_t reply_block_size) |
118 | { | 118 | { |
119 | const struct GNUNET_DNS_Advertisement *ad; | 119 | const struct GNUNET_DNS_Advertisement *ad; |
120 | struct GNUNET_HashCode phash; | 120 | struct GNUNET_HashCode phash; |
121 | 121 | ||
122 | switch (type) | 122 | switch (type) |
123 | { | ||
124 | case GNUNET_BLOCK_TYPE_DNS: | ||
125 | if (0 != xquery_size) | ||
126 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
127 | |||
128 | if (NULL == reply_block) | ||
129 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
130 | |||
131 | if (sizeof (struct GNUNET_DNS_Advertisement) != reply_block_size) | ||
132 | { | ||
133 | GNUNET_break_op (0); | ||
134 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
135 | } | ||
136 | ad = reply_block; | ||
137 | |||
138 | if (ntohl (ad->purpose.size) != | ||
139 | sizeof (struct GNUNET_DNS_Advertisement) - | ||
140 | sizeof (struct GNUNET_CRYPTO_EddsaSignature)) | ||
141 | { | ||
142 | GNUNET_break_op (0); | ||
143 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
144 | } | ||
145 | if (0 == | ||
146 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh | ||
147 | (ad->expiration_time)).rel_value_us) | ||
148 | { | ||
149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
150 | "DNS advertisement has expired\n"); | ||
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
152 | } | ||
153 | if (GNUNET_OK != | ||
154 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, | ||
155 | &ad->purpose, | ||
156 | &ad->signature, | ||
157 | &ad->peer.public_key)) | ||
158 | { | 123 | { |
159 | GNUNET_break_op (0); | 124 | case GNUNET_BLOCK_TYPE_DNS: |
160 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 125 | if (0 != xquery_size) |
126 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
127 | |||
128 | if (NULL == reply_block) | ||
129 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
130 | |||
131 | if (sizeof(struct GNUNET_DNS_Advertisement) != reply_block_size) | ||
132 | { | ||
133 | GNUNET_break_op(0); | ||
134 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
135 | } | ||
136 | ad = reply_block; | ||
137 | |||
138 | if (ntohl(ad->purpose.size) != | ||
139 | sizeof(struct GNUNET_DNS_Advertisement) - | ||
140 | sizeof(struct GNUNET_CRYPTO_EddsaSignature)) | ||
141 | { | ||
142 | GNUNET_break_op(0); | ||
143 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
144 | } | ||
145 | if (0 == | ||
146 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh | ||
147 | (ad->expiration_time)).rel_value_us) | ||
148 | { | ||
149 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
150 | "DNS advertisement has expired\n"); | ||
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
152 | } | ||
153 | if (GNUNET_OK != | ||
154 | GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, | ||
155 | &ad->purpose, | ||
156 | &ad->signature, | ||
157 | &ad->peer.public_key)) | ||
158 | { | ||
159 | GNUNET_break_op(0); | ||
160 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
161 | } | ||
162 | GNUNET_CRYPTO_hash(reply_block, | ||
163 | reply_block_size, | ||
164 | &phash); | ||
165 | if (GNUNET_YES == | ||
166 | GNUNET_BLOCK_GROUP_bf_test_and_set(bg, | ||
167 | &phash)) | ||
168 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
169 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
170 | |||
171 | default: | ||
172 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
161 | } | 173 | } |
162 | GNUNET_CRYPTO_hash (reply_block, | ||
163 | reply_block_size, | ||
164 | &phash); | ||
165 | if (GNUNET_YES == | ||
166 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
167 | &phash)) | ||
168 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
169 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
170 | default: | ||
171 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
172 | } | ||
173 | } | 174 | } |
174 | 175 | ||
175 | 176 | ||
@@ -185,11 +186,11 @@ block_plugin_dns_evaluate (void *cls, | |||
185 | * (or if extracting a key from a block of this type does not work) | 186 | * (or if extracting a key from a block of this type does not work) |
186 | */ | 187 | */ |
187 | static int | 188 | static int |
188 | block_plugin_dns_get_key (void *cls, | 189 | block_plugin_dns_get_key(void *cls, |
189 | enum GNUNET_BLOCK_Type type, | 190 | enum GNUNET_BLOCK_Type type, |
190 | const void *block, | 191 | const void *block, |
191 | size_t block_size, | 192 | size_t block_size, |
192 | struct GNUNET_HashCode *key) | 193 | struct GNUNET_HashCode *key) |
193 | { | 194 | { |
194 | /* we cannot extract a key from a block of this type */ | 195 | /* we cannot extract a key from a block of this type */ |
195 | return GNUNET_SYSERR; | 196 | return GNUNET_SYSERR; |
@@ -200,7 +201,7 @@ block_plugin_dns_get_key (void *cls, | |||
200 | * Entry point for the plugin. | 201 | * Entry point for the plugin. |
201 | */ | 202 | */ |
202 | void * | 203 | void * |
203 | libgnunet_plugin_block_dns_init (void *cls) | 204 | libgnunet_plugin_block_dns_init(void *cls) |
204 | { | 205 | { |
205 | static enum GNUNET_BLOCK_Type types[] = | 206 | static enum GNUNET_BLOCK_Type types[] = |
206 | { | 207 | { |
@@ -209,7 +210,7 @@ libgnunet_plugin_block_dns_init (void *cls) | |||
209 | }; | 210 | }; |
210 | struct GNUNET_BLOCK_PluginFunctions *api; | 211 | struct GNUNET_BLOCK_PluginFunctions *api; |
211 | 212 | ||
212 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 213 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); |
213 | api->evaluate = &block_plugin_dns_evaluate; | 214 | api->evaluate = &block_plugin_dns_evaluate; |
214 | api->get_key = &block_plugin_dns_get_key; | 215 | api->get_key = &block_plugin_dns_get_key; |
215 | api->create_group = &block_plugin_dns_create_group; | 216 | api->create_group = &block_plugin_dns_create_group; |
@@ -222,11 +223,11 @@ libgnunet_plugin_block_dns_init (void *cls) | |||
222 | * Exit point from the plugin. | 223 | * Exit point from the plugin. |
223 | */ | 224 | */ |
224 | void * | 225 | void * |
225 | libgnunet_plugin_block_dns_done (void *cls) | 226 | libgnunet_plugin_block_dns_done(void *cls) |
226 | { | 227 | { |
227 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 228 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
228 | 229 | ||
229 | GNUNET_free (api); | 230 | GNUNET_free(api); |
230 | return NULL; | 231 | return NULL; |
231 | } | 232 | } |
232 | 233 | ||