diff options
Diffstat (limited to 'src/revocation/gnunet-revocation.c')
-rw-r--r-- | src/revocation/gnunet-revocation.c | 500 |
1 files changed, 253 insertions, 247 deletions
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index b5be65a5f..da93e6903 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.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 revocation/gnunet-revocation.c | 22 | * @file revocation/gnunet-revocation.c |
@@ -91,23 +91,23 @@ static struct GNUNET_SCHEDULER_Task *pow_task; | |||
91 | * @param cls closure | 91 | * @param cls closure |
92 | */ | 92 | */ |
93 | static void | 93 | static void |
94 | do_shutdown (void *cls) | 94 | do_shutdown(void *cls) |
95 | { | 95 | { |
96 | if (NULL != el) | 96 | if (NULL != el) |
97 | { | 97 | { |
98 | GNUNET_IDENTITY_ego_lookup_cancel (el); | 98 | GNUNET_IDENTITY_ego_lookup_cancel(el); |
99 | el = NULL; | 99 | el = NULL; |
100 | } | 100 | } |
101 | if (NULL != q) | 101 | if (NULL != q) |
102 | { | 102 | { |
103 | GNUNET_REVOCATION_query_cancel (q); | 103 | GNUNET_REVOCATION_query_cancel(q); |
104 | q = NULL; | 104 | q = NULL; |
105 | } | 105 | } |
106 | if (NULL != h) | 106 | if (NULL != h) |
107 | { | 107 | { |
108 | GNUNET_REVOCATION_revoke_cancel (h); | 108 | GNUNET_REVOCATION_revoke_cancel(h); |
109 | h = NULL; | 109 | h = NULL; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
@@ -118,25 +118,28 @@ do_shutdown (void *cls) | |||
118 | * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error | 118 | * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error |
119 | */ | 119 | */ |
120 | static void | 120 | static void |
121 | print_query_result (void *cls, int is_valid) | 121 | print_query_result(void *cls, int is_valid) |
122 | { | 122 | { |
123 | q = NULL; | 123 | q = NULL; |
124 | switch (is_valid) | 124 | switch (is_valid) |
125 | { | 125 | { |
126 | case GNUNET_YES: | 126 | case GNUNET_YES: |
127 | fprintf (stdout, _ ("Key `%s' is valid\n"), test_ego); | 127 | fprintf(stdout, _("Key `%s' is valid\n"), test_ego); |
128 | break; | 128 | break; |
129 | case GNUNET_NO: | 129 | |
130 | fprintf (stdout, _ ("Key `%s' has been revoked\n"), test_ego); | 130 | case GNUNET_NO: |
131 | break; | 131 | fprintf(stdout, _("Key `%s' has been revoked\n"), test_ego); |
132 | case GNUNET_SYSERR: | 132 | break; |
133 | fprintf (stdout, "%s", _ ("Internal error\n")); | 133 | |
134 | break; | 134 | case GNUNET_SYSERR: |
135 | default: | 135 | fprintf(stdout, "%s", _("Internal error\n")); |
136 | GNUNET_break (0); | 136 | break; |
137 | break; | 137 | |
138 | } | 138 | default: |
139 | GNUNET_SCHEDULER_shutdown (); | 139 | GNUNET_break(0); |
140 | break; | ||
141 | } | ||
142 | GNUNET_SCHEDULER_shutdown(); | ||
140 | } | 143 | } |
141 | 144 | ||
142 | 145 | ||
@@ -147,45 +150,47 @@ print_query_result (void *cls, int is_valid) | |||
147 | * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error | 150 | * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error |
148 | */ | 151 | */ |
149 | static void | 152 | static void |
150 | print_revocation_result (void *cls, int is_valid) | 153 | print_revocation_result(void *cls, int is_valid) |
151 | { | 154 | { |
152 | h = NULL; | 155 | h = NULL; |
153 | switch (is_valid) | 156 | switch (is_valid) |
154 | { | 157 | { |
155 | case GNUNET_YES: | 158 | case GNUNET_YES: |
156 | if (NULL != revoke_ego) | 159 | if (NULL != revoke_ego) |
157 | fprintf (stdout, | 160 | fprintf(stdout, |
158 | _ ("Key for ego `%s' is still valid, revocation failed (!)\n"), | 161 | _("Key for ego `%s' is still valid, revocation failed (!)\n"), |
159 | revoke_ego); | 162 | revoke_ego); |
160 | else | 163 | else |
161 | fprintf (stdout, "%s", _ ("Revocation failed (!)\n")); | 164 | fprintf(stdout, "%s", _("Revocation failed (!)\n")); |
162 | break; | 165 | break; |
163 | case GNUNET_NO: | 166 | |
164 | if (NULL != revoke_ego) | 167 | case GNUNET_NO: |
165 | fprintf (stdout, | 168 | if (NULL != revoke_ego) |
166 | _ ("Key for ego `%s' has been successfully revoked\n"), | 169 | fprintf(stdout, |
167 | revoke_ego); | 170 | _("Key for ego `%s' has been successfully revoked\n"), |
168 | else | 171 | revoke_ego); |
169 | fprintf (stdout, "%s", _ ("Revocation successful.\n")); | 172 | else |
170 | break; | 173 | fprintf(stdout, "%s", _("Revocation successful.\n")); |
171 | case GNUNET_SYSERR: | 174 | break; |
172 | fprintf (stdout, | 175 | |
173 | "%s", | 176 | case GNUNET_SYSERR: |
174 | _ ("Internal error, key revocation might have failed\n")); | 177 | fprintf(stdout, |
175 | break; | 178 | "%s", |
176 | default: | 179 | _("Internal error, key revocation might have failed\n")); |
177 | GNUNET_break (0); | 180 | break; |
178 | break; | 181 | |
179 | } | 182 | default: |
180 | GNUNET_SCHEDULER_shutdown (); | 183 | GNUNET_break(0); |
184 | break; | ||
185 | } | ||
186 | GNUNET_SCHEDULER_shutdown(); | ||
181 | } | 187 | } |
182 | 188 | ||
183 | 189 | ||
184 | /** | 190 | /** |
185 | * Data needed to perform a revocation. | 191 | * Data needed to perform a revocation. |
186 | */ | 192 | */ |
187 | struct RevocationData | 193 | struct RevocationData { |
188 | { | ||
189 | /** | 194 | /** |
190 | * Public key. | 195 | * Public key. |
191 | */ | 196 | */ |
@@ -207,14 +212,14 @@ struct RevocationData | |||
207 | * Perform the revocation. | 212 | * Perform the revocation. |
208 | */ | 213 | */ |
209 | static void | 214 | static void |
210 | perform_revocation (const struct RevocationData *rd) | 215 | perform_revocation(const struct RevocationData *rd) |
211 | { | 216 | { |
212 | h = GNUNET_REVOCATION_revoke (cfg, | 217 | h = GNUNET_REVOCATION_revoke(cfg, |
213 | &rd->key, | 218 | &rd->key, |
214 | &rd->sig, | 219 | &rd->sig, |
215 | rd->pow, | 220 | rd->pow, |
216 | &print_revocation_result, | 221 | &print_revocation_result, |
217 | NULL); | 222 | NULL); |
218 | } | 223 | } |
219 | 224 | ||
220 | 225 | ||
@@ -225,16 +230,16 @@ perform_revocation (const struct RevocationData *rd) | |||
225 | * @param rd data to sync | 230 | * @param rd data to sync |
226 | */ | 231 | */ |
227 | static void | 232 | static void |
228 | sync_rd (const struct RevocationData *rd) | 233 | sync_rd(const struct RevocationData *rd) |
229 | { | 234 | { |
230 | if ((NULL != filename) && | 235 | if ((NULL != filename) && |
231 | (sizeof (struct RevocationData) == | 236 | (sizeof(struct RevocationData) == |
232 | GNUNET_DISK_fn_write (filename, | 237 | GNUNET_DISK_fn_write(filename, |
233 | &rd, | 238 | &rd, |
234 | sizeof (rd), | 239 | sizeof(rd), |
235 | GNUNET_DISK_PERM_USER_READ | | 240 | GNUNET_DISK_PERM_USER_READ | |
236 | GNUNET_DISK_PERM_USER_WRITE))) | 241 | GNUNET_DISK_PERM_USER_WRITE))) |
237 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 242 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", filename); |
238 | } | 243 | } |
239 | 244 | ||
240 | 245 | ||
@@ -244,17 +249,17 @@ sync_rd (const struct RevocationData *rd) | |||
244 | * @param cls the `struct RevocationData` | 249 | * @param cls the `struct RevocationData` |
245 | */ | 250 | */ |
246 | static void | 251 | static void |
247 | calculate_pow_shutdown (void *cls) | 252 | calculate_pow_shutdown(void *cls) |
248 | { | 253 | { |
249 | struct RevocationData *rd = cls; | 254 | struct RevocationData *rd = cls; |
250 | 255 | ||
251 | if (NULL != pow_task) | 256 | if (NULL != pow_task) |
252 | { | 257 | { |
253 | GNUNET_SCHEDULER_cancel (pow_task); | 258 | GNUNET_SCHEDULER_cancel(pow_task); |
254 | pow_task = NULL; | 259 | pow_task = NULL; |
255 | } | 260 | } |
256 | sync_rd (rd); | 261 | sync_rd(rd); |
257 | GNUNET_free (rd); | 262 | GNUNET_free(rd); |
258 | } | 263 | } |
259 | 264 | ||
260 | 265 | ||
@@ -264,53 +269,53 @@ calculate_pow_shutdown (void *cls) | |||
264 | * @param cls the `struct RevocationData` | 269 | * @param cls the `struct RevocationData` |
265 | */ | 270 | */ |
266 | static void | 271 | static void |
267 | calculate_pow (void *cls) | 272 | calculate_pow(void *cls) |
268 | { | 273 | { |
269 | struct RevocationData *rd = cls; | 274 | struct RevocationData *rd = cls; |
270 | 275 | ||
271 | /* store temporary results */ | 276 | /* store temporary results */ |
272 | pow_task = NULL; | 277 | pow_task = NULL; |
273 | if (0 == (rd->pow % 128)) | 278 | if (0 == (rd->pow % 128)) |
274 | sync_rd (rd); | 279 | sync_rd(rd); |
275 | /* display progress estimate */ | 280 | /* display progress estimate */ |
276 | if ((0 == ((1 << matching_bits) / 100 / 50)) || | 281 | if ((0 == ((1 << matching_bits) / 100 / 50)) || |
277 | (0 == (rd->pow % ((1 << matching_bits) / 100 / 50)))) | 282 | (0 == (rd->pow % ((1 << matching_bits) / 100 / 50)))) |
278 | fprintf (stderr, "%s", "."); | 283 | fprintf(stderr, "%s", "."); |
279 | if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) || | 284 | if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) || |
280 | (0 == (rd->pow % ((1 << matching_bits) / 100))))) | 285 | (0 == (rd->pow % ((1 << matching_bits) / 100))))) |
281 | fprintf (stderr, | 286 | fprintf(stderr, |
282 | " - @ %3u%% (estimate)\n", | 287 | " - @ %3u%% (estimate)\n", |
283 | (unsigned int) (rd->pow * 100) / (1 << matching_bits)); | 288 | (unsigned int)(rd->pow * 100) / (1 << matching_bits)); |
284 | /* actually do POW calculation */ | 289 | /* actually do POW calculation */ |
285 | rd->pow++; | 290 | rd->pow++; |
286 | if (GNUNET_OK == GNUNET_REVOCATION_check_pow (&rd->key, | 291 | if (GNUNET_OK == GNUNET_REVOCATION_check_pow(&rd->key, |
287 | rd->pow, | 292 | rd->pow, |
288 | (unsigned int) matching_bits)) | 293 | (unsigned int)matching_bits)) |
289 | { | ||
290 | if ((NULL != filename) && | ||
291 | (sizeof (struct RevocationData) != | ||
292 | GNUNET_DISK_fn_write (filename, | ||
293 | rd, | ||
294 | sizeof (struct RevocationData), | ||
295 | GNUNET_DISK_PERM_USER_READ | | ||
296 | GNUNET_DISK_PERM_USER_WRITE))) | ||
297 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | ||
298 | if (perform) | ||
299 | { | 294 | { |
300 | perform_revocation (rd); | 295 | if ((NULL != filename) && |
301 | } | 296 | (sizeof(struct RevocationData) != |
302 | else | 297 | GNUNET_DISK_fn_write(filename, |
303 | { | 298 | rd, |
304 | fprintf (stderr, "%s", "\n"); | 299 | sizeof(struct RevocationData), |
305 | fprintf (stderr, | 300 | GNUNET_DISK_PERM_USER_READ | |
306 | _ ("Revocation certificate for `%s' stored in `%s'\n"), | 301 | GNUNET_DISK_PERM_USER_WRITE))) |
307 | revoke_ego, | 302 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", filename); |
308 | filename); | 303 | if (perform) |
309 | GNUNET_SCHEDULER_shutdown (); | 304 | { |
305 | perform_revocation(rd); | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | fprintf(stderr, "%s", "\n"); | ||
310 | fprintf(stderr, | ||
311 | _("Revocation certificate for `%s' stored in `%s'\n"), | ||
312 | revoke_ego, | ||
313 | filename); | ||
314 | GNUNET_SCHEDULER_shutdown(); | ||
315 | } | ||
316 | return; | ||
310 | } | 317 | } |
311 | return; | 318 | pow_task = GNUNET_SCHEDULER_add_now(&calculate_pow, rd); |
312 | } | ||
313 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); | ||
314 | } | 319 | } |
315 | 320 | ||
316 | 321 | ||
@@ -321,57 +326,57 @@ calculate_pow (void *cls) | |||
321 | * @param ego the ego, NULL if not found | 326 | * @param ego the ego, NULL if not found |
322 | */ | 327 | */ |
323 | static void | 328 | static void |
324 | ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | 329 | ego_callback(void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
325 | { | 330 | { |
326 | struct RevocationData *rd; | 331 | struct RevocationData *rd; |
327 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | 332 | struct GNUNET_CRYPTO_EcdsaPublicKey key; |
328 | 333 | ||
329 | el = NULL; | 334 | el = NULL; |
330 | if (NULL == ego) | 335 | if (NULL == ego) |
331 | { | ||
332 | fprintf (stdout, _ ("Ego `%s' not found.\n"), revoke_ego); | ||
333 | GNUNET_SCHEDULER_shutdown (); | ||
334 | return; | ||
335 | } | ||
336 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); | ||
337 | rd = GNUNET_new (struct RevocationData); | ||
338 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && | ||
339 | (sizeof (struct RevocationData) == | ||
340 | GNUNET_DISK_fn_read (filename, rd, sizeof (struct RevocationData)))) | ||
341 | { | ||
342 | if (0 != GNUNET_memcmp (&rd->key, &key)) | ||
343 | { | 336 | { |
344 | fprintf (stderr, | 337 | fprintf(stdout, _("Ego `%s' not found.\n"), revoke_ego); |
345 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), | 338 | GNUNET_SCHEDULER_shutdown(); |
346 | filename, | ||
347 | revoke_ego); | ||
348 | GNUNET_free (rd); | ||
349 | return; | 339 | return; |
350 | } | 340 | } |
351 | } | 341 | GNUNET_IDENTITY_ego_get_public_key(ego, &key); |
342 | rd = GNUNET_new(struct RevocationData); | ||
343 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test(filename)) && | ||
344 | (sizeof(struct RevocationData) == | ||
345 | GNUNET_DISK_fn_read(filename, rd, sizeof(struct RevocationData)))) | ||
346 | { | ||
347 | if (0 != GNUNET_memcmp(&rd->key, &key)) | ||
348 | { | ||
349 | fprintf(stderr, | ||
350 | _("Error: revocation certificate in `%s' is not for `%s'\n"), | ||
351 | filename, | ||
352 | revoke_ego); | ||
353 | GNUNET_free(rd); | ||
354 | return; | ||
355 | } | ||
356 | } | ||
352 | else | 357 | else |
353 | { | 358 | { |
354 | GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key ( | 359 | GNUNET_REVOCATION_sign_revocation(GNUNET_IDENTITY_ego_get_private_key( |
355 | ego), | 360 | ego), |
356 | &rd->sig); | 361 | &rd->sig); |
357 | rd->key = key; | 362 | rd->key = key; |
358 | } | 363 | } |
359 | if (GNUNET_YES == | 364 | if (GNUNET_YES == |
360 | GNUNET_REVOCATION_check_pow (&key, rd->pow, (unsigned int) matching_bits)) | 365 | GNUNET_REVOCATION_check_pow(&key, rd->pow, (unsigned int)matching_bits)) |
361 | { | 366 | { |
362 | fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); | 367 | fprintf(stderr, "%s", _("Revocation certificate ready\n")); |
363 | if (perform) | 368 | if (perform) |
364 | perform_revocation (rd); | 369 | perform_revocation(rd); |
365 | else | 370 | else |
366 | GNUNET_SCHEDULER_shutdown (); | 371 | GNUNET_SCHEDULER_shutdown(); |
367 | GNUNET_free (rd); | 372 | GNUNET_free(rd); |
368 | return; | 373 | return; |
369 | } | 374 | } |
370 | fprintf (stderr, | 375 | fprintf(stderr, |
371 | "%s", | 376 | "%s", |
372 | _ ("Revocation certificate not ready, calculating proof of work\n")); | 377 | _("Revocation certificate not ready, calculating proof of work\n")); |
373 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); | 378 | pow_task = GNUNET_SCHEDULER_add_now(&calculate_pow, rd); |
374 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, rd); | 379 | GNUNET_SCHEDULER_add_shutdown(&calculate_pow_shutdown, rd); |
375 | } | 380 | } |
376 | 381 | ||
377 | 382 | ||
@@ -384,85 +389,85 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
384 | * @param c configuration | 389 | * @param c configuration |
385 | */ | 390 | */ |
386 | static void | 391 | static void |
387 | run (void *cls, | 392 | run(void *cls, |
388 | char *const *args, | 393 | char *const *args, |
389 | const char *cfgfile, | 394 | const char *cfgfile, |
390 | const struct GNUNET_CONFIGURATION_Handle *c) | 395 | const struct GNUNET_CONFIGURATION_Handle *c) |
391 | { | 396 | { |
392 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 397 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
393 | struct RevocationData rd; | 398 | struct RevocationData rd; |
394 | 399 | ||
395 | cfg = c; | 400 | cfg = c; |
396 | if (NULL != test_ego) | 401 | if (NULL != test_ego) |
397 | { | ||
398 | if (GNUNET_OK != | ||
399 | GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego, | ||
400 | strlen (test_ego), | ||
401 | &pk)) | ||
402 | { | 402 | { |
403 | fprintf (stderr, _ ("Public key `%s' malformed\n"), test_ego); | 403 | if (GNUNET_OK != |
404 | GNUNET_CRYPTO_ecdsa_public_key_from_string(test_ego, | ||
405 | strlen(test_ego), | ||
406 | &pk)) | ||
407 | { | ||
408 | fprintf(stderr, _("Public key `%s' malformed\n"), test_ego); | ||
409 | return; | ||
410 | } | ||
411 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
412 | q = GNUNET_REVOCATION_query(cfg, &pk, &print_query_result, NULL); | ||
413 | if (NULL != revoke_ego) | ||
414 | fprintf( | ||
415 | stderr, | ||
416 | "%s", | ||
417 | _( | ||
418 | "Testing and revoking at the same time is not allowed, only executing test.\n")); | ||
404 | return; | 419 | return; |
405 | } | 420 | } |
406 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 421 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, |
407 | q = GNUNET_REVOCATION_query (cfg, &pk, &print_query_result, NULL); | 422 | "REVOCATION", |
408 | if (NULL != revoke_ego) | 423 | "WORKBITS", |
409 | fprintf ( | 424 | &matching_bits)) |
410 | stderr, | ||
411 | "%s", | ||
412 | _ ( | ||
413 | "Testing and revoking at the same time is not allowed, only executing test.\n")); | ||
414 | return; | ||
415 | } | ||
416 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | ||
417 | "REVOCATION", | ||
418 | "WORKBITS", | ||
419 | &matching_bits)) | ||
420 | { | ||
421 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
422 | "REVOCATION", | ||
423 | "WORKBITS"); | ||
424 | return; | ||
425 | } | ||
426 | if (NULL != revoke_ego) | ||
427 | { | ||
428 | if (! perform && (NULL == filename)) | ||
429 | { | 425 | { |
430 | fprintf (stderr, | 426 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
431 | "%s", | 427 | "REVOCATION", |
432 | _ ("No filename to store revocation certificate given.\n")); | 428 | "WORKBITS"); |
433 | return; | 429 | return; |
434 | } | 430 | } |
435 | /* main code here */ | 431 | if (NULL != revoke_ego) |
436 | el = GNUNET_IDENTITY_ego_lookup (cfg, revoke_ego, &ego_callback, NULL); | ||
437 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
438 | return; | ||
439 | } | ||
440 | if ((NULL != filename) && (perform)) | ||
441 | { | ||
442 | if (sizeof (rd) != GNUNET_DISK_fn_read (filename, &rd, sizeof (rd))) | ||
443 | { | 432 | { |
444 | fprintf (stderr, | 433 | if (!perform && (NULL == filename)) |
445 | _ ("Failed to read revocation certificate from `%s'\n"), | 434 | { |
446 | filename); | 435 | fprintf(stderr, |
436 | "%s", | ||
437 | _("No filename to store revocation certificate given.\n")); | ||
438 | return; | ||
439 | } | ||
440 | /* main code here */ | ||
441 | el = GNUNET_IDENTITY_ego_lookup(cfg, revoke_ego, &ego_callback, NULL); | ||
442 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
447 | return; | 443 | return; |
448 | } | 444 | } |
449 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 445 | if ((NULL != filename) && (perform)) |
450 | if (GNUNET_YES != | ||
451 | GNUNET_REVOCATION_check_pow (&rd.key, | ||
452 | rd.pow, | ||
453 | (unsigned int) matching_bits)) | ||
454 | { | 446 | { |
455 | struct RevocationData *cp = GNUNET_new (struct RevocationData); | 447 | if (sizeof(rd) != GNUNET_DISK_fn_read(filename, &rd, sizeof(rd))) |
456 | 448 | { | |
457 | *cp = rd; | 449 | fprintf(stderr, |
458 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cp); | 450 | _("Failed to read revocation certificate from `%s'\n"), |
459 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, cp); | 451 | filename); |
452 | return; | ||
453 | } | ||
454 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
455 | if (GNUNET_YES != | ||
456 | GNUNET_REVOCATION_check_pow(&rd.key, | ||
457 | rd.pow, | ||
458 | (unsigned int)matching_bits)) | ||
459 | { | ||
460 | struct RevocationData *cp = GNUNET_new(struct RevocationData); | ||
461 | |||
462 | *cp = rd; | ||
463 | pow_task = GNUNET_SCHEDULER_add_now(&calculate_pow, cp); | ||
464 | GNUNET_SCHEDULER_add_shutdown(&calculate_pow_shutdown, cp); | ||
465 | return; | ||
466 | } | ||
467 | perform_revocation(&rd); | ||
460 | return; | 468 | return; |
461 | } | 469 | } |
462 | perform_revocation (&rd); | 470 | fprintf(stderr, "%s", _("No action specified. Nothing to do.\n")); |
463 | return; | ||
464 | } | ||
465 | fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n")); | ||
466 | } | 471 | } |
467 | 472 | ||
468 | 473 | ||
@@ -474,53 +479,54 @@ run (void *cls, | |||
474 | * @return 0 ok, 1 on error | 479 | * @return 0 ok, 1 on error |
475 | */ | 480 | */ |
476 | int | 481 | int |
477 | main (int argc, char *const *argv) | 482 | main(int argc, char *const *argv) |
478 | { | 483 | { |
479 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 484 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
480 | 485 | GNUNET_GETOPT_option_string('f', | |
481 | GNUNET_GETOPT_option_string ('f', | 486 | "filename", |
482 | "filename", | 487 | "NAME", |
483 | "NAME", | 488 | gettext_noop( |
484 | gettext_noop ( | 489 | "use NAME for the name of the revocation file"), |
485 | "use NAME for the name of the revocation file"), | 490 | &filename), |
486 | &filename), | 491 | |
487 | 492 | GNUNET_GETOPT_option_string( | |
488 | GNUNET_GETOPT_option_string ( | ||
489 | 'R', | 493 | 'R', |
490 | "revoke", | 494 | "revoke", |
491 | "NAME", | 495 | "NAME", |
492 | gettext_noop ( | 496 | gettext_noop( |
493 | "revoke the private key associated for the the private key associated with the ego NAME "), | 497 | "revoke the private key associated for the the private key associated with the ego NAME "), |
494 | &revoke_ego), | 498 | &revoke_ego), |
495 | 499 | ||
496 | GNUNET_GETOPT_option_flag ( | 500 | GNUNET_GETOPT_option_flag( |
497 | 'p', | 501 | 'p', |
498 | "perform", | 502 | "perform", |
499 | gettext_noop ( | 503 | gettext_noop( |
500 | "actually perform revocation, otherwise we just do the precomputation"), | 504 | "actually perform revocation, otherwise we just do the precomputation"), |
501 | &perform), | 505 | &perform), |
502 | 506 | ||
503 | GNUNET_GETOPT_option_string ('t', | 507 | GNUNET_GETOPT_option_string('t', |
504 | "test", | 508 | "test", |
505 | "KEY", | 509 | "KEY", |
506 | gettext_noop ( | 510 | gettext_noop( |
507 | "test if the public key KEY has been revoked"), | 511 | "test if the public key KEY has been revoked"), |
508 | &test_ego), | 512 | &test_ego), |
513 | |||
514 | GNUNET_GETOPT_OPTION_END | ||
515 | }; | ||
509 | 516 | ||
510 | GNUNET_GETOPT_OPTION_END}; | 517 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
511 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
512 | return 2; | 518 | return 2; |
513 | 519 | ||
514 | ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, | 520 | ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, |
515 | argv, | 521 | argv, |
516 | "gnunet-revocation", | 522 | "gnunet-revocation", |
517 | gettext_noop ("help text"), | 523 | gettext_noop("help text"), |
518 | options, | 524 | options, |
519 | &run, | 525 | &run, |
520 | NULL)) | 526 | NULL)) |
521 | ? ret | 527 | ? ret |
522 | : 1; | 528 | : 1; |
523 | GNUNET_free ((void *) argv); | 529 | GNUNET_free((void *)argv); |
524 | return ret; | 530 | return ret; |
525 | } | 531 | } |
526 | 532 | ||