aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2022-07-01 14:41:41 +0200
committerTristan Schwieren <tristan.schwieren@tum.de>2022-07-01 14:41:41 +0200
commit2c8ab6b923a99e5a97cfca0185f1d300cb774f08 (patch)
treef03a67ca8f1a991a0bf2e3434c4ea3243c6f3ce8 /src/reclaim
parentb50b97b20e986129f2da30eb0754a9921b80c4b3 (diff)
downloadgnunet-2c8ab6b923a99e5a97cfca0185f1d300cb774f08.tar.gz
gnunet-2c8ab6b923a99e5a97cfca0185f1d300cb774f08.zip
- refactored DID create
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/did_core.c122
-rw-r--r--src/reclaim/did_core.h9
-rw-r--r--src/reclaim/gnunet-did.c54
3 files changed, 76 insertions, 109 deletions
diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
index dea1c82c3..2d0a3c525 100644
--- a/src/reclaim/did_core.c
+++ b/src/reclaim/did_core.c
@@ -32,9 +32,20 @@
32#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d" 32#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d"
33 33
34static DID_resolve_callback *resolve_cb; 34static DID_resolve_callback *resolve_cb;
35static DID_action_callback *action_cb;
36static void *closure; 35static void *closure;
37 36
37struct DID_resolve_return
38{
39 DID_resolve_callback *cb;
40 void *cls;
41};
42
43struct DID_action_return
44{
45 DID_action_callback *cb;
46 void *cls;
47};
48
38// ------------------------------------------------ // 49// ------------------------------------------------ //
39// -------------------- Resolve ------------------- // 50// -------------------- Resolve ------------------- //
40// ------------------------------------------------ // 51// ------------------------------------------------ //
@@ -117,72 +128,23 @@ DID_create_did_store_cb (void *cls,
117 int32_t success, 128 int32_t success,
118 const char *emsg) 129 const char *emsg)
119{ 130{
131 DID_action_callback *cb = ((struct DID_action_return *) cls)->cb;
132 void *cls2 = ((struct DID_action_return *) cls)->cls;
133 free (cls);
134
120 if (GNUNET_OK == success) 135 if (GNUNET_OK == success)
121 { 136 {
122 // TEST 137 cb (GNUNET_OK, (void *) cls2);
123 struct GNUNET_IDENTITY_PublicKey *pkey_test;
124 GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) closure,
125 pkey_test);
126 printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
127
128 printf ("cls3: %s\n", (char *) closure);
129 action_cb (GNUNET_OK, closure);
130 } 138 }
131 else 139 else
132 { 140 {
133 printf ("%s\n", emsg); 141 printf ("%s\n", emsg);
134 action_cb (GNUNET_NO, closure); 142 cb (GNUNET_NO, (void *) cls2);
135 }
136}
137
138/**
139 * @brief Store DID Document in Namestore
140 *
141 * @param didd_str String endoced DID Docuement
142 * @param ego Identity whos DID Document is stored
143 */
144static enum GNUNET_GenericReturnValue
145DID_create_did_store (struct GNUNET_NAMESTORE_Handle *namestore_handle,
146 char *didd_str, struct GNUNET_IDENTITY_Ego *ego)
147{
148
149 struct GNUNET_TIME_Relative expire_time;
150 struct GNUNET_GNSRECORD_Data record_data;
151 const struct GNUNET_IDENTITY_PrivateKey *skey;
152
153 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (
154 DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_time))
155 {
156 printf ("Failed to read given expiration time\n");
157 return GNUNET_NO;
158 } 143 }
159
160 record_data.data = didd_str;
161 record_data.expiration_time = expire_time.rel_value_us;
162 record_data.data_size = strlen (didd_str) + 1;
163 record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
164 record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
165
166 skey = GNUNET_IDENTITY_ego_get_private_key (ego);
167
168 // TEST
169 struct GNUNET_IDENTITY_PublicKey *pkey_test;
170 GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) closure,
171 pkey_test);
172 printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
173
174 GNUNET_NAMESTORE_records_store (namestore_handle,
175 skey,
176 DID_DOCUMENT_LABEL,
177 1, // FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records
178 &record_data,
179 &DID_create_did_store_cb,
180 NULL);
181
182 return GNUNET_OK;
183} 144}
184 145
185// TODO: Expiration time missing 146// TODO: Expiration time missing
147// TODO: Check if ego already has a DID document
186 148
187/** 149/**
188 * @brief Creates a DID and saves DID Document in Namestore. 150 * @brief Creates a DID and saves DID Document in Namestore.
@@ -199,37 +161,59 @@ DID_create_did_store (struct GNUNET_NAMESTORE_Handle *namestore_handle,
199enum GNUNET_GenericReturnValue 161enum GNUNET_GenericReturnValue
200DID_create (const struct GNUNET_IDENTITY_Ego *ego, 162DID_create (const struct GNUNET_IDENTITY_Ego *ego,
201 const char *did_document, 163 const char *did_document,
202 const struct GNUNET_CONFIGURATION_Handle *cfg_handle,
203 struct GNUNET_IDENTITY_Handle *identity_handle,
204 struct GNUNET_NAMESTORE_Handle *namestore_handle, 164 struct GNUNET_NAMESTORE_Handle *namestore_handle,
205 DID_action_callback *cont, 165 DID_action_callback *cont,
206 void *cls) 166 void *cls)
207{ 167{
208 struct GNUNET_IDENTITY_PublicKey pkey; 168 struct GNUNET_IDENTITY_PublicKey pkey;
169 struct GNUNET_TIME_Relative expire_time;
170 struct GNUNET_GNSRECORD_Data record_data;
209 171
210 GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); 172 // Check if ego has EdDSA key
173 GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) ego,
174 &pkey);
211 175
212 if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY) 176 if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY)
213 { 177 {
214 printf ("The EGO has to have an EDDSA key pair\n"); 178 printf ("The EGO has to have an EdDSA key pair\n");
215 return GNUNET_NO; 179 return GNUNET_NO;
216 } 180 }
217 181
182 // No DID Document is given a default one is created
218 if (did_document != NULL) 183 if (did_document != NULL)
219 printf ( 184 printf (
220 "DID Docuement is read from \"DID-document\" argument (EXPERIMENTAL)\n"); 185 "DID Docuement is read from \"DID-document\" argument (EXPERIMENTAL)\n");
221 else 186 else
222 did_document = DID_pkey_to_did_document (&pkey); 187 did_document = DID_pkey_to_did_document (&pkey);
223 188
189 // TODO: Get the expiration time as argument
190 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (
191 DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_time))
192 {
193 printf ("Failed to read given expiration time\n");
194 return GNUNET_NO;
195 }
196
197 // Create record
198 record_data.data = did_document;
199 record_data.expiration_time = expire_time.rel_value_us;
200 record_data.data_size = strlen (did_document) + 1;
201 record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
202 record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
224 203
225 // TEST 204 // Create closure for record store callback
226 struct GNUNET_IDENTITY_PublicKey *pkey_test; 205 struct DID_action_return *cls2 = malloc (sizeof(struct DID_action_return));
227 GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) cls, 206 cls2->cb = cont;
228 pkey_test); 207 cls2->cls = cls;
229 printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
230 208
231 action_cb = cont; 209 // Store record
232 closure = cls; 210 GNUNET_NAMESTORE_records_store (namestore_handle,
211 GNUNET_IDENTITY_ego_get_private_key (ego),
212 DID_DOCUMENT_LABEL,
213 1, // FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records
214 &record_data,
215 &DID_create_did_store_cb,
216 (void *) cls2);
233 217
234 return DID_create_did_store (namestore_handle, did_document, ego); 218 return GNUNET_OK;
235} 219}
diff --git a/src/reclaim/did_core.h b/src/reclaim/did_core.h
index 8b4837e59..6cde18342 100644
--- a/src/reclaim/did_core.h
+++ b/src/reclaim/did_core.h
@@ -29,6 +29,7 @@
29#include "gnunet_namestore_service.h" 29#include "gnunet_namestore_service.h"
30#include "gnunet_gns_service.h" 30#include "gnunet_gns_service.h"
31#include "gnunet_gnsrecord_lib.h" 31#include "gnunet_gnsrecord_lib.h"
32#include "gnunet_identity_service.h"
32#include "did_helper.h" 33#include "did_helper.h"
33#include "jansson.h" 34#include "jansson.h"
34 35
@@ -96,12 +97,8 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego,
96 * @brief Creates a DID and saves DID Document in Namestore. 97 * @brief Creates a DID and saves DID Document in Namestore.
97 * 98 *
98 * @param ego ego for which the DID should be created. 99 * @param ego ego for which the DID should be created.
99 * If ego==NULL a new ego is created
100 * @param did_document did_document that should be saved in namestore. 100 * @param did_document did_document that should be saved in namestore.
101 * If ego==NULL did_document can also be NULL. 101 * If did_document==NULL -> Default DID document is created.
102 * Default DID document is created.
103 * @param cfg_handle pointer to configuration handle
104 * @param identity_handle pointer to identity handle. Can be NULL if ego!=NULL
105 * @param namestore_handle 102 * @param namestore_handle
106 * @param cont callback function 103 * @param cont callback function
107 * @param cls closure 104 * @param cls closure
@@ -109,8 +106,6 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego,
109enum GNUNET_GenericReturnValue 106enum GNUNET_GenericReturnValue
110DID_create (const struct GNUNET_IDENTITY_Ego *ego, 107DID_create (const struct GNUNET_IDENTITY_Ego *ego,
111 const char *did_document, 108 const char *did_document,
112 const struct GNUNET_CONFIGURATION_Handle *cfg_handle,
113 struct GNUNET_IDENTITY_Handle *identity_handle,
114 struct GNUNET_NAMESTORE_Handle *namestore_handle, 109 struct GNUNET_NAMESTORE_Handle *namestore_handle,
115 DID_action_callback *cont, 110 DID_action_callback *cont,
116 void *cls); 111 void *cls);
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c
index 18b171486..c865e8295 100644
--- a/src/reclaim/gnunet-did.c
+++ b/src/reclaim/gnunet-did.c
@@ -354,27 +354,29 @@ remove_did_document (remove_did_document_callback cont, void *cls)
354 } 354 }
355} 355}
356 356
357static void create_did (); 357// Needed because create_did_ego_lookup_cb() and
358// create_did_ego_create_cb() can call each other
359static void create_did_ego_lockup_cb ();
358 360
359/** 361/**
360 * @brief Create a DID(-Document). Called after DID has been created 362 * @brief Create a DID(-Document). Called after DID has been created
363 * Prints status and the DID.
361 * 364 *
362 */ 365 */
363static void 366static void
364create_did_cb (enum GNUNET_GenericReturnValue status, void *cls) 367create_did_cb (enum GNUNET_GenericReturnValue status, void *cls)
365{ 368{
366 struct GNUNET_IDENTITY_Ego *ego;
367 // char *did;
368
369 if (GNUNET_OK == status) 369 if (GNUNET_OK == status)
370 { 370 {
371 printf ("DID has been created\n"); 371 printf ("DID has been created.\n%s\n", (char *) cls);
372 // ego = (struct GNUNET_IDENTITY_Ego *) cls; 372 free (cls);
373 // did = DID_identity_to_did(ego); 373 ret = 0;
374 printf ("cls4: %s\n", (char *) cls);
375 } 374 }
376 else 375 else
377 printf ("An error occured while creating the DID\n"), ret = 1; 376 {
377 printf ("An error occured while creating the DID\n");
378 ret = 1;
379 }
378 380
379 GNUNET_SCHEDULER_add_now (&cleanup, NULL); 381 GNUNET_SCHEDULER_add_now (&cleanup, NULL);
380 return; 382 return;
@@ -396,27 +398,23 @@ create_did_ego_create_cb (void *cls,
396 return; 398 return;
397 } 399 }
398 400
399 create_did (); 401 GNUNET_IDENTITY_ego_lookup (my_cfg,
402 egoname,
403 &create_did_ego_lockup_cb,
404 NULL);
400} 405}
401 406
402/** 407/**
403 * @brief Create a DID(-Document). Called after ego lookup 408 * @brief Create a DID(-Document). Called after ego lookup
404 * 409 *
405 * @param cls
406 * @param ego
407 */ 410 */
408static void 411static void
409create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) 412create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
410{ 413{
411 // struct GNUNET_IDENTITY_Ego *ego_test;
412 struct GNUNET_IDENTITY_PublicKey *pkey_test;
413 printf("test3\n");
414
415 if (ego == NULL) 414 if (ego == NULL)
416 { 415 {
417 // If Ego was not found. Create new one first 416 // If Ego was not found. Create new one first
418 printf ("Ego was not found. Creating new one.\n"); 417 printf ("Ego was not found. Creating new one.\n");
419
420 GNUNET_IDENTITY_create (identity_handle, 418 GNUNET_IDENTITY_create (identity_handle,
421 egoname, 419 egoname,
422 NULL, 420 NULL,
@@ -426,20 +424,10 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
426 } 424 }
427 else 425 else
428 { 426 {
429 printf("test1\n"); 427 char *did = DID_identity_to_did (ego);
430 cls = (void *) ego; 428 void *cls = malloc (strlen (did) + 1);
431 429 strcpy (cls, did);
432 // TEST 430 DID_create (ego, NULL, namestore_handle, create_did_cb, cls);
433 // ego_test = (struct GNUNET_IDENTITY_Ego *) cls;
434 GNUNET_IDENTITY_ego_get_public_key (ego, pkey_test);
435 printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
436 printf("test4\n");
437
438 // TODO: Check if ego already has a DID document
439 // DO a resolve
440
441 DID_create (ego, NULL, my_cfg, identity_handle, namestore_handle,
442 create_did_cb, cls);
443 } 431 }
444} 432}
445 433
@@ -450,6 +438,7 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
450static void 438static void
451create_did () 439create_did ()
452{ 440{
441 // Expire has to be set
453 if (expire == NULL) 442 if (expire == NULL)
454 { 443 {
455 printf ( 444 printf (
@@ -459,6 +448,7 @@ create_did ()
459 return; 448 return;
460 } 449 }
461 450
451 // Ego name to be set
462 if (egoname == NULL) 452 if (egoname == NULL)
463 { 453 {
464 printf ("Set the Ego argument to create a new DID(-Document)\n"); 454 printf ("Set the Ego argument to create a new DID(-Document)\n");
@@ -466,8 +456,6 @@ create_did ()
466 ret = 1; 456 ret = 1;
467 return; 457 return;
468 } 458 }
469
470 printf("test2\n");
471 459
472 GNUNET_IDENTITY_ego_lookup (my_cfg, 460 GNUNET_IDENTITY_ego_lookup (my_cfg,
473 egoname, 461 egoname,