diff options
Diffstat (limited to 'src/fs/plugin_block_fs.c')
-rw-r--r-- | src/fs/plugin_block_fs.c | 181 |
1 files changed, 42 insertions, 139 deletions
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index 8e90589cf..468dd96a3 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2010, 2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -56,75 +56,67 @@ | |||
56 | */ | 56 | */ |
57 | static enum GNUNET_BLOCK_EvaluationResult | 57 | static enum GNUNET_BLOCK_EvaluationResult |
58 | block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | 58 | block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type, |
59 | const struct GNUNET_HashCode * query, | 59 | const struct GNUNET_HashCode *query, |
60 | struct GNUNET_CONTAINER_BloomFilter **bf, | 60 | struct GNUNET_CONTAINER_BloomFilter **bf, |
61 | int32_t bf_mutator, const void *xquery, | 61 | int32_t bf_mutator, const void *xquery, |
62 | size_t xquery_size, const void *reply_block, | 62 | size_t xquery_size, const void *reply_block, |
63 | size_t reply_block_size) | 63 | size_t reply_block_size) |
64 | { | 64 | { |
65 | const struct SBlock *sb; | 65 | const struct UBlock *ub; |
66 | struct GNUNET_HashCode hc; | ||
66 | struct GNUNET_HashCode chash; | 67 | struct GNUNET_HashCode chash; |
67 | struct GNUNET_HashCode mhash; | 68 | struct GNUNET_HashCode mhash; |
68 | const struct GNUNET_HashCode *nsid; | ||
69 | struct GNUNET_HashCode sh; | ||
70 | 69 | ||
71 | switch (type) | 70 | switch (type) |
72 | { | 71 | { |
73 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | 72 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: |
74 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 73 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
75 | if (xquery_size != 0) | 74 | if (0 != xquery_size) |
76 | { | 75 | { |
77 | GNUNET_break_op (0); | 76 | GNUNET_break_op (0); |
78 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 77 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; |
79 | } | 78 | } |
80 | if (reply_block == NULL) | 79 | if (NULL == reply_block) |
81 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 80 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
82 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | 81 | return GNUNET_BLOCK_EVALUATION_OK_LAST; |
83 | case GNUNET_BLOCK_TYPE_FS_KBLOCK: | 82 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
84 | case GNUNET_BLOCK_TYPE_FS_NBLOCK: | 83 | if (0 != xquery_size) |
85 | if (xquery_size != 0) | ||
86 | { | 84 | { |
87 | GNUNET_break_op (0); | 85 | GNUNET_break_op (0); |
88 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 86 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; |
89 | } | 87 | } |
90 | if (reply_block == NULL) | 88 | if (NULL == reply_block) |
91 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 89 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
92 | if (NULL != bf) | 90 | |
91 | if (reply_block_size < sizeof (struct UBlock)) | ||
93 | { | 92 | { |
94 | GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); | 93 | GNUNET_break_op (0); |
95 | GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); | 94 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
96 | if (NULL != *bf) | ||
97 | { | ||
98 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) | ||
99 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); | ||
104 | } | ||
105 | GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); | ||
106 | } | 95 | } |
107 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | 96 | ub = reply_block; |
108 | case GNUNET_BLOCK_TYPE_FS_SBLOCK: | 97 | GNUNET_CRYPTO_hash (&ub->verification_key, |
109 | if (xquery_size != sizeof (struct GNUNET_HashCode)) | 98 | sizeof (ub->verification_key), |
99 | &hc); | ||
100 | if (0 != memcmp (&hc, | ||
101 | query, | ||
102 | sizeof (struct GNUNET_HashCode))) | ||
110 | { | 103 | { |
111 | GNUNET_break_op (0); | 104 | GNUNET_break_op (0); |
112 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 105 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
113 | } | 106 | } |
114 | if (reply_block == NULL) | 107 | if (reply_block_size != ntohl (ub->purpose.size) + sizeof (struct GNUNET_PseudonymSignature)) |
115 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 108 | { |
116 | nsid = xquery; | 109 | GNUNET_break_op (0); |
117 | if (reply_block_size < sizeof (struct SBlock)) | 110 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
111 | } | ||
112 | if (GNUNET_OK != | ||
113 | GNUNET_PSEUDONYM_verify (&ub->purpose, | ||
114 | &ub->signature, | ||
115 | &ub->verification_key)) | ||
118 | { | 116 | { |
119 | GNUNET_break_op (0); | 117 | GNUNET_break_op (0); |
120 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 118 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
121 | } | 119 | } |
122 | sb = reply_block; | ||
123 | GNUNET_CRYPTO_hash (&sb->subspace, | ||
124 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
125 | &sh); | ||
126 | if (0 != memcmp (nsid, &sh, sizeof (struct GNUNET_HashCode))) | ||
127 | return GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT; | ||
128 | if (NULL != bf) | 120 | if (NULL != bf) |
129 | { | 121 | { |
130 | GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); | 122 | GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); |
@@ -161,11 +153,9 @@ block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
161 | static int | 153 | static int |
162 | block_plugin_fs_get_key (void *cls, enum GNUNET_BLOCK_Type type, | 154 | block_plugin_fs_get_key (void *cls, enum GNUNET_BLOCK_Type type, |
163 | const void *block, size_t block_size, | 155 | const void *block, size_t block_size, |
164 | struct GNUNET_HashCode * key) | 156 | struct GNUNET_HashCode *key) |
165 | { | 157 | { |
166 | const struct KBlock *kb; | 158 | const struct UBlock *ub; |
167 | const struct SBlock *sb; | ||
168 | const struct NBlock *nb; | ||
169 | 159 | ||
170 | switch (type) | 160 | switch (type) |
171 | { | 161 | { |
@@ -173,104 +163,19 @@ block_plugin_fs_get_key (void *cls, enum GNUNET_BLOCK_Type type, | |||
173 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 163 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: |
174 | GNUNET_CRYPTO_hash (block, block_size, key); | 164 | GNUNET_CRYPTO_hash (block, block_size, key); |
175 | return GNUNET_OK; | 165 | return GNUNET_OK; |
176 | case GNUNET_BLOCK_TYPE_FS_KBLOCK: | 166 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
177 | if (block_size < sizeof (struct KBlock)) | 167 | if (block_size < sizeof (struct UBlock)) |
178 | { | ||
179 | GNUNET_break_op (0); | ||
180 | return GNUNET_NO; | ||
181 | } | ||
182 | kb = block; | ||
183 | if (block_size - sizeof (struct KBlock) != | ||
184 | ntohl (kb->purpose.size) - | ||
185 | sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) - | ||
186 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)) | ||
187 | { | ||
188 | GNUNET_break_op (0); | ||
189 | return GNUNET_NO; | ||
190 | } | ||
191 | if (GNUNET_OK != | ||
192 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK, | ||
193 | &kb->purpose, &kb->signature, &kb->keyspace)) | ||
194 | { | ||
195 | GNUNET_break_op (0); | ||
196 | return GNUNET_NO; | ||
197 | } | ||
198 | if (key != NULL) | ||
199 | GNUNET_CRYPTO_hash (&kb->keyspace, | ||
200 | sizeof (struct | ||
201 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
202 | key); | ||
203 | return GNUNET_OK; | ||
204 | case GNUNET_BLOCK_TYPE_FS_SBLOCK: | ||
205 | if (block_size < sizeof (struct SBlock)) | ||
206 | { | ||
207 | GNUNET_break_op (0); | ||
208 | return GNUNET_NO; | ||
209 | } | ||
210 | sb = block; | ||
211 | if (block_size != | ||
212 | ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature)) | ||
213 | { | ||
214 | GNUNET_break_op (0); | ||
215 | return GNUNET_NO; | ||
216 | } | ||
217 | if (GNUNET_OK != | ||
218 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK, | ||
219 | &sb->purpose, &sb->signature, &sb->subspace)) | ||
220 | { | ||
221 | GNUNET_break_op (0); | ||
222 | return GNUNET_NO; | ||
223 | } | ||
224 | if (key != NULL) | ||
225 | *key = sb->identifier; | ||
226 | return GNUNET_OK; | ||
227 | case GNUNET_BLOCK_TYPE_FS_NBLOCK: | ||
228 | if (block_size < sizeof (struct NBlock)) | ||
229 | { | 168 | { |
230 | GNUNET_break_op (0); | 169 | GNUNET_break (0); |
231 | return GNUNET_NO; | 170 | return GNUNET_SYSERR; |
232 | } | ||
233 | nb = block; | ||
234 | if (block_size - sizeof (struct NBlock) != | ||
235 | ntohl (nb->ns_purpose.size) - | ||
236 | sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) - | ||
237 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)) | ||
238 | { | ||
239 | GNUNET_break_op (0); | ||
240 | return GNUNET_NO; | ||
241 | } | ||
242 | if (block_size != | ||
243 | ntohl (nb->ksk_purpose.size) + | ||
244 | sizeof (struct GNUNET_CRYPTO_RsaSignature)) | ||
245 | { | ||
246 | GNUNET_break_op (0); | ||
247 | return GNUNET_NO; | ||
248 | } | ||
249 | if (GNUNET_OK != | ||
250 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG, | ||
251 | &nb->ksk_purpose, &nb->ksk_signature, | ||
252 | &nb->keyspace)) | ||
253 | { | ||
254 | GNUNET_break_op (0); | ||
255 | return GNUNET_NO; | ||
256 | } | ||
257 | if (GNUNET_OK != | ||
258 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK, | ||
259 | &nb->ns_purpose, &nb->ns_signature, | ||
260 | &nb->subspace)) | ||
261 | { | ||
262 | GNUNET_break_op (0); | ||
263 | return GNUNET_NO; | ||
264 | } | 171 | } |
265 | /* FIXME: we used to xor ID with NSID, | 172 | ub = block; |
266 | * why not here? */ | 173 | GNUNET_CRYPTO_hash (&ub->verification_key, |
267 | if (key != NULL) | 174 | sizeof (ub->verification_key), |
268 | GNUNET_CRYPTO_hash (&nb->keyspace, | 175 | key); |
269 | sizeof (struct | ||
270 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
271 | key); | ||
272 | return GNUNET_OK; | 176 | return GNUNET_OK; |
273 | default: | 177 | default: |
178 | GNUNET_break (0); | ||
274 | return GNUNET_SYSERR; | 179 | return GNUNET_SYSERR; |
275 | } | 180 | } |
276 | } | 181 | } |
@@ -286,9 +191,7 @@ libgnunet_plugin_block_fs_init (void *cls) | |||
286 | { | 191 | { |
287 | GNUNET_BLOCK_TYPE_FS_DBLOCK, | 192 | GNUNET_BLOCK_TYPE_FS_DBLOCK, |
288 | GNUNET_BLOCK_TYPE_FS_IBLOCK, | 193 | GNUNET_BLOCK_TYPE_FS_IBLOCK, |
289 | GNUNET_BLOCK_TYPE_FS_KBLOCK, | 194 | GNUNET_BLOCK_TYPE_FS_UBLOCK, |
290 | GNUNET_BLOCK_TYPE_FS_SBLOCK, | ||
291 | GNUNET_BLOCK_TYPE_FS_NBLOCK, | ||
292 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 195 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
293 | }; | 196 | }; |
294 | struct GNUNET_BLOCK_PluginFunctions *api; | 197 | struct GNUNET_BLOCK_PluginFunctions *api; |