diff options
Diffstat (limited to 'src/reclaim/gnunet-did.c')
-rw-r--r-- | src/reclaim/gnunet-did.c | 212 |
1 files changed, 89 insertions, 123 deletions
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c index 3629c22f8..18b171486 100644 --- a/src/reclaim/gnunet-did.c +++ b/src/reclaim/gnunet-did.c | |||
@@ -205,16 +205,16 @@ get_did_for_ego () | |||
205 | * @param rd the records in the reply | 205 | * @param rd the records in the reply |
206 | */ | 206 | */ |
207 | static void | 207 | static void |
208 | print_did_document( | 208 | print_did_document ( |
209 | enum GNUNET_GenericReturnValue status, | 209 | enum GNUNET_GenericReturnValue status, |
210 | char *did_document, | 210 | char *did_document, |
211 | void *cls | 211 | void *cls |
212 | ) | 212 | ) |
213 | { | 213 | { |
214 | if (GNUNET_OK == status) | 214 | if (GNUNET_OK == status) |
215 | printf("%s\n", did_document); | 215 | printf ("%s\n", did_document); |
216 | else | 216 | else |
217 | printf("An error occured: %s\n", did_document); | 217 | printf ("An error occured: %s\n", did_document); |
218 | 218 | ||
219 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | 219 | GNUNET_SCHEDULER_add_now (cleanup, NULL); |
220 | ret = 0; | 220 | ret = 0; |
@@ -225,7 +225,7 @@ print_did_document( | |||
225 | * @brief Resolve a DID given by the user. | 225 | * @brief Resolve a DID given by the user. |
226 | */ | 226 | */ |
227 | static void | 227 | static void |
228 | resolve_did_document () | 228 | resolve_did () |
229 | { | 229 | { |
230 | struct GNUNET_IDENTITY_PublicKey pkey; | 230 | struct GNUNET_IDENTITY_PublicKey pkey; |
231 | 231 | ||
@@ -237,10 +237,10 @@ resolve_did_document () | |||
237 | return; | 237 | return; |
238 | } | 238 | } |
239 | 239 | ||
240 | if (GNUNET_OK != DID_resolve(did, gns_handle, print_did_document, NULL)) | 240 | if (GNUNET_OK != DID_resolve (did, gns_handle, print_did_document, NULL)) |
241 | { | 241 | { |
242 | printf("An error occured while resoling the DID\n"); | 242 | printf ("An error occured while resoling the DID\n"); |
243 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | 243 | GNUNET_SCHEDULER_add_now (cleanup, NULL); |
244 | ret = 0; | 244 | ret = 0; |
245 | return; | 245 | return; |
246 | } | 246 | } |
@@ -354,64 +354,53 @@ remove_did_document (remove_did_document_callback cont, void *cls) | |||
354 | } | 354 | } |
355 | } | 355 | } |
356 | 356 | ||
357 | static void create_did (); | ||
357 | 358 | ||
358 | /** | 359 | /** |
359 | * @brief Create a DID. Store DID in Namestore cb | 360 | * @brief Create a DID(-Document). Called after DID has been created |
360 | * | 361 | * |
361 | */ | 362 | */ |
362 | static void | 363 | static void |
363 | create_did_store_cb (void *cls, int32_t success, const char *emsg) | 364 | create_did_cb (enum GNUNET_GenericReturnValue status, void *cls) |
364 | { | 365 | { |
366 | struct GNUNET_IDENTITY_Ego *ego; | ||
367 | // char *did; | ||
368 | |||
369 | if (GNUNET_OK == status) | ||
370 | { | ||
371 | printf ("DID has been created\n"); | ||
372 | // ego = (struct GNUNET_IDENTITY_Ego *) cls; | ||
373 | // did = DID_identity_to_did(ego); | ||
374 | printf ("cls4: %s\n", (char *) cls); | ||
375 | } | ||
376 | else | ||
377 | printf ("An error occured while creating the DID\n"), ret = 1; | ||
378 | |||
365 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 379 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
366 | ret = 0; | ||
367 | return; | 380 | return; |
368 | } | 381 | } |
369 | 382 | ||
370 | /** | 383 | /** |
371 | * @brief Create a did. Store DID in Namestore | 384 | * @brief Create a DID(-Document) - Called after a new Identity has been created. |
372 | * | ||
373 | * @param didd_str String endoced DID Docuement | ||
374 | * @param ego Identity whos DID Document is stored | ||
375 | */ | 385 | */ |
376 | static void | 386 | static void |
377 | create_did_store (char *didd_str, struct GNUNET_IDENTITY_Ego *ego) | 387 | create_did_ego_create_cb (void *cls, |
388 | const struct GNUNET_IDENTITY_PrivateKey *pk, | ||
389 | const char *emsg) | ||
378 | { | 390 | { |
379 | 391 | if (emsg != NULL) | |
380 | struct GNUNET_TIME_Relative expire_time; | ||
381 | struct GNUNET_GNSRECORD_Data record_data; | ||
382 | const struct GNUNET_IDENTITY_PrivateKey *skey; | ||
383 | |||
384 | if (GNUNET_STRINGS_fancy_time_to_relative ((NULL != expire) ? | ||
385 | expire : | ||
386 | GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME, | ||
387 | &expire_time) == GNUNET_OK) | ||
388 | { | 392 | { |
389 | record_data.data = didd_str; | 393 | printf ("%s\n", emsg); |
390 | record_data.expiration_time = expire_time.rel_value_us; | ||
391 | record_data.data_size = strlen (didd_str) + 1; | ||
392 | record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"), | ||
393 | record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
394 | |||
395 | skey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
396 | |||
397 | GNUNET_NAMESTORE_records_store (namestore_handle, | ||
398 | skey, | ||
399 | GNUNET_GNS_EMPTY_LABEL_AT, | ||
400 | 1, // FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records | ||
401 | &record_data, | ||
402 | &create_did_store_cb, | ||
403 | NULL); | ||
404 | } | ||
405 | else { | ||
406 | printf ("Failed to read given expiration time\n"); | ||
407 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 394 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
408 | ret = 1; | 395 | ret = 1; |
409 | return; | 396 | return; |
410 | } | 397 | } |
398 | |||
399 | create_did (); | ||
411 | } | 400 | } |
412 | 401 | ||
413 | /** | 402 | /** |
414 | * @brief Create a did ego lockup cb | 403 | * @brief Create a DID(-Document). Called after ego lookup |
415 | * | 404 | * |
416 | * @param cls | 405 | * @param cls |
417 | * @param ego | 406 | * @param ego |
@@ -419,96 +408,71 @@ create_did_store (char *didd_str, struct GNUNET_IDENTITY_Ego *ego) | |||
419 | static void | 408 | static void |
420 | create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | 409 | create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) |
421 | { | 410 | { |
422 | struct GNUNET_IDENTITY_PublicKey pkey; | 411 | // struct GNUNET_IDENTITY_Ego *ego_test; |
423 | char *didd_str; | 412 | struct GNUNET_IDENTITY_PublicKey *pkey_test; |
413 | printf("test3\n"); | ||
424 | 414 | ||
425 | if (ego == NULL) | 415 | if (ego == NULL) |
426 | { | 416 | { |
427 | printf ("EGO not found\n"); | 417 | // If Ego was not found. Create new one first |
428 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 418 | printf ("Ego was not found. Creating new one.\n"); |
429 | ret = 1; | ||
430 | return; | ||
431 | } | ||
432 | 419 | ||
433 | GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); | 420 | GNUNET_IDENTITY_create (identity_handle, |
434 | 421 | egoname, | |
435 | if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY) | 422 | NULL, |
436 | { | 423 | GNUNET_IDENTITY_TYPE_EDDSA, |
437 | printf ("The EGO has to have an EDDSA key pair\n"); | 424 | &create_did_ego_create_cb, |
438 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 425 | egoname); |
439 | ret = 1; | ||
440 | return; | ||
441 | } | 426 | } |
442 | 427 | else | |
443 | if (didd != NULL) | ||
444 | { | 428 | { |
445 | printf ( | 429 | printf("test1\n"); |
446 | "DID Docuement is read from \"did-document\" argument (EXPERIMENTAL)\n"); | 430 | cls = (void *) ego; |
447 | didd_str = strdup (didd); | ||
448 | } | ||
449 | else { | ||
450 | // Generate DID Docuement from public key | ||
451 | didd_str = DID_pkey_to_did_document (&pkey); | ||
452 | } | ||
453 | 431 | ||
454 | // Print DID Document to stdout | 432 | // TEST |
455 | printf ("%s\n", didd_str); | 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"); | ||
456 | 437 | ||
457 | // Store the DID Document | 438 | // TODO: Check if ego already has a DID document |
458 | create_did_store (didd_str, ego); | 439 | // DO a resolve |
459 | 440 | ||
460 | // Save DID Document String to GNS | 441 | DID_create (ego, NULL, my_cfg, identity_handle, namestore_handle, |
461 | free (didd_str); | 442 | create_did_cb, cls); |
443 | } | ||
462 | } | 444 | } |
463 | 445 | ||
464 | /** | 446 | /** |
465 | * @brief Create a did document - Create a new identity first | 447 | * @brief Create a DID(-Document). |
448 | * | ||
466 | */ | 449 | */ |
467 | static void | 450 | static void |
468 | create_did_document_ego_create_cb (void *cls, | 451 | create_did () |
469 | const struct GNUNET_IDENTITY_PrivateKey *pk, | ||
470 | const char *emsg) | ||
471 | { | 452 | { |
472 | 453 | if (expire == NULL) | |
473 | if (emsg != NULL) | ||
474 | { | 454 | { |
475 | printf ("%s\n", emsg); | 455 | printf ( |
456 | "Set the Expiration-time argument to create a new DID(-Document)\n"); | ||
476 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 457 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
477 | ret = 1; | 458 | ret = 1; |
478 | return; | 459 | return; |
479 | } | 460 | } |
480 | 461 | ||
481 | GNUNET_IDENTITY_ego_lookup (my_cfg, | 462 | if (egoname == NULL) |
482 | egoname, | ||
483 | &create_did_ego_lockup_cb, | ||
484 | NULL); | ||
485 | } | ||
486 | |||
487 | /** | ||
488 | * @brief Create a did document | ||
489 | * | ||
490 | */ | ||
491 | static void | ||
492 | create_did_document () | ||
493 | { | ||
494 | if ((egoname != NULL) && (expire != NULL)) | ||
495 | { | 463 | { |
496 | // TODO: Check if ego already has a DID document | 464 | printf ("Set the Ego argument to create a new DID(-Document)\n"); |
497 | |||
498 | GNUNET_IDENTITY_create (identity_handle, | ||
499 | egoname, | ||
500 | NULL, | ||
501 | GNUNET_IDENTITY_TYPE_EDDSA, | ||
502 | &create_did_document_ego_create_cb, | ||
503 | egoname); | ||
504 | } | ||
505 | else { | ||
506 | printf ( | ||
507 | "Set the EGO and the Expiration-time argument to create a new DID(-Document)\n"); | ||
508 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 465 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
509 | ret = 1; | 466 | ret = 1; |
510 | return; | 467 | return; |
511 | } | 468 | } |
469 | |||
470 | printf("test2\n"); | ||
471 | |||
472 | GNUNET_IDENTITY_ego_lookup (my_cfg, | ||
473 | egoname, | ||
474 | &create_did_ego_lockup_cb, | ||
475 | NULL); | ||
512 | } | 476 | } |
513 | 477 | ||
514 | 478 | ||
@@ -521,7 +485,7 @@ create_did_document () | |||
521 | static void | 485 | static void |
522 | replace_did_document_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | 486 | replace_did_document_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) |
523 | { | 487 | { |
524 | create_did_store (didd, ego); | 488 | // create_did_store (didd, ego); |
525 | } | 489 | } |
526 | 490 | ||
527 | /** | 491 | /** |
@@ -567,7 +531,7 @@ post_ego_iteration (void *cls) | |||
567 | } | 531 | } |
568 | else if (1 == get) | 532 | else if (1 == get) |
569 | { | 533 | { |
570 | resolve_did_document (); | 534 | resolve_did (); |
571 | } | 535 | } |
572 | else if (1 == remove_did) | 536 | else if (1 == remove_did) |
573 | { | 537 | { |
@@ -575,7 +539,7 @@ post_ego_iteration (void *cls) | |||
575 | } | 539 | } |
576 | else if (1 == create) | 540 | else if (1 == create) |
577 | { | 541 | { |
578 | create_did_document (); | 542 | create_did (); |
579 | } | 543 | } |
580 | else { | 544 | else { |
581 | // No Argument found | 545 | // No Argument found |
@@ -600,16 +564,18 @@ process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego, | |||
600 | GNUNET_SCHEDULER_add_now (&post_ego_iteration, NULL); | 564 | GNUNET_SCHEDULER_add_now (&post_ego_iteration, NULL); |
601 | return; | 565 | return; |
602 | } | 566 | } |
603 | if (NULL == name) | 567 | |
604 | return; | 568 | // if (NULL == name) |
605 | if ((1 == create) && | 569 | // return; |
606 | (0 == strncmp (name, egoname, strlen (egoname))) && | 570 | // if ((1 == create) && |
607 | (1 != ego_exists)) | 571 | // (0 == strncmp (name, egoname, strlen (egoname))) && |
608 | { | 572 | // (1 != ego_exists)) |
609 | fprintf (stderr, "%s already exists!\n", egoname); | 573 | // { |
610 | ego_exists = 1; | 574 | // fprintf (stderr, "%s already exists!\n", egoname); |
611 | return; | 575 | // ego_exists = 1; |
612 | } | 576 | // return; |
577 | // } | ||
578 | |||
613 | if (1 == show_all) | 579 | if (1 == show_all) |
614 | { | 580 | { |
615 | did_str = DID_identity_to_did (ego); | 581 | did_str = DID_identity_to_did (ego); |