diff options
author | Tristan Schwieren <tristan.schwieren@tum.de> | 2022-07-06 15:10:33 +0200 |
---|---|---|
committer | Tristan Schwieren <tristan.schwieren@tum.de> | 2022-07-06 15:10:33 +0200 |
commit | 9c008dbed86125e74286f4a9c7da0f586fc7e04d (patch) | |
tree | 034b6c9b36f6c808496cbea8054e6f6e1a691ecc /src/reclaim | |
parent | 00047451b7e2e466c0f8b887280054bac3106cbd (diff) | |
download | gnunet-9c008dbed86125e74286f4a9c7da0f586fc7e04d.tar.gz gnunet-9c008dbed86125e74286f4a9c7da0f586fc7e04d.zip |
- didlib; use expire value
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/did_core.c | 31 | ||||
-rw-r--r-- | src/reclaim/did_core.h | 6 | ||||
-rw-r--r-- | src/reclaim/gnunet-did.c | 46 |
3 files changed, 46 insertions, 37 deletions
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 @@ | |||
24 | * @author Tristan Schwieren | 24 | * @author Tristan Schwieren |
25 | */ | 25 | */ |
26 | 26 | ||
27 | // DO: Expiration time missing in create | ||
28 | // Add Expiration TIME to json DID document | ||
27 | 29 | ||
28 | // TODO: Expiration time missing in create | ||
29 | // TODO: Check if ego already has a DID document in create | 30 | // TODO: Check if ego already has a DID document in create |
30 | // TODO: Store DID document with empty label and own type (maybe DID-Document or Json??) | ||
31 | // TODO: Store DID document as compact JSON in GNS but resolve it with newlines | 31 | // TODO: Store DID document as compact JSON in GNS but resolve it with newlines |
32 | 32 | ||
33 | #include "did_core.h" | 33 | // TODO: Store DID document with empty label and own type (maybe DID-Document or JSON??) |
34 | 34 | ||
35 | // #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT | 35 | #include "did_core.h" |
36 | #define DID_DOCUMENT_LABEL "didd" | ||
37 | #define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d" | ||
38 | 36 | ||
39 | struct DID_resolve_return | 37 | struct DID_resolve_return |
40 | { | 38 | { |
@@ -89,10 +87,7 @@ DID_resolve_gns_lookup_cb ( | |||
89 | * Calls the given callback function with the resolved DID Document and the given closure. | 87 | * Calls the given callback function with the resolved DID Document and the given closure. |
90 | * If the did can not be resolved did_document is NULL. | 88 | * If the did can not be resolved did_document is NULL. |
91 | * | 89 | * |
92 | * @param did DID that is resolved | 90 | * @param did DID that is resolved000G055PGJ4RJSS4G8HWCP86AWF1C6TF2DW2K3BW05HHRKSJG38NT2Z3JGe |
93 | * @param gns_handle pointer to gns handle. | ||
94 | * @param cont callback function | ||
95 | * @param cls closure | ||
96 | */ | 91 | */ |
97 | enum GNUNET_GenericReturnValue | 92 | enum GNUNET_GenericReturnValue |
98 | DID_resolve (const char *did, | 93 | DID_resolve (const char *did, |
@@ -109,7 +104,7 @@ DID_resolve (const char *did, | |||
109 | if (GNUNET_OK != DID_did_to_pkey (did, &pkey)) | 104 | if (GNUNET_OK != DID_did_to_pkey (did, &pkey)) |
110 | return GNUNET_NO; | 105 | return GNUNET_NO; |
111 | 106 | ||
112 | // Create closure for lockup callback | 107 | // Create closure for lookup callback |
113 | struct DID_resolve_return *cls2 = malloc (sizeof(struct DID_resolve_return)); | 108 | struct DID_resolve_return *cls2 = malloc (sizeof(struct DID_resolve_return)); |
114 | cls2->cb = cont; | 109 | cls2->cb = cont; |
115 | cls2->cls = cls; | 110 | cls2->cls = cls; |
@@ -161,12 +156,13 @@ DID_create_did_store_cb (void *cls, | |||
161 | enum GNUNET_GenericReturnValue | 156 | enum GNUNET_GenericReturnValue |
162 | DID_create (const struct GNUNET_IDENTITY_Ego *ego, | 157 | DID_create (const struct GNUNET_IDENTITY_Ego *ego, |
163 | const char *did_document, | 158 | const char *did_document, |
159 | const struct GNUNET_TIME_Relative *expire_time, | ||
164 | struct GNUNET_NAMESTORE_Handle *namestore_handle, | 160 | struct GNUNET_NAMESTORE_Handle *namestore_handle, |
165 | DID_action_callback *cont, | 161 | DID_action_callback *cont, |
166 | void *cls) | 162 | void *cls) |
167 | { | 163 | { |
168 | struct GNUNET_IDENTITY_PublicKey pkey; | 164 | struct GNUNET_IDENTITY_PublicKey pkey; |
169 | struct GNUNET_TIME_Relative expire_time; | 165 | // struct GNUNET_TIME_Relative expire_time; |
170 | struct GNUNET_GNSRECORD_Data record_data; | 166 | struct GNUNET_GNSRECORD_Data record_data; |
171 | 167 | ||
172 | // Ego, namestore_handle and cont must be set | 168 | // Ego, namestore_handle and cont must be set |
@@ -176,7 +172,6 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego, | |||
176 | // Check if ego has EdDSA key | 172 | // Check if ego has EdDSA key |
177 | GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) ego, | 173 | GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) ego, |
178 | &pkey); | 174 | &pkey); |
179 | |||
180 | if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY) | 175 | if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY) |
181 | { | 176 | { |
182 | printf ("The EGO has to have an EdDSA key pair\n"); | 177 | printf ("The EGO has to have an EdDSA key pair\n"); |
@@ -190,17 +185,9 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego, | |||
190 | else | 185 | else |
191 | did_document = DID_pkey_to_did_document (&pkey); | 186 | did_document = DID_pkey_to_did_document (&pkey); |
192 | 187 | ||
193 | // TODO: Get the expiration time as argument | ||
194 | if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative ( | ||
195 | DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_time)) | ||
196 | { | ||
197 | printf ("Failed to read given expiration time\n"); | ||
198 | return GNUNET_NO; | ||
199 | } | ||
200 | |||
201 | // Create record | 188 | // Create record |
202 | record_data.data = did_document; | 189 | record_data.data = did_document; |
203 | record_data.expiration_time = expire_time.rel_value_us; | 190 | record_data.expiration_time = expire_time->rel_value_us; |
204 | record_data.data_size = strlen (did_document) + 1; | 191 | record_data.data_size = strlen (did_document) + 1; |
205 | record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"), | 192 | record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"), |
206 | record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 193 | 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 @@ | |||
33 | #include "did_helper.h" | 33 | #include "did_helper.h" |
34 | #include "jansson.h" | 34 | #include "jansson.h" |
35 | 35 | ||
36 | // #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT | ||
37 | #define DID_DOCUMENT_LABEL "didd" | ||
38 | #define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "365d" | ||
39 | |||
36 | /** | 40 | /** |
37 | * @brief Signature of a callback function that is called after a did has been resolved. | 41 | * @brief Signature of a callback function that is called after a did has been resolved. |
38 | * did_document contains an Error message if DID can not be resolved. | 42 | * did_document contains an Error message if DID can not be resolved. |
@@ -99,6 +103,7 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego, | |||
99 | * @param ego ego for which the DID should be created. | 103 | * @param ego ego for which the DID should be created. |
100 | * @param did_document did_document that should be saved in namestore. | 104 | * @param did_document did_document that should be saved in namestore. |
101 | * If did_document==NULL -> Default DID document is created. | 105 | * If did_document==NULL -> Default DID document is created. |
106 | * @param expire_time | ||
102 | * @param namestore_handle | 107 | * @param namestore_handle |
103 | * @param cont callback function | 108 | * @param cont callback function |
104 | * @param cls closure | 109 | * @param cls closure |
@@ -106,6 +111,7 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego, | |||
106 | enum GNUNET_GenericReturnValue | 111 | enum GNUNET_GenericReturnValue |
107 | DID_create (const struct GNUNET_IDENTITY_Ego *ego, | 112 | DID_create (const struct GNUNET_IDENTITY_Ego *ego, |
108 | const char *did_document, | 113 | const char *did_document, |
114 | const struct GNUNET_TIME_Relative *expire_time, | ||
109 | struct GNUNET_NAMESTORE_Handle *namestore_handle, | 115 | struct GNUNET_NAMESTORE_Handle *namestore_handle, |
110 | DID_action_callback *cont, | 116 | DID_action_callback *cont, |
111 | void *cls); | 117 | 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 @@ | |||
36 | #include "platform.h" | 36 | #include "platform.h" |
37 | #include "gnunet_util_lib.h" | 37 | #include "gnunet_util_lib.h" |
38 | #include "gnunet_namestore_service.h" | 38 | #include "gnunet_namestore_service.h" |
39 | #include "gnunet_identity_service.h" | ||
39 | #include "gnunet_gns_service.h" | 40 | #include "gnunet_gns_service.h" |
40 | #include "gnunet_gnsrecord_lib.h" | 41 | #include "gnunet_gnsrecord_lib.h" |
41 | #include "did_helper.h" | 42 | #include "did_helper.h" |
@@ -157,7 +158,7 @@ cleanup (void *cls) | |||
157 | // get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | 158 | // get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) |
158 | // { | 159 | // { |
159 | // char *did_str; | 160 | // char *did_str; |
160 | // | 161 | // |
161 | // if (ego == NULL) | 162 | // if (ego == NULL) |
162 | // { | 163 | // { |
163 | // printf ("EGO not found\n"); | 164 | // printf ("EGO not found\n"); |
@@ -166,9 +167,9 @@ cleanup (void *cls) | |||
166 | // return; | 167 | // return; |
167 | // } | 168 | // } |
168 | // did_str = DID_identity_to_did (ego); | 169 | // did_str = DID_identity_to_did (ego); |
169 | // | 170 | // |
170 | // printf ("%s\n", did_str); | 171 | // printf ("%s\n", did_str); |
171 | // | 172 | // |
172 | // GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 173 | // GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
173 | // ret = 0; | 174 | // ret = 0; |
174 | // return; | 175 | // return; |
@@ -426,9 +427,34 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
426 | { | 427 | { |
427 | char *did = DID_identity_to_did (ego); | 428 | char *did = DID_identity_to_did (ego); |
428 | void *cls = malloc (strlen (did) + 1); | 429 | void *cls = malloc (strlen (did) + 1); |
430 | struct GNUNET_TIME_Relative expire_relative; | ||
431 | |||
432 | if (expire == NULL) | ||
433 | { | ||
434 | GNUNET_STRINGS_fancy_time_to_relative ( | ||
435 | DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_relative); | ||
436 | } | ||
437 | else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (expire, | ||
438 | & | ||
439 | expire_relative)) | ||
440 | { | ||
441 | printf ("Failed to read given expiration time\n"); | ||
442 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | ||
443 | ret = 1; | ||
444 | return; | ||
445 | } | ||
446 | |||
429 | strcpy (cls, did); | 447 | strcpy (cls, did); |
430 | // TODO: Add DID_document argument | 448 | // TODO: Add DID_document argument |
431 | DID_create (ego, NULL, namestore_handle, create_did_cb, cls); | 449 | if (GNUNET_OK != DID_create (ego, NULL, &expire_relative, namestore_handle, |
450 | create_did_cb, | ||
451 | cls)) | ||
452 | { | ||
453 | printf ("An error occured while creating the DID.\n"); | ||
454 | ret = 1; | ||
455 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | ||
456 | return; | ||
457 | } | ||
432 | } | 458 | } |
433 | } | 459 | } |
434 | 460 | ||
@@ -439,16 +465,6 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
439 | static void | 465 | static void |
440 | create_did () | 466 | create_did () |
441 | { | 467 | { |
442 | // Expire has to be set | ||
443 | if (expire == NULL) | ||
444 | { | ||
445 | printf ( | ||
446 | "Set the Expiration-time argument to create a new DID(-Document)\n"); | ||
447 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | ||
448 | ret = 1; | ||
449 | return; | ||
450 | } | ||
451 | |||
452 | // Ego name to be set | 468 | // Ego name to be set |
453 | if (egoname == NULL) | 469 | if (egoname == NULL) |
454 | { | 470 | { |
@@ -515,7 +531,7 @@ static void | |||
515 | post_ego_iteration (void *cls) | 531 | post_ego_iteration (void *cls) |
516 | { | 532 | { |
517 | // TODO: Check that only one argument is set | 533 | // TODO: Check that only one argument is set |
518 | 534 | ||
519 | if (1 == replace) | 535 | if (1 == replace) |
520 | { | 536 | { |
521 | replace_did_document (); | 537 | replace_did_document (); |