diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-09-15 10:09:58 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-09-15 10:09:58 +0000 |
commit | 34da67bc38727903c39136db9e17a804f172f3b7 (patch) | |
tree | a93f8921186918c0758f2fe48d5c37426b1ca29a | |
parent | 120fbd80a09ff7b4b934572c5ee295bf75b7046b (diff) | |
download | gnunet-34da67bc38727903c39136db9e17a804f172f3b7.tar.gz gnunet-34da67bc38727903c39136db9e17a804f172f3b7.zip |
- fix leaks, add token list
-rw-r--r-- | src/identity-token/plugin_rest_identity_token.c | 182 | ||||
-rw-r--r-- | src/rest/rest.c | 2 |
2 files changed, 177 insertions, 7 deletions
diff --git a/src/identity-token/plugin_rest_identity_token.c b/src/identity-token/plugin_rest_identity_token.c index f12069c32..8af6e8a00 100644 --- a/src/identity-token/plugin_rest_identity_token.c +++ b/src/identity-token/plugin_rest_identity_token.c | |||
@@ -244,6 +244,12 @@ struct RequestHandle | |||
244 | */ | 244 | */ |
245 | json_t *payload; | 245 | json_t *payload; |
246 | 246 | ||
247 | /** | ||
248 | * Response object | ||
249 | */ | ||
250 | struct JsonApiObject *resp_object; | ||
251 | |||
252 | |||
247 | }; | 253 | }; |
248 | 254 | ||
249 | 255 | ||
@@ -258,6 +264,8 @@ cleanup_handle (struct RequestHandle *handle) | |||
258 | struct EgoEntry *ego_tmp; | 264 | struct EgoEntry *ego_tmp; |
259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
260 | "Cleaning up\n"); | 266 | "Cleaning up\n"); |
267 | if (NULL != handle->resp_object) | ||
268 | GNUNET_REST_jsonapi_object_delete (handle->resp_object); | ||
261 | if (NULL != handle->name) | 269 | if (NULL != handle->name) |
262 | GNUNET_free (handle->name); | 270 | GNUNET_free (handle->name); |
263 | if (NULL != handle->timeout_task) | 271 | if (NULL != handle->timeout_task) |
@@ -340,7 +348,6 @@ sign_and_return_token (void *cls, | |||
340 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; | 348 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; |
341 | struct MHD_Response *resp; | 349 | struct MHD_Response *resp; |
342 | struct JsonApiResource *json_resource; | 350 | struct JsonApiResource *json_resource; |
343 | struct JsonApiObject *json_obj; | ||
344 | struct RequestHandle *handle = cls; | 351 | struct RequestHandle *handle = cls; |
345 | 352 | ||
346 | time = GNUNET_TIME_absolute_get().abs_value_us; | 353 | time = GNUNET_TIME_absolute_get().abs_value_us; |
@@ -396,7 +403,7 @@ sign_and_return_token (void *cls, | |||
396 | json_decref (handle->header); | 403 | json_decref (handle->header); |
397 | json_decref (handle->payload); | 404 | json_decref (handle->payload); |
398 | 405 | ||
399 | json_obj = GNUNET_REST_jsonapi_object_new (); | 406 | handle->resp_object = GNUNET_REST_jsonapi_object_new (); |
400 | 407 | ||
401 | json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_IDENTITY_TOKEN, | 408 | json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_IDENTITY_TOKEN, |
402 | lbl_str); | 409 | lbl_str); |
@@ -415,11 +422,10 @@ sign_and_return_token (void *cls, | |||
415 | GNUNET_REST_JSONAPI_IDENTITY_TOKEN, | 422 | GNUNET_REST_JSONAPI_IDENTITY_TOKEN, |
416 | token_str); | 423 | token_str); |
417 | json_decref (token_str); | 424 | json_decref (token_str); |
418 | GNUNET_REST_jsonapi_object_resource_add (json_obj, json_resource); | 425 | GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource); |
419 | GNUNET_REST_jsonapi_data_serialize (json_obj, &result_str); | 426 | GNUNET_REST_jsonapi_data_serialize (handle->resp_object, &result_str); |
420 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Result %s\n", result_str); | 427 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Result %s\n", result_str); |
421 | resp = GNUNET_REST_create_json_response (result_str); | 428 | resp = GNUNET_REST_create_json_response (result_str); |
422 | GNUNET_REST_jsonapi_object_delete (json_obj); | ||
423 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 429 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
424 | GNUNET_free (result_str); | 430 | GNUNET_free (result_str); |
425 | cleanup_handle (handle); | 431 | cleanup_handle (handle); |
@@ -598,7 +604,171 @@ issue_token_cont (struct RestConnectionDataHandle *con, | |||
598 | } | 604 | } |
599 | 605 | ||
600 | 606 | ||
607 | /** | ||
608 | * Build a GNUid token for identity | ||
609 | * @param handle the handle | ||
610 | * @param ego_entry the ego to build the token for | ||
611 | * @param name name of the ego | ||
612 | * @param token_aud token audience | ||
613 | * @param token the resulting gnuid token | ||
614 | * @return identifier string of token (label) | ||
615 | */ | ||
616 | static void | ||
617 | return_token_list (void *cls, | ||
618 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
619 | { | ||
620 | char* result_str; | ||
621 | struct RequestHandle *handle = cls; | ||
622 | struct MHD_Response *resp; | ||
623 | |||
624 | GNUNET_REST_jsonapi_data_serialize (handle->resp_object, &result_str); | ||
625 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Result %s\n", result_str); | ||
626 | resp = GNUNET_REST_create_json_response (result_str); | ||
627 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | ||
628 | GNUNET_free (result_str); | ||
629 | cleanup_handle (handle); | ||
630 | } | ||
631 | |||
632 | /** | ||
633 | * Collect all tokens for ego | ||
634 | */ | ||
635 | static void | ||
636 | token_collect (void *cls, | ||
637 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
638 | const char *label, | ||
639 | unsigned int rd_count, | ||
640 | const struct GNUNET_GNSRECORD_Data *rd) | ||
641 | { | ||
642 | int i; | ||
643 | char* data; | ||
644 | struct RequestHandle *handle = cls; | ||
645 | struct EgoEntry *ego_tmp; | ||
646 | struct JsonApiResource *json_resource; | ||
647 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | ||
648 | json_t *issuer; | ||
649 | json_t *token; | ||
650 | |||
651 | if (NULL == label) | ||
652 | { | ||
653 | ego_tmp = handle->ego_head; | ||
654 | GNUNET_CONTAINER_DLL_remove (handle->ego_head, | ||
655 | handle->ego_tail, | ||
656 | ego_tmp); | ||
657 | GNUNET_free (ego_tmp->identifier); | ||
658 | GNUNET_free (ego_tmp->keystring); | ||
659 | GNUNET_free (ego_tmp); | ||
660 | |||
661 | if (NULL == handle->ego_head) | ||
662 | { | ||
663 | //Done | ||
664 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding token END\n"); | ||
665 | handle->ns_it = NULL; | ||
666 | GNUNET_SCHEDULER_add_now (&return_token_list, handle); | ||
667 | return; | ||
668 | } | ||
669 | |||
670 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Next ego: %s\n", handle->ego_head->identifier); | ||
671 | priv_key = GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego); | ||
672 | handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, | ||
673 | priv_key, | ||
674 | &token_collect, | ||
675 | handle); | ||
676 | return; | ||
677 | } | ||
678 | |||
679 | for (i = 0; i < rd_count; i++) | ||
680 | { | ||
681 | if (rd[i].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN) | ||
682 | { | ||
683 | data = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
684 | rd[i].data, | ||
685 | rd[i].data_size); | ||
686 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding token: %s\n", data); | ||
687 | json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_IDENTITY_TOKEN, | ||
688 | label); | ||
689 | issuer = json_string (handle->ego_head->identifier); | ||
690 | GNUNET_REST_jsonapi_resource_add_attr (json_resource, | ||
691 | GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST, | ||
692 | issuer); | ||
693 | json_decref (issuer); | ||
694 | token = json_string (data); | ||
695 | GNUNET_REST_jsonapi_resource_add_attr (json_resource, | ||
696 | GNUNET_REST_JSONAPI_IDENTITY_TOKEN, | ||
697 | token); | ||
698 | json_decref (token); | ||
699 | |||
700 | GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource); | ||
701 | GNUNET_free (data); | ||
702 | } | ||
703 | } | ||
704 | |||
705 | GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it); | ||
706 | } | ||
707 | |||
708 | |||
709 | |||
710 | /** | ||
711 | * Respond to OPTIONS request | ||
712 | * | ||
713 | * @param con_handle the connection handle | ||
714 | * @param url the url | ||
715 | * @param cls the RequestHandle | ||
716 | */ | ||
717 | static void | ||
718 | list_token_cont (struct RestConnectionDataHandle *con_handle, | ||
719 | const char* url, | ||
720 | void *cls) | ||
721 | { | ||
722 | char* ego_val; | ||
723 | struct GNUNET_HashCode key; | ||
724 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | ||
725 | struct RequestHandle *handle = cls; | ||
726 | struct EgoEntry *ego_entry; | ||
727 | struct EgoEntry *ego_tmp; | ||
728 | |||
729 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST, | ||
730 | strlen (GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST), | ||
731 | &key); | ||
732 | |||
733 | if ( GNUNET_YES == | ||
734 | GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map, | ||
735 | &key) ) | ||
736 | { | ||
737 | ego_val = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, | ||
738 | &key); | ||
739 | //Remove non-matching egos | ||
740 | for (ego_entry = handle->ego_head; | ||
741 | NULL != ego_entry;) | ||
742 | { | ||
743 | ego_tmp = ego_entry; | ||
744 | ego_entry = ego_entry->next; | ||
745 | if (0 != strcmp (ego_val, ego_tmp->identifier)) | ||
746 | { | ||
747 | GNUNET_CONTAINER_DLL_remove (handle->ego_head, | ||
748 | handle->ego_tail, | ||
749 | ego_tmp); | ||
750 | GNUNET_free (ego_tmp->identifier); | ||
751 | GNUNET_free (ego_tmp->keystring); | ||
752 | GNUNET_free (ego_tmp); | ||
753 | } | ||
754 | } | ||
755 | } | ||
756 | handle->resp_object = GNUNET_REST_jsonapi_object_new (); | ||
757 | if (NULL == handle->ego_head) | ||
758 | { | ||
759 | //Done | ||
760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No results.\n"); | ||
761 | GNUNET_SCHEDULER_add_now (&return_token_list, handle); | ||
762 | return; | ||
763 | } | ||
764 | priv_key = GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego); | ||
765 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); | ||
766 | handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, | ||
767 | priv_key, | ||
768 | &token_collect, | ||
769 | handle); | ||
601 | 770 | ||
771 | } | ||
602 | 772 | ||
603 | 773 | ||
604 | /** | 774 | /** |
@@ -637,6 +807,7 @@ init_cont (struct RequestHandle *handle) | |||
637 | static const struct GNUNET_REST_RestConnectionHandler handlers[] = { | 807 | static const struct GNUNET_REST_RestConnectionHandler handlers[] = { |
638 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TOKEN_ISSUE, &issue_token_cont}, | 808 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TOKEN_ISSUE, &issue_token_cont}, |
639 | //{MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_TOKEN_CHECK, &check_token_cont}, | 809 | //{MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_TOKEN_CHECK, &check_token_cont}, |
810 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TOKEN, &list_token_cont}, | ||
640 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY_TOKEN, &options_cont}, | 811 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY_TOKEN, &options_cont}, |
641 | GNUNET_REST_HANDLER_END | 812 | GNUNET_REST_HANDLER_END |
642 | }; | 813 | }; |
@@ -746,7 +917,6 @@ rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle, | |||
746 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, | 917 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, |
747 | &list_ego, | 918 | &list_ego, |
748 | handle); | 919 | handle); |
749 | GNUNET_strdup ("Timeout"); | ||
750 | handle->timeout_task = | 920 | handle->timeout_task = |
751 | GNUNET_SCHEDULER_add_delayed (handle->timeout, | 921 | GNUNET_SCHEDULER_add_delayed (handle->timeout, |
752 | &do_error, | 922 | &do_error, |
diff --git a/src/rest/rest.c b/src/rest/rest.c index 95a5d0605..d04bfdee1 100644 --- a/src/rest/rest.c +++ b/src/rest/rest.c | |||
@@ -305,10 +305,10 @@ GNUNET_REST_jsonapi_object_delete (struct JsonApiObject *resp) | |||
305 | for (res = resp->res_list_head; | 305 | for (res = resp->res_list_head; |
306 | res != NULL;) | 306 | res != NULL;) |
307 | { | 307 | { |
308 | res_next = res->next; | ||
308 | GNUNET_CONTAINER_DLL_remove (resp->res_list_head, | 309 | GNUNET_CONTAINER_DLL_remove (resp->res_list_head, |
309 | resp->res_list_tail, | 310 | resp->res_list_tail, |
310 | res); | 311 | res); |
311 | res_next = res->next; | ||
312 | GNUNET_REST_jsonapi_resource_delete (res); | 312 | GNUNET_REST_jsonapi_resource_delete (res); |
313 | res = res_next; | 313 | res = res_next; |
314 | } | 314 | } |