aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/gnunet-revocation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/revocation/gnunet-revocation.c')
-rw-r--r--src/revocation/gnunet-revocation.c274
1 files changed, 117 insertions, 157 deletions
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index 4b8fa15bb..b5be65a5f 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -118,26 +118,19 @@ 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 */
120static void 120static void
121print_query_result (void *cls, 121print_query_result (void *cls, int is_valid)
122 int is_valid)
123{ 122{
124 q = NULL; 123 q = NULL;
125 switch (is_valid) 124 switch (is_valid)
126 { 125 {
127 case GNUNET_YES: 126 case GNUNET_YES:
128 FPRINTF (stdout, 127 fprintf (stdout, _ ("Key `%s' is valid\n"), test_ego);
129 _("Key `%s' is valid\n"),
130 test_ego);
131 break; 128 break;
132 case GNUNET_NO: 129 case GNUNET_NO:
133 FPRINTF (stdout, 130 fprintf (stdout, _ ("Key `%s' has been revoked\n"), test_ego);
134 _("Key `%s' has been revoked\n"),
135 test_ego);
136 break; 131 break;
137 case GNUNET_SYSERR: 132 case GNUNET_SYSERR:
138 FPRINTF (stdout, 133 fprintf (stdout, "%s", _ ("Internal error\n"));
139 "%s",
140 _("Internal error\n"));
141 break; 134 break;
142 default: 135 default:
143 GNUNET_break (0); 136 GNUNET_break (0);
@@ -154,36 +147,31 @@ print_query_result (void *cls,
154 * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error 147 * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error
155 */ 148 */
156static void 149static void
157print_revocation_result (void *cls, 150print_revocation_result (void *cls, int is_valid)
158 int is_valid)
159{ 151{
160 h = NULL; 152 h = NULL;
161 switch (is_valid) 153 switch (is_valid)
162 { 154 {
163 case GNUNET_YES: 155 case GNUNET_YES:
164 if (NULL != revoke_ego) 156 if (NULL != revoke_ego)
165 FPRINTF (stdout, 157 fprintf (stdout,
166 _("Key for ego `%s' is still valid, revocation failed (!)\n"), 158 _ ("Key for ego `%s' is still valid, revocation failed (!)\n"),
167 revoke_ego); 159 revoke_ego);
168 else 160 else
169 FPRINTF (stdout, 161 fprintf (stdout, "%s", _ ("Revocation failed (!)\n"));
170 "%s",
171 _("Revocation failed (!)\n"));
172 break; 162 break;
173 case GNUNET_NO: 163 case GNUNET_NO:
174 if (NULL != revoke_ego) 164 if (NULL != revoke_ego)
175 FPRINTF (stdout, 165 fprintf (stdout,
176 _("Key for ego `%s' has been successfully revoked\n"), 166 _ ("Key for ego `%s' has been successfully revoked\n"),
177 revoke_ego); 167 revoke_ego);
178 else 168 else
179 FPRINTF (stdout, 169 fprintf (stdout, "%s", _ ("Revocation successful.\n"));
180 "%s",
181 _("Revocation successful.\n"));
182 break; 170 break;
183 case GNUNET_SYSERR: 171 case GNUNET_SYSERR:
184 FPRINTF (stdout, 172 fprintf (stdout,
185 "%s", 173 "%s",
186 _("Internal error, key revocation might have failed\n")); 174 _ ("Internal error, key revocation might have failed\n"));
187 break; 175 break;
188 default: 176 default:
189 GNUNET_break (0); 177 GNUNET_break (0);
@@ -239,16 +227,14 @@ perform_revocation (const struct RevocationData *rd)
239static void 227static void
240sync_rd (const struct RevocationData *rd) 228sync_rd (const struct RevocationData *rd)
241{ 229{
242 if ( (NULL != filename) && 230 if ((NULL != filename) &&
243 (sizeof (struct RevocationData) == 231 (sizeof (struct RevocationData) ==
244 GNUNET_DISK_fn_write (filename, 232 GNUNET_DISK_fn_write (filename,
245 &rd, 233 &rd,
246 sizeof (rd), 234 sizeof (rd),
247 GNUNET_DISK_PERM_USER_READ | 235 GNUNET_DISK_PERM_USER_READ |
248 GNUNET_DISK_PERM_USER_WRITE)) ) 236 GNUNET_DISK_PERM_USER_WRITE)))
249 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 237 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
250 "write",
251 filename);
252} 238}
253 239
254 240
@@ -287,48 +273,44 @@ calculate_pow (void *cls)
287 if (0 == (rd->pow % 128)) 273 if (0 == (rd->pow % 128))
288 sync_rd (rd); 274 sync_rd (rd);
289 /* display progress estimate */ 275 /* display progress estimate */
290 if ( (0 == ((1 << matching_bits) / 100 / 50)) || 276 if ((0 == ((1 << matching_bits) / 100 / 50)) ||
291 (0 == (rd->pow % ((1 << matching_bits) / 100 / 50))) ) 277 (0 == (rd->pow % ((1 << matching_bits) / 100 / 50))))
292 FPRINTF (stderr, "%s", "."); 278 fprintf (stderr, "%s", ".");
293 if ( (0 != rd->pow) && 279 if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) ||
294 ( (0 == ((1 << matching_bits) / 100)) || 280 (0 == (rd->pow % ((1 << matching_bits) / 100)))))
295 (0 == (rd->pow % ((1 << matching_bits) / 100))) ) ) 281 fprintf (stderr,
296 FPRINTF (stderr, " - @ %3u%% (estimate)\n", 282 " - @ %3u%% (estimate)\n",
297 (unsigned int) (rd->pow * 100) / (1 << matching_bits)); 283 (unsigned int) (rd->pow * 100) / (1 << matching_bits));
298 /* actually do POW calculation */ 284 /* actually do POW calculation */
299 rd->pow++; 285 rd->pow++;
300 if (GNUNET_OK == 286 if (GNUNET_OK == GNUNET_REVOCATION_check_pow (&rd->key,
301 GNUNET_REVOCATION_check_pow (&rd->key, 287 rd->pow,
302 rd->pow, 288 (unsigned int) matching_bits))
303 (unsigned int) matching_bits))
304 { 289 {
305 if ( (NULL != filename) && 290 if ((NULL != filename) &&
306 (sizeof (struct RevocationData) != 291 (sizeof (struct RevocationData) !=
307 GNUNET_DISK_fn_write (filename, 292 GNUNET_DISK_fn_write (filename,
308 rd, 293 rd,
309 sizeof (struct RevocationData), 294 sizeof (struct RevocationData),
310 GNUNET_DISK_PERM_USER_READ | 295 GNUNET_DISK_PERM_USER_READ |
311 GNUNET_DISK_PERM_USER_WRITE)) ) 296 GNUNET_DISK_PERM_USER_WRITE)))
312 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 297 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
313 "write",
314 filename);
315 if (perform) 298 if (perform)
316 { 299 {
317 perform_revocation (rd); 300 perform_revocation (rd);
318 } 301 }
319 else 302 else
320 { 303 {
321 FPRINTF (stderr, "%s", "\n"); 304 fprintf (stderr, "%s", "\n");
322 FPRINTF (stderr, 305 fprintf (stderr,
323 _("Revocation certificate for `%s' stored in `%s'\n"), 306 _ ("Revocation certificate for `%s' stored in `%s'\n"),
324 revoke_ego, 307 revoke_ego,
325 filename); 308 filename);
326 GNUNET_SCHEDULER_shutdown (); 309 GNUNET_SCHEDULER_shutdown ();
327 } 310 }
328 return; 311 return;
329 } 312 }
330 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, 313 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd);
331 rd);
332} 314}
333 315
334 316
@@ -339,8 +321,7 @@ calculate_pow (void *cls)
339 * @param ego the ego, NULL if not found 321 * @param ego the ego, NULL if not found
340 */ 322 */
341static void 323static void
342ego_callback (void *cls, 324ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
343 const struct GNUNET_IDENTITY_Ego *ego)
344{ 325{
345 struct RevocationData *rd; 326 struct RevocationData *rd;
346 struct GNUNET_CRYPTO_EcdsaPublicKey key; 327 struct GNUNET_CRYPTO_EcdsaPublicKey key;
@@ -348,28 +329,20 @@ ego_callback (void *cls,
348 el = NULL; 329 el = NULL;
349 if (NULL == ego) 330 if (NULL == ego)
350 { 331 {
351 FPRINTF (stdout, 332 fprintf (stdout, _ ("Ego `%s' not found.\n"), revoke_ego);
352 _("Ego `%s' not found.\n"),
353 revoke_ego);
354 GNUNET_SCHEDULER_shutdown (); 333 GNUNET_SCHEDULER_shutdown ();
355 return; 334 return;
356 } 335 }
357 GNUNET_IDENTITY_ego_get_public_key (ego, 336 GNUNET_IDENTITY_ego_get_public_key (ego, &key);
358 &key);
359 rd = GNUNET_new (struct RevocationData); 337 rd = GNUNET_new (struct RevocationData);
360 if ( (NULL != filename) && 338 if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) &&
361 (GNUNET_YES == 339 (sizeof (struct RevocationData) ==
362 GNUNET_DISK_file_test (filename)) && 340 GNUNET_DISK_fn_read (filename, rd, sizeof (struct RevocationData))))
363 (sizeof (struct RevocationData) ==
364 GNUNET_DISK_fn_read (filename,
365 rd,
366 sizeof (struct RevocationData))) )
367 { 341 {
368 if (0 != GNUNET_memcmp (&rd->key, 342 if (0 != GNUNET_memcmp (&rd->key, &key))
369 &key))
370 { 343 {
371 fprintf (stderr, 344 fprintf (stderr,
372 _("Error: revocation certificate in `%s' is not for `%s'\n"), 345 _ ("Error: revocation certificate in `%s' is not for `%s'\n"),
373 filename, 346 filename,
374 revoke_ego); 347 revoke_ego);
375 GNUNET_free (rd); 348 GNUNET_free (rd);
@@ -378,18 +351,15 @@ ego_callback (void *cls,
378 } 351 }
379 else 352 else
380 { 353 {
381 GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key (ego), 354 GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key (
355 ego),
382 &rd->sig); 356 &rd->sig);
383 rd->key = key; 357 rd->key = key;
384 } 358 }
385 if (GNUNET_YES == 359 if (GNUNET_YES ==
386 GNUNET_REVOCATION_check_pow (&key, 360 GNUNET_REVOCATION_check_pow (&key, rd->pow, (unsigned int) matching_bits))
387 rd->pow,
388 (unsigned int) matching_bits))
389 { 361 {
390 FPRINTF (stderr, 362 fprintf (stderr, "%s", _ ("Revocation certificate ready\n"));
391 "%s",
392 _("Revocation certificate ready\n"));
393 if (perform) 363 if (perform)
394 perform_revocation (rd); 364 perform_revocation (rd);
395 else 365 else
@@ -397,13 +367,11 @@ ego_callback (void *cls,
397 GNUNET_free (rd); 367 GNUNET_free (rd);
398 return; 368 return;
399 } 369 }
400 FPRINTF (stderr, 370 fprintf (stderr,
401 "%s", 371 "%s",
402 _("Revocation certificate not ready, calculating proof of work\n")); 372 _ ("Revocation certificate not ready, calculating proof of work\n"));
403 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, 373 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd);
404 rd); 374 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, rd);
405 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
406 rd);
407} 375}
408 376
409 377
@@ -429,31 +397,26 @@ run (void *cls,
429 { 397 {
430 if (GNUNET_OK != 398 if (GNUNET_OK !=
431 GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego, 399 GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego,
432 strlen (test_ego), 400 strlen (test_ego),
433 &pk)) 401 &pk))
434 { 402 {
435 FPRINTF (stderr, 403 fprintf (stderr, _ ("Public key `%s' malformed\n"), test_ego);
436 _("Public key `%s' malformed\n"),
437 test_ego);
438 return; 404 return;
439 } 405 }
440 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 406 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
441 NULL); 407 q = GNUNET_REVOCATION_query (cfg, &pk, &print_query_result, NULL);
442 q = GNUNET_REVOCATION_query (cfg,
443 &pk,
444 &print_query_result,
445 NULL);
446 if (NULL != revoke_ego) 408 if (NULL != revoke_ego)
447 FPRINTF (stderr, 409 fprintf (
448 "%s", 410 stderr,
449 _("Testing and revoking at the same time is not allowed, only executing test.\n")); 411 "%s",
412 _ (
413 "Testing and revoking at the same time is not allowed, only executing test.\n"));
450 return; 414 return;
451 } 415 }
452 if (GNUNET_OK != 416 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
453 GNUNET_CONFIGURATION_get_value_number (cfg, 417 "REVOCATION",
454 "REVOCATION", 418 "WORKBITS",
455 "WORKBITS", 419 &matching_bits))
456 &matching_bits))
457 { 420 {
458 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 421 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
459 "REVOCATION", 422 "REVOCATION",
@@ -462,37 +425,28 @@ run (void *cls,
462 } 425 }
463 if (NULL != revoke_ego) 426 if (NULL != revoke_ego)
464 { 427 {
465 if ( !perform && (NULL == filename) ) 428 if (! perform && (NULL == filename))
466 { 429 {
467 FPRINTF (stderr, 430 fprintf (stderr,
468 "%s", 431 "%s",
469 _("No filename to store revocation certificate given.\n")); 432 _ ("No filename to store revocation certificate given.\n"));
470 return; 433 return;
471 } 434 }
472 /* main code here */ 435 /* main code here */
473 el = GNUNET_IDENTITY_ego_lookup (cfg, 436 el = GNUNET_IDENTITY_ego_lookup (cfg, revoke_ego, &ego_callback, NULL);
474 revoke_ego, 437 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
475 &ego_callback,
476 NULL);
477 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
478 NULL);
479 return; 438 return;
480 } 439 }
481 if ( (NULL != filename) && 440 if ((NULL != filename) && (perform))
482 (perform) )
483 { 441 {
484 if (sizeof (rd) != 442 if (sizeof (rd) != GNUNET_DISK_fn_read (filename, &rd, sizeof (rd)))
485 GNUNET_DISK_fn_read (filename,
486 &rd,
487 sizeof (rd)))
488 { 443 {
489 fprintf (stderr, 444 fprintf (stderr,
490 _("Failed to read revocation certificate from `%s'\n"), 445 _ ("Failed to read revocation certificate from `%s'\n"),
491 filename); 446 filename);
492 return; 447 return;
493 } 448 }
494 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 449 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
495 NULL);
496 if (GNUNET_YES != 450 if (GNUNET_YES !=
497 GNUNET_REVOCATION_check_pow (&rd.key, 451 GNUNET_REVOCATION_check_pow (&rd.key,
498 rd.pow, 452 rd.pow,
@@ -501,18 +455,14 @@ run (void *cls,
501 struct RevocationData *cp = GNUNET_new (struct RevocationData); 455 struct RevocationData *cp = GNUNET_new (struct RevocationData);
502 456
503 *cp = rd; 457 *cp = rd;
504 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, 458 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cp);
505 cp); 459 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, cp);
506 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
507 cp);
508 return; 460 return;
509 } 461 }
510 perform_revocation (&rd); 462 perform_revocation (&rd);
511 return; 463 return;
512 } 464 }
513 FPRINTF (stderr, 465 fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n"));
514 "%s",
515 _("No action specified. Nothing to do.\n"));
516} 466}
517 467
518 468
@@ -531,36 +481,46 @@ main (int argc, char *const *argv)
531 GNUNET_GETOPT_option_string ('f', 481 GNUNET_GETOPT_option_string ('f',
532 "filename", 482 "filename",
533 "NAME", 483 "NAME",
534 gettext_noop ("use NAME for the name of the revocation file"), 484 gettext_noop (
485 "use NAME for the name of the revocation file"),
535 &filename), 486 &filename),
536 487
537 GNUNET_GETOPT_option_string ('R', 488 GNUNET_GETOPT_option_string (
538 "revoke", 489 'R',
539 "NAME", 490 "revoke",
540 gettext_noop ("revoke the private key associated for the the private key associated with the ego NAME "), 491 "NAME",
541 &revoke_ego), 492 gettext_noop (
542 493 "revoke the private key associated for the the private key associated with the ego NAME "),
543 GNUNET_GETOPT_option_flag ('p', 494 &revoke_ego),
544 "perform", 495
545 gettext_noop ("actually perform revocation, otherwise we just do the precomputation"), 496 GNUNET_GETOPT_option_flag (
546 &perform), 497 'p',
498 "perform",
499 gettext_noop (
500 "actually perform revocation, otherwise we just do the precomputation"),
501 &perform),
547 502
548 GNUNET_GETOPT_option_string ('t', 503 GNUNET_GETOPT_option_string ('t',
549 "test", 504 "test",
550 "KEY", 505 "KEY",
551 gettext_noop ("test if the public key KEY has been revoked"), 506 gettext_noop (
552 &test_ego), 507 "test if the public key KEY has been revoked"),
508 &test_ego),
553 509
554 GNUNET_GETOPT_OPTION_END 510 GNUNET_GETOPT_OPTION_END};
555 };
556 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))
557 return 2; 512 return 2;
558 513
559 ret = (GNUNET_OK == 514 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
560 GNUNET_PROGRAM_run (argc, argv, "gnunet-revocation", 515 argv,
561 gettext_noop ("help text"), options, &run, 516 "gnunet-revocation",
562 NULL)) ? ret : 1; 517 gettext_noop ("help text"),
563 GNUNET_free ((void*) argv); 518 options,
519 &run,
520 NULL))
521 ? ret
522 : 1;
523 GNUNET_free ((void *) argv);
564 return ret; 524 return ret;
565} 525}
566 526