aboutsummaryrefslogtreecommitdiff
path: root/src/identity-token
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-09-14 12:52:50 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-09-14 12:52:50 +0000
commit215e6b26f3a8cda9e6829f06dcf069606a644e97 (patch)
treede35ae63481bcb792cd3b7e9c29a0da17fbd7fcc /src/identity-token
parenta03831ba80b2936e19a4b64f512d557dfa0adf43 (diff)
downloadgnunet-215e6b26f3a8cda9e6829f06dcf069606a644e97.tar.gz
gnunet-215e6b26f3a8cda9e6829f06dcf069606a644e97.zip
- fix install path for plugins
Diffstat (limited to 'src/identity-token')
-rw-r--r--src/identity-token/Makefile.am2
-rw-r--r--src/identity-token/plugin_rest_identity_token.c559
2 files changed, 91 insertions, 470 deletions
diff --git a/src/identity-token/Makefile.am b/src/identity-token/Makefile.am
index a5c36aff2..227909424 100644
--- a/src/identity-token/Makefile.am
+++ b/src/identity-token/Makefile.am
@@ -20,7 +20,7 @@ pkgcfg_DATA = \
20 identity-token.conf 20 identity-token.conf
21 21
22if HAVE_REST 22if HAVE_REST
23lib_LTLIBRARIES = \ 23plugin_LTLIBRARIES = \
24 libgnunet_plugin_rest_identity_token.la 24 libgnunet_plugin_rest_identity_token.la
25endif 25endif
26 26
diff --git a/src/identity-token/plugin_rest_identity_token.c b/src/identity-token/plugin_rest_identity_token.c
index e5abe00ee..d0694d6ed 100644
--- a/src/identity-token/plugin_rest_identity_token.c
+++ b/src/identity-token/plugin_rest_identity_token.c
@@ -35,50 +35,44 @@
35/** 35/**
36 * REST root namespace 36 * REST root namespace
37 */ 37 */
38#define GNUNET_REST_API_NS_IDENTITY "/identity" 38#define GNUNET_REST_API_NS_IDENTITY_TOKEN "/token"
39 39
40/** 40/**
41 * State while collecting all egos 41 * Issue namespace
42 */ 42 */
43#define ID_REST_STATE_INIT 0 43#define GNUNET_REST_API_NS_IDENTITY_TOKEN_ISSUE "/token/issue"
44 44
45/** 45/**
46 * Done collecting egos 46 * Check namespace
47 */ 47 */
48#define ID_REST_STATE_POST_INIT 1 48#define GNUNET_REST_API_NS_IDENTITY_TOKEN_CHECK "/token/check"
49 49
50/**
51 * Resource type
52 */
53#define GNUNET_REST_JSONAPI_IDENTITY_EGO "ego"
54 50
55/** 51/**
56 * Name attribute 52 * State while collecting all egos
57 */ 53 */
58#define GNUNET_REST_JSONAPI_IDENTITY_NAME "name" 54#define ID_REST_STATE_INIT 0
59 55
60/** 56/**
61 * Attribute to rename "name" TODO we changed id to the pubkey 57 * Done collecting egos
62 * so this can be unified with "name"
63 */ 58 */
64#define GNUNET_REST_JSONAPI_IDENTITY_NEWNAME "newname" 59#define ID_REST_STATE_POST_INIT 1
65 60
66/** 61/**
67 * URL parameter to change the subsytem for ego 62 * Resource type
68 */ 63 */
69#define GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM "subsystem" 64#define GNUNET_REST_JSONAPI_IDENTITY_TOKEN "token"
70
71 65
72/** 66/**
73 * URL parameter to create a GNUid token for a specific audience 67 * URL parameter to create a GNUid token for a specific audience
74 */ 68 */
75#define GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN "create_token_for" 69#define GNUNET_REST_JSONAPI_IDENTITY_AUD_REQUEST "audience"
76 70
77/** 71/**
78 * Attribute containing the GNUid token if 72 * URL parameter to create a GNUid token for a specific issuer (EGO)
79 * GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN was requested
80 */ 73 */
81#define GNUNET_REST_JSONAPI_IDENTITY_GNUID "gnuid_token" 74#define GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST "issuer"
75
82 76
83/** 77/**
84 * Error messages 78 * Error messages
@@ -199,11 +193,6 @@ struct RequestHandle
199 char *name; 193 char *name;
200 194
201 /** 195 /**
202 * The subsystem set from REST
203 */
204 char *subsys;
205
206 /**
207 * The url 196 * The url
208 */ 197 */
209 char *url; 198 char *url;
@@ -248,8 +237,6 @@ cleanup_handle (struct RequestHandle *handle)
248 GNUNET_SCHEDULER_cancel (handle->timeout_task); 237 GNUNET_SCHEDULER_cancel (handle->timeout_task);
249 if (NULL != handle->identity_handle) 238 if (NULL != handle->identity_handle)
250 GNUNET_IDENTITY_disconnect (handle->identity_handle); 239 GNUNET_IDENTITY_disconnect (handle->identity_handle);
251 if (NULL != handle->subsys)
252 GNUNET_free (handle->subsys);
253 if (NULL != handle->url) 240 if (NULL != handle->url)
254 GNUNET_free (handle->url); 241 GNUNET_free (handle->url);
255 if (NULL != handle->emsg) 242 if (NULL != handle->emsg)
@@ -298,8 +285,9 @@ do_error (void *cls,
298 * @param name name of the ego 285 * @param name name of the ego
299 * @param token_aud token audience 286 * @param token_aud token audience
300 * @param token the resulting gnuid token 287 * @param token the resulting gnuid token
288 * @return identifier string of token (label)
301 */ 289 */
302static void 290static char*
303make_gnuid_token (struct RequestHandle *handle, 291make_gnuid_token (struct RequestHandle *handle,
304 struct EgoEntry *ego_entry, 292 struct EgoEntry *ego_entry,
305 const char *name, 293 const char *name,
@@ -376,67 +364,9 @@ make_gnuid_token (struct RequestHandle *handle,
376 GNUNET_free (payload_str); 364 GNUNET_free (payload_str);
377 GNUNET_free (payload_base64); 365 GNUNET_free (payload_base64);
378 GNUNET_free (purpose); 366 GNUNET_free (purpose);
379 GNUNET_free (lbl_str);
380 json_decref (header); 367 json_decref (header);
381 json_decref (payload); 368 json_decref (payload);
382} 369 return lbl_str;
383
384/**
385 * Callback for IDENTITY_get()
386 *
387 * @param cls the RequestHandle
388 * @param ego the Ego found
389 * @param ctx the context
390 * @param name the id of the ego
391 */
392static void
393get_ego_for_subsys (void *cls,
394 struct GNUNET_IDENTITY_Ego *ego,
395 void **ctx,
396 const char *name)
397{
398 struct RequestHandle *handle = cls;
399 struct JsonApiObject *json_object;
400 struct JsonApiResource *json_resource;
401 struct EgoEntry *ego_entry;
402 struct MHD_Response *resp;
403 json_t *name_json;
404 char *result_str;
405
406 json_object = GNUNET_REST_jsonapi_object_new ();
407
408 for (ego_entry = handle->ego_head;
409 NULL != ego_entry;
410 ego_entry = ego_entry->next)
411 {
412 if ( (NULL != name) && (0 != strcmp (name, ego_entry->identifier)) )
413 continue;
414 if (NULL == name)
415 continue;
416 json_resource = GNUNET_REST_jsonapi_resource_new
417 (GNUNET_REST_JSONAPI_IDENTITY_EGO, ego_entry->keystring);
418 name_json = json_string (ego_entry->identifier);
419 GNUNET_REST_jsonapi_resource_add_attr (json_resource,
420 GNUNET_REST_JSONAPI_IDENTITY_NAME,
421 name_json);
422 json_decref (name_json);
423 GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource);
424 break;
425 }
426 if (0 == GNUNET_REST_jsonapi_object_resource_count (json_object))
427 {
428 GNUNET_REST_jsonapi_object_delete (json_object);
429 handle->emsg = GNUNET_strdup("No identity matches results!");
430 GNUNET_SCHEDULER_add_now (&do_error, handle);
431 return;
432 }
433 GNUNET_REST_jsonapi_data_serialize (json_object, &result_str);
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
435 resp = GNUNET_REST_create_json_response (result_str);
436 GNUNET_REST_jsonapi_object_delete (json_object);
437 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
438 GNUNET_free (result_str);
439 cleanup_handle (handle);
440} 370}
441 371
442/** 372/**
@@ -447,16 +377,16 @@ get_ego_for_subsys (void *cls,
447 * @param cls the request handle 377 * @param cls the request handle
448 */ 378 */
449static void 379static void
450ego_info_response (struct RestConnectionDataHandle *con, 380issue_token_cont (struct RestConnectionDataHandle *con,
451 const char *url, 381 const char *url,
452 void *cls) 382 void *cls)
453{ 383{
454 const char *egoname; 384 const char *egoname;
455 char *result_str; 385 char *result_str;
456 char *subsys_val; 386 char *res_id;
457 char *create_token_for; 387 char *ego_val;
458 char *token; 388 char *token;
459 char *keystring; 389 char *audience;
460 struct RequestHandle *handle = cls; 390 struct RequestHandle *handle = cls;
461 struct EgoEntry *ego_entry; 391 struct EgoEntry *ego_entry;
462 struct GNUNET_HashCode key; 392 struct GNUNET_HashCode key;
@@ -466,404 +396,97 @@ ego_info_response (struct RestConnectionDataHandle *con,
466 json_t *name_str; 396 json_t *name_str;
467 json_t *token_str; 397 json_t *token_str;
468 398
469 if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, GNUNET_REST_API_NS_IDENTITY)) 399 if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url,
400 GNUNET_REST_API_NS_IDENTITY_TOKEN_ISSUE))
470 { 401 {
471 resp = GNUNET_REST_create_json_response (NULL); 402 resp = GNUNET_REST_create_json_response (NULL);
472 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST); 403 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
473 cleanup_handle (handle); 404 cleanup_handle (handle);
474 return; 405 return;
475 } 406 }
407
476 egoname = NULL; 408 egoname = NULL;
477 keystring = NULL; 409 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST,
478 if (strlen (GNUNET_REST_API_NS_IDENTITY) < strlen (handle->url)) 410 strlen (GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST),
479 {
480 keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY)+1];
481 //Return all egos
482 for (ego_entry = handle->ego_head;
483 NULL != ego_entry;
484 ego_entry = ego_entry->next)
485 {
486 if ( (NULL != keystring) && (0 != strcmp (keystring, ego_entry->keystring)) )
487 continue;
488 egoname = ego_entry->identifier;
489 }
490 }
491
492 if ( NULL == egoname ) {
493 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM,
494 strlen (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM),
495 &key);
496 if ( GNUNET_YES ==
497 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
498 &key) )
499 {
500 subsys_val = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
501 &key);
502 if (NULL != subsys_val)
503 {
504 GNUNET_asprintf (&handle->subsys, "%s", subsys_val);
505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsys_val);
506 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
507 handle->subsys,
508 &get_ego_for_subsys,
509 handle);
510 return;
511 }
512 }
513 }
514
515 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN,
516 strlen (GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN),
517 &key); 411 &key);
518
519 //Token audience
520 create_token_for = NULL;
521 if ( GNUNET_YES == 412 if ( GNUNET_YES ==
522 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map, 413 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
523 &key) ) 414 &key) )
524 create_token_for = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
525 &key);
526
527 json_object = GNUNET_REST_jsonapi_object_new ();
528
529 //Return all egos
530 for (ego_entry = handle->ego_head;
531 NULL != ego_entry;
532 ego_entry = ego_entry->next)
533 { 415 {
534 if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) ) 416 ego_val = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
535 continue; 417 &key);
536 json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_IDENTITY_EGO, 418 if (NULL != ego_val)
537 ego_entry->keystring);
538 name_str = json_string (ego_entry->identifier);
539 GNUNET_REST_jsonapi_resource_add_attr (
540 json_resource,
541 GNUNET_REST_JSONAPI_IDENTITY_NAME,
542 name_str);
543 json_decref (name_str);
544 if (NULL != create_token_for)
545 { 419 {
546 make_gnuid_token (handle, 420 for (ego_entry = handle->ego_head;
547 ego_entry, 421 NULL != ego_entry;
548 ego_entry->identifier, 422 ego_entry = ego_entry->next)
549 create_token_for, 423 {
550 &token); 424 if (0 != strcmp (ego_val, ego_entry->keystring))
551 token_str = json_string (token); 425 continue;
552 GNUNET_free (token); 426 egoname = ego_entry->identifier;
553 GNUNET_REST_jsonapi_resource_add_attr (json_resource, 427 }
554 GNUNET_REST_JSONAPI_IDENTITY_GNUID, 428 GNUNET_free (ego_val);
555 token_str);
556 json_decref (token_str);
557 } 429 }
558 GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource); 430 if (NULL == egoname)
559 }
560 if (0 == GNUNET_REST_jsonapi_object_resource_count (json_object))
561 {
562 GNUNET_REST_jsonapi_object_delete (json_object);
563 handle->emsg = GNUNET_strdup ("No identities found!");
564 GNUNET_SCHEDULER_add_now (&do_error, handle);
565 return;
566 }
567 GNUNET_REST_jsonapi_data_serialize (json_object, &result_str);
568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
569 resp = GNUNET_REST_create_json_response (result_str);
570 GNUNET_REST_jsonapi_object_delete (json_object);
571 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
572 GNUNET_free (result_str);
573 cleanup_handle (handle);
574}
575
576/**
577 * Processing finished
578 *
579 * @param cls request handle
580 * @param emsg error message
581 */
582static void
583do_finished (void *cls, const char *emsg)
584{
585 struct RequestHandle *handle = cls;
586 struct MHD_Response *resp;
587
588 handle->op = NULL;
589 if (NULL != emsg)
590 {
591 handle->emsg = GNUNET_strdup (emsg);
592 GNUNET_SCHEDULER_add_now (&do_error, handle);
593 return;
594 }
595 resp = GNUNET_REST_create_json_response (NULL);
596 handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
597 cleanup_handle (handle);
598}
599
600/**
601 * Create a new ego
602 *
603 * @param con rest handle
604 * @param url url
605 * @param cls request handle
606 */
607static void
608ego_create_cont (struct RestConnectionDataHandle *con,
609 const char *url,
610 void *cls)
611{
612 struct RequestHandle *handle = cls;
613 struct EgoEntry *ego_entry;
614 struct MHD_Response *resp;
615 struct JsonApiObject *json_obj;
616 struct JsonApiResource *json_res;
617 json_t *egoname_json;
618 const char* egoname;
619 char term_data[handle->data_size+1];
620
621 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
622 {
623 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
624 GNUNET_SCHEDULER_add_now (&do_error, handle);
625 return;
626 }
627 if (0 >= handle->data_size)
628 {
629 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
630 GNUNET_SCHEDULER_add_now (&do_error, handle);
631 return;
632 }
633 term_data[handle->data_size] = '\0';
634 memcpy (term_data, handle->data, handle->data_size);
635 json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
636 if (NULL == json_obj)
637 {
638 GNUNET_SCHEDULER_add_now (&do_error, handle);
639 return;
640 }
641 if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
642 {
643 GNUNET_REST_jsonapi_object_delete (json_obj);
644 handle->emsg = GNUNET_strdup ("Provided resource count invalid");
645 GNUNET_SCHEDULER_add_now (&do_error, handle);
646 return;
647 }
648 json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
649 if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO))
650 {
651 GNUNET_REST_jsonapi_object_delete (json_obj);
652 resp = GNUNET_REST_create_json_response (NULL);
653 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
654 cleanup_handle (handle);
655 return;
656 }
657 egoname_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_NAME);
658 if (!json_is_string (egoname_json))
659 {
660 GNUNET_REST_jsonapi_object_delete (json_obj);
661 handle->emsg = GNUNET_strdup ("No name provided");
662 GNUNET_SCHEDULER_add_now (&do_error, handle);
663 return;
664 }
665 egoname = json_string_value (egoname_json);
666 for (ego_entry = handle->ego_head;
667 NULL != ego_entry;
668 ego_entry = ego_entry->next)
669 {
670 if (0 == strcasecmp (egoname, ego_entry->identifier))
671 { 431 {
672 GNUNET_REST_jsonapi_object_delete (json_obj);
673 resp = GNUNET_REST_create_json_response (NULL); 432 resp = GNUNET_REST_create_json_response (NULL);
674 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); 433 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
675 cleanup_handle (handle); 434 cleanup_handle (handle);
676 return; 435 return;
677 } 436 }
678 } 437 }
679 GNUNET_asprintf (&handle->name, "%s", egoname);
680 GNUNET_REST_jsonapi_object_delete (json_obj);
681 handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
682 handle->name,
683 &do_finished,
684 handle);
685}
686
687 438
688/** 439 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_AUD_REQUEST,
689 * Handle ego edit request 440 strlen (GNUNET_REST_JSONAPI_IDENTITY_AUD_REQUEST),
690 * 441 &key);
691 * @param con rest connection handle
692 * @param url the url that is requested
693 * @param cls the RequestHandle
694 */
695static void
696ego_edit_cont (struct RestConnectionDataHandle *con,
697 const char *url,
698 void *cls)
699{
700 struct JsonApiObject *json_obj;
701 struct JsonApiResource *json_res;
702 struct RequestHandle *handle = cls;
703 struct EgoEntry *ego_entry;
704 struct MHD_Response *resp;
705 json_t *subsys_json;
706 json_t *name_json;
707 const char *keystring;
708 const char *subsys;
709 const char *newname;
710 char term_data[handle->data_size+1];
711 int ego_exists = GNUNET_NO;
712
713 if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url))
714 {
715 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
716 GNUNET_SCHEDULER_add_now (&do_error, handle);
717 return;
718 }
719
720 keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
721
722 for (ego_entry = handle->ego_head;
723 NULL != ego_entry;
724 ego_entry = ego_entry->next)
725 {
726 if (0 != strcasecmp (keystring, ego_entry->keystring))
727 continue;
728 ego_exists = GNUNET_YES;
729 break;
730 }
731 442
732 if (GNUNET_NO == ego_exists) 443 //Token audience
444 audience = NULL;
445 if ( GNUNET_YES !=
446 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
447 &key) )
733 { 448 {
734 resp = GNUNET_REST_create_json_response (NULL); 449 resp = GNUNET_REST_create_json_response (NULL);
735 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); 450 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
736 cleanup_handle (handle); 451 cleanup_handle (handle);
737 return; 452 return;
738 } 453 }
454 audience = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
455 &key);
739 456
740 if (0 >= handle->data_size) 457 json_object = GNUNET_REST_jsonapi_object_new ();
741 {
742 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
743 GNUNET_SCHEDULER_add_now (&do_error, handle);
744 return;
745 }
746
747 term_data[handle->data_size] = '\0';
748 memcpy (term_data, handle->data, handle->data_size);
749 json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
750
751 if (NULL == json_obj)
752 {
753 handle->emsg = GNUNET_strdup ("Data invalid");
754 GNUNET_SCHEDULER_add_now (&do_error, handle);
755 return;
756 }
757
758 if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
759 {
760 GNUNET_REST_jsonapi_object_delete (json_obj);
761 handle->emsg = GNUNET_strdup ("Resource amount invalid");
762 GNUNET_SCHEDULER_add_now (&do_error, handle);
763 return;
764 }
765 json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
766
767 if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO))
768 {
769 GNUNET_REST_jsonapi_object_delete (json_obj);
770 handle->emsg = GNUNET_strdup ("Resource type invalid");
771 GNUNET_SCHEDULER_add_now (&do_error, handle);
772 return;
773 }
774
775 //This is a rename
776 name_json = GNUNET_REST_jsonapi_resource_read_attr (json_res,
777 GNUNET_REST_JSONAPI_IDENTITY_NEWNAME);
778 if ((NULL != name_json) && json_is_string (name_json))
779 {
780 newname = json_string_value (name_json);
781 for (ego_entry = handle->ego_head;
782 NULL != ego_entry;
783 ego_entry = ego_entry->next)
784 {
785 if (0 == strcasecmp (newname, ego_entry->identifier) &&
786 0 != strcasecmp (keystring, ego_entry->keystring))
787 {
788 //Ego with same name not allowed
789 GNUNET_REST_jsonapi_object_delete (json_obj);
790 resp = GNUNET_REST_create_json_response (NULL);
791 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
792 cleanup_handle (handle);
793 return;
794 }
795 }
796 handle->op = GNUNET_IDENTITY_rename (handle->identity_handle,
797 ego_entry->identifier,
798 newname,
799 &do_finished,
800 handle);
801 GNUNET_REST_jsonapi_object_delete (json_obj);
802 return;
803 }
804
805 //Set subsystem
806 subsys_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM);
807 if ( (NULL != subsys_json) && json_is_string (subsys_json))
808 {
809 subsys = json_string_value (subsys_json);
810 GNUNET_asprintf (&handle->subsys, "%s", subsys);
811 GNUNET_REST_jsonapi_object_delete (json_obj);
812 handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
813 handle->subsys,
814 ego_entry->ego,
815 &do_finished,
816 handle);
817 return;
818 }
819 GNUNET_REST_jsonapi_object_delete (json_obj);
820 handle->emsg = GNUNET_strdup ("Subsystem not provided");
821 GNUNET_SCHEDULER_add_now (&do_error, handle);
822}
823
824void
825ego_delete_cont (struct RestConnectionDataHandle *con_handle,
826 const char* url,
827 void *cls)
828{
829 const char *keystring;
830 struct EgoEntry *ego_entry;
831 struct MHD_Response *resp;
832 struct RequestHandle *handle = cls;
833 int ego_exists = GNUNET_NO;
834
835 if (strlen (GNUNET_REST_API_NS_IDENTITY) >= strlen (handle->url))
836 {
837 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
838 GNUNET_SCHEDULER_add_now (&do_error, handle);
839 return;
840 }
841
842 keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
843 for (ego_entry = handle->ego_head;
844 NULL != ego_entry;
845 ego_entry = ego_entry->next)
846 {
847 if (0 != strcasecmp (keystring, ego_entry->keystring))
848 continue;
849 ego_exists = GNUNET_YES;
850 break;
851 }
852 if (GNUNET_NO == ego_exists)
853 {
854 resp = GNUNET_REST_create_json_response (NULL);
855 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
856 cleanup_handle (handle);
857 return;
858 }
859 handle->op = GNUNET_IDENTITY_delete (handle->identity_handle,
860 ego_entry->identifier,
861 &do_finished,
862 handle);
863 458
459 //create token
460 res_id = make_gnuid_token (handle,
461 ego_entry,
462 ego_entry->identifier,
463 audience,
464 &token);
465 token_str = json_string (token);
466 json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_IDENTITY_TOKEN,
467 res_id);
468 GNUNET_free (res_id);
469 name_str = json_string (ego_entry->identifier);
470 GNUNET_REST_jsonapi_resource_add_attr (json_resource,
471 GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST,
472 name_str);
473 json_decref (name_str);
474
475 GNUNET_free (token);
476 GNUNET_REST_jsonapi_resource_add_attr (json_resource,
477 GNUNET_REST_JSONAPI_IDENTITY_TOKEN,
478 token_str);
479 json_decref (token_str);
480 GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource);
481 GNUNET_REST_jsonapi_data_serialize (json_object, &result_str);
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
483 resp = GNUNET_REST_create_json_response (result_str);
484 GNUNET_REST_jsonapi_object_delete (json_object);
485 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
486 GNUNET_free (result_str);
487 cleanup_handle (handle);
864} 488}
865 489
866
867/** 490/**
868 * Respond to OPTIONS request 491 * Respond to OPTIONS request
869 * 492 *
@@ -898,11 +521,9 @@ static void
898init_cont (struct RequestHandle *handle) 521init_cont (struct RequestHandle *handle)
899{ 522{
900 static const struct GNUNET_REST_RestConnectionHandler handlers[] = { 523 static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
901 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_info_response}, 524 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TOKEN_ISSUE, &issue_token_cont},
902 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create_cont}, 525 //{MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_TOKEN_CHECK, &check_token_cont},
903 {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &ego_edit_cont}, 526 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY_TOKEN, &options_cont},
904 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY, &ego_delete_cont},
905 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont},
906 GNUNET_REST_HANDLER_END 527 GNUNET_REST_HANDLER_END
907 }; 528 };
908 529
@@ -1029,7 +650,7 @@ rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
1029 * @return NULL on error, otherwise the plugin context 650 * @return NULL on error, otherwise the plugin context
1030 */ 651 */
1031void * 652void *
1032libgnunet_plugin_rest_identity_init (void *cls) 653libgnunet_plugin_rest_identity_token_init (void *cls)
1033{ 654{
1034 static struct Plugin plugin; 655 static struct Plugin plugin;
1035 struct GNUNET_REST_Plugin *api; 656 struct GNUNET_REST_Plugin *api;
@@ -1041,7 +662,7 @@ libgnunet_plugin_rest_identity_init (void *cls)
1041 plugin.cfg = cfg; 662 plugin.cfg = cfg;
1042 api = GNUNET_new (struct GNUNET_REST_Plugin); 663 api = GNUNET_new (struct GNUNET_REST_Plugin);
1043 api->cls = &plugin; 664 api->cls = &plugin;
1044 api->name = GNUNET_REST_API_NS_IDENTITY; 665 api->name = GNUNET_REST_API_NS_IDENTITY_TOKEN;
1045 api->process_request = &rest_identity_process_request; 666 api->process_request = &rest_identity_process_request;
1046 GNUNET_asprintf (&allow_methods, 667 GNUNET_asprintf (&allow_methods,
1047 "%s, %s, %s, %s, %s", 668 "%s, %s, %s, %s, %s",
@@ -1052,7 +673,7 @@ libgnunet_plugin_rest_identity_init (void *cls)
1052 MHD_HTTP_METHOD_OPTIONS); 673 MHD_HTTP_METHOD_OPTIONS);
1053 674
1054 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 675 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1055 _("Identity REST API initialized\n")); 676 _("Identity Token REST API initialized\n"));
1056 return api; 677 return api;
1057} 678}
1058 679
@@ -1064,7 +685,7 @@ libgnunet_plugin_rest_identity_init (void *cls)
1064 * @return always NULL 685 * @return always NULL
1065 */ 686 */
1066void * 687void *
1067libgnunet_plugin_rest_identity_done (void *cls) 688libgnunet_plugin_rest_identity_token_done (void *cls)
1068{ 689{
1069 struct GNUNET_REST_Plugin *api = cls; 690 struct GNUNET_REST_Plugin *api = cls;
1070 struct Plugin *plugin = api->cls; 691 struct Plugin *plugin = api->cls;
@@ -1073,7 +694,7 @@ libgnunet_plugin_rest_identity_done (void *cls)
1073 GNUNET_free_non_null (allow_methods); 694 GNUNET_free_non_null (allow_methods);
1074 GNUNET_free (api); 695 GNUNET_free (api);
1075 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1076 "Identity REST plugin is finished\n"); 697 "Identity Token REST plugin is finished\n");
1077 return NULL; 698 return NULL;
1078} 699}
1079 700