From 9c008dbed86125e74286f4a9c7da0f586fc7e04d Mon Sep 17 00:00:00 2001 From: Tristan Schwieren Date: Wed, 6 Jul 2022 15:10:33 +0200 Subject: - didlib; use expire value --- src/reclaim/did_core.c | 31 +++++++++---------------------- src/reclaim/did_core.h | 6 ++++++ src/reclaim/gnunet-did.c | 46 +++++++++++++++++++++++++++++++--------------- 3 files changed, 46 insertions(+), 37 deletions(-) (limited to 'src/reclaim') diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c index 16bdb0bdb..f43b7e7eb 100644 --- a/src/reclaim/did_core.c +++ b/src/reclaim/did_core.c @@ -24,17 +24,15 @@ * @author Tristan Schwieren */ +// DO: Expiration time missing in create +// Add Expiration TIME to json DID document -// TODO: Expiration time missing in create // TODO: Check if ego already has a DID document in create -// TODO: Store DID document with empty label and own type (maybe DID-Document or Json??) // TODO: Store DID document as compact JSON in GNS but resolve it with newlines -#include "did_core.h" +// TODO: Store DID document with empty label and own type (maybe DID-Document or JSON??) -// #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT -#define DID_DOCUMENT_LABEL "didd" -#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d" +#include "did_core.h" struct DID_resolve_return { @@ -89,10 +87,7 @@ DID_resolve_gns_lookup_cb ( * Calls the given callback function with the resolved DID Document and the given closure. * If the did can not be resolved did_document is NULL. * - * @param did DID that is resolved - * @param gns_handle pointer to gns handle. - * @param cont callback function - * @param cls closure + * @param did DID that is resolved000G055PGJ4RJSS4G8HWCP86AWF1C6TF2DW2K3BW05HHRKSJG38NT2Z3JGe */ enum GNUNET_GenericReturnValue DID_resolve (const char *did, @@ -109,7 +104,7 @@ DID_resolve (const char *did, if (GNUNET_OK != DID_did_to_pkey (did, &pkey)) return GNUNET_NO; - // Create closure for lockup callback + // Create closure for lookup callback struct DID_resolve_return *cls2 = malloc (sizeof(struct DID_resolve_return)); cls2->cb = cont; cls2->cls = cls; @@ -161,12 +156,13 @@ DID_create_did_store_cb (void *cls, enum GNUNET_GenericReturnValue DID_create (const struct GNUNET_IDENTITY_Ego *ego, const char *did_document, + const struct GNUNET_TIME_Relative *expire_time, struct GNUNET_NAMESTORE_Handle *namestore_handle, DID_action_callback *cont, void *cls) { struct GNUNET_IDENTITY_PublicKey pkey; - struct GNUNET_TIME_Relative expire_time; + // struct GNUNET_TIME_Relative expire_time; struct GNUNET_GNSRECORD_Data record_data; // Ego, namestore_handle and cont must be set @@ -176,7 +172,6 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego, // Check if ego has EdDSA key GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) ego, &pkey); - if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY) { printf ("The EGO has to have an EdDSA key pair\n"); @@ -190,17 +185,9 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego, else did_document = DID_pkey_to_did_document (&pkey); - // TODO: Get the expiration time as argument - if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative ( - DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_time)) - { - printf ("Failed to read given expiration time\n"); - return GNUNET_NO; - } - // Create record record_data.data = did_document; - record_data.expiration_time = expire_time.rel_value_us; + record_data.expiration_time = expire_time->rel_value_us; record_data.data_size = strlen (did_document) + 1; record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"), record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; diff --git a/src/reclaim/did_core.h b/src/reclaim/did_core.h index 6cde18342..842424e14 100644 --- a/src/reclaim/did_core.h +++ b/src/reclaim/did_core.h @@ -33,6 +33,10 @@ #include "did_helper.h" #include "jansson.h" +// #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT +#define DID_DOCUMENT_LABEL "didd" +#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "365d" + /** * @brief Signature of a callback function that is called after a did has been resolved. * did_document contains an Error message if DID can not be resolved. @@ -99,6 +103,7 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego, * @param ego ego for which the DID should be created. * @param did_document did_document that should be saved in namestore. * If did_document==NULL -> Default DID document is created. + * @param expire_time * @param namestore_handle * @param cont callback function * @param cls closure @@ -106,6 +111,7 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego, enum GNUNET_GenericReturnValue DID_create (const struct GNUNET_IDENTITY_Ego *ego, const char *did_document, + const struct GNUNET_TIME_Relative *expire_time, struct GNUNET_NAMESTORE_Handle *namestore_handle, DID_action_callback *cont, void *cls); diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c index 55eedfbd7..fb9a8e9a1 100644 --- a/src/reclaim/gnunet-did.c +++ b/src/reclaim/gnunet-did.c @@ -36,6 +36,7 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_namestore_service.h" +#include "gnunet_identity_service.h" #include "gnunet_gns_service.h" #include "gnunet_gnsrecord_lib.h" #include "did_helper.h" @@ -157,7 +158,7 @@ cleanup (void *cls) // get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) // { // char *did_str; -// +// // if (ego == NULL) // { // printf ("EGO not found\n"); @@ -166,9 +167,9 @@ cleanup (void *cls) // return; // } // did_str = DID_identity_to_did (ego); -// +// // printf ("%s\n", did_str); -// +// // GNUNET_SCHEDULER_add_now (&cleanup, NULL); // ret = 0; // return; @@ -426,9 +427,34 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) { char *did = DID_identity_to_did (ego); void *cls = malloc (strlen (did) + 1); + struct GNUNET_TIME_Relative expire_relative; + + if (expire == NULL) + { + GNUNET_STRINGS_fancy_time_to_relative ( + DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_relative); + } + else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (expire, + & + expire_relative)) + { + printf ("Failed to read given expiration time\n"); + GNUNET_SCHEDULER_add_now (cleanup, NULL); + ret = 1; + return; + } + strcpy (cls, did); // TODO: Add DID_document argument - DID_create (ego, NULL, namestore_handle, create_did_cb, cls); + if (GNUNET_OK != DID_create (ego, NULL, &expire_relative, namestore_handle, + create_did_cb, + cls)) + { + printf ("An error occured while creating the DID.\n"); + ret = 1; + GNUNET_SCHEDULER_add_now (&cleanup, NULL); + return; + } } } @@ -439,16 +465,6 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) static void create_did () { - // Expire has to be set - if (expire == NULL) - { - printf ( - "Set the Expiration-time argument to create a new DID(-Document)\n"); - GNUNET_SCHEDULER_add_now (&cleanup, NULL); - ret = 1; - return; - } - // Ego name to be set if (egoname == NULL) { @@ -515,7 +531,7 @@ static void post_ego_iteration (void *cls) { // TODO: Check that only one argument is set - + if (1 == replace) { replace_did_document (); -- cgit v1.2.3