From ee5cfec8640886ea3fa3f582cb04347762feebbd Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Mon, 20 Apr 2020 16:56:16 +0200 Subject: fix tests --- src/include/gnunet_revocation_service.h | 2 +- src/revocation/gnunet-revocation.c | 4 +++- src/revocation/revocation.h | 2 +- src/revocation/revocation_api.c | 11 +++++++++-- src/revocation/test_revocation.c | 22 ++++++++++++---------- src/revocation/test_revocation.conf | 1 + 6 files changed, 27 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_revocation_service.h b/src/include/gnunet_revocation_service.h index 226dce357..b2f81b67a 100644 --- a/src/include/gnunet_revocation_service.h +++ b/src/include/gnunet_revocation_service.h @@ -201,7 +201,7 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, * @return a handle for use in PoW rounds */ struct GNUNET_REVOCATION_PowCalculationHandle* -GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, +GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, int epochs, unsigned int difficulty); diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index c33f12c90..5f3df0ee0 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.c @@ -345,6 +345,7 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) { struct GNUNET_REVOCATION_Pow *pow; struct GNUNET_CRYPTO_EcdsaPublicKey key; + const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; int epochs; @@ -356,6 +357,7 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) return; } GNUNET_IDENTITY_ego_get_public_key (ego, &key); + privkey = GNUNET_IDENTITY_ego_get_private_key (ego); pow = GNUNET_new (struct GNUNET_REVOCATION_Pow); if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && (sizeof(struct GNUNET_REVOCATION_Pow) == @@ -406,7 +408,7 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) "%s", _ ("Revocation certificate not ready, calculating proof of work\n")); if (NULL == ph) - ph = GNUNET_REVOCATION_pow_init (&key, + ph = GNUNET_REVOCATION_pow_init (privkey, 1, /* Epochs */ matching_bits); pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); diff --git a/src/revocation/revocation.h b/src/revocation/revocation.h index b2769da0e..868c2b853 100644 --- a/src/revocation/revocation.h +++ b/src/revocation/revocation.h @@ -92,7 +92,7 @@ struct RevokeMessage /** * Number that causes a hash collision with the @e public_key. */ - struct GNUNET_REVOCATION_Pow proof_of_work GNUNET_PACKED; + struct GNUNET_REVOCATION_Pow proof_of_work; }; diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c index f2261ff4f..fba10a4d5 100644 --- a/src/revocation/revocation_api.c +++ b/src/revocation/revocation_api.c @@ -472,7 +472,7 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, * @return a handle for use in PoW rounds */ struct GNUNET_REVOCATION_PowCalculationHandle* -GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, +GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, int epochs, unsigned int difficulty) { @@ -480,8 +480,15 @@ GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); - pc->pow.key = *key; pc->pow.timestamp = GNUNET_TIME_absolute_hton (ts); + pc->pow.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); + pc->pow.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); + GNUNET_CRYPTO_ecdsa_key_get_public (key, &pc->pow.key); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_ecdsa_sign_ (key, + &pc->pow.purpose, + &pc->pow.signature)); pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); pc->difficulty = difficulty; diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c index 012bac09e..07f5e6e61 100644 --- a/src/revocation/test_revocation.c +++ b/src/revocation/test_revocation.c @@ -45,7 +45,7 @@ struct TestPeer struct GNUNET_IDENTITY_EgoLookup *ego_lookup; struct GNUNET_REVOCATION_Handle *revok_handle; struct GNUNET_CORE_Handle *ch; - uint64_t pow; + struct GNUNET_REVOCATION_PowCalculationHandle *pow; }; static struct TestPeer testpeers[2]; @@ -146,6 +146,7 @@ static void ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) { static int completed = 0; + const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; if ((NULL != ego) && (cls == &testpeers[0])) { @@ -159,30 +160,31 @@ ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) testpeers[1].ego_lookup = NULL; testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego); GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); - GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); - testpeers[1].pow = 0; + privkey = GNUNET_IDENTITY_ego_get_private_key (ego); + testpeers[1].pow = GNUNET_REVOCATION_pow_init (privkey, + 1, + 5); int res = - GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); + GNUNET_REVOCATION_pow_round (testpeers[1].pow); while (GNUNET_OK != res) { - testpeers[1].pow++; res = - GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); + GNUNET_REVOCATION_pow_round (testpeers[1].pow); } fprintf (stderr, "Done calculating proof of work\n"); completed++; } if (2 == completed) { + const struct GNUNET_REVOCATION_Pow *pow; + pow = GNUNET_REVOCATION_pow_get (testpeers[1].pow); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, - &testpeers[1].pubkey, - &testpeers[1].sig, - testpeers[1].pow, + pow, &revocation_cb, NULL); + GNUNET_REVOCATION_pow_cleanup (testpeers[1].pow); } } diff --git a/src/revocation/test_revocation.conf b/src/revocation/test_revocation.conf index 3b04150c1..f195429b4 100644 --- a/src/revocation/test_revocation.conf +++ b/src/revocation/test_revocation.conf @@ -7,6 +7,7 @@ SERVICEHOME=$GNUNET_TMP/test-revocation-service [revocation] WORKBITS = 3 IMMEDIATE_START = YES +EPOCH_LENGTH = 365 d [identity] # Directory where we store information about our egos -- cgit v1.2.3