diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-01-14 16:25:30 +0100 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-01-14 16:25:30 +0100 |
commit | 7064aca619f59b7c19ff7e8c645d48995728a66c (patch) | |
tree | acabf3b65ced9734a6e7830e57fc52643768dc5a /src | |
parent | 821db736f668e6fd31255b2baad974e52bbbaee8 (diff) | |
download | gnunet-7064aca619f59b7c19ff7e8c645d48995728a66c.tar.gz gnunet-7064aca619f59b7c19ff7e8c645d48995728a66c.zip |
-code review
Diffstat (limited to 'src')
-rw-r--r-- | src/did/gnunet-did.c | 320 |
1 files changed, 187 insertions, 133 deletions
diff --git a/src/did/gnunet-did.c b/src/did/gnunet-did.c index 70dac4812..2ebef7601 100644 --- a/src/did/gnunet-did.c +++ b/src/did/gnunet-did.c | |||
@@ -18,11 +18,14 @@ | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | // TODO: Own GNS type | 21 | /** |
22 | // TODO: Save delete and move DIDD to root - look for other with same sub | 22 | * FIXME: Do we only want to handle EdDSA identities? |
23 | // TODO: uncrustify | 23 | * TODO: Own GNS record type |
24 | // TODO: Unit Tests | 24 | * TODO: Fix overwrite of records in @ if present look for other with same sub |
25 | 25 | * TODO. Tests | |
26 | * TODO: Move constants to did.h | ||
27 | * FIXME: Remove and lookup require differnt representations (did vs egoname) | ||
28 | */ | ||
26 | 29 | ||
27 | /** | 30 | /** |
28 | * @author Tristan Schwieren | 31 | * @author Tristan Schwieren |
@@ -71,6 +74,11 @@ static int create; | |||
71 | static int show; | 74 | static int show; |
72 | 75 | ||
73 | /** | 76 | /** |
77 | * Show DID for Ego Flag | ||
78 | */ | ||
79 | static int show_all; | ||
80 | |||
81 | /** | ||
74 | * DID Attribut String | 82 | * DID Attribut String |
75 | */ | 83 | */ |
76 | static char *did; | 84 | static char *did; |
@@ -83,43 +91,80 @@ static char *didd; | |||
83 | /** | 91 | /** |
84 | * Ego Attribut String | 92 | * Ego Attribut String |
85 | */ | 93 | */ |
86 | static char *ego; | 94 | static char *egoname; |
87 | 95 | ||
88 | /** | 96 | /** |
89 | * Ego name Attribut String | 97 | * DID Document expiration Date Attribut String |
90 | */ | ||
91 | static char *name; | ||
92 | |||
93 | /** | ||
94 | * DID Document expiration Date Attribut String | ||
95 | */ | 98 | */ |
96 | static char *expire; | 99 | static char *expire; |
97 | 100 | ||
101 | /* | ||
102 | * Handle to the GNS service | ||
103 | */ | ||
98 | static struct GNUNET_GNS_Handle *gns_handle; | 104 | static struct GNUNET_GNS_Handle *gns_handle; |
105 | |||
106 | /* | ||
107 | * Handle to the NAMESTORE service | ||
108 | */ | ||
99 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 109 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; |
110 | |||
111 | /* | ||
112 | * Handle to the IDENTITY service | ||
113 | */ | ||
100 | static struct GNUNET_IDENTITY_Handle *identity_handle; | 114 | static struct GNUNET_IDENTITY_Handle *identity_handle; |
115 | |||
116 | |||
117 | /* | ||
118 | * The configuration | ||
119 | */ | ||
101 | const static struct GNUNET_CONFIGURATION_Handle *my_cfg; | 120 | const static struct GNUNET_CONFIGURATION_Handle *my_cfg; |
102 | 121 | ||
103 | /** | 122 | /** |
123 | * Give ego exists | ||
124 | */ | ||
125 | static int ego_exists = 0; | ||
126 | |||
127 | /** | ||
104 | * @brief Disconnect and shutdown | 128 | * @brief Disconnect and shutdown |
105 | * @param cls closure | 129 | * @param cls closure |
106 | */ | 130 | */ |
107 | static void | 131 | static void |
108 | cleanup (void *cls) | 132 | cleanup (void *cls) |
109 | { | 133 | { |
110 | GNUNET_GNS_disconnect (gns_handle); | 134 | if (NULL != gns_handle) |
111 | GNUNET_NAMESTORE_disconnect (namestore_handle); | 135 | GNUNET_GNS_disconnect (gns_handle); |
112 | GNUNET_IDENTITY_disconnect (identity_handle); | 136 | if (NULL != namestore_handle) |
113 | 137 | GNUNET_NAMESTORE_disconnect (namestore_handle); | |
114 | free(did); | 138 | if (NULL != identity_handle) |
115 | free(didd); | 139 | GNUNET_IDENTITY_disconnect (identity_handle); |
116 | free(ego); | 140 | |
117 | free(name); | 141 | GNUNET_free (did); |
118 | free(expire); | 142 | GNUNET_free (didd); |
143 | GNUNET_free (egoname); | ||
144 | GNUNET_free (expire); | ||
119 | 145 | ||
120 | GNUNET_SCHEDULER_shutdown (); | 146 | GNUNET_SCHEDULER_shutdown (); |
121 | } | 147 | } |
122 | 148 | ||
149 | char* | ||
150 | ego_to_did (struct GNUNET_IDENTITY_Ego *ego) | ||
151 | { | ||
152 | struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key | ||
153 | char *pkey_str; | ||
154 | char *did_str; | ||
155 | size_t pkey_len; | ||
156 | |||
157 | GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); | ||
158 | |||
159 | pkey_str = GNUNET_IDENTITY_public_key_to_string (&pkey); | ||
160 | GNUNET_asprintf (&did_str, "%s%s", | ||
161 | GNUNET_DID_METHOD_RECLAIM_PREFIX, | ||
162 | pkey_str); | ||
163 | |||
164 | free (pkey_str); | ||
165 | return did_str; | ||
166 | } | ||
167 | |||
123 | /** | 168 | /** |
124 | * @brief Callback for ego loockup of get_did_for_ego() | 169 | * @brief Callback for ego loockup of get_did_for_ego() |
125 | * | 170 | * |
@@ -129,10 +174,7 @@ cleanup (void *cls) | |||
129 | static void | 174 | static void |
130 | get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | 175 | get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) |
131 | { | 176 | { |
132 | struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key | 177 | char *did_str; |
133 | char * pkey_str; | ||
134 | char * did_str; | ||
135 | size_t pkey_len; | ||
136 | 178 | ||
137 | if (ego == NULL) | 179 | if (ego == NULL) |
138 | { | 180 | { |
@@ -141,18 +183,10 @@ get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
141 | ret = 1; | 183 | ret = 1; |
142 | return; | 184 | return; |
143 | } | 185 | } |
144 | 186 | did_str = ego_to_did (ego); | |
145 | GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); | ||
146 | |||
147 | pkey_str = GNUNET_IDENTITY_public_key_to_string (&pkey); // Convert public key to string | ||
148 | pkey_len = strlen(pkey_str); | ||
149 | did_str = malloc(pkey_len + strlen(GNUNET_DID_METHOD_RECLAIM_PREFIX) + 1); | ||
150 | sprintf (did_str, "GNUNET_DID_METHOD_RECLAIM_PREFIX%s", pkey_str); // Convert the public key to a DID str | ||
151 | 187 | ||
152 | printf ("%s\n", did_str); | 188 | printf ("%s\n", did_str); |
153 | 189 | ||
154 | free(pkey_str); | ||
155 | free(did_str); | ||
156 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 190 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
157 | ret = 0; | 191 | ret = 0; |
158 | return; | 192 | return; |
@@ -165,10 +199,10 @@ get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
165 | static void | 199 | static void |
166 | get_did_for_ego () | 200 | get_did_for_ego () |
167 | { | 201 | { |
168 | if (ego != NULL) | 202 | if (egoname != NULL) |
169 | { | 203 | { |
170 | GNUNET_IDENTITY_ego_lookup (my_cfg, | 204 | GNUNET_IDENTITY_ego_lookup (my_cfg, |
171 | ego, | 205 | egoname, |
172 | &get_did_for_ego_lookup_cb, | 206 | &get_did_for_ego_lookup_cb, |
173 | NULL); | 207 | NULL); |
174 | } | 208 | } |
@@ -195,10 +229,10 @@ get_pkey_from_attr_did (struct GNUNET_IDENTITY_PublicKey *pkey) | |||
195 | */ | 229 | */ |
196 | char pkey_str[59]; | 230 | char pkey_str[59]; |
197 | 231 | ||
198 | if ((1 != (sscanf (did, "GNUNET_DID_METHOD_RECLAIM_PREFIX%58s", pkey_str))) || | 232 | if ((1 != (sscanf (did, GNUNET_DID_METHOD_RECLAIM_PREFIX"%58s", pkey_str))) || |
199 | (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (pkey_str, pkey))) | 233 | (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (pkey_str, pkey))) |
200 | { | 234 | { |
201 | fprintf (stderr, _ ("Invalid DID `%s'\n"), pkey_str); | 235 | fprintf (stderr, _("Invalid DID `%s'\n"), pkey_str); |
202 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | 236 | GNUNET_SCHEDULER_add_now (cleanup, NULL); |
203 | ret = 1; | 237 | ret = 1; |
204 | return; | 238 | return; |
@@ -232,11 +266,12 @@ print_did_document ( | |||
232 | return; | 266 | return; |
233 | } | 267 | } |
234 | 268 | ||
235 | if(rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT) { | 269 | if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT) |
270 | { | ||
236 | printf ("%s\n", (char *) rd[0].data); | 271 | printf ("%s\n", (char *) rd[0].data); |
237 | } | 272 | } |
238 | else { | 273 | else { |
239 | printf("DID Document is not a TXT record\n"); | 274 | printf ("DID Document is not a TXT record\n"); |
240 | } | 275 | } |
241 | 276 | ||
242 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | 277 | GNUNET_SCHEDULER_add_now (cleanup, NULL); |
@@ -262,9 +297,7 @@ resolve_did_document () | |||
262 | 297 | ||
263 | get_pkey_from_attr_did (&pkey); | 298 | get_pkey_from_attr_did (&pkey); |
264 | 299 | ||
265 | // TODO: Check the type of returned records | 300 | GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey, GNUNET_DNSPARSER_TYPE_TXT, |
266 | /* FIXME-MSC: Use "@" */ | ||
267 | GNUNET_GNS_lookup (gns_handle, "didd", &pkey, GNUNET_DNSPARSER_TYPE_TXT, | ||
268 | GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL); | 301 | GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL); |
269 | } | 302 | } |
270 | 303 | ||
@@ -277,7 +310,7 @@ typedef void | |||
277 | 310 | ||
278 | /** | 311 | /** |
279 | * @brief A Structure containing a cont and cls. Can be passed as a cls to a callback function | 312 | * @brief A Structure containing a cont and cls. Can be passed as a cls to a callback function |
280 | * | 313 | * |
281 | */ | 314 | */ |
282 | struct Event | 315 | struct Event |
283 | { | 316 | { |
@@ -298,10 +331,8 @@ remove_did_document_namestore_cb (void *cls, int32_t success, const char *emgs) | |||
298 | { | 331 | { |
299 | struct Event *event; | 332 | struct Event *event; |
300 | 333 | ||
301 | if (success == GNUNET_YES) | 334 | if (success != GNUNET_SYSERR) |
302 | { | 335 | { |
303 | printf ("DID Document has been removed\n"); | ||
304 | |||
305 | event = (struct Event *) cls; | 336 | event = (struct Event *) cls; |
306 | 337 | ||
307 | if (event->cont != NULL) | 338 | if (event->cont != NULL) |
@@ -315,8 +346,7 @@ remove_did_document_namestore_cb (void *cls, int32_t success, const char *emgs) | |||
315 | ret = 0; | 346 | ret = 0; |
316 | return; | 347 | return; |
317 | } | 348 | } |
318 | } | 349 | } else { |
319 | else { | ||
320 | printf ("Something went wrong when deleting the DID Document\n"); | 350 | printf ("Something went wrong when deleting the DID Document\n"); |
321 | 351 | ||
322 | if (emgs != NULL) | 352 | if (emgs != NULL) |
@@ -344,7 +374,7 @@ remove_did_document_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
344 | 374 | ||
345 | GNUNET_NAMESTORE_records_store (namestore_handle, | 375 | GNUNET_NAMESTORE_records_store (namestore_handle, |
346 | skey, | 376 | skey, |
347 | "didd", | 377 | GNUNET_GNS_EMPTY_LABEL_AT, |
348 | 0, | 378 | 0, |
349 | NULL, | 379 | NULL, |
350 | &remove_did_document_namestore_cb, | 380 | &remove_did_document_namestore_cb, |
@@ -359,7 +389,7 @@ remove_did_document (remove_did_document_callback cont, void *cls) | |||
359 | { | 389 | { |
360 | struct Event *event; | 390 | struct Event *event; |
361 | 391 | ||
362 | if (ego == NULL) | 392 | if (egoname == NULL) |
363 | { | 393 | { |
364 | printf ("Remove requieres an ego option\n"); | 394 | printf ("Remove requieres an ego option\n"); |
365 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | 395 | GNUNET_SCHEDULER_add_now (cleanup, NULL); |
@@ -372,7 +402,7 @@ remove_did_document (remove_did_document_callback cont, void *cls) | |||
372 | event->cls = cls; | 402 | event->cls = cls; |
373 | 403 | ||
374 | GNUNET_IDENTITY_ego_lookup (my_cfg, | 404 | GNUNET_IDENTITY_ego_lookup (my_cfg, |
375 | ego, | 405 | egoname, |
376 | &remove_did_document_ego_lookup_cb, | 406 | &remove_did_document_ego_lookup_cb, |
377 | (void *) event); | 407 | (void *) event); |
378 | } | 408 | } |
@@ -520,7 +550,6 @@ create_did_generate (struct GNUNET_IDENTITY_PublicKey pkey) | |||
520 | static void | 550 | static void |
521 | create_did_store_cb (void *cls, int32_t success, const char *emsg) | 551 | create_did_store_cb (void *cls, int32_t success, const char *emsg) |
522 | { | 552 | { |
523 | printf ("DID Document has been stored to namestore\n"); | ||
524 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 553 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
525 | ret = 0; | 554 | ret = 0; |
526 | return; | 555 | return; |
@@ -540,16 +569,14 @@ create_did_store (char *didd_str, struct GNUNET_IDENTITY_Ego *ego) | |||
540 | struct GNUNET_GNSRECORD_Data record_data; | 569 | struct GNUNET_GNSRECORD_Data record_data; |
541 | const struct GNUNET_IDENTITY_PrivateKey *skey; | 570 | const struct GNUNET_IDENTITY_PrivateKey *skey; |
542 | 571 | ||
543 | if(expire == NULL) { | 572 | if (GNUNET_STRINGS_fancy_time_to_relative ((NULL != expire) ? |
544 | expire = GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME; | 573 | expire : |
545 | } | 574 | GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME, |
546 | 575 | &expire_time) == GNUNET_OK) | |
547 | if (GNUNET_STRINGS_fancy_time_to_relative (expire, &expire_time) == | ||
548 | GNUNET_OK) | ||
549 | { | 576 | { |
550 | record_data.data = (void *) didd_str; | 577 | record_data.data = didd_str; |
551 | record_data.expiration_time = expire_time.rel_value_us; | 578 | record_data.expiration_time = expire_time.rel_value_us; |
552 | record_data.data_size = strlen (didd_str); | 579 | record_data.data_size = strlen (didd_str) + 1; |
553 | record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"), | 580 | record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"), |
554 | record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 581 | record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
555 | 582 | ||
@@ -557,8 +584,8 @@ create_did_store (char *didd_str, struct GNUNET_IDENTITY_Ego *ego) | |||
557 | 584 | ||
558 | GNUNET_NAMESTORE_records_store (namestore_handle, | 585 | GNUNET_NAMESTORE_records_store (namestore_handle, |
559 | skey, | 586 | skey, |
560 | "didd", | 587 | GNUNET_GNS_EMPTY_LABEL_AT, |
561 | 1, | 588 | 1, //FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records |
562 | &record_data, | 589 | &record_data, |
563 | &create_did_store_cb, | 590 | &create_did_store_cb, |
564 | NULL); | 591 | NULL); |
@@ -605,22 +632,19 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
605 | { | 632 | { |
606 | printf ( | 633 | printf ( |
607 | "DID Docuement is read from \"did-document\" argument (EXPERIMENTAL)\n"); | 634 | "DID Docuement is read from \"did-document\" argument (EXPERIMENTAL)\n"); |
608 | didd_str = didd; | 635 | didd_str = strdup (didd); |
609 | } | 636 | } |
610 | else { | 637 | else { |
611 | // Generate DID Docuement from public key | 638 | // Generate DID Docuement from public key |
612 | didd_str = create_did_generate (pkey); | 639 | didd_str = create_did_generate (pkey); |
613 | } | 640 | } |
614 | 641 | ||
615 | // Print DID Docuement to stdout | 642 | // Print DID Document to stdout |
616 | printf ("%s\n", didd_str); | 643 | printf ("%s\n", didd_str); |
617 | 644 | ||
618 | // Store the DID Docuement | 645 | // Store the DID Document |
619 | create_did_store (didd_str, ego); | 646 | create_did_store (didd_str, ego); |
620 | 647 | ||
621 | /* FIXME-MSC: Comment does not match code. | ||
622 | * Also unsure of you want to free this. You may want to free | ||
623 | * didd on shutdown instead*/ | ||
624 | // Save DID Document String to GNS | 648 | // Save DID Document String to GNS |
625 | free (didd_str); | 649 | free (didd_str); |
626 | } | 650 | } |
@@ -633,7 +657,6 @@ create_did_document_ego_create_cb (void *cls, | |||
633 | const struct GNUNET_IDENTITY_PrivateKey *pk, | 657 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
634 | const char *emsg) | 658 | const char *emsg) |
635 | { | 659 | { |
636 | const char *ego_name; | ||
637 | 660 | ||
638 | if (emsg != NULL) | 661 | if (emsg != NULL) |
639 | { | 662 | { |
@@ -643,10 +666,8 @@ create_did_document_ego_create_cb (void *cls, | |||
643 | return; | 666 | return; |
644 | } | 667 | } |
645 | 668 | ||
646 | ego_name = (char *) cls; | ||
647 | |||
648 | GNUNET_IDENTITY_ego_lookup (my_cfg, | 669 | GNUNET_IDENTITY_ego_lookup (my_cfg, |
649 | ego_name, | 670 | egoname, |
650 | &create_did_ego_lockup_cb, | 671 | &create_did_ego_lockup_cb, |
651 | NULL); | 672 | NULL); |
652 | } | 673 | } |
@@ -658,27 +679,18 @@ create_did_document_ego_create_cb (void *cls, | |||
658 | static void | 679 | static void |
659 | create_did_document () | 680 | create_did_document () |
660 | { | 681 | { |
661 | if ((name != NULL)&& (expire != NULL)) | 682 | if ((egoname != NULL) && (expire != NULL)) |
662 | { | 683 | { |
663 | GNUNET_IDENTITY_create (identity_handle, | 684 | GNUNET_IDENTITY_create (identity_handle, |
664 | name, | 685 | egoname, |
665 | NULL, | 686 | NULL, |
666 | GNUNET_IDENTITY_TYPE_EDDSA, | 687 | GNUNET_IDENTITY_TYPE_EDDSA, |
667 | &create_did_document_ego_create_cb, | 688 | &create_did_document_ego_create_cb, |
668 | (void *) name); | 689 | egoname); |
669 | } | ||
670 | else if ((ego != NULL) && (expire != NULL) ) | ||
671 | { | ||
672 | GNUNET_IDENTITY_ego_lookup (my_cfg, | ||
673 | ego, | ||
674 | &create_did_ego_lockup_cb, | ||
675 | NULL); | ||
676 | } | 690 | } |
677 | else { | 691 | else { |
678 | /* FIXME-MSC: This is confusing. Why name OR ego? | ||
679 | * The expiration should be optional */ | ||
680 | printf ( | 692 | printf ( |
681 | "Set the NAME or the EGO and the Expiration-time argument to create a new DID(-Document)\n"); | 693 | "Set the EGO and the Expiration-time argument to create a new DID(-Document)\n"); |
682 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 694 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
683 | ret = 1; | 695 | ret = 1; |
684 | return; | 696 | return; |
@@ -707,7 +719,7 @@ static void | |||
707 | replace_did_document_remove_cb (void *cls) | 719 | replace_did_document_remove_cb (void *cls) |
708 | { | 720 | { |
709 | GNUNET_IDENTITY_ego_lookup (my_cfg, | 721 | GNUNET_IDENTITY_ego_lookup (my_cfg, |
710 | ego, | 722 | egoname, |
711 | &replace_did_document_ego_lookup_cb, | 723 | &replace_did_document_ego_lookup_cb, |
712 | NULL); | 724 | NULL); |
713 | } | 725 | } |
@@ -719,7 +731,7 @@ replace_did_document_remove_cb (void *cls) | |||
719 | static void | 731 | static void |
720 | replace_did_document () | 732 | replace_did_document () |
721 | { | 733 | { |
722 | if ((didd != NULL)|| (expire != NULL)) | 734 | if ((didd != NULL) && (expire != NULL)) |
723 | { | 735 | { |
724 | remove_did_document (&replace_did_document_remove_cb, NULL); | 736 | remove_did_document (&replace_did_document_remove_cb, NULL); |
725 | } | 737 | } |
@@ -732,6 +744,78 @@ replace_did_document () | |||
732 | } | 744 | } |
733 | } | 745 | } |
734 | 746 | ||
747 | static void | ||
748 | post_ego_iteration (void *cls) | ||
749 | { | ||
750 | if (1 == replace) | ||
751 | { | ||
752 | replace_did_document (); | ||
753 | } | ||
754 | else if (1 == get) | ||
755 | { | ||
756 | resolve_did_document (); | ||
757 | } | ||
758 | else if (1 == remove_did) | ||
759 | { | ||
760 | remove_did_document (NULL, NULL); | ||
761 | } | ||
762 | else if (1 == create) | ||
763 | { | ||
764 | create_did_document (); | ||
765 | } | ||
766 | else { | ||
767 | // No Argument found | ||
768 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | ||
769 | return; | ||
770 | } | ||
771 | } | ||
772 | |||
773 | static void | ||
774 | process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego, | ||
775 | void **ctx, const char*name) | ||
776 | { | ||
777 | char *did_str; | ||
778 | |||
779 | if (ego == NULL) | ||
780 | { | ||
781 | if (1 == ego_exists) | ||
782 | { | ||
783 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | ||
784 | return; | ||
785 | } | ||
786 | GNUNET_SCHEDULER_add_now (&post_ego_iteration, NULL); | ||
787 | return; | ||
788 | } | ||
789 | if (NULL == name) | ||
790 | return; | ||
791 | if ((1 == create) && | ||
792 | (0 == strncmp (name, egoname, strlen (egoname))) && | ||
793 | (1 != ego_exists)) | ||
794 | { | ||
795 | fprintf(stderr, "%s already exists!\n", egoname); | ||
796 | ego_exists = 1; | ||
797 | return; | ||
798 | } | ||
799 | if (1 == show_all) | ||
800 | { | ||
801 | did_str = ego_to_did (ego); | ||
802 | printf ("%s\n", did_str); | ||
803 | GNUNET_free (did_str); | ||
804 | return; | ||
805 | } | ||
806 | if (1 == show) | ||
807 | { | ||
808 | if (0 == strncmp (name, egoname, strlen (egoname))) | ||
809 | { | ||
810 | did_str = ego_to_did (ego); | ||
811 | printf ("%s\n", did_str); | ||
812 | GNUNET_free (did_str); | ||
813 | return; | ||
814 | } | ||
815 | } | ||
816 | } | ||
817 | |||
818 | |||
735 | 819 | ||
736 | static void | 820 | static void |
737 | run (void *cls, | 821 | run (void *cls, |
@@ -741,7 +825,6 @@ run (void *cls, | |||
741 | { | 825 | { |
742 | gns_handle = GNUNET_GNS_connect (c); | 826 | gns_handle = GNUNET_GNS_connect (c); |
743 | namestore_handle = GNUNET_NAMESTORE_connect (c); | 827 | namestore_handle = GNUNET_NAMESTORE_connect (c); |
744 | identity_handle = GNUNET_IDENTITY_connect (c, NULL, NULL); | ||
745 | my_cfg = c; | 828 | my_cfg = c; |
746 | 829 | ||
747 | // check if GNS_handle could connect | 830 | // check if GNS_handle could connect |
@@ -754,53 +837,23 @@ run (void *cls, | |||
754 | // check if NAMESTORE_handle could connect | 837 | // check if NAMESTORE_handle could connect |
755 | if (namestore_handle == NULL) | 838 | if (namestore_handle == NULL) |
756 | { | 839 | { |
840 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | ||
757 | ret = 1; | 841 | ret = 1; |
758 | return; | 842 | return; |
759 | } | 843 | } |
760 | 844 | ||
761 | // check if IDENTITY_handle could connect | 845 | identity_handle = GNUNET_IDENTITY_connect (c, &process_dids, NULL); |
762 | if (identity_handle == NULL) | 846 | if (identity_handle == NULL) |
763 | { | 847 | { |
848 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | ||
764 | ret = 1; | 849 | ret = 1; |
765 | return; | 850 | return; |
766 | } | 851 | } |
767 | |||
768 | if (1 == replace) | ||
769 | { | ||
770 | replace_did_document (); | ||
771 | } | ||
772 | else if (1 == get) | ||
773 | { | ||
774 | resolve_did_document (); | ||
775 | } | ||
776 | else if (1 == remove_did) | ||
777 | { | ||
778 | remove_did_document (NULL, NULL); | ||
779 | } | ||
780 | else if (1 == create) | ||
781 | { | ||
782 | create_did_document (); | ||
783 | } | ||
784 | else if (1 == show) | ||
785 | { | ||
786 | get_did_for_ego (); | ||
787 | } | ||
788 | else { | ||
789 | // No Argument found | ||
790 | printf ( | ||
791 | "No correct argument combination found. Use gnunet-did -h for help"); | ||
792 | ret = 1; | ||
793 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | ||
794 | return; | ||
795 | } | ||
796 | } | 852 | } |
797 | 853 | ||
798 | int | 854 | int |
799 | main (int argc, char *const argv[]) | 855 | main (int argc, char *const argv[]) |
800 | { | 856 | { |
801 | /* FIXME-MSC: An option to list all identities (their DIDs) that have a | ||
802 | * DID document would be nice. | ||
803 | */ | ||
804 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 857 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
805 | GNUNET_GETOPT_option_flag ('C', | 858 | GNUNET_GETOPT_option_flag ('C', |
806 | "create", | 859 | "create", |
@@ -819,19 +872,24 @@ main (int argc, char *const argv[]) | |||
819 | GNUNET_GETOPT_option_flag ('r', | 872 | GNUNET_GETOPT_option_flag ('r', |
820 | "remove", | 873 | "remove", |
821 | gettext_noop ( | 874 | gettext_noop ( |
822 | "Remove the DID Document with DID from GNUnet"), | 875 | "Remove the DID"), |
823 | &remove_did), | 876 | &remove_did), |
824 | GNUNET_GETOPT_option_flag ('R', | 877 | GNUNET_GETOPT_option_flag ('R', |
825 | "replace", | 878 | "replace", |
826 | gettext_noop ("Replace the DID Document."), | 879 | gettext_noop ("Replace the DID Document."), |
827 | &replace), | 880 | &replace), |
881 | GNUNET_GETOPT_option_flag ('A', | ||
882 | "--show-all", | ||
883 | gettext_noop ("Replace the DID Document."), | ||
884 | &show_all), | ||
828 | GNUNET_GETOPT_option_string ('d', | 885 | GNUNET_GETOPT_option_string ('d', |
829 | "did", | 886 | "did", |
830 | "DID", | 887 | "DID", |
831 | gettext_noop ("The DID to work with"), | 888 | gettext_noop ( |
889 | "The Decentralized Identity (DID)"), | ||
832 | &did), | 890 | &did), |
833 | GNUNET_GETOPT_option_string ('D', | 891 | GNUNET_GETOPT_option_string ('D', |
834 | "did-docuement", | 892 | "--did-document", |
835 | "JSON", | 893 | "JSON", |
836 | gettext_noop ( | 894 | gettext_noop ( |
837 | "The DID Document to store in GNUNET"), | 895 | "The DID Document to store in GNUNET"), |
@@ -839,13 +897,8 @@ main (int argc, char *const argv[]) | |||
839 | GNUNET_GETOPT_option_string ('e', | 897 | GNUNET_GETOPT_option_string ('e', |
840 | "ego", | 898 | "ego", |
841 | "EGO", | 899 | "EGO", |
842 | gettext_noop ("The EGO to work with"), | 900 | gettext_noop ("The name of the EGO"), |
843 | &ego), | 901 | &egoname), |
844 | GNUNET_GETOPT_option_string ('n', | ||
845 | "name", | ||
846 | "NAME", | ||
847 | gettext_noop ("The name of the created EGO"), | ||
848 | &name), | ||
849 | GNUNET_GETOPT_option_string ('t', | 902 | GNUNET_GETOPT_option_string ('t', |
850 | "expiration-time", | 903 | "expiration-time", |
851 | "TIME", | 904 | "TIME", |
@@ -858,7 +911,8 @@ main (int argc, char *const argv[]) | |||
858 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, | 911 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, |
859 | argv, | 912 | argv, |
860 | "gnunet-did", | 913 | "gnunet-did", |
861 | ("did command line tool"), | 914 | _ ( |
915 | "Manage Decentralized Identities (DIDs)"), | ||
862 | options, | 916 | options, |
863 | &run, | 917 | &run, |
864 | NULL)) | 918 | NULL)) |