aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-04-20 16:56:16 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-04-20 16:56:16 +0200
commitee5cfec8640886ea3fa3f582cb04347762feebbd (patch)
treec884ba6d0b6304fb635e4fd1a482fdffc91cf6f3 /src
parent6d61330e3ae457a27f10247cd9caf53987604143 (diff)
downloadgnunet-ee5cfec8640886ea3fa3f582cb04347762feebbd.tar.gz
gnunet-ee5cfec8640886ea3fa3f582cb04347762feebbd.zip
fix tests
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_revocation_service.h2
-rw-r--r--src/revocation/gnunet-revocation.c4
-rw-r--r--src/revocation/revocation.h2
-rw-r--r--src/revocation/revocation_api.c11
-rw-r--r--src/revocation/test_revocation.c22
-rw-r--r--src/revocation/test_revocation.conf1
6 files changed, 27 insertions, 15 deletions
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,
201 * @return a handle for use in PoW rounds 201 * @return a handle for use in PoW rounds
202 */ 202 */
203struct GNUNET_REVOCATION_PowCalculationHandle* 203struct GNUNET_REVOCATION_PowCalculationHandle*
204GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, 204GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
205 int epochs, 205 int epochs,
206 unsigned int difficulty); 206 unsigned int difficulty);
207 207
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)
345{ 345{
346 struct GNUNET_REVOCATION_Pow *pow; 346 struct GNUNET_REVOCATION_Pow *pow;
347 struct GNUNET_CRYPTO_EcdsaPublicKey key; 347 struct GNUNET_CRYPTO_EcdsaPublicKey key;
348 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
348 struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; 349 struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL;
349 int epochs; 350 int epochs;
350 351
@@ -356,6 +357,7 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
356 return; 357 return;
357 } 358 }
358 GNUNET_IDENTITY_ego_get_public_key (ego, &key); 359 GNUNET_IDENTITY_ego_get_public_key (ego, &key);
360 privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
359 pow = GNUNET_new (struct GNUNET_REVOCATION_Pow); 361 pow = GNUNET_new (struct GNUNET_REVOCATION_Pow);
360 if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && 362 if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) &&
361 (sizeof(struct GNUNET_REVOCATION_Pow) == 363 (sizeof(struct GNUNET_REVOCATION_Pow) ==
@@ -406,7 +408,7 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
406 "%s", 408 "%s",
407 _ ("Revocation certificate not ready, calculating proof of work\n")); 409 _ ("Revocation certificate not ready, calculating proof of work\n"));
408 if (NULL == ph) 410 if (NULL == ph)
409 ph = GNUNET_REVOCATION_pow_init (&key, 411 ph = GNUNET_REVOCATION_pow_init (privkey,
410 1, /* Epochs */ 412 1, /* Epochs */
411 matching_bits); 413 matching_bits);
412 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); 414 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
92 /** 92 /**
93 * Number that causes a hash collision with the @e public_key. 93 * Number that causes a hash collision with the @e public_key.
94 */ 94 */
95 struct GNUNET_REVOCATION_Pow proof_of_work GNUNET_PACKED; 95 struct GNUNET_REVOCATION_Pow proof_of_work;
96}; 96};
97 97
98 98
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,
472 * @return a handle for use in PoW rounds 472 * @return a handle for use in PoW rounds
473 */ 473 */
474struct GNUNET_REVOCATION_PowCalculationHandle* 474struct GNUNET_REVOCATION_PowCalculationHandle*
475GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, 475GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
476 int epochs, 476 int epochs,
477 unsigned int difficulty) 477 unsigned int difficulty)
478{ 478{
@@ -480,8 +480,15 @@ GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
480 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); 480 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get ();
481 481
482 pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); 482 pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
483 pc->pow.key = *key;
484 pc->pow.timestamp = GNUNET_TIME_absolute_hton (ts); 483 pc->pow.timestamp = GNUNET_TIME_absolute_hton (ts);
484 pc->pow.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
485 pc->pow.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
486 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
487 GNUNET_CRYPTO_ecdsa_key_get_public (key, &pc->pow.key);
488 GNUNET_assert (GNUNET_OK ==
489 GNUNET_CRYPTO_ecdsa_sign_ (key,
490 &pc->pow.purpose,
491 &pc->pow.signature));
485 pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 492 pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
486 UINT64_MAX); 493 UINT64_MAX);
487 pc->difficulty = difficulty; 494 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
45 struct GNUNET_IDENTITY_EgoLookup *ego_lookup; 45 struct GNUNET_IDENTITY_EgoLookup *ego_lookup;
46 struct GNUNET_REVOCATION_Handle *revok_handle; 46 struct GNUNET_REVOCATION_Handle *revok_handle;
47 struct GNUNET_CORE_Handle *ch; 47 struct GNUNET_CORE_Handle *ch;
48 uint64_t pow; 48 struct GNUNET_REVOCATION_PowCalculationHandle *pow;
49}; 49};
50 50
51static struct TestPeer testpeers[2]; 51static struct TestPeer testpeers[2];
@@ -146,6 +146,7 @@ static void
146ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) 146ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
147{ 147{
148 static int completed = 0; 148 static int completed = 0;
149 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
149 150
150 if ((NULL != ego) && (cls == &testpeers[0])) 151 if ((NULL != ego) && (cls == &testpeers[0]))
151 { 152 {
@@ -159,30 +160,31 @@ ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
159 testpeers[1].ego_lookup = NULL; 160 testpeers[1].ego_lookup = NULL;
160 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego); 161 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
161 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); 162 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey);
162 GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig);
163
164 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); 163 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n");
165 testpeers[1].pow = 0; 164 privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
165 testpeers[1].pow = GNUNET_REVOCATION_pow_init (privkey,
166 1,
167 5);
166 int res = 168 int res =
167 GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); 169 GNUNET_REVOCATION_pow_round (testpeers[1].pow);
168 while (GNUNET_OK != res) 170 while (GNUNET_OK != res)
169 { 171 {
170 testpeers[1].pow++;
171 res = 172 res =
172 GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); 173 GNUNET_REVOCATION_pow_round (testpeers[1].pow);
173 } 174 }
174 fprintf (stderr, "Done calculating proof of work\n"); 175 fprintf (stderr, "Done calculating proof of work\n");
175 completed++; 176 completed++;
176 } 177 }
177 if (2 == completed) 178 if (2 == completed)
178 { 179 {
180 const struct GNUNET_REVOCATION_Pow *pow;
181 pow = GNUNET_REVOCATION_pow_get (testpeers[1].pow);
179 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); 182 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n");
180 testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, 183 testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
181 &testpeers[1].pubkey, 184 pow,
182 &testpeers[1].sig,
183 testpeers[1].pow,
184 &revocation_cb, 185 &revocation_cb,
185 NULL); 186 NULL);
187 GNUNET_REVOCATION_pow_cleanup (testpeers[1].pow);
186 } 188 }
187} 189}
188 190
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
7[revocation] 7[revocation]
8WORKBITS = 3 8WORKBITS = 3
9IMMEDIATE_START = YES 9IMMEDIATE_START = YES
10EPOCH_LENGTH = 365 d
10 11
11[identity] 12[identity]
12# Directory where we store information about our egos 13# Directory where we store information about our egos