aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2021-12-20 13:24:54 +0100
committerTristan Schwieren <tristan.schwieren@tum.de>2021-12-20 13:24:54 +0100
commit5a272fc9281e612b4f6d7b75b62e4672dc17866d (patch)
treeee992d82fe0c2938186f87d70604f71736b4f03a
parent3586f9360aac1f6ba580cacc00accce9aab00893 (diff)
downloadgnunet-5a272fc9281e612b4f6d7b75b62e4672dc17866d.tar.gz
gnunet-5a272fc9281e612b4f6d7b75b62e4672dc17866d.zip
-did expiration time fix
-rw-r--r--src/did/gnunet-did.c84
1 files changed, 57 insertions, 27 deletions
diff --git a/src/did/gnunet-did.c b/src/did/gnunet-did.c
index 2efc116cd..aa1a9188f 100644
--- a/src/did/gnunet-did.c
+++ b/src/did/gnunet-did.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V. 3 Copyright (C) 2012-2021 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -17,6 +17,14 @@
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20
21// TODO: Public Key in DID Docuement
22// TODO: Correct Key type
23// TODO: valid time when setting DID Docuement - replace - create
24// TODO: uncrustify
25// TODO: Unit Tests
26
27
20/** 28/**
21 * @author Tristan Schwieren 29 * @author Tristan Schwieren
22 * @file src/did/gnunet-did.c 30 * @file src/did/gnunet-did.c
@@ -80,17 +88,21 @@ static char *attr_ego;
80 */ 88 */
81static char *attr_name; 89static char *attr_name;
82 90
91/**
92 * Attribute expire
93 */
94static char *attr_expire;
95
83static struct GNUNET_GNS_Handle * gns_handle; 96static struct GNUNET_GNS_Handle * gns_handle;
84static struct GNUNET_NAMESTORE_Handle * namestore_handle; 97static struct GNUNET_NAMESTORE_Handle * namestore_handle;
85static struct GNUNET_IDENTITY_Handle * identity_handle; 98static struct GNUNET_IDENTITY_Handle * identity_handle;
86const static struct GNUNET_CONFIGURATION_Handle * my_cfg; 99const static struct GNUNET_CONFIGURATION_Handle * my_cfg;
87 100
88// TODO 101// TODO
89// static void replace_did_document(); - use remove_did_document and add_did_document
90// eddsa only 102// eddsa only
91// Set the duration for the didd record
92// safe delete the didd record - look for other with same sub 103// safe delete the didd record - look for other with same sub
93// Add a data DID Document type 104// Add a data DID Document type
105// Set Record flag when storing did
94 106
95/** 107/**
96 * @brief Disconnect and shutdown 108 * @brief Disconnect and shutdown
@@ -191,8 +203,6 @@ print_did_document(
191 uint32_t rd_count, 203 uint32_t rd_count,
192 const struct GNUNET_GNSRECORD_Data *rd) 204 const struct GNUNET_GNSRECORD_Data *rd)
193{ 205{
194 printf("Going to print did\n");
195 // TODO: Remove "store.sock" at the end of print
196 if (rd_count != 1) 206 if (rd_count != 1)
197 { 207 {
198 printf("An ego should only have one DID Document"); 208 printf("An ego should only have one DID Document");
@@ -226,7 +236,6 @@ resolve_did_document()
226 get_pkey_from_attr_did(&pkey); 236 get_pkey_from_attr_did(&pkey);
227 237
228 // TODO: Check the type of returned records 238 // TODO: Check the type of returned records
229 printf("Start GNS lockup\n");
230 GNUNET_GNS_lookup(gns_handle, "didd", &pkey, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL); 239 GNUNET_GNS_lookup(gns_handle, "didd", &pkey, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL);
231} 240}
232 241
@@ -427,22 +436,34 @@ create_did_store_cb(void *cls, int32_t success, const char *emsg){
427static void 436static void
428create_did_store(char * didd_str, struct GNUNET_IDENTITY_Ego * ego) 437create_did_store(char * didd_str, struct GNUNET_IDENTITY_Ego * ego)
429{ 438{
430 const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego); 439
431 const struct GNUNET_GNSRECORD_Data record_data = { 440 struct GNUNET_TIME_Relative expire_time;
432 (void *) didd_str, 441 struct GNUNET_GNSRECORD_Data record_data;
433 (uint64_t) 86400000000, // =1d TODO: Set to user preference 442 const struct GNUNET_IDENTITY_PrivateKey * skey;
434 strlen(didd_str), 443
435 GNUNET_GNSRECORD_typename_to_number("TXT"), 444 if(GNUNET_STRINGS_fancy_time_to_relative(attr_expire, &expire_time) != GNUNET_OK)
436 0 445 {
437 }; 446 record_data.data = (void *) didd_str;
438 447 record_data.expiration_time = expire_time.rel_value_us;
439 GNUNET_NAMESTORE_records_store( namestore_handle, 448 record_data.data_size = strlen(didd_str);
440 skey, 449 record_data.record_type = GNUNET_GNSRECORD_typename_to_number("TXT"),
441 "didd", 450 record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
442 1, 451
443 &record_data, 452 skey = GNUNET_IDENTITY_ego_get_private_key(ego);
444 &create_did_store_cb, 453
445 NULL); 454 GNUNET_NAMESTORE_records_store( namestore_handle,
455 skey,
456 "didd",
457 1,
458 &record_data,
459 &create_did_store_cb,
460 NULL);
461 } else {
462 printf("Failed to read given expiration time\n");
463 GNUNET_SCHEDULER_add_now(&cleanup, NULL);
464 ret = 1;
465 return;
466 }
446} 467}
447 468
448/** 469/**
@@ -527,23 +548,27 @@ create_did_document_ego_create_cb(void *cls,
527 NULL); 548 NULL);
528} 549}
529 550
551/**
552 * @brief Create a did document
553 *
554 */
530static void 555static void
531create_did_document() 556create_did_document()
532{ 557{
533 if(attr_name != NULL){ 558 if(attr_name != NULL || attr_expire != NULL){
534 GNUNET_IDENTITY_create(identity_handle, 559 GNUNET_IDENTITY_create(identity_handle,
535 attr_name, 560 attr_name,
536 NULL, 561 NULL,
537 GNUNET_IDENTITY_TYPE_EDDSA, 562 GNUNET_IDENTITY_TYPE_EDDSA,
538 &create_did_document_ego_create_cb, 563 &create_did_document_ego_create_cb,
539 (void *) attr_name); 564 (void *) attr_name);
540 } else if (attr_ego != NULL) { 565 } else if (attr_ego != NULL || attr_expire != NULL) {
541 GNUNET_IDENTITY_ego_lookup(my_cfg, 566 GNUNET_IDENTITY_ego_lookup(my_cfg,
542 attr_ego, 567 attr_ego,
543 &create_did_ego_lockup_cb, 568 &create_did_ego_lockup_cb,
544 NULL); 569 NULL);
545 } else { 570 } else {
546 printf("Set the NAME or the EGO argument to create a new DID(-Document)\n"); 571 printf("Set the NAME or the EGO and the Expiration-time argument to create a new DID(-Document)\n");
547 GNUNET_SCHEDULER_add_now(&cleanup, NULL); 572 GNUNET_SCHEDULER_add_now(&cleanup, NULL);
548 ret = 1; 573 ret = 1;
549 return; 574 return;
@@ -584,11 +609,11 @@ replace_did_document_remove_cb(void * cls)
584static void 609static void
585replace_did_document() 610replace_did_document()
586{ 611{
587 if (attr_didd != NULL) 612 if (attr_didd != NULL || attr_expire != NULL)
588 { 613 {
589 remove_did_document(&replace_did_document_remove_cb, NULL); 614 remove_did_document(&replace_did_document_remove_cb, NULL);
590 } else { 615 } else {
591 printf("Set the DID Document argument to repalce the DID Document\n"); 616 printf("Set the DID Document and expiration time argument to repalce the DID Document\n");
592 GNUNET_SCHEDULER_add_now(&cleanup, NULL); 617 GNUNET_SCHEDULER_add_now(&cleanup, NULL);
593 ret = 1; 618 ret = 1;
594 return; 619 return;
@@ -688,6 +713,11 @@ main (int argc, char *const argv[])
688 "NAME", 713 "NAME",
689 gettext_noop ("The name of the created EGO"), 714 gettext_noop ("The name of the created EGO"),
690 &attr_name), 715 &attr_name),
716 GNUNET_GETOPT_option_string ('t',
717 "expiration-time",
718 "TIME",
719 gettext_noop ("The time until the DID Document is going to expire (e.g. 5d)"),
720 &attr_expire),
691 GNUNET_GETOPT_OPTION_END 721 GNUNET_GETOPT_OPTION_END
692 }; 722 };
693 723