diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-10-15 11:57:30 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-10-15 12:11:23 +0200 |
commit | 5d498b8e1b50373636126956d1c6addfd11ade5e (patch) | |
tree | f7b7f140838ed52668ad3d02eadbc94cc9936318 /src/revocation/gnunet-revocation.c | |
parent | 5680378974db794d67b75473435a0651fad0cd24 (diff) | |
download | gnunet-5d498b8e1b50373636126956d1c6addfd11ade5e.tar.gz gnunet-5d498b8e1b50373636126956d1c6addfd11ade5e.zip |
- fix revocation
Diffstat (limited to 'src/revocation/gnunet-revocation.c')
-rw-r--r-- | src/revocation/gnunet-revocation.c | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index 2ba5d0420..d59ea7c81 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.c | |||
@@ -213,7 +213,7 @@ static void | |||
213 | perform_revocation () | 213 | perform_revocation () |
214 | { | 214 | { |
215 | h = GNUNET_REVOCATION_revoke (cfg, | 215 | h = GNUNET_REVOCATION_revoke (cfg, |
216 | &proof_of_work, | 216 | proof_of_work, |
217 | &print_revocation_result, | 217 | &print_revocation_result, |
218 | NULL); | 218 | NULL); |
219 | } | 219 | } |
@@ -228,11 +228,12 @@ perform_revocation () | |||
228 | static void | 228 | static void |
229 | sync_pow () | 229 | sync_pow () |
230 | { | 230 | { |
231 | size_t psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); | ||
231 | if ((NULL != filename) && | 232 | if ((NULL != filename) && |
232 | (sizeof(struct GNUNET_REVOCATION_PowP) != | 233 | (psize != |
233 | GNUNET_DISK_fn_write (filename, | 234 | GNUNET_DISK_fn_write (filename, |
234 | &proof_of_work, | 235 | proof_of_work, |
235 | sizeof(struct GNUNET_REVOCATION_PowP), | 236 | psize, |
236 | GNUNET_DISK_PERM_USER_READ | 237 | GNUNET_DISK_PERM_USER_READ |
237 | | GNUNET_DISK_PERM_USER_WRITE))) | 238 | | GNUNET_DISK_PERM_USER_WRITE))) |
238 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 239 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); |
@@ -269,6 +270,7 @@ static void | |||
269 | calculate_pow (void *cls) | 270 | calculate_pow (void *cls) |
270 | { | 271 | { |
271 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; | 272 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; |
273 | size_t psize; | ||
272 | 274 | ||
273 | /* store temporary results */ | 275 | /* store temporary results */ |
274 | pow_task = NULL; | 276 | pow_task = NULL; |
@@ -277,11 +279,12 @@ calculate_pow (void *cls) | |||
277 | /* actually do POW calculation */ | 279 | /* actually do POW calculation */ |
278 | if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) | 280 | if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) |
279 | { | 281 | { |
282 | psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); | ||
280 | if ((NULL != filename) && | 283 | if ((NULL != filename) && |
281 | (sizeof(struct GNUNET_REVOCATION_PowP) != | 284 | (psize != |
282 | GNUNET_DISK_fn_write (filename, | 285 | GNUNET_DISK_fn_write (filename, |
283 | &proof_of_work, | 286 | proof_of_work, |
284 | sizeof(struct GNUNET_REVOCATION_PowP), | 287 | psize, |
285 | GNUNET_DISK_PERM_USER_READ | 288 | GNUNET_DISK_PERM_USER_READ |
286 | | GNUNET_DISK_PERM_USER_WRITE))) | 289 | | GNUNET_DISK_PERM_USER_WRITE))) |
287 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 290 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); |
@@ -328,6 +331,7 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
328 | struct GNUNET_IDENTITY_PublicKey key; | 331 | struct GNUNET_IDENTITY_PublicKey key; |
329 | const struct GNUNET_IDENTITY_PrivateKey *privkey; | 332 | const struct GNUNET_IDENTITY_PrivateKey *privkey; |
330 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; | 333 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; |
334 | size_t psize; | ||
331 | 335 | ||
332 | el = NULL; | 336 | el = NULL; |
333 | if (NULL == ego) | 337 | if (NULL == ego) |
@@ -338,12 +342,15 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
338 | } | 342 | } |
339 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); | 343 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); |
340 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); | 344 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
341 | memset (&proof_of_work, 0, sizeof (proof_of_work)); | 345 | proof_of_work = GNUNET_malloc (GNUNET_REVOCATION_MAX_PROOF_SIZE); |
342 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && | 346 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && |
343 | (sizeof(proof_of_work) == | 347 | (0 < (psize = |
344 | GNUNET_DISK_fn_read (filename, &proof_of_work, sizeof(proof_of_work)))) | 348 | GNUNET_DISK_fn_read (filename, proof_of_work, |
349 | GNUNET_REVOCATION_MAX_PROOF_SIZE)))) | ||
345 | { | 350 | { |
346 | if (0 != GNUNET_memcmp (&proof_of_work.key, &key)) | 351 | size_t ksize = GNUNET_IDENTITY_key_get_length (&key); |
352 | if (((psize - sizeof (*proof_of_work)) < ksize) || // Key too small | ||
353 | (0 != memcmp (&proof_of_work[1], &key, ksize))) // Keys do not match | ||
347 | { | 354 | { |
348 | fprintf (stderr, | 355 | fprintf (stderr, |
349 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), | 356 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), |
@@ -352,7 +359,7 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
352 | return; | 359 | return; |
353 | } | 360 | } |
354 | if (GNUNET_YES == | 361 | if (GNUNET_YES == |
355 | GNUNET_REVOCATION_check_pow (&proof_of_work, | 362 | GNUNET_REVOCATION_check_pow (proof_of_work, |
356 | (unsigned int) matching_bits, | 363 | (unsigned int) matching_bits, |
357 | epoch_duration)) | 364 | epoch_duration)) |
358 | { | 365 | { |
@@ -369,7 +376,7 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
369 | fprintf (stderr, | 376 | fprintf (stderr, |
370 | "%s", | 377 | "%s", |
371 | _ ("Continuing calculation where left off...\n")); | 378 | _ ("Continuing calculation where left off...\n")); |
372 | ph = GNUNET_REVOCATION_pow_start (&proof_of_work, | 379 | ph = GNUNET_REVOCATION_pow_start (proof_of_work, |
373 | epochs, | 380 | epochs, |
374 | matching_bits); | 381 | matching_bits); |
375 | } | 382 | } |
@@ -379,8 +386,8 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
379 | if (NULL == ph) | 386 | if (NULL == ph) |
380 | { | 387 | { |
381 | GNUNET_REVOCATION_pow_init (privkey, | 388 | GNUNET_REVOCATION_pow_init (privkey, |
382 | &proof_of_work); | 389 | proof_of_work); |
383 | ph = GNUNET_REVOCATION_pow_start (&proof_of_work, | 390 | ph = GNUNET_REVOCATION_pow_start (proof_of_work, |
384 | epochs, /* Epochs */ | 391 | epochs, /* Epochs */ |
385 | matching_bits); | 392 | matching_bits); |
386 | } | 393 | } |
@@ -404,6 +411,7 @@ run (void *cls, | |||
404 | const struct GNUNET_CONFIGURATION_Handle *c) | 411 | const struct GNUNET_CONFIGURATION_Handle *c) |
405 | { | 412 | { |
406 | struct GNUNET_IDENTITY_PublicKey pk; | 413 | struct GNUNET_IDENTITY_PublicKey pk; |
414 | size_t psize; | ||
407 | 415 | ||
408 | cfg = c; | 416 | cfg = c; |
409 | if (NULL != test_ego) | 417 | if (NULL != test_ego) |
@@ -462,23 +470,33 @@ run (void *cls, | |||
462 | } | 470 | } |
463 | if ((NULL != filename) && (perform)) | 471 | if ((NULL != filename) && (perform)) |
464 | { | 472 | { |
465 | if (sizeof(proof_of_work) != GNUNET_DISK_fn_read (filename, | 473 | size_t bread; |
466 | &proof_of_work, | 474 | proof_of_work = GNUNET_malloc (GNUNET_REVOCATION_MAX_PROOF_SIZE); |
467 | sizeof(proof_of_work))) | 475 | if (0 < (bread = GNUNET_DISK_fn_read (filename, |
476 | proof_of_work, | ||
477 | GNUNET_REVOCATION_MAX_PROOF_SIZE))) | ||
468 | { | 478 | { |
469 | fprintf (stderr, | 479 | fprintf (stderr, |
470 | _ ("Failed to read revocation certificate from `%s'\n"), | 480 | _ ("Failed to read revocation certificate from `%s'\n"), |
471 | filename); | 481 | filename); |
472 | return; | 482 | return; |
473 | } | 483 | } |
484 | psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); | ||
485 | if (bread != psize) | ||
486 | { | ||
487 | fprintf (stderr, | ||
488 | _ ("Revocation certificate corrupted in `%s'\n"), | ||
489 | filename); | ||
490 | return; | ||
491 | } | ||
474 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 492 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
475 | if (GNUNET_YES != | 493 | if (GNUNET_YES != |
476 | GNUNET_REVOCATION_check_pow (&proof_of_work, | 494 | GNUNET_REVOCATION_check_pow (proof_of_work, |
477 | (unsigned int) matching_bits, | 495 | (unsigned int) matching_bits, |
478 | epoch_duration)) | 496 | epoch_duration)) |
479 | { | 497 | { |
480 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; | 498 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; |
481 | ph = GNUNET_REVOCATION_pow_start (&proof_of_work, | 499 | ph = GNUNET_REVOCATION_pow_start (proof_of_work, |
482 | epochs, /* Epochs */ | 500 | epochs, /* Epochs */ |
483 | matching_bits); | 501 | matching_bits); |
484 | 502 | ||