aboutsummaryrefslogtreecommitdiff
path: root/src/cli/reclaim
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/reclaim')
-rw-r--r--src/cli/reclaim/.gitignore2
-rw-r--r--src/cli/reclaim/Makefile.am55
-rw-r--r--src/cli/reclaim/gnunet-did.c646
-rw-r--r--src/cli/reclaim/gnunet-reclaim.c928
-rwxr-xr-xsrc/cli/reclaim/test_reclaim.sh31
-rwxr-xr-xsrc/cli/reclaim/test_reclaim_attribute.sh40
-rwxr-xr-xsrc/cli/reclaim/test_reclaim_consume.sh49
-rwxr-xr-xsrc/cli/reclaim/test_reclaim_issue.sh42
-rwxr-xr-xsrc/cli/reclaim/test_reclaim_revoke.sh65
9 files changed, 1858 insertions, 0 deletions
diff --git a/src/cli/reclaim/.gitignore b/src/cli/reclaim/.gitignore
new file mode 100644
index 000000000..49e84eb66
--- /dev/null
+++ b/src/cli/reclaim/.gitignore
@@ -0,0 +1,2 @@
1gnunet-reclaim
2gnunet-did
diff --git a/src/cli/reclaim/Makefile.am b/src/cli/reclaim/Makefile.am
new file mode 100644
index 000000000..1a9273f6b
--- /dev/null
+++ b/src/cli/reclaim/Makefile.am
@@ -0,0 +1,55 @@
1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3
4 plugindir = $(libdir)/gnunet
5
6if USE_COVERAGE
7 AM_CFLAGS = --coverage -O0
8 XLIB = -lgcov
9endif
10
11
12EXTRA_DIST = \
13 $(check_SCRIPTS)
14
15pkgcfgdir= $(pkgdatadir)/config.d/
16
17libexecdir= $(pkglibdir)/libexec/
18
19bin_PROGRAMS = \
20 gnunet-reclaim \
21 gnunet-did
22
23gnunet_reclaim_SOURCES = \
24 gnunet-reclaim.c
25gnunet_reclaim_LDADD = \
26 $(top_builddir)/src/lib/util/libgnunetutil.la \
27 $(top_builddir)/src/service/namestore/libgnunetnamestore.la \
28 $(top_builddir)/src/service/reclaim/libgnunetreclaim.la \
29 $(top_builddir)/src/service/identity/libgnunetidentity.la \
30 $(GN_LIBINTL)
31
32gnunet_did_SOURCES = \
33 gnunet-did.c
34gnunet_did_LDADD = \
35 $(top_builddir)/src/lib/util/libgnunetutil.la \
36 $(top_builddir)/src/service/gns/libgnunetgns.la \
37 $(top_builddir)/src/lib/gnsrecord/libgnunetgnsrecord.la \
38 $(top_builddir)/src/service/identity/libgnunetidentity.la \
39 $(top_builddir)/src/service/namestore/libgnunetnamestore.la \
40 $(top_builddir)/src/service/reclaim/libgnunetdid.la \
41 -ljansson
42gnunet_did_CFLAGS = \
43 -I$(top_builddir)/src/service/reclaim
44
45check_SCRIPTS = \
46 test_reclaim_attribute.sh \
47 test_reclaim_issue.sh \
48 test_reclaim_consume.sh
49
50if ENABLE_TEST_RUN
51 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
52 TESTS = \
53 $(check_SCRIPTS) \
54 $(check_PROGRAMS)
55endif
diff --git a/src/cli/reclaim/gnunet-did.c b/src/cli/reclaim/gnunet-did.c
new file mode 100644
index 000000000..33f6c5657
--- /dev/null
+++ b/src/cli/reclaim/gnunet-did.c
@@ -0,0 +1,646 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2022 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * FIXME: Do we only want to handle EdDSA identities?
23 * TODO: Own GNS record type
24 * TODO: Fix overwrite of records in @ if present look for other with same sub
25 * TODO. Tests
26 * TODO: Move constants to did.h
27 * FIXME: Remove and lookup require differnt representations (did vs egoname)
28 */
29
30/**
31 * @author Tristan Schwieren
32 * @file src/did/gnunet-did.c
33 * @brief DID Method Wrapper
34 *
35 */
36#include "platform.h"
37#include "gnunet_util_lib.h"
38#include "gnunet_namestore_service.h"
39#include "gnunet_identity_service.h"
40#include "gnunet_gns_service.h"
41#include "gnunet_gnsrecord_lib.h"
42#include "did_core.h"
43#include "jansson.h"
44
45#define GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME "1d"
46
47/**
48 * return value
49 */
50static int ret;
51
52/**
53 * Replace DID Document Flag
54 */
55static int replace;
56
57/**
58 * Remove DID Document Flag
59 */
60static int remove_did;
61
62/**
63 * Get DID Documement for DID Flag
64 */
65static int get;
66
67/**
68 * Create DID Document Flag
69 */
70static int create;
71
72/**
73 * Show DID for Ego Flag
74 */
75static int show;
76
77/**
78 * Show DID for Ego Flag
79 */
80static int show_all;
81
82/**
83 * DID Attribut String
84 */
85static char *did;
86
87/**
88 * DID Document Attribut String
89 */
90static char *didd;
91
92/**
93 * Ego Attribut String
94 */
95static char *egoname;
96
97/**
98 * DID Document expiration Date Attribut String
99 */
100static char *expire;
101
102/*
103 * Handle to the GNS service
104 */
105static struct GNUNET_GNS_Handle *gns_handle;
106
107/*
108 * Handle to the NAMESTORE service
109 */
110static struct GNUNET_NAMESTORE_Handle *namestore_handle;
111
112/*
113 * Handle to the IDENTITY service
114 */
115static struct GNUNET_IDENTITY_Handle *identity_handle;
116
117
118/*
119 * The configuration
120 */
121const static struct GNUNET_CONFIGURATION_Handle *my_cfg;
122
123/**
124 * Give ego exists
125 */
126static int ego_exists = 0;
127
128/**
129 * @brief Disconnect and shutdown
130 * @param cls closure
131 */
132static void
133cleanup (void *cls)
134{
135 if (NULL != gns_handle)
136 GNUNET_GNS_disconnect (gns_handle);
137 if (NULL != namestore_handle)
138 GNUNET_NAMESTORE_disconnect (namestore_handle);
139 if (NULL != identity_handle)
140 GNUNET_IDENTITY_disconnect (identity_handle);
141
142 GNUNET_free (did);
143 GNUNET_free (didd);
144 GNUNET_free (egoname);
145 GNUNET_free (expire);
146
147 GNUNET_SCHEDULER_shutdown ();
148}
149
150/**
151 * @brief GNS lookup callback. Prints the DID Document to standard out.
152 * Fails if there is more than one DID record.
153 *
154 * @param cls closure
155 * @param rd_count number of records in @a rd
156 * @param rd the records in the reply
157 */
158static void
159print_did_document (
160 enum GNUNET_GenericReturnValue status,
161 char *did_document,
162 void *cls
163 )
164{
165 if (GNUNET_OK == status)
166 printf ("%s\n", did_document);
167 else
168 printf ("An error occured: %s\n", did_document);
169
170 GNUNET_SCHEDULER_add_now (cleanup, NULL);
171 ret = 0;
172 return;
173}
174
175/**
176 * @brief Resolve a DID given by the user.
177 */
178static void
179resolve_did ()
180{
181
182 if (did == NULL)
183 {
184 printf ("Set DID option to resolve DID\n");
185 GNUNET_SCHEDULER_add_now (cleanup, NULL);
186 ret = 1;
187 return;
188 }
189
190 if (GNUNET_OK != DID_resolve (did, gns_handle, print_did_document, NULL))
191 {
192 printf ("An error occured while resoling the DID\n");
193 GNUNET_SCHEDULER_add_now (cleanup, NULL);
194 ret = 0;
195 return;
196 }
197}
198
199
200/**
201 * @brief Signature of a callback function that is called after a did has been removed
202 */
203typedef void
204(*remove_did_document_callback) (void *cls);
205
206/**
207 * @brief A Structure containing a cont and cls. Can be passed as a cls to a callback function
208 *
209 */
210struct Event
211{
212 remove_did_document_callback cont;
213 void *cls;
214};
215
216/**
217 * @brief Implements the GNUNET_NAMESTORE_ContinuationWithStatus
218 * Calls the callback function and cls in the event struct
219 *
220 * @param cls closure containing the event struct
221 * @param success
222 * @param emgs
223 */
224static void
225remove_did_document_namestore_cb (void *cls, enum GNUNET_ErrorCode ec)
226{
227 struct Event *event;
228
229 if (GNUNET_EC_NONE == ec)
230 {
231 event = (struct Event *) cls;
232
233 if (event->cont != NULL)
234 {
235 event->cont (event->cls);
236 free (event);
237 }
238 else {
239 free (event);
240 GNUNET_SCHEDULER_add_now (cleanup, NULL);
241 ret = 0;
242 return;
243 }
244 }
245 else {
246 printf ("Something went wrong when deleting the DID Document\n");
247
248 printf ("%s\n", GNUNET_ErrorCode_get_hint (ec));
249
250 GNUNET_SCHEDULER_add_now (cleanup, NULL);
251 ret = 0;
252 return;
253 }
254}
255
256/**
257 * @brief Callback called after the ego has been locked up
258 *
259 * @param cls closure
260 * @param ego the ego returned by the identity service
261 */
262static void
263remove_did_document_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
264{
265 const struct GNUNET_CRYPTO_PrivateKey *skey =
266 GNUNET_IDENTITY_ego_get_private_key (ego);
267
268 GNUNET_NAMESTORE_records_store (namestore_handle,
269 skey,
270 GNUNET_GNS_EMPTY_LABEL_AT,
271 0,
272 NULL,
273 &remove_did_document_namestore_cb,
274 cls);
275}
276
277/**
278 * @brief Remove a DID Document
279 */
280static void
281remove_did_document (remove_did_document_callback cont, void *cls)
282{
283 struct Event *event;
284
285 if (egoname == NULL)
286 {
287 printf ("Remove requieres an ego option\n");
288 GNUNET_SCHEDULER_add_now (cleanup, NULL);
289 ret = 1;
290 return;
291 }
292 else {
293 event = malloc (sizeof(*event));
294 event->cont = cont;
295 event->cls = cls;
296
297 GNUNET_IDENTITY_ego_lookup (my_cfg,
298 egoname,
299 &remove_did_document_ego_lookup_cb,
300 (void *) event);
301 }
302}
303
304// Needed because create_did_ego_lookup_cb() and
305// create_did_ego_create_cb() can call each other
306static void create_did_ego_lockup_cb ();
307
308/**
309 * @brief Create a DID(-Document). Called after DID has been created
310 * Prints status and the DID.
311 *
312 */
313static void
314create_did_cb (enum GNUNET_GenericReturnValue status, void *cls)
315{
316 if (GNUNET_OK == status)
317 {
318 printf ("DID has been created.\n%s\n", (char *) cls);
319 free (cls);
320 ret = 0;
321 }
322 else
323 {
324 printf ("An error occured while creating the DID.\n");
325 ret = 1;
326 }
327
328 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
329 return;
330}
331
332/**
333 * @brief Create a DID(-Document) - Called after a new Identity has been created.
334 */
335static void
336create_did_ego_create_cb (void *cls,
337 const struct GNUNET_CRYPTO_PrivateKey *pk,
338 enum GNUNET_ErrorCode ec)
339{
340 if (GNUNET_EC_NONE != ec)
341 {
342 printf ("%s\n", GNUNET_ErrorCode_get_hint (ec));
343 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
344 ret = 1;
345 return;
346 }
347
348 GNUNET_IDENTITY_ego_lookup (my_cfg,
349 egoname,
350 &create_did_ego_lockup_cb,
351 NULL);
352}
353
354/**
355 * @brief Create a DID(-Document). Called after ego lookup
356 *
357 */
358static void
359create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
360{
361 if (ego == NULL)
362 {
363 // If Ego was not found. Create new one first
364 printf ("Ego was not found. Creating new one.\n");
365 GNUNET_IDENTITY_create (identity_handle,
366 egoname,
367 NULL,
368 GNUNET_PUBLIC_KEY_TYPE_EDDSA,
369 &create_did_ego_create_cb,
370 egoname);
371 }
372 else
373 {
374 char *did = DID_identity_to_did (ego);
375 void *cls = malloc (strlen (did) + 1);
376 struct GNUNET_TIME_Relative expire_relative;
377
378 if (expire == NULL)
379 {
380 GNUNET_STRINGS_fancy_time_to_relative (
381 DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_relative);
382 }
383 else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (expire,
384 &
385 expire_relative))
386 {
387 printf ("Failed to read given expiration time\n");
388 GNUNET_SCHEDULER_add_now (cleanup, NULL);
389 ret = 1;
390 return;
391 }
392
393 strcpy (cls, did);
394 // TODO: Add DID_document argument
395 if (GNUNET_OK != DID_create (ego,
396 NULL,
397 &expire_relative,
398 namestore_handle,
399 create_did_cb,
400 cls))
401 {
402 printf ("An error occured while creating the DID.\n");
403 ret = 1;
404 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
405 return;
406 }
407 }
408}
409
410/**
411 * @brief Create a DID(-Document).
412 *
413 */
414static void
415create_did ()
416{
417 // Ego name to be set
418 if (egoname == NULL)
419 {
420 printf ("Set the Ego argument to create a new DID(-Document)\n");
421 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
422 ret = 1;
423 return;
424 }
425
426 GNUNET_IDENTITY_ego_lookup (my_cfg,
427 egoname,
428 &create_did_ego_lockup_cb,
429 NULL);
430}
431
432
433/**
434 * @brief Replace a DID Docuemnt. Callback function after ego lockup
435 *
436 * @param cls
437 * @param ego
438 */
439static void
440replace_did_document_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
441{
442 // create_did_store (didd, ego);
443}
444
445/**
446 * @brief Replace a DID Document. Callback functiona after remove
447 *
448 * @param cls
449 */
450static void
451replace_did_document_remove_cb (void *cls)
452{
453 GNUNET_IDENTITY_ego_lookup (my_cfg,
454 egoname,
455 &replace_did_document_ego_lookup_cb,
456 NULL);
457}
458
459/**
460 * @brief Replace a DID Docuemnt
461 *
462 */
463static void
464replace_did_document ()
465{
466 if ((didd != NULL) && (expire != NULL))
467 {
468 remove_did_document (&replace_did_document_remove_cb, NULL);
469 }
470 else {
471 printf (
472 "Set the DID Document and expiration time argument to replace the DID Document\n");
473 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
474 ret = 1;
475 return;
476 }
477}
478
479static void
480post_ego_iteration (void *cls)
481{
482 // TODO: Check that only one argument is set
483
484 if (1 == replace)
485 {
486 replace_did_document ();
487 }
488 else if (1 == get)
489 {
490 resolve_did ();
491 }
492 else if (1 == remove_did)
493 {
494 remove_did_document (NULL, NULL);
495 }
496 else if (1 == create)
497 {
498 create_did ();
499 }
500 else {
501 // No Argument found
502 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
503 return;
504 }
505}
506
507static void
508process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego,
509 void **ctx, const char*name)
510{
511 char *did_str;
512
513 if (ego == NULL)
514 {
515 if (1 == ego_exists)
516 {
517 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
518 return;
519 }
520 GNUNET_SCHEDULER_add_now (&post_ego_iteration, NULL);
521 return;
522 }
523
524 if (1 == show_all)
525 {
526 did_str = DID_identity_to_did (ego);
527 printf ("%s:\n\t%s\n", name, did_str);
528 GNUNET_free (did_str);
529 return;
530 }
531 if (1 == show)
532 {
533 if (0 == strncmp (name, egoname, strlen (egoname)))
534 {
535 did_str = DID_identity_to_did (ego);
536 printf ("%s:\n\t%s\n", name, did_str);
537 GNUNET_free (did_str);
538 return;
539 }
540 }
541}
542
543
544
545static void
546run (void *cls,
547 char *const *args,
548 const char *cfgfile,
549 const struct GNUNET_CONFIGURATION_Handle *c)
550{
551 gns_handle = GNUNET_GNS_connect (c);
552 namestore_handle = GNUNET_NAMESTORE_connect (c);
553 my_cfg = c;
554
555 // check if GNS_handle could connect
556 if (gns_handle == NULL)
557 {
558 ret = 1;
559 return;
560 }
561
562 // check if NAMESTORE_handle could connect
563 if (namestore_handle == NULL)
564 {
565 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
566 ret = 1;
567 return;
568 }
569
570 identity_handle = GNUNET_IDENTITY_connect (c, &process_dids, NULL);
571 if (identity_handle == NULL)
572 {
573 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
574 ret = 1;
575 return;
576 }
577}
578
579int
580main (int argc, char *const argv[])
581{
582 struct GNUNET_GETOPT_CommandLineOption options[] = {
583 GNUNET_GETOPT_option_flag ('C',
584 "create",
585 gettext_noop (
586 "Create a DID Document and display its DID"),
587 &create),
588 GNUNET_GETOPT_option_flag ('g',
589 "get",
590 gettext_noop (
591 "Get the DID Document associated with the given DID"),
592 &get),
593 GNUNET_GETOPT_option_flag ('r',
594 "remove",
595 gettext_noop (
596 "Remove the DID"),
597 &remove_did),
598 GNUNET_GETOPT_option_flag ('R',
599 "replace",
600 gettext_noop ("Replace the DID Document."),
601 &replace),
602 GNUNET_GETOPT_option_flag ('s',
603 "show",
604 gettext_noop ("Show the DID for a given ego"),
605 &show),
606 GNUNET_GETOPT_option_flag ('A',
607 "show-all",
608 gettext_noop ("Show egos with DIDs"),
609 &show_all),
610 GNUNET_GETOPT_option_string ('d',
611 "did",
612 "DID",
613 gettext_noop (
614 "The Decentralized Identity (DID)"),
615 &did),
616 GNUNET_GETOPT_option_string ('D',
617 "did-document",
618 "JSON",
619 gettext_noop (
620 "The DID Document to store in GNUNET"),
621 &didd),
622 GNUNET_GETOPT_option_string ('e',
623 "ego",
624 "EGO",
625 gettext_noop ("The name of the EGO"),
626 &egoname),
627 GNUNET_GETOPT_option_string ('t',
628 "expiration-time",
629 "TIME",
630 gettext_noop (
631 "The time until the DID Document is going to expire (e.g. 5d)"),
632 &expire),
633 GNUNET_GETOPT_OPTION_END
634 };
635
636 if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
637 argv,
638 "gnunet-did",
639 "Manage Decentralized Identities (DIDs)",
640 options,
641 &run,
642 NULL))
643 return 1;
644 else
645 return ret;
646}
diff --git a/src/cli/reclaim/gnunet-reclaim.c b/src/cli/reclaim/gnunet-reclaim.c
new file mode 100644
index 000000000..efb2c2902
--- /dev/null
+++ b/src/cli/reclaim/gnunet-reclaim.c
@@ -0,0 +1,928 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Martin Schanzenbach
22 * @file src/reclaim/gnunet-reclaim.c
23 * @brief Identity Provider utility
24 *
25 */
26#include "platform.h"
27#include <inttypes.h>
28
29#include "gnunet_util_lib.h"
30
31#include "gnunet_identity_service.h"
32#include "gnunet_namestore_service.h"
33#include "gnunet_reclaim_service.h"
34#include "gnunet_signatures.h"
35/**
36 * return value
37 */
38static int ret;
39
40/**
41 * List attribute flag
42 */
43static int list;
44
45/**
46 * List credentials flag
47 */
48static int list_credentials;
49
50/**
51 * Credential ID string
52 */
53static char *credential_id;
54
55/**
56 * Credential ID
57 */
58static struct GNUNET_RECLAIM_Identifier credential;
59
60/**
61 * Credential name
62 */
63static char *credential_name;
64
65/**
66 * Credential type
67 */
68static char *credential_type;
69
70/**
71 * Credential exists
72 */
73static int credential_exists;
74
75/**
76 * Relying party
77 */
78static char *rp;
79
80/**
81 * The attribute
82 */
83static char *attr_name;
84
85/**
86 * Attribute value
87 */
88static char *attr_value;
89
90/**
91 * Attributes to issue
92 */
93static char *issue_attrs;
94
95/**
96 * Ticket to consume
97 */
98static char *consume_ticket;
99
100/**
101 * Attribute type
102 */
103static char *type_str;
104
105/**
106 * Ticket to revoke
107 */
108static char *revoke_ticket;
109
110/**
111 * Ticket listing
112 */
113static int list_tickets;
114
115/**
116 * Ego name
117 */
118static char *ego_name;
119
120/**
121 * Identity handle
122 */
123static struct GNUNET_IDENTITY_Handle *identity_handle;
124
125/**
126 * reclaim handle
127 */
128static struct GNUNET_RECLAIM_Handle *reclaim_handle;
129
130/**
131 * reclaim operation
132 */
133static struct GNUNET_RECLAIM_Operation *reclaim_op;
134
135/**
136 * Attribute iterator
137 */
138static struct GNUNET_RECLAIM_AttributeIterator *attr_iterator;
139
140/**
141 * Credential iterator
142 */
143static struct GNUNET_RECLAIM_CredentialIterator *cred_iterator;
144
145
146/**
147 * Ticket iterator
148 */
149static struct GNUNET_RECLAIM_TicketIterator *ticket_iterator;
150
151
152/**
153 * ego private key
154 */
155static const struct GNUNET_CRYPTO_PrivateKey *pkey;
156
157/**
158 * rp public key
159 */
160static struct GNUNET_CRYPTO_PublicKey rp_key;
161
162/**
163 * Ticket to consume
164 */
165static struct GNUNET_RECLAIM_Ticket ticket;
166
167/**
168 * Attribute list
169 */
170static struct GNUNET_RECLAIM_AttributeList *attr_list;
171
172/**
173 * Attribute expiration interval
174 */
175static struct GNUNET_TIME_Relative exp_interval;
176
177/**
178 * Timeout task
179 */
180static struct GNUNET_SCHEDULER_Task *timeout;
181
182/**
183 * Cleanup task
184 */
185static struct GNUNET_SCHEDULER_Task *cleanup_task;
186
187/**
188 * Claim to store
189 */
190struct GNUNET_RECLAIM_Attribute *claim;
191
192/**
193 * Claim to delete
194 */
195static char *attr_delete;
196
197/**
198 * Claim object to delete
199 */
200static struct GNUNET_RECLAIM_Attribute *attr_to_delete;
201
202static void
203do_cleanup (void *cls)
204{
205 cleanup_task = NULL;
206 if (NULL != timeout)
207 GNUNET_SCHEDULER_cancel (timeout);
208 if (NULL != reclaim_op)
209 GNUNET_RECLAIM_cancel (reclaim_op);
210 if (NULL != attr_iterator)
211 GNUNET_RECLAIM_get_attributes_stop (attr_iterator);
212 if (NULL != cred_iterator)
213 GNUNET_RECLAIM_get_credentials_stop (cred_iterator);
214 if (NULL != ticket_iterator)
215 GNUNET_RECLAIM_ticket_iteration_stop (ticket_iterator);
216 if (NULL != reclaim_handle)
217 GNUNET_RECLAIM_disconnect (reclaim_handle);
218 if (NULL != identity_handle)
219 GNUNET_IDENTITY_disconnect (identity_handle);
220 if (NULL != attr_list)
221 {
222 GNUNET_RECLAIM_attribute_list_destroy (attr_list);
223 attr_list = NULL;
224 }
225 if (NULL != attr_to_delete)
226 GNUNET_free (attr_to_delete);
227 if (NULL == credential_type)
228 GNUNET_free (credential_type);
229}
230
231
232static void
233ticket_issue_cb (void *cls,
234 const struct GNUNET_RECLAIM_Ticket *ticket,
235 const struct GNUNET_RECLAIM_PresentationList *presentations)
236{
237 char *ticket_str;
238
239 reclaim_op = NULL;
240 if (NULL != ticket)
241 {
242 ticket_str =
243 GNUNET_STRINGS_data_to_string_alloc (ticket,
244 sizeof(
245 struct GNUNET_RECLAIM_Ticket));
246 printf ("%s\n", ticket_str);
247 GNUNET_free (ticket_str);
248 }
249 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
250}
251
252
253static void
254store_cont (void *cls, int32_t success, const char *emsg)
255{
256 reclaim_op = NULL;
257 if (GNUNET_SYSERR == success)
258 {
259 fprintf (stderr, "%s\n", emsg);
260 }
261 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
262}
263
264
265static void
266process_attrs (void *cls,
267 const struct GNUNET_CRYPTO_PublicKey *identity,
268 const struct GNUNET_RECLAIM_Attribute *attr,
269 const struct GNUNET_RECLAIM_Presentation *presentation)
270{
271 char *value_str;
272 char *id;
273 const char *attr_type;
274
275 if (NULL == identity)
276 {
277 reclaim_op = NULL;
278 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
279 return;
280 }
281 if (NULL == attr)
282 {
283 ret = 1;
284 return;
285 }
286 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type);
287 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
288 value_str = NULL;
289 if (NULL == presentation)
290 {
291 value_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type,
292 attr->data,
293 attr->data_size);
294 }
295 else
296 {
297 struct GNUNET_RECLAIM_AttributeListEntry *ale;
298 struct GNUNET_RECLAIM_AttributeList *al
299 = GNUNET_RECLAIM_presentation_get_attributes (presentation);
300
301 for (ale = al->list_head; NULL != ale; ale = ale->next)
302 {
303 if (0 != strncmp (attr->data, ale->attribute->name, attr->data_size))
304 continue;
305 value_str
306 = GNUNET_RECLAIM_attribute_value_to_string (ale->attribute->type,
307 ale->attribute->data,
308 ale->attribute->data_size);
309 break;
310 }
311 }
312 fprintf (stdout,
313 "Name: %s; Value: %s (%s); Flag %u; ID: %s %s\n",
314 attr->name,
315 (NULL != value_str) ? value_str : "???",
316 attr_type,
317 attr->flag,
318 id,
319 (NULL == presentation) ? "" : "(ATTESTED)");
320 GNUNET_free (value_str);
321 GNUNET_free (id);
322}
323
324
325static void
326ticket_iter_err (void *cls)
327{
328 ticket_iterator = NULL;
329 fprintf (stderr, "Failed to iterate over tickets\n");
330 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
331}
332
333
334static void
335ticket_iter_fin (void *cls)
336{
337 ticket_iterator = NULL;
338 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
339}
340
341
342static void
343ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
344{
345 char *aud;
346 char *ref;
347 char *tkt;
348
349 aud =
350 GNUNET_STRINGS_data_to_string_alloc (&ticket->audience,
351 sizeof(struct
352 GNUNET_CRYPTO_PublicKey));
353 ref = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof(ticket->rnd));
354 tkt =
355 GNUNET_STRINGS_data_to_string_alloc (ticket,
356 sizeof(struct GNUNET_RECLAIM_Ticket));
357 fprintf (stdout, "Ticket: %s | ID: %s | Audience: %s\n", tkt, ref, aud);
358 GNUNET_free (aud);
359 GNUNET_free (ref);
360 GNUNET_free (tkt);
361 GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator);
362}
363
364
365static void
366iter_error (void *cls)
367{
368 attr_iterator = NULL;
369 cred_iterator = NULL;
370 fprintf (stderr, "Failed\n");
371
372 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
373}
374
375
376static void
377timeout_task (void *cls)
378{
379 timeout = NULL;
380 ret = 1;
381 fprintf (stderr, "Timeout\n");
382 if (NULL == cleanup_task)
383 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
384}
385
386
387static void
388process_rvk (void *cls, int success, const char *msg)
389{
390 reclaim_op = NULL;
391 if (GNUNET_OK != success)
392 {
393 fprintf (stderr, "Revocation failed.\n");
394 ret = 1;
395 }
396 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
397}
398
399
400static void
401process_delete (void *cls, int success, const char *msg)
402{
403 reclaim_op = NULL;
404 if (GNUNET_OK != success)
405 {
406 fprintf (stderr, "Deletion failed.\n");
407 ret = 1;
408 }
409 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
410}
411
412
413static void
414iter_finished (void *cls)
415{
416 char *data;
417 size_t data_size;
418 int type;
419
420 attr_iterator = NULL;
421 if (list)
422 {
423 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
424 return;
425 }
426
427 if (issue_attrs)
428 {
429 reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle,
430 pkey,
431 &rp_key,
432 attr_list,
433 &ticket_issue_cb,
434 NULL);
435 return;
436 }
437 if (consume_ticket)
438 {
439 reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle,
440 pkey,
441 &ticket,
442 &process_attrs,
443 NULL);
444 timeout = GNUNET_SCHEDULER_add_delayed (
445 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
446 &timeout_task,
447 NULL);
448 return;
449 }
450 if (revoke_ticket)
451 {
452 reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle,
453 pkey,
454 &ticket,
455 &process_rvk,
456 NULL);
457 return;
458 }
459 if (attr_delete)
460 {
461 if (NULL == attr_to_delete)
462 {
463 fprintf (stdout, "No such attribute ``%s''\n", attr_delete);
464 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
465 return;
466 }
467 reclaim_op = GNUNET_RECLAIM_attribute_delete (reclaim_handle,
468 pkey,
469 attr_to_delete,
470 &process_delete,
471 NULL);
472 return;
473 }
474 if (attr_name)
475 {
476 if (NULL == type_str)
477 type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
478 else
479 type = GNUNET_RECLAIM_attribute_typename_to_number (type_str);
480
481 GNUNET_assert (GNUNET_SYSERR !=
482 GNUNET_RECLAIM_attribute_string_to_value (type,
483 attr_value,
484 (void **) &data,
485 &data_size));
486 if (NULL != claim)
487 {
488 claim->type = type;
489 claim->data = data;
490 claim->data_size = data_size;
491 }
492 else
493 {
494 claim =
495 GNUNET_RECLAIM_attribute_new (attr_name, NULL, type, data, data_size);
496 }
497 if (NULL != credential_id)
498 {
499 claim->credential = credential;
500 }
501 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
502 pkey,
503 claim,
504 &exp_interval,
505 &store_cont,
506 NULL);
507 GNUNET_free (data);
508 GNUNET_free (claim);
509 return;
510 }
511 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
512}
513
514
515static void
516iter_cb (void *cls,
517 const struct GNUNET_CRYPTO_PublicKey *identity,
518 const struct GNUNET_RECLAIM_Attribute *attr)
519{
520 struct GNUNET_RECLAIM_AttributeListEntry *le;
521 char *attrs_tmp;
522 char *attr_str;
523 char *label;
524 char *id;
525 const char *attr_type;
526
527 if ((NULL != attr_name) && (NULL == claim))
528 {
529 if (0 == strcasecmp (attr_name, attr->name))
530 {
531 claim = GNUNET_RECLAIM_attribute_new (attr->name,
532 &attr->credential,
533 attr->type,
534 attr->data,
535 attr->data_size);
536 claim->id = attr->id;
537 }
538 }
539 else if (issue_attrs)
540 {
541 attrs_tmp = GNUNET_strdup (issue_attrs);
542 attr_str = strtok (attrs_tmp, ",");
543 while (NULL != attr_str)
544 {
545 if (0 != strcasecmp (attr_str, attr->name))
546 {
547 attr_str = strtok (NULL, ",");
548 continue;
549 }
550 le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
551 le->attribute = GNUNET_RECLAIM_attribute_new (attr->name,
552 &attr->credential,
553 attr->type,
554 attr->data,
555 attr->data_size);
556 le->attribute->flag = attr->flag;
557 le->attribute->id = attr->id;
558 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
559 attr_list->list_tail,
560 le);
561 break;
562 }
563 GNUNET_free (attrs_tmp);
564 }
565 else if (attr_delete && (NULL == attr_to_delete))
566 {
567 label = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
568 if (0 == strcasecmp (attr_delete, label))
569 {
570 attr_to_delete = GNUNET_RECLAIM_attribute_new (attr->name,
571 &attr->credential,
572 attr->type,
573 attr->data,
574 attr->data_size);
575 attr_to_delete->id = attr->id;
576 }
577 GNUNET_free (label);
578 }
579 else if (list)
580 {
581 attr_str = GNUNET_RECLAIM_attribute_value_to_string (attr->type,
582 attr->data,
583 attr->data_size);
584 attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type);
585 id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
586 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->credential))
587 {
588 fprintf (stdout,
589 "%s: ``%s'' (%s); ID: %s\n",
590 attr->name,
591 attr_str,
592 attr_type,
593 id);
594 }
595 else
596 {
597 char *cred_id =
598 GNUNET_STRINGS_data_to_string_alloc (&attr->credential,
599 sizeof(attr->credential));
600 fprintf (stdout,
601 "%s: ``%s'' in credential presentation `%s' (%s); ID: %s\n",
602 attr->name,
603 attr_str,
604 cred_id,
605 attr_type,
606 id);
607 GNUNET_free (cred_id);
608
609 }
610 GNUNET_free (id);
611 }
612 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
613}
614
615
616static void
617cred_iter_finished (void *cls)
618{
619 cred_iterator = NULL;
620
621 // Add new credential
622 if ((NULL != credential_name) &&
623 (NULL != attr_value))
624 {
625 enum GNUNET_RECLAIM_CredentialType ctype =
626 GNUNET_RECLAIM_credential_typename_to_number (credential_type);
627 struct GNUNET_RECLAIM_Credential *credential =
628 GNUNET_RECLAIM_credential_new (credential_name,
629 ctype,
630 attr_value,
631 strlen (attr_value));
632 reclaim_op = GNUNET_RECLAIM_credential_store (reclaim_handle,
633 pkey,
634 credential,
635 &exp_interval,
636 store_cont,
637 NULL);
638 return;
639
640 }
641 if (list_credentials)
642 {
643 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
644 return;
645 }
646 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
647 pkey,
648 &iter_error,
649 NULL,
650 &iter_cb,
651 NULL,
652 &iter_finished,
653 NULL);
654
655}
656
657
658static void
659cred_iter_cb (void *cls,
660 const struct GNUNET_CRYPTO_PublicKey *identity,
661 const struct GNUNET_RECLAIM_Credential *cred)
662{
663 char *cred_str;
664 char *attr_str;
665 char *id;
666 const char *cred_type;
667 struct GNUNET_RECLAIM_AttributeListEntry *ale;
668
669 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (&credential,
670 &cred->id))
671 credential_exists = GNUNET_YES;
672 if (list_credentials)
673 {
674 cred_str = GNUNET_RECLAIM_credential_value_to_string (cred->type,
675 cred->data,
676 cred->data_size);
677 cred_type = GNUNET_RECLAIM_credential_number_to_typename (cred->type);
678 id = GNUNET_STRINGS_data_to_string_alloc (&cred->id, sizeof(cred->id));
679 fprintf (stdout,
680 "%s: ``%s'' (%s); ID: %s\n",
681 cred->name,
682 cred_str,
683 cred_type,
684 id);
685 struct GNUNET_RECLAIM_AttributeList *attrs =
686 GNUNET_RECLAIM_credential_get_attributes (cred);
687 if (NULL != attrs)
688 {
689 fprintf (stdout,
690 "\t Attributes:\n");
691 for (ale = attrs->list_head; NULL != ale; ale = ale->next)
692 {
693 attr_str = GNUNET_RECLAIM_attribute_value_to_string (
694 ale->attribute->type,
695 ale->attribute->data,
696 ale->attribute->data_size);
697 fprintf (stdout,
698 "\t %s: %s\n", ale->attribute->name, attr_str);
699 GNUNET_free (attr_str);
700 }
701 GNUNET_RECLAIM_attribute_list_destroy (attrs);
702 }
703 GNUNET_free (id);
704 }
705 GNUNET_RECLAIM_get_credentials_next (cred_iterator);
706}
707
708
709static void
710start_process ()
711{
712 if (NULL == pkey)
713 {
714 fprintf (stderr, "Ego %s not found\n", ego_name);
715 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
716 return;
717 }
718 if (NULL == credential_type)
719 credential_type = GNUNET_strdup ("JWT");
720 credential = GNUNET_RECLAIM_ID_ZERO;
721 if (NULL != credential_id)
722 GNUNET_STRINGS_string_to_data (credential_id,
723 strlen (credential_id),
724 &credential, sizeof(credential));
725 credential_exists = GNUNET_NO;
726 if (list_tickets)
727 {
728 ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle,
729 pkey,
730 &ticket_iter_err,
731 NULL,
732 &ticket_iter,
733 NULL,
734 &ticket_iter_fin,
735 NULL);
736 return;
737 }
738
739 if ((NULL != rp) &&
740 (GNUNET_OK !=
741 GNUNET_CRYPTO_public_key_from_string (rp, &rp_key)) )
742 {
743 fprintf (stderr, "%s is not a public key!\n", rp);
744 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
745 return;
746 }
747 if (NULL != consume_ticket)
748 GNUNET_STRINGS_string_to_data (consume_ticket,
749 strlen (consume_ticket),
750 &ticket,
751 sizeof(struct GNUNET_RECLAIM_Ticket));
752 if (NULL != revoke_ticket)
753 GNUNET_STRINGS_string_to_data (revoke_ticket,
754 strlen (revoke_ticket),
755 &ticket,
756 sizeof(struct GNUNET_RECLAIM_Ticket));
757
758 attr_list = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
759 claim = NULL;
760 cred_iterator = GNUNET_RECLAIM_get_credentials_start (reclaim_handle,
761 pkey,
762 &iter_error,
763 NULL,
764 &cred_iter_cb,
765 NULL,
766 &cred_iter_finished,
767 NULL);
768
769}
770
771
772static int init = GNUNET_YES;
773
774static void
775ego_cb (void *cls,
776 struct GNUNET_IDENTITY_Ego *ego,
777 void **ctx,
778 const char *name)
779{
780 if (NULL == name)
781 {
782 if (GNUNET_YES == init)
783 {
784 init = GNUNET_NO;
785 start_process ();
786 }
787 return;
788 }
789 if (0 != strcmp (name, ego_name))
790 return;
791 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
792}
793
794
795static void
796run (void *cls,
797 char *const *args,
798 const char *cfgfile,
799 const struct GNUNET_CONFIGURATION_Handle *c)
800{
801 ret = 0;
802 if (NULL == ego_name)
803 {
804 ret = 1;
805 fprintf (stderr, _ ("Ego is required\n"));
806 return;
807 }
808
809 if ((NULL == attr_value) && (NULL != attr_name))
810 {
811 ret = 1;
812 fprintf (stderr, _ ("Attribute value missing!\n"));
813 return;
814 }
815
816 if ((NULL == rp) && (NULL != issue_attrs))
817 {
818 ret = 1;
819 fprintf (stderr, _ ("Requesting party key is required!\n"));
820 return;
821 }
822
823 reclaim_handle = GNUNET_RECLAIM_connect (c);
824 // Get Ego
825 identity_handle = GNUNET_IDENTITY_connect (c, &ego_cb, NULL);
826}
827
828
829int
830main (int argc, char *const argv[])
831{
832 exp_interval = GNUNET_TIME_UNIT_HOURS;
833 struct GNUNET_GETOPT_CommandLineOption options[] = {
834 GNUNET_GETOPT_option_string ('a',
835 "add",
836 "NAME",
837 gettext_noop ("Add or update an attribute NAME"),
838 &attr_name),
839 GNUNET_GETOPT_option_string ('d',
840 "delete",
841 "ID",
842 gettext_noop ("Delete the attribute with ID"),
843 &attr_delete),
844 GNUNET_GETOPT_option_string ('V',
845 "value",
846 "VALUE",
847 gettext_noop ("The attribute VALUE"),
848 &attr_value),
849 GNUNET_GETOPT_option_string ('e',
850 "ego",
851 "EGO",
852 gettext_noop ("The EGO to use"),
853 &ego_name),
854 GNUNET_GETOPT_option_string ('r',
855 "rp",
856 "RP",
857 gettext_noop (
858 "Specify the relying party for issue"),
859 &rp),
860 GNUNET_GETOPT_option_flag ('D',
861 "dump",
862 gettext_noop ("List attributes for EGO"),
863 &list),
864 GNUNET_GETOPT_option_flag ('A',
865 "credentials",
866 gettext_noop ("List credentials for EGO"),
867 &list_credentials),
868 GNUNET_GETOPT_option_string ('I',
869 "credential-id",
870 "CREDENTIAL_ID",
871 gettext_noop (
872 "Credential to use for attribute"),
873 &credential_id),
874 GNUNET_GETOPT_option_string ('N',
875 "credential-name",
876 "NAME",
877 gettext_noop ("Credential name"),
878 &credential_name),
879 GNUNET_GETOPT_option_string ('i',
880 "issue",
881 "A1,A2,...",
882 gettext_noop (
883 "Issue a ticket for a set of attributes separated by comma"),
884 &issue_attrs),
885 GNUNET_GETOPT_option_string ('C',
886 "consume",
887 "TICKET",
888 gettext_noop ("Consume a ticket"),
889 &consume_ticket),
890 GNUNET_GETOPT_option_string ('R',
891 "revoke",
892 "TICKET",
893 gettext_noop ("Revoke a ticket"),
894 &revoke_ticket),
895 GNUNET_GETOPT_option_string ('t',
896 "type",
897 "TYPE",
898 gettext_noop ("Type of attribute"),
899 &type_str),
900 GNUNET_GETOPT_option_string ('u',
901 "credential-type",
902 "TYPE",
903 gettext_noop ("Type of credential"),
904 &credential_type),
905 GNUNET_GETOPT_option_flag ('T',
906 "tickets",
907 gettext_noop ("List tickets of ego"),
908 &list_tickets),
909 GNUNET_GETOPT_option_relative_time ('E',
910 "expiration",
911 "INTERVAL",
912 gettext_noop (
913 "Expiration interval of the attribute"),
914 &exp_interval),
915
916 GNUNET_GETOPT_OPTION_END
917 };
918 if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
919 argv,
920 "gnunet-reclaim",
921 _ ("re:claimID command line tool"),
922 options,
923 &run,
924 NULL))
925 return 1;
926 else
927 return ret;
928}
diff --git a/src/cli/reclaim/test_reclaim.sh b/src/cli/reclaim/test_reclaim.sh
new file mode 100755
index 000000000..da93b10f7
--- /dev/null
+++ b/src/cli/reclaim/test_reclaim.sh
@@ -0,0 +1,31 @@
1#!/bin/sh
2#trap "gnunet-arm -e -c test_reclaim_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf
27gnunet-identity -C testego -c test_reclaim.conf
28valgrind gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
29gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf
30gnunet-reclaim -e testego -D -c test_reclaim.conf
31gnunet-arm -e -c test_reclaim.conf
diff --git a/src/cli/reclaim/test_reclaim_attribute.sh b/src/cli/reclaim/test_reclaim_attribute.sh
new file mode 100755
index 000000000..17f7863d4
--- /dev/null
+++ b/src/cli/reclaim/test_reclaim_attribute.sh
@@ -0,0 +1,40 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_reclaim.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf
27#gnunet-arm -i rest -c test_reclaim.conf
28gnunet-identity -C testego -c test_reclaim.conf
29gnunet-identity -C rpego -c test_reclaim.conf
30TEST_KEY=$(gnunet-identity -d -e testego -q -c test_reclaim.conf)
31gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
32gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf
33if test $? != 0
34then
35 echo "Failed."
36 exit 1
37fi
38
39#curl localhost:7776/reclaim/attributes/testego
40gnunet-arm -e -c test_reclaim.conf
diff --git a/src/cli/reclaim/test_reclaim_consume.sh b/src/cli/reclaim/test_reclaim_consume.sh
new file mode 100755
index 000000000..8a88136c6
--- /dev/null
+++ b/src/cli/reclaim/test_reclaim_consume.sh
@@ -0,0 +1,49 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_reclaim.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1>/dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout >/dev/null 2>&1 && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf
27#gnunet-arm -i rest -c test_reclaim.conf
28gnunet-arm -I
29gnunet-identity -C testego -c test_reclaim.conf
30gnunet-identity -C rpego -c test_reclaim.conf
31SUBJECT_KEY=$(gnunet-identity -d -e rpego -q -c test_reclaim.conf)
32TEST_KEY=$(gnunet-identity -d -e testego -q -c test_reclaim.conf)
33gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
34gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf
35TICKET=$(gnunet-reclaim -e testego -i "email,name" -r $SUBJECT_KEY -c test_reclaim.conf | awk '{print $1}')
36gnunet-namestore -z testego -D -c test_reclaim.conf
37gnunet-identity -d -c test_reclaim.conf
38sleep 1
39gnunet-reclaim -e rpego -C $TICKET -c test_reclaim.conf
40
41RES=$?
42gnunet-identity -D testego -c test_reclaim.conf
43gnunet-identity -D rpego -c test_reclaim.conf
44gnunet-arm -e -c test_reclaim.conf
45if test $RES != 0
46then
47 echo "Failed."
48fi
49
diff --git a/src/cli/reclaim/test_reclaim_issue.sh b/src/cli/reclaim/test_reclaim_issue.sh
new file mode 100755
index 000000000..63140e54c
--- /dev/null
+++ b/src/cli/reclaim/test_reclaim_issue.sh
@@ -0,0 +1,42 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_reclaim.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout >/dev/null 2>&1 && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf
27#gnunet-arm -i rest -c test_reclaim.conf
28gnunet-identity -C testego -c test_reclaim.conf
29gnunet-identity -C rpego -c test_reclaim.conf
30SUBJECT_KEY=$(gnunet-identity -d -e rpego -q -c test_reclaim.conf)
31TEST_KEY=$(gnunet-identity -d -e testego -q -c test_reclaim.conf)
32gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
33gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf
34#gnunet-reclaim -e testego -D -c test_reclaim.conf
35gnunet-reclaim -e testego -i "email,name" -r $SUBJECT_KEY -c test_reclaim.conf > /dev/null 2>&1
36if test $? != 0
37then
38 echo "Failed."
39 exit 1
40fi
41#curl http://localhost:7776/reclaim/attributes/testego
42gnunet-arm -e -c test_reclaim.conf
diff --git a/src/cli/reclaim/test_reclaim_revoke.sh b/src/cli/reclaim/test_reclaim_revoke.sh
new file mode 100755
index 000000000..da091a1ee
--- /dev/null
+++ b/src/cli/reclaim/test_reclaim_revoke.sh
@@ -0,0 +1,65 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_reclaim.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout >/dev/null 2&>1 && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf >/dev/null 2&>1
27gnunet-identity -C alice -c test_reclaim.conf
28gnunet-identity -C bob -c test_reclaim.conf
29gnunet-identity -C eve -c test_reclaim.conf
30ALICE_KEY=$(gnunet-identity -d -e alice -q -c test_reclaim.conf)
31BOB_KEY=$(gnunet-identity -d -e bob -q -c test_reclaim.conf)
32EVE_KEY=$(gnunet-identity -d -e eve -q -c test_reclaim.conf)
33gnunet-reclaim -e alice -E 15s -a email -V john@doe.gnu -c test_reclaim.conf
34gnunet-reclaim -e alice -E 15s -a name -V John -c test_reclaim.conf
35TICKET_BOB=$(gnunet-reclaim -e alice -i "email,name" -r $BOB_KEY -c test_reclaim.conf | awk '{print $1}')
36#gnunet-reclaim -e bob -C $TICKET_BOB -c test_reclaim.conf
37TICKET_EVE=$(gnunet-reclaim -e alice -i "email" -r $EVE_KEY -c test_reclaim.conf | awk '{print $1}')
38gnunet-namestore -z alice -D
39echo "Revoking $TICKET"
40gnunet-reclaim -e alice -R $TICKET_EVE -c test_reclaim.conf
41gnunet-namestore -z alice -D
42sleep 16
43echo "Consuming $TICKET"
44
45gnunet-reclaim -e eve -C $TICKET_EVE -c test_reclaim.conf
46if test $? = 0
47then
48 echo "Eve can still resolve attributes..."
49 gnunet-arm -e -c test_reclaim.conf
50 exit 1
51fi
52
53gnunet-arm -e -c test_reclaim.conf
54gnunet-arm -s -c test_reclaim.conf >/dev/null 2&>1
55
56gnunet-reclaim -e bob -C $TICKET_BOB -c test_reclaim.conf
57#gnunet-reclaim -e bob -C $TICKET_BOB -c test_reclaim.conf >/dev/null 2&>1
58if test $? != 0
59then
60 echo "Bob cannot resolve attributes..."
61 gnunet-arm -e -c test_reclaim.conf
62 exit 1
63fi
64
65gnunet-arm -e -c test_reclaim.conf