aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2021-12-14 14:01:46 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2021-12-21 17:17:14 +0100
commitf1da382aea44fbc0b543725a8c29ca32924300b7 (patch)
tree77eff9a89bcb5e9273be20d531be943310fd8e9b
parenta22f99e9a4c7dfd67bf02feab55845fabd0458f4 (diff)
downloadgnunet-f1da382aea44fbc0b543725a8c29ca32924300b7.tar.gz
gnunet-f1da382aea44fbc0b543725a8c29ca32924300b7.zip
-did not working remove abstraction
-rw-r--r--src/did/gnunet-did.c147
1 files changed, 94 insertions, 53 deletions
diff --git a/src/did/gnunet-did.c b/src/did/gnunet-did.c
index 1967334ee..62047beaf 100644
--- a/src/did/gnunet-did.c
+++ b/src/did/gnunet-did.c
@@ -36,9 +36,9 @@
36static int ret; 36static int ret;
37 37
38/** 38/**
39 * Attribute Add 39 * Attribute replace
40 */ 40 */
41static int attr_add; 41static int attr_replace;
42 42
43/** 43/**
44 * Attribute remove 44 * Attribute remove
@@ -66,6 +66,11 @@ static int attr_show;
66static char *attr_did; 66static char *attr_did;
67 67
68/** 68/**
69 * Attribute did document
70 */
71static char *attr_didd;
72
73/**
69 * Attribute ego 74 * Attribute ego
70 */ 75 */
71static char *attr_ego; 76static char *attr_ego;
@@ -84,7 +89,6 @@ const static struct GNUNET_CONFIGURATION_Handle * my_cfg;
84// static void replace_did_document(); - use remove_did_document and add_did_document 89// static void replace_did_document(); - use remove_did_document and add_did_document
85// eddsa only 90// eddsa only
86// welche properties? 91// welche properties?
87// cleans?
88 92
89// Add a data DID Document type 93// Add a data DID Document type
90 94
@@ -224,11 +228,19 @@ resolve_did_document()
224} 228}
225 229
226 230
231typedef void
232(*remove_did_document_callback) (void * cls);
233
234struct remove_did_document_cont_cls {
235 remove_did_document_callback cont;
236 void * cls;
237};
238
227/** 239/**
228 * @brief Callback after the DID has been removed 240 * @brief Callback after the DID has been removed
229 */ 241 */
230static void 242static void
231remove_did_cb(){ 243remove_did_cb(void * cls){
232 // Test if record was removed from Namestore 244 // Test if record was removed from Namestore
233 printf("DID Document has been removed\n"); 245 printf("DID Document has been removed\n");
234 GNUNET_SCHEDULER_add_now(cleanup, NULL); 246 GNUNET_SCHEDULER_add_now(cleanup, NULL);
@@ -243,48 +255,50 @@ remove_did_cb(){
243 * @param ego the ego returned by the identity service 255 * @param ego the ego returned by the identity service
244 */ 256 */
245static void 257static void
246remove_did_ego_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego){ 258remove_did_ego_lookup_cb(void * cls, struct GNUNET_IDENTITY_Ego * ego){
247 const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego); 259 //const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego);
248 const int emp[0]; 260 //const int emp[0];
249 struct GNUNET_GNSRECORD_Data rd = { 261 //struct GNUNET_GNSRECORD_Data rd = {
250 .data = &emp, 262 // .data = &emp,
251 .expiration_time = 0, 263 // .expiration_time = 0,
252 .data_size = 0, 264 // .data_size = 0,
253 .record_type = 0, 265 // .record_type = 0,
254 .flags = GNUNET_GNSRECORD_RF_NONE 266 // .flags = GNUNET_GNSRECORD_RF_NONE
255 }; 267 //};
256 268
257 GNUNET_NAMESTORE_records_store (namestore_handle, 269 struct remove_did_document_cont_cls * blob = (struct remove_did_document_cont_cls *) cls;
258 skey, 270 printf("2: %d\n", * ((int *) (blob->cls)));
259 "didd", 271
260 0, 272 //GNUNET_NAMESTORE_records_store (namestore_handle,
261 &rd, 273 // skey,
262 &remove_did_cb, 274 // "didd",
263 NULL); 275 // 0,
276 // &rd,
277 // &remove_did_cb,
278 // NULL);
264} 279}
265 280
281
266/** 282/**
267 * @brief Remove a DID Document 283 * @brief Remove a DID Document
268 */ 284 */
269static void 285static void
270remove_did_document() 286remove_did_document(remove_did_document_callback cont, void * cls)
271{ 287{
272 if(attr_ego == NULL) { 288 if(attr_ego == NULL) {
273 printf("Remove requieres an ego option\n"); 289 printf("Remove requieres an ego option\n");
274 GNUNET_SCHEDULER_add_now(cleanup, NULL); 290 GNUNET_SCHEDULER_add_now(cleanup, NULL);
275 ret = 1; 291 ret = 1;
276 return; 292 return;
277 } else if (attr_ego != NULL) { 293 } else {
294 struct remove_did_document_cont_cls blob = {cont, cls};
295 printf("1: %d\n", * (int *) blob.cls);
296
278 GNUNET_IDENTITY_ego_lookup(my_cfg, 297 GNUNET_IDENTITY_ego_lookup(my_cfg,
279 attr_ego, 298 attr_ego,
280 &remove_did_ego_lookup_cb, 299 &remove_did_ego_lookup_cb,
281 NULL); 300 (void *) &blob);
282 } else { 301 }
283 printf("Something during the remove went wrong. Make sure you set the options correct\n");
284 GNUNET_SCHEDULER_add_now(&cleanup, NULL);
285 ret = 1;
286 return;
287 }
288} 302}
289 303
290 304
@@ -334,10 +348,17 @@ create_did_generate(struct GNUNET_IDENTITY_PublicKey pkey)
334 printf("DID Document could not be encoded"); 348 printf("DID Document could not be encoded");
335 GNUNET_SCHEDULER_add_now(&cleanup, NULL); 349 GNUNET_SCHEDULER_add_now(&cleanup, NULL);
336 ret = 1; 350 ret = 1;
337 return; 351 return NULL;
338 } 352 }
339 353
340 // TODO: FREEEEEE 354 free(did_json);
355 free(pkey_multibase_json);
356 free(context_1_json);
357 free(context_2_json);
358 free(auth_type_json);
359 free(auth_json);
360 free(auth_1_json);
361 free(didd);
341 362
342 return didd_str; 363 return didd_str;
343} 364}
@@ -404,6 +425,7 @@ create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego)
404 printf("DEBUG: Key type: %d\n", pkey.type); 425 printf("DEBUG: Key type: %d\n", pkey.type);
405 426
406 // check if the key is of right type (EDDSA) 427 // check if the key is of right type (EDDSA)
428
407 // What does "Defined by the GNS zone type value in NBO" mean? 429 // What does "Defined by the GNS zone type value in NBO" mean?
408 //if (pkey.type != GNUNET_IDENTITY_TYPE_EDDSA) { 430 //if (pkey.type != GNUNET_IDENTITY_TYPE_EDDSA) {
409 if (false) 431 if (false)
@@ -414,10 +436,17 @@ create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego)
414 return; 436 return;
415 } 437 }
416 438
417 // TODO: Check if a an option with a DID Docuement was supplied 439 char * didd_str;
418 440
419 // Generate DID Docuement from public key 441 if(attr_didd != NULL)
420 char * didd_str = create_did_generate(pkey); 442 {
443 // TODO: Check if given DIDD is valid
444 printf("DID Docuement is read from \"did-document\" argument (EXPERIMENTAL)\n");
445 didd_str = attr_didd;
446 } else {
447 // Generate DID Docuement from public key
448 didd_str = create_did_generate(pkey);
449 }
421 450
422 // Print DID Docuement to stdout 451 // Print DID Docuement to stdout
423 printf("%s\n", didd_str); 452 printf("%s\n", didd_str);
@@ -476,11 +505,26 @@ create_did_document()
476 } 505 }
477} 506}
478 507
508static void
509hello_world(void * arg)
510{
511 printf("arg: %d\n", * (int *) arg);
512 printf("Hello World!\n");
513 GNUNET_SCHEDULER_add_now(&cleanup, NULL);
514 ret = 1;
515 return;
516}
479 517
480static void 518static void
481add_did_document() 519replace_did_document()
482{ 520{
483 printf("Do nothing\n"); 521 // Do remove
522 // Change remove to use coustome cb
523 // use create_did_store
524
525 int var = 42;
526
527 remove_did_document(&hello_world, (void *) &var);
484} 528}
485 529
486 530
@@ -513,20 +557,12 @@ run (void *cls,
513 return; 557 return;
514 } 558 }
515 559
516 // TODO: Check for more than one argument given 560 if (1 == attr_replace) {
517 if(false) 561 replace_did_document();
518 {
519 ret = 1;
520 GNUNET_SCHEDULER_add_now(cleanup, NULL);
521 return;
522 }
523
524 if (1 == attr_add) {
525 add_did_document();
526 } else if (1 == attr_get) { 562 } else if (1 == attr_get) {
527 resolve_did_document(); 563 resolve_did_document();
528 } else if (1 == attr_remove) { 564 } else if (1 == attr_remove) {
529 remove_did_document(); 565 remove_did_document(&remove_did_cb, NULL);
530 } else if (1 == attr_create) { 566 } else if (1 == attr_create) {
531 create_did_document(); 567 create_did_document();
532 } else if (1 == attr_show) { 568 } else if (1 == attr_show) {
@@ -548,10 +584,6 @@ main (int argc, char *const argv[])
548 "create", 584 "create",
549 gettext_noop ("Create a DID Document and display its DID"), 585 gettext_noop ("Create a DID Document and display its DID"),
550 &attr_create), 586 &attr_create),
551 GNUNET_GETOPT_option_flag ('a',
552 "add",
553 gettext_noop ("Add a DID Document and display its DID"),
554 &attr_add),
555 GNUNET_GETOPT_option_flag ('g', 587 GNUNET_GETOPT_option_flag ('g',
556 "get", 588 "get",
557 gettext_noop ("Get the DID Document associated with the given DID"), 589 gettext_noop ("Get the DID Document associated with the given DID"),
@@ -564,11 +596,20 @@ main (int argc, char *const argv[])
564 "remove", 596 "remove",
565 gettext_noop ("Remove the DID Document with DID from GNUNET"), 597 gettext_noop ("Remove the DID Document with DID from GNUNET"),
566 &attr_remove), 598 &attr_remove),
599 GNUNET_GETOPT_option_flag ('R',
600 "replace",
601 gettext_noop ("Replace the DID Document."),
602 &attr_replace),
567 GNUNET_GETOPT_option_string ('d', 603 GNUNET_GETOPT_option_string ('d',
568 "did", 604 "did",
569 "DID", 605 "DID",
570 gettext_noop ("The DID to work with"), 606 gettext_noop ("The DID to work with"),
571 &attr_did), 607 &attr_did),
608 GNUNET_GETOPT_option_string ('D',
609 "did-docuement",
610 "JSON",
611 gettext_noop ("The DID Document to store in GNUNET"),
612 &attr_didd),
572 GNUNET_GETOPT_option_string ('e', 613 GNUNET_GETOPT_option_string ('e',
573 "ego", 614 "ego",
574 "EGO", 615 "EGO",