2 This file is part of GNUnet.
3 Copyright (C) 2009, 2013, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file revocation/test_revocation.c
22 * @brief base testcase for revocation exchange
23 * @author Matthias Wachs
24 * @author Christian Grothoff
27 #include "gnunet_core_service.h"
28 #include "gnunet_identity_service.h"
29 #include "gnunet_revocation_service.h"
30 #include "gnunet_testbed_service.h"
32 #define NUM_TEST_PEERS 2
36 struct GNUNET_TESTBED_Peer *p;
37 struct GNUNET_TESTBED_Operation *identity_op;
38 struct GNUNET_TESTBED_Operation *core_op;
39 struct GNUNET_IDENTITY_Handle *idh;
40 const struct GNUNET_CONFIGURATION_Handle *cfg;
41 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
42 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
43 struct GNUNET_CRYPTO_EcdsaSignature sig;
44 struct GNUNET_IDENTITY_Operation *create_id_op;
45 struct GNUNET_IDENTITY_EgoLookup *ego_lookup;
46 struct GNUNET_REVOCATION_Handle *revok_handle;
47 struct GNUNET_CORE_Handle *ch;
51 static struct TestPeer testpeers[2];
54 * Return value from main, set to 0 on success.
60 do_shutdown (void *cls)
62 for (unsigned int c = 0; c < NUM_TEST_PEERS; c++)
64 if (NULL != testpeers[c].create_id_op)
66 GNUNET_IDENTITY_cancel (testpeers[c].create_id_op);
67 testpeers[c].create_id_op = NULL;
69 if (NULL != testpeers[c].ego_lookup)
71 GNUNET_IDENTITY_ego_lookup_cancel (testpeers[c].ego_lookup);
72 testpeers[c].ego_lookup = NULL;
74 if (NULL != testpeers[c].revok_handle)
76 GNUNET_REVOCATION_revoke_cancel (testpeers[c].revok_handle);
77 testpeers[c].revok_handle = NULL;
79 if (NULL != testpeers[c].identity_op)
81 GNUNET_TESTBED_operation_done (testpeers[c].identity_op);
82 testpeers[c].identity_op = NULL;
84 if (NULL != testpeers[c].core_op)
86 GNUNET_TESTBED_operation_done (testpeers[c].core_op);
87 testpeers[c].core_op = NULL;
94 check_revocation (void *cls);
98 revocation_remote_cb (void *cls,
101 static int repeat = 0;
103 if (GNUNET_NO == is_valid)
105 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
106 "Local revocation successful\n");
108 GNUNET_SCHEDULER_shutdown ();
114 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
120 "Flooding of revocation failed\n");
122 GNUNET_SCHEDULER_shutdown ();
127 check_revocation (void *cls)
129 GNUNET_REVOCATION_query (testpeers[0].cfg,
130 &testpeers[1].pubkey,
131 &revocation_remote_cb, NULL);
136 revocation_cb (void *cls,
139 testpeers[1].revok_handle = NULL;
140 if (GNUNET_NO == is_valid)
142 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
143 "Revocation successful\n");
144 check_revocation (NULL);
151 const struct GNUNET_IDENTITY_Ego *ego)
153 static int completed = 0;
155 if ((NULL != ego) && (cls == &testpeers[0]))
157 testpeers[0].ego_lookup = NULL;
158 testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
159 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[0].pubkey);
162 if ((NULL != ego) && (cls == &testpeers[1]))
164 testpeers[1].ego_lookup = NULL;
165 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
166 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey);
167 GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig);
169 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
170 "Calculating proof of work...\n");
171 testpeers[1].pow = 0;
172 int res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey,
173 testpeers[1].pow, 5);
174 while (GNUNET_OK != res)
177 res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey,
182 "Done calculating proof of work\n");
187 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
189 testpeers[1].revok_handle
190 = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
191 &testpeers[1].pubkey,
194 &revocation_cb, NULL);
200 identity_create_cb (void *cls,
203 static int completed = 0;
205 if ((NULL == emsg) && (cls == &testpeers[0]))
207 testpeers[0].create_id_op = NULL;
210 if ((NULL == emsg) && (cls == &testpeers[1]))
212 testpeers[1].create_id_op = NULL;
218 "Identities created\n");
219 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg,
223 testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg,
231 identity_completion_cb (void *cls,
232 struct GNUNET_TESTBED_Operation *op,
236 static int completed = 0;
239 if (NUM_TEST_PEERS != completed)
242 "All peers connected @ IDENTITY ...\n");
243 testpeers[0].create_id_op
244 = GNUNET_IDENTITY_create (testpeers[0].idh,
248 testpeers[1].create_id_op
249 = GNUNET_IDENTITY_create (testpeers[1].idh,
257 identity_connect_adapter (void *cls,
258 const struct GNUNET_CONFIGURATION_Handle *cfg)
260 struct TestPeer *me = cls;
263 me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
265 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
266 "Failed to create IDENTITY handle \n");
272 identity_disconnect_adapter (void *cls,
275 struct TestPeer *me = cls;
276 GNUNET_IDENTITY_disconnect (me->idh);
282 connect_cb (void *cls,
283 const struct GNUNET_PeerIdentity *peer,
284 struct GNUNET_MQ_Handle *mq)
286 static int connects = 0;
289 if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects)
292 "All peers connected @ CORE ...\n");
294 /* Connect to identity service */
295 testpeers[0].identity_op
296 = GNUNET_TESTBED_service_connect (NULL,
297 testpeers[0].p, "identity",
298 &identity_completion_cb, NULL,
299 &identity_connect_adapter,
300 &identity_disconnect_adapter,
302 testpeers[1].identity_op
303 = GNUNET_TESTBED_service_connect (NULL,
304 testpeers[1].p, "identity",
305 *identity_completion_cb, NULL,
306 &identity_connect_adapter,
307 &identity_disconnect_adapter,
315 core_completion_cb (void *cls,
316 struct GNUNET_TESTBED_Operation *op,
320 static int completed = 0;
323 if (NUM_TEST_PEERS == completed)
325 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
326 "Connected to CORE\n");
332 core_connect_adapter (void *cls,
333 const struct GNUNET_CONFIGURATION_Handle *cfg)
335 struct TestPeer *me = cls;
338 me->ch = GNUNET_CORE_connect (cfg,
345 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
346 "Failed to create CORE handle \n");
352 core_disconnect_adapter (void *cls,
355 struct TestPeer *me = cls;
357 GNUNET_CORE_disconnect (me->ch);
363 test_connection (void *cls,
364 struct GNUNET_TESTBED_RunHandle *h,
365 unsigned int num_peers,
366 struct GNUNET_TESTBED_Peer **peers,
367 unsigned int links_succeeded,
368 unsigned int links_failed)
372 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
374 if (NUM_TEST_PEERS != num_peers)
378 "Only %u out of %u peers were started ...\n",
381 GNUNET_SCHEDULER_shutdown ();
384 /* We are generating a CLIQUE */
385 if (NUM_TEST_PEERS * (NUM_TEST_PEERS -1) == links_succeeded)
387 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
388 "Testbed connected peers, initializing test\n");
389 for (c = 0; c < num_peers; c++)
391 testpeers[c].p = peers[c];
393 = GNUNET_TESTBED_service_connect (NULL,
396 &core_completion_cb, NULL,
397 &core_connect_adapter,
398 &core_disconnect_adapter,
404 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
405 "Testbed failed to connect peers\n");
407 GNUNET_SCHEDULER_shutdown ();
418 /* Connecting initial topology */
419 (void) GNUNET_TESTBED_test_run ("test-revocation",
420 "test_revocation.conf",
423 &test_connection, NULL);
427 /* end of test_revocation.c */