GNUnet 0.21.0
reclaim_plugin.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
27#include "platform.h"
28#include "microhttpd.h"
29#include <inttypes.h>
30#include <jansson.h>
31#include "gnunet_gns_service.h"
34#include "gnunet_reclaim_lib.h"
36#include "gnunet_rest_lib.h"
37#include "gnunet_rest_plugin.h"
38#include "gnunet_signatures.h"
39#include "json_reclaim.h"
43#define GNUNET_REST_API_NS_RECLAIM "/reclaim"
44
48#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES "/reclaim/attributes"
49
53#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL "/reclaim/credential"
54
58#define GNUNET_REST_API_NS_IDENTITY_TICKETS "/reclaim/tickets"
59
63#define GNUNET_REST_API_NS_IDENTITY_REVOKE "/reclaim/revoke"
64
68#define GNUNET_REST_API_NS_IDENTITY_CONSUME "/reclaim/consume"
69
73#define ID_REST_STATE_INIT 0
74
78#define ID_REST_STATE_POST_INIT 1
79
84
88static char *allow_methods;
89
93static struct EgoEntry *ego_head;
94
98static struct EgoEntry *ego_tail;
99
103static int state;
104
109
114
118struct Plugin
119{
120 const struct GNUNET_CONFIGURATION_Handle *cfg;
121};
122
126struct EgoEntry
127{
131 struct EgoEntry *next;
132
136 struct EgoEntry *prev;
137
141 char *identifier;
142
146 char *keystring;
147
151 struct GNUNET_IDENTITY_Ego *ego;
152};
153
154
155struct RequestHandle
156{
160 struct RequestHandle *next;
161
165 struct RequestHandle *prev;
166
170 struct EgoEntry *ego_entry;
171
176
181
186
191
196
201
206
211
216
221
226
231
235 void *proc_cls;
236
240 char *url;
241
245 char *emsg;
246
250 int response_code;
251
255 json_t *resp_object;
256};
257
262
267
268
273static void
274cleanup_handle (void *cls)
275{
276 struct RequestHandle *handle = cls;
277
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
279 if (NULL != handle->resp_object)
280 json_decref (handle->resp_object);
281 if (NULL != handle->timeout_task)
282 GNUNET_SCHEDULER_cancel (handle->timeout_task);
283 if (NULL != handle->attr_it)
285 if (NULL != handle->cred_it)
287 if (NULL != handle->ticket_it)
289 if (NULL != handle->url)
290 GNUNET_free (handle->url);
291 if (NULL != handle->emsg)
292 GNUNET_free (handle->emsg);
293 if (NULL != handle->attr_list)
297 handle);
299}
300
301
307static void
308do_error (void *cls)
309{
310 struct RequestHandle *handle = cls;
311 struct MHD_Response *resp;
312 char *json_error;
313
314 GNUNET_asprintf (&json_error, "{ \"error\" : \"%s\" }", handle->emsg);
315 if (0 == handle->response_code)
316 {
317 handle->response_code = MHD_HTTP_BAD_REQUEST;
318 }
319 resp = GNUNET_REST_create_response (json_error);
320 GNUNET_assert (MHD_NO != MHD_add_response_header (resp, "Content-Type",
321 "application/json"));
322 handle->proc (handle->proc_cls, resp, handle->response_code);
324 GNUNET_free (json_error);
325}
326
327
333static void
334do_timeout (void *cls)
335{
336 struct RequestHandle *handle = cls;
337
338 handle->timeout_task = NULL;
340}
341
342
343static void
345{
347}
348
349
350static void
351finished_cont (void *cls, int32_t success, const char *emsg)
352{
353 struct RequestHandle *handle = cls;
354 struct MHD_Response *resp;
355
356 handle->idp_op = NULL;
357 if (GNUNET_OK != success)
358 {
360 return;
361 }
362 resp = GNUNET_REST_create_response (emsg);
363 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
364 "Content-Type",
365 "application/json"));
366 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
367 "Access-Control-Allow-Methods",
369 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
371}
372
373
374static void
375delete_finished_cb (void *cls, int32_t success, const char *emsg)
376{
377 struct RequestHandle *handle = cls;
378 struct MHD_Response *resp;
379
380 if (GNUNET_OK != success)
381 {
383 return;
384 }
385 resp = GNUNET_REST_create_response (emsg);
386 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
387 "Access-Control-Allow-Methods",
389 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
391}
392
393
399static void
401{
402 char *result_str;
403 struct RequestHandle *handle = cls;
404 struct MHD_Response *resp;
405
406 result_str = json_dumps (handle->resp_object, 0);
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
408 resp = GNUNET_REST_create_response (result_str);
409 GNUNET_assert (MHD_NO !=
410 MHD_add_response_header (resp,
411 "Access-Control-Allow-Methods",
413 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
414 GNUNET_free (result_str);
416}
417
418
419static void
421{
422 struct RequestHandle *handle = cls;
423
424 // Done
425 handle->attr_it = NULL;
426 handle->cred_it = NULL;
427 handle->ticket_it = NULL;
429}
430
431
436static void
438{
439 json_t *json_resource;
440 struct RequestHandle *handle = cls;
441 json_t *value;
442 char *tmp;
443
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n");
446 json_resource = json_object ();
447 GNUNET_free (tmp);
448 json_array_append (handle->resp_object, json_resource);
449
450 tmp =
452 sizeof(struct
454 value = json_string (tmp);
455 json_object_set_new (json_resource, "issuer", value);
456 GNUNET_free (tmp);
457 tmp =
459 sizeof(struct
461 value = json_string (tmp);
462 json_object_set_new (json_resource, "audience", value);
463 GNUNET_free (tmp);
465 value = json_string (tmp);
466 json_object_set_new (json_resource, "rnd", value);
467 GNUNET_free (tmp);
469}
470
471
472static void
474 const char *url,
475 void *cls)
476{
477 struct RequestHandle *handle = cls;
478 const struct GNUNET_CRYPTO_PrivateKey *identity_priv;
479 const char *identity;
480 struct EgoEntry *ego_entry;
481 struct GNUNET_RECLAIM_Credential *attribute;
482 struct GNUNET_TIME_Relative exp;
483 char term_data[handle->rest_handle->data_size + 1];
484 json_t *data_json;
485 json_error_t err;
486 struct GNUNET_JSON_Specification attrspec[] =
489
491 "Adding an credential for %s.\n",
492 handle->url);
493 if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen (
494 handle->url))
495 {
496 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
498 return;
499 }
500 identity = handle->url + strlen (
502
503 for (ego_entry = ego_head; NULL != ego_entry;
504 ego_entry = ego_entry->next)
505 if (0 == strcmp (identity, ego_entry->identifier))
506 break;
507
508 if (NULL == ego_entry)
509 {
510 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity);
511 return;
512 }
513 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
514
515 if (0 >= handle->rest_handle->data_size)
516 {
518 return;
519 }
520
521 term_data[handle->rest_handle->data_size] = '\0';
522 GNUNET_memcpy (term_data,
523 handle->rest_handle->data,
524 handle->rest_handle->data_size);
525 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
526 if (GNUNET_OK != GNUNET_JSON_parse (data_json, attrspec, NULL, NULL))
527 {
528 json_decref (data_json);
530 "Unable to parse JSON from %s\n",
531 term_data);
533 return;
534 }
535 json_decref (data_json);
536 if (NULL == attribute)
537 {
539 "Unable to parse credential from %s\n",
540 term_data);
542 return;
543 }
547 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
548 GNUNET_RECLAIM_id_generate (&attribute->id);
551 identity_priv,
552 attribute,
553 &exp,
555 handle);
556 GNUNET_JSON_parse_free (attrspec);
557}
558
559
564static void
566 const struct GNUNET_CRYPTO_PublicKey *identity,
567 const struct GNUNET_RECLAIM_Credential *cred)
568{
569 struct RequestHandle *handle = cls;
570 struct GNUNET_RECLAIM_AttributeList *attrs;
572 struct GNUNET_TIME_Absolute exp;
573 json_t *attr_obj;
574 json_t *cred_obj;
575 const char *type;
576 char *tmp_value;
577 char *id_str;
578 char *issuer;
579
580
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential: %s\n",
582 cred->name);
586 cred->data,
587 cred->data_size);
588 cred_obj = json_object ();
589 json_object_set_new (cred_obj, "value", json_string (tmp_value));
590 json_object_set_new (cred_obj, "name", json_string (cred->name));
592 json_object_set_new (cred_obj, "type", json_string (type));
593 if (NULL != issuer)
594 {
595 json_object_set_new (cred_obj, "issuer", json_string (issuer));
596 GNUNET_free (issuer);
597 }
599 &exp))
600 {
601 json_object_set_new (cred_obj, "expiration", json_integer (
602 exp.abs_value_us));
603 }
605 sizeof(cred->id));
606 json_object_set_new (cred_obj, "id", json_string (id_str));
607 GNUNET_free (tmp_value);
608 GNUNET_free (id_str);
609 if (NULL != attrs)
610 {
611 json_t *attr_arr = json_array ();
612 for (ale = attrs->list_head; NULL != ale; ale = ale->next)
613 {
614 tmp_value =
616 ale->attribute->data,
617 ale->attribute->data_size);
618 attr_obj = json_object ();
619 json_object_set_new (attr_obj, "value", json_string (tmp_value));
620 json_object_set_new (attr_obj, "name", json_string (
621 ale->attribute->name));
622
623 json_object_set_new (attr_obj, "flag", json_string ("1")); // FIXME
625 json_object_set_new (attr_obj, "type", json_string (type));
626 json_object_set_new (attr_obj, "id", json_string (""));
627 json_object_set_new (attr_obj, "credential", json_string (""));
628 json_array_append_new (attr_arr, attr_obj);
629 GNUNET_free (tmp_value);
630 }
631 json_object_set_new (cred_obj, "attributes", attr_arr);
632 }
633 json_array_append_new (handle->resp_object, cred_obj);
634 if (NULL != attrs)
637}
638
639
647static void
649 const char *url,
650 void *cls)
651{
652 struct RequestHandle *handle = cls;
653 const struct GNUNET_CRYPTO_PrivateKey *priv_key;
654 struct EgoEntry *ego_entry;
655 char *identity;
656
658 "Getting credentials for %s.\n",
659 handle->url);
660 if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen (
661 handle->url))
662 {
663 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
665 return;
666 }
667 identity = handle->url + strlen (
669
670 for (ego_entry = ego_head; NULL != ego_entry;
671 ego_entry = ego_entry->next)
672 if (0 == strcmp (identity, ego_entry->identifier))
673 break;
674 handle->resp_object = json_array ();
675
676
677 if (NULL == ego_entry)
678 {
679 // Done
680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
682 return;
683 }
684 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
686 priv_key,
688 handle,
690 handle,
691 &
693 handle);
694}
695
696
704static void
706 const char *url,
707 void *cls)
708{
709 struct RequestHandle *handle = cls;
710 const struct GNUNET_CRYPTO_PrivateKey *priv_key;
711 struct GNUNET_RECLAIM_Credential attr;
712 struct EgoEntry *ego_entry;
713 char *identity_id_str;
714 char *identity;
715 char *id;
716
717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting credential.\n");
718 if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen (
719 handle->url))
720 {
721 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
723 return;
724 }
725 identity_id_str =
726 strdup (handle->url + strlen (
728 identity = strtok (identity_id_str, "/");
729 id = strtok (NULL, "/");
730 if ((NULL == identity) || (NULL == id))
731 {
732 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
733 GNUNET_free (identity_id_str);
735 return;
736 }
737
738 for (ego_entry = ego_head; NULL != ego_entry;
739 ego_entry = ego_entry->next)
740 if (0 == strcmp (identity, ego_entry->identifier))
741 break;
742 handle->resp_object = json_array ();
743 if (NULL == ego_entry)
744 {
745 // Done
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
747 GNUNET_free (identity_id_str);
749 return;
750 }
751 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
752 memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Credential));
753 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
754 attr.name = "";
756 priv_key,
757 &attr,
759 handle);
760 GNUNET_free (identity_id_str);
761}
762
763
771static void
773 const char *url,
774 void *cls)
775{
776 const struct GNUNET_CRYPTO_PrivateKey *priv_key;
777 struct RequestHandle *handle = cls;
778 struct EgoEntry *ego_entry;
779 char *identity;
780
782 "Getting tickets for %s.\n",
783 handle->url);
784 if (strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) >= strlen (handle->url))
785 {
786 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
788 return;
789 }
791
792 for (ego_entry = ego_head; NULL != ego_entry;
793 ego_entry = ego_entry->next)
794 if (0 == strcmp (identity, ego_entry->identifier))
795 break;
796 handle->resp_object = json_array ();
797
798 if (NULL == ego_entry)
799 {
800 // Done
801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
803 return;
804 }
805 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
806 handle->ticket_it =
808 priv_key,
810 handle,
812 handle,
814 handle);
815}
816
817
818static void
820 const char *url,
821 void *cls)
822{
823 const struct GNUNET_CRYPTO_PrivateKey *identity_priv;
824 const char *identity;
825 struct RequestHandle *handle = cls;
826 struct EgoEntry *ego_entry;
827 struct GNUNET_RECLAIM_Attribute *attribute;
828 struct GNUNET_TIME_Relative exp;
829 char term_data[handle->rest_handle->data_size + 1];
830 json_t *data_json;
831 json_error_t err;
832 struct GNUNET_JSON_Specification attrspec[] =
834
836 "Adding an attribute for %s.\n",
837 handle->url);
838 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
839 {
840 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
842 return;
843 }
845
846 for (ego_entry = ego_head; NULL != ego_entry;
847 ego_entry = ego_entry->next)
848 if (0 == strcmp (identity, ego_entry->identifier))
849 break;
850
851 if (NULL == ego_entry)
852 {
853 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity);
854 return;
855 }
856 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
857
858 if (0 >= handle->rest_handle->data_size)
859 {
861 return;
862 }
863
864 term_data[handle->rest_handle->data_size] = '\0';
865 GNUNET_memcpy (term_data,
866 handle->rest_handle->data,
867 handle->rest_handle->data_size);
868 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
870 GNUNET_JSON_parse (data_json, attrspec, NULL, NULL));
871 json_decref (data_json);
872 if (NULL == attribute)
873 {
875 "Unable to parse attribute from %s\n",
876 term_data);
878 return;
879 }
883 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
884 GNUNET_RECLAIM_id_generate (&attribute->id);
887 identity_priv,
888 attribute,
889 &exp,
891 handle);
892 GNUNET_JSON_parse_free (attrspec);
893}
894
895
906 const char *claim)
907{
908 char *jwt_string;
909 struct GNUNET_RECLAIM_Attribute *attr;
910 char delim[] = ".";
911 const char *type_str = NULL;
912 const char *val_str = NULL;
913 char *data;
914 size_t data_size;
915 uint32_t type;
916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
917 char *decoded_jwt;
918 json_t *json_val;
919 json_error_t *json_err = NULL;
920
922 cred->data,
923 cred->data_size);
924 char *jwt_body = strtok (jwt_string, delim);
925 jwt_body = strtok (NULL, delim);
926 GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body),
927 (void **) &decoded_jwt);
928 json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
929 const char *key;
930 json_t *value;
931 json_object_foreach (json_val, key, value) {
932 if (0 == strcasecmp (key,claim))
933 {
934 val_str = json_dumps (value, JSON_ENCODE_ANY);
935 }
936 }
937 type_str = "String";
940 (void **) &data,
941 &data_size))
942 {
944 "Attribute value from JWT Parser invalid!\n");
946 "Error: Referenced Claim Name not Found",
947 (void **) &data,
948 &data_size);
949 attr = GNUNET_RECLAIM_attribute_new (claim, &cred->id,
951 attr->id = cred->id;
952 attr->flag = 1;
953 }
954 else
955 {
956 attr = GNUNET_RECLAIM_attribute_new (claim, &cred->id,
958 attr->id = cred->id;
959 attr->flag = 1;
960 }
961 return attr;
962}
963
964
969static void
970attr_collect (void *cls,
971 const struct GNUNET_CRYPTO_PublicKey *identity,
972 const struct GNUNET_RECLAIM_Attribute *attr)
973{
974 struct RequestHandle *handle = cls;
975 json_t *attr_obj;
976 const char *type;
977 char *id_str;
978
979 char *tmp_value;
981 attr->data,
982 attr->data_size);
983 attr_obj = json_object ();
984 json_object_set_new (attr_obj, "value", json_string (tmp_value));
985 json_object_set_new (attr_obj, "name", json_string (attr->name));
986
988 json_object_set_new (attr_obj, "flag", json_string ("0"));
989 else
990 json_object_set_new (attr_obj, "flag", json_string ("1"));
992 json_object_set_new (attr_obj, "type", json_string (type));
994 sizeof(attr->id));
995 json_object_set_new (attr_obj, "id", json_string (id_str));
996 GNUNET_free (id_str);
998 sizeof(attr->credential));
999 json_object_set_new (attr_obj, "credential", json_string (id_str));
1000 GNUNET_free (id_str);
1001 json_array_append (handle->resp_object, attr_obj);
1002 json_decref (attr_obj);
1003 GNUNET_free (tmp_value);
1005}
1006
1007
1015static void
1017 const char *url,
1018 void *cls)
1019{
1020 const struct GNUNET_CRYPTO_PrivateKey *priv_key;
1021 struct RequestHandle *handle = cls;
1022 struct EgoEntry *ego_entry;
1023 char *identity;
1024
1026 "Getting attributes for %s.\n",
1027 handle->url);
1028 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
1029 {
1030 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
1032 return;
1033 }
1035
1036 for (ego_entry = ego_head; NULL != ego_entry;
1037 ego_entry = ego_entry->next)
1038 if (0 == strcmp (identity, ego_entry->identifier))
1039 break;
1040 handle->resp_object = json_array ();
1041
1042
1043 if (NULL == ego_entry)
1044 {
1045 // Done
1046 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
1048 return;
1049 }
1050 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1052 priv_key,
1054 handle,
1055 &attr_collect,
1056 handle,
1058 handle);
1059}
1060
1061
1069static void
1071 const char *url,
1072 void *cls)
1073{
1074 const struct GNUNET_CRYPTO_PrivateKey *priv_key;
1075 struct RequestHandle *handle = cls;
1076 struct GNUNET_RECLAIM_Attribute attr;
1077 struct EgoEntry *ego_entry;
1078 char *identity_id_str;
1079 char *identity;
1080 char *id;
1081
1082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n");
1083 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
1084 {
1085 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
1087 return;
1088 }
1089 identity_id_str =
1090 strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1);
1091 identity = strtok (identity_id_str, "/");
1092 id = strtok (NULL, "/");
1093 if ((NULL == identity) || (NULL == id))
1094 {
1095 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
1096 GNUNET_free (identity_id_str);
1098 return;
1099 }
1100
1101 for (ego_entry = ego_head; NULL != ego_entry;
1102 ego_entry = ego_entry->next)
1103 if (0 == strcmp (identity, ego_entry->identifier))
1104 break;
1105 handle->resp_object = json_array ();
1106 if (NULL == ego_entry)
1107 {
1108 // Done
1109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
1110 GNUNET_free (identity_id_str);
1112 return;
1113 }
1114 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1115 memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute));
1116 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
1117 attr.name = "";
1119 priv_key,
1120 &attr,
1122 handle);
1123 GNUNET_free (identity_id_str);
1124}
1125
1126
1127static void
1129 const char *url,
1130 void *cls)
1131{
1132 const struct GNUNET_CRYPTO_PrivateKey *identity_priv;
1133 struct RequestHandle *handle = cls;
1134 struct EgoEntry *ego_entry;
1135 struct GNUNET_RECLAIM_Ticket *ticket = NULL;
1136 struct GNUNET_CRYPTO_PublicKey tmp_pk;
1137 char term_data[handle->rest_handle->data_size + 1];
1138 json_t *data_json;
1139 json_error_t err;
1140 struct GNUNET_JSON_Specification tktspec[] =
1142
1143 if (0 >= handle->rest_handle->data_size)
1144 {
1146 return;
1147 }
1148
1149 term_data[handle->rest_handle->data_size] = '\0';
1150 GNUNET_memcpy (term_data,
1151 handle->rest_handle->data,
1152 handle->rest_handle->data_size);
1153 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
1154 if ((NULL == data_json) ||
1155 (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL)))
1156 {
1157 handle->emsg = GNUNET_strdup ("Not a ticket!\n");
1159 GNUNET_JSON_parse_free (tktspec);
1160 if (NULL != data_json)
1161 json_decref (data_json);
1162 return;
1163 }
1164 json_decref (data_json);
1165 if (NULL == ticket)
1166 {
1168 "Unable to parse ticket from %s\n",
1169 term_data);
1171 return;
1172 }
1173
1174 for (ego_entry = ego_head; NULL != ego_entry;
1175 ego_entry = ego_entry->next)
1176 {
1177 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
1178 if (0 == memcmp (&ticket->identity,
1179 &tmp_pk,
1180 sizeof(struct GNUNET_CRYPTO_PublicKey)))
1181 break;
1182 }
1183 if (NULL == ego_entry)
1184 {
1185 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
1186 GNUNET_JSON_parse_free (tktspec);
1187 return;
1188 }
1189 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1190
1192 identity_priv,
1193 ticket,
1195 handle);
1196 GNUNET_JSON_parse_free (tktspec);
1197}
1198
1199
1200static void
1202 const struct GNUNET_CRYPTO_PublicKey *identity,
1203 const struct GNUNET_RECLAIM_Attribute *attr,
1204 const struct GNUNET_RECLAIM_Presentation *presentation)
1205{
1206 struct RequestHandle *handle = cls;
1207 char *val_str;
1208 json_t *value;
1209
1210 if (NULL == identity)
1211 {
1213 return;
1214 }
1215
1216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
1218 attr->data,
1219 attr->data_size);
1220 if (NULL == val_str)
1221 {
1223 "Failed to parse value for: %s\n",
1224 attr->name);
1225 return;
1226 }
1227 value = json_string (val_str);
1228 json_object_set_new (handle->resp_object, attr->name, value);
1229 json_decref (value);
1230 GNUNET_free (val_str);
1231}
1232
1233
1234static void
1236 const char *url,
1237 void *cls)
1238{
1239 const struct GNUNET_CRYPTO_PrivateKey *identity_priv;
1240 struct RequestHandle *handle = cls;
1241 struct EgoEntry *ego_entry;
1243 struct GNUNET_CRYPTO_PublicKey tmp_pk;
1244 char term_data[handle->rest_handle->data_size + 1];
1245 json_t *data_json;
1246 json_error_t err;
1247 struct GNUNET_JSON_Specification tktspec[] =
1249
1250 if (0 >= handle->rest_handle->data_size)
1251 {
1253 return;
1254 }
1255
1256 term_data[handle->rest_handle->data_size] = '\0';
1257 GNUNET_memcpy (term_data,
1258 handle->rest_handle->data,
1259 handle->rest_handle->data_size);
1260 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
1261 if (NULL == data_json)
1262 {
1264 "Unable to parse JSON Object from %s\n",
1265 term_data);
1267 return;
1268 }
1269 if (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL))
1270 {
1271 handle->emsg = GNUNET_strdup ("Not a ticket!\n");
1273 GNUNET_JSON_parse_free (tktspec);
1274 json_decref (data_json);
1275 return;
1276 }
1277 for (ego_entry = ego_head; NULL != ego_entry;
1278 ego_entry = ego_entry->next)
1279 {
1280 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
1281 if (0 == memcmp (&ticket->audience,
1282 &tmp_pk,
1283 sizeof(struct GNUNET_CRYPTO_PublicKey)))
1284 break;
1285 }
1286 if (NULL == ego_entry)
1287 {
1288 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
1289 GNUNET_JSON_parse_free (tktspec);
1290 return;
1291 }
1292 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1293 handle->resp_object = json_object ();
1295 identity_priv,
1296 ticket,
1297 &consume_cont,
1298 handle);
1299 GNUNET_JSON_parse_free (tktspec);
1300}
1301
1302
1310static void
1312 const char *url,
1313 void *cls)
1314{
1315 struct MHD_Response *resp;
1316 struct RequestHandle *handle = cls;
1317
1318 // For now, independent of path return all options
1319 resp = GNUNET_REST_create_response (NULL);
1320 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1321 "Access-Control-Allow-Methods",
1322 allow_methods));
1323 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1325 return;
1326}
1327
1328
1361static void
1362list_ego (void *cls,
1363 struct GNUNET_IDENTITY_Ego *ego,
1364 void **ctx,
1365 const char *identifier)
1366{
1367 struct EgoEntry *ego_entry;
1369
1370 if (NULL == ego)
1371 {
1373 return;
1374 }
1376 {
1377 ego_entry = GNUNET_new (struct EgoEntry);
1380 ego_entry->ego = ego;
1381 ego_entry->identifier = GNUNET_strdup (identifier);
1383 ego_tail,
1384 ego_entry);
1385 }
1386 /* Ego renamed or added */
1387 if (identifier != NULL)
1388 {
1389 for (ego_entry = ego_head; NULL != ego_entry;
1390 ego_entry = ego_entry->next)
1391 {
1392 if (ego_entry->ego == ego)
1393 {
1394 /* Rename */
1395 GNUNET_free (ego_entry->identifier);
1396 ego_entry->identifier = GNUNET_strdup (identifier);
1397 break;
1398 }
1399 }
1400 if (NULL == ego_entry)
1401 {
1402 /* Add */
1403 ego_entry = GNUNET_new (struct EgoEntry);
1406 ego_entry->ego = ego;
1407 ego_entry->identifier = GNUNET_strdup (identifier);
1409 ego_tail,
1410 ego_entry);
1411 }
1412 }
1413 else
1414 {
1415 /* Delete */
1416 for (ego_entry = ego_head; NULL != ego_entry;
1417 ego_entry = ego_entry->next)
1418 {
1419 if (ego_entry->ego == ego)
1420 break;
1421 }
1422 if (NULL == ego_entry)
1423 return; /* Not found */
1424
1426 ego_tail,
1427 ego_entry);
1428 GNUNET_free (ego_entry->identifier);
1429 GNUNET_free (ego_entry->keystring);
1430 GNUNET_free (ego_entry);
1431 return;
1432 }
1433
1434}
1435
1436
1439 struct GNUNET_REST_RequestHandle *rest_handle,
1441 void *proc_cls)
1442{
1443 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1445 static const struct GNUNET_REST_RequestHandler handlers[] =
1446 { { MHD_HTTP_METHOD_GET,
1448 { MHD_HTTP_METHOD_POST,
1450 { MHD_HTTP_METHOD_DELETE,
1452 { MHD_HTTP_METHOD_GET,
1454 { MHD_HTTP_METHOD_POST,
1456 { MHD_HTTP_METHOD_DELETE,
1458 { MHD_HTTP_METHOD_GET,
1460 { MHD_HTTP_METHOD_POST,
1462 { MHD_HTTP_METHOD_POST,
1464 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
1466
1467 handle->response_code = 0;
1469 handle->proc_cls = proc_cls;
1470 handle->proc = proc;
1471 handle->rest_handle = rest_handle;
1472
1473 handle->url = GNUNET_strdup (rest_handle->url);
1474 if (handle->url[strlen (handle->url) - 1] == '/')
1475 handle->url[strlen (handle->url) - 1] = '\0';
1476 handle->timeout_task =
1480 handle);
1481 if (GNUNET_NO ==
1482 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1483 {
1485 return GNUNET_NO;
1486 }
1487
1488 return GNUNET_YES;
1489}
1490
1491
1498void *
1500{
1501 static struct Plugin plugin;
1502 struct GNUNET_REST_Plugin *api;
1503
1504 rcfg = c;
1505 if (NULL != plugin.cfg)
1506 return NULL; /* can only initialize once! */
1507 memset (&plugin, 0, sizeof(struct Plugin));
1508 plugin.cfg = rcfg;
1509 api = GNUNET_new (struct GNUNET_REST_Plugin);
1510 api->cls = &plugin;
1513 "%s, %s, %s, %s, %s",
1514 MHD_HTTP_METHOD_GET,
1515 MHD_HTTP_METHOD_POST,
1516 MHD_HTTP_METHOD_PUT,
1517 MHD_HTTP_METHOD_DELETE,
1518 MHD_HTTP_METHOD_OPTIONS);
1523 _ ("Identity Provider REST API initialized\n"));
1524 return api;
1525}
1526
1527
1534void *
1536{
1537 struct Plugin *plugin = api->cls;
1538 struct RequestHandle *request;
1539 struct EgoEntry *ego_entry;
1540 struct EgoEntry *ego_tmp;
1541
1542 plugin->cfg = NULL;
1543 while (NULL != (request = requests_head))
1544 do_error (request);
1545 if (NULL != idp)
1547 if (NULL != identity_handle)
1549 for (ego_entry = ego_head; NULL != ego_entry;)
1550 {
1551 ego_tmp = ego_entry;
1552 ego_entry = ego_entry->next;
1553 GNUNET_free (ego_tmp->identifier);
1554 GNUNET_free (ego_tmp->keystring);
1555 GNUNET_free (ego_tmp);
1556 }
1557
1559 GNUNET_free (api);
1561 "Identity Provider REST plugin is finished\n");
1562 return NULL;
1563}
1564
1565
1566/* end of plugin_rest_reclaim.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct TestcasePlugin * plugin
The process handle to the testbed service.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_Handle * ctx
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
struct GNUNET_RECLAIM_Attribute * claim
Claim to store.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
static char * type_str
Attribute type.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:40
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
API to the GNS service.
API that can be used to manipulate GNS record data.
Identity service; implements identity management for GNUnet.
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:94
enum GNUNET_GenericReturnValue GNUNET_JSON_parse(const json_t *root, struct GNUNET_JSON_Specification *spec, const char **error_json_name, unsigned int *error_line)
Navigate and parse data in a JSON tree.
Definition: json.c:32
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end(void)
End of a parser specification.
Definition: json_helper.c:32
Identity attribute definitions.
reclaim service; implements identity and personal data sharing for GNUnet
API for helper library to parse/create REST.
GNUnet service REST plugin header.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
const struct GNUNET_CRYPTO_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:517
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:487
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:732
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:529
#define GNUNET_log(kind,...)
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:551
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_RECLAIM_attribute_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'claim' of an attribute to the binary representation.
void GNUNET_RECLAIM_attribute_list_destroy(struct GNUNET_RECLAIM_AttributeList *attrs)
Destroy claim list.
char * GNUNET_RECLAIM_credential_get_issuer(const struct GNUNET_RECLAIM_Credential *cred)
char * GNUNET_RECLAIM_credential_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the 'claim' of an credential to a string.
#define GNUNET_RECLAIM_id_is_zero(a)
const char * GNUNET_RECLAIM_credential_number_to_typename(uint32_t type)
Convert an credential type number to the corresponding credential type string.
struct GNUNET_RECLAIM_AttributeList * GNUNET_RECLAIM_credential_get_attributes(const struct GNUNET_RECLAIM_Credential *cred)
Convert an credential type name to the corresponding number.
#define GNUNET_RECLAIM_id_generate(id)
int GNUNET_RECLAIM_credential_get_expiration(const struct GNUNET_RECLAIM_Credential *cred, struct GNUNET_TIME_Absolute *exp)
char * GNUNET_RECLAIM_attribute_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the 'claim' of an attribute to a string.
struct GNUNET_RECLAIM_Attribute * GNUNET_RECLAIM_attribute_new(const char *attr_name, const struct GNUNET_RECLAIM_Identifier *credential, uint32_t type, const void *data, size_t data_size)
Create a new attribute claim.
const char * GNUNET_RECLAIM_attribute_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string.
uint32_t GNUNET_RECLAIM_attribute_typename_to_number(const char *typename)
Convert a type name to the corresponding number.
void GNUNET_RECLAIM_disconnect(struct GNUNET_RECLAIM_Handle *h)
Disconnect from identity provider service.
Definition: reclaim_api.c:1145
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_credential_store(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const struct GNUNET_RECLAIM_Credential *credential, const struct GNUNET_TIME_Relative *exp_interval, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
Store a credential.
Definition: reclaim_api.c:1249
void GNUNET_RECLAIM_ticket_iteration_next(struct GNUNET_RECLAIM_TicketIterator *it)
Calls the ticket processor specified in GNUNET_RECLAIM_ticket_iteration_start for the next record.
Definition: reclaim_api.c:1643
void GNUNET_RECLAIM_get_attributes_stop(struct GNUNET_RECLAIM_AttributeIterator *it)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1393
void GNUNET_RECLAIM_get_credentials_next(struct GNUNET_RECLAIM_CredentialIterator *ait)
Calls the record processor specified in GNUNET_RECLAIM_get_credentials_start for the next record.
Definition: reclaim_api.c:1456
struct GNUNET_RECLAIM_AttributeIterator * GNUNET_RECLAIM_get_attributes_start(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *identity, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
List all attributes for a local identity.
Definition: reclaim_api.c:1334
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_ticket_revoke(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *identity, const struct GNUNET_RECLAIM_Ticket *ticket, GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls)
Revoked an issued ticket.
Definition: reclaim_api.c:1694
void GNUNET_RECLAIM_get_attributes_next(struct GNUNET_RECLAIM_AttributeIterator *it)
Calls the record processor specified in GNUNET_RECLAIM_get_attributes_start for the next record.
Definition: reclaim_api.c:1379
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_ticket_consume(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *identity, const struct GNUNET_RECLAIM_Ticket *ticket, GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls)
Consumes an issued ticket.
Definition: reclaim_api.c:1551
struct GNUNET_RECLAIM_Handle * GNUNET_RECLAIM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the re:claimID service.
Definition: reclaim_api.c:1113
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_store(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const struct GNUNET_RECLAIM_Attribute *attr, const struct GNUNET_TIME_Relative *exp_interval, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
Store an attribute.
Definition: reclaim_api.c:1164
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_delete(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const struct GNUNET_RECLAIM_Attribute *attr, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
Delete an attribute.
Definition: reclaim_api.c:1208
struct GNUNET_RECLAIM_TicketIterator * GNUNET_RECLAIM_ticket_iteration_start(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *identity, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_RECLAIM_TicketCallback proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Lists all tickets that have been issued to remote identites (relying parties)
Definition: reclaim_api.c:1591
void GNUNET_RECLAIM_get_credentials_stop(struct GNUNET_RECLAIM_CredentialIterator *ait)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1471
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_credential_delete(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const struct GNUNET_RECLAIM_Credential *cred, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
Delete a credential.
Definition: reclaim_api.c:1293
void GNUNET_RECLAIM_ticket_iteration_stop(struct GNUNET_RECLAIM_TicketIterator *it)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1663
struct GNUNET_RECLAIM_CredentialIterator * GNUNET_RECLAIM_get_credentials_start(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *identity, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_RECLAIM_CredentialResult proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
List all credentials for a local identity.
Definition: reclaim_api.c:1411
int GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn, const struct GNUNET_REST_RequestHandler *handlers, struct GNUNET_REST_RequestHandlerError *err, void *cls)
Definition: rest.c:64
void(* GNUNET_REST_ResultProcessor)(void *cls, struct MHD_Response *resp, int status)
Iterator called on obtained result for a REST result.
#define GNUNET_REST_HANDLER_END
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:44
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1299
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1272
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:764
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:789
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1724
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_HOURS
One hour.
@ MHD_HTTP_BAD_REQUEST
Bad Request [RFC7231, Section 6.5.1].
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_credential(struct GNUNET_RECLAIM_Credential **cred)
JSON Specification for credential claims.
Definition: json_reclaim.c:385
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_attribute(struct GNUNET_RECLAIM_Attribute **attr)
JSON Specification for Reclaim claims.
Definition: json_reclaim.c:146
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_ticket(struct GNUNET_RECLAIM_Ticket **ticket)
JSON Specification for Reclaim tickets.
Definition: json_reclaim.c:265
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static struct EgoEntry * ego_tail
Ego list.
#define GNUNET_REST_API_NS_IDENTITY_REVOKE
Revoke namespace.
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
static void finished_cont(void *cls, int32_t success, const char *emsg)
#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL
Credential namespace.
struct GNUNET_RECLAIM_Attribute * parse_jwt(const struct GNUNET_RECLAIM_Credential *cred, const char *claim)
Parse a JWT and return the respective claim value as Attribute.
void * REST_reclaim_done(struct GNUNET_REST_Plugin *api)
Exit point from the plugin.
static void delete_finished_cb(void *cls, int32_t success, const char *emsg)
static void do_timeout(void *cls)
Task run on timeout, sends error message.
#define GNUNET_REST_API_NS_IDENTITY_TICKETS
Ticket namespace.
#define GNUNET_REST_API_NS_IDENTITY_CONSUME
Revoke namespace.
static void return_response(void *cls)
Return attributes for identity.
#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES
Attribute namespace.
static void delete_credential_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Deletes credential from an identity.
static void revoke_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
static void consume_cont(void *cls, const struct GNUNET_CRYPTO_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr, const struct GNUNET_RECLAIM_Presentation *presentation)
#define GNUNET_REST_API_NS_RECLAIM
REST root namespace.
static void delete_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List attributes for identity request.
void * REST_reclaim_init(struct GNUNET_CONFIGURATION_Handle *c)
Entry point for the plugin.
static void collect_error_cb(void *cls)
static void list_tickets_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List tickets for identity request.
#define ID_REST_STATE_INIT
State while collecting all egos.
static struct RequestHandle * requests_head
DLL.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
static int state
The processing state.
static struct EgoEntry * ego_head
Ego list.
static void cred_collect(void *cls, const struct GNUNET_CRYPTO_PublicKey *identity, const struct GNUNET_RECLAIM_Credential *cred)
Collect all credentials for an ego.
static void list_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
If listing is enabled, prints information about the egos.
static void list_credential_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Lists credential for identity request.
enum GNUNET_GenericReturnValue REST_reclaim_process_request(void *plugin, struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
static void add_credential_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
static char * allow_methods
HTTP methods allows for this plugin.
static void collect_finished_cb(void *cls)
static void attr_collect(void *cls, const struct GNUNET_CRYPTO_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr)
Collect all attributes for an ego.
static struct RequestHandle * requests_tail
DLL.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static void add_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
static void list_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List attributes for identity request.
static void consume_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
const struct GNUNET_CONFIGURATION_Handle * rcfg
The configuration handle.
#define ID_REST_STATE_POST_INIT
Done collecting egos.
static void do_error(void *cls)
Task run on error, sends error message.
static void ticket_collect(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
Collect all attributes for an ego.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
The default namestore ego.
char * identifier
Ego Identifier.
struct EgoEntry * prev
DLL.
char * keystring
Public key string.
struct EgoEntry * next
DLL.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
void * cls
Closure for all of the callbacks.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Handle for an ego.
Definition: identity.h:37
Handle for the service.
Definition: identity_api.c:97
Handle for an operation with the identity service.
Definition: identity_api.c:41
Entry in parser specification for GNUNET_JSON_parse().
void * cls
Closure for parser and cleaner.
Handle for a attribute iterator operation.
Definition: reclaim_api.c:181
struct GNUNET_RECLAIM_Attribute * attribute
The attribute claim.
struct GNUNET_RECLAIM_AttributeListEntry * next
DLL.
A list of GNUNET_RECLAIM_Attribute structures.
struct GNUNET_RECLAIM_AttributeListEntry * list_head
List head.
const char * name
The name of the attribute.
struct GNUNET_RECLAIM_Identifier credential
Referenced ID of credential (may be GNUNET_RECLAIM_ID_ZERO if self-creded)
struct GNUNET_RECLAIM_Identifier id
ID.
uint32_t type
Type of Claim.
const void * data
Binary value stored as attribute value.
size_t data_size
Number of bytes in data.
Handle for a credential iterator operation.
Definition: reclaim_api.c:248
uint32_t type
Type/Format of Claim.
const char * name
The name of the credential.
const void * data
Binary value stored as credential value.
size_t data_size
Number of bytes in data.
struct GNUNET_RECLAIM_Identifier id
ID.
Handle to the service.
Definition: reclaim_api.c:316
Handle for an operation with the service.
Definition: reclaim_api.c:40
A credential presentation.
Handle for a ticket iterator operation.
Definition: reclaim_api.c:118
The authorization ticket.
struct GNUNET_CRYPTO_PublicKey audience
The ticket audience (= relying party)
struct GNUNET_RECLAIM_Identifier rnd
The ticket random identifier.
struct GNUNET_CRYPTO_PublicKey identity
The ticket issuer (= the user)
struct returned by the initialization function of the plugin
char * name
Plugin name.
void * cls
The closure of the plugin.
const char * url
The url as string.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
The request handle.
Definition: config_plugin.c:46
struct GNUNET_RECLAIM_TicketIterator * ticket_it
Ticket iterator.
struct GNUNET_RECLAIM_Ticket ticket
A ticket.
char * emsg
Error response message.
Definition: gns_plugin.c:142
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
struct RequestHandle * prev
DLL.
Definition: config_plugin.c:55
struct GNUNET_RECLAIM_AttributeList * attr_list
Attribute claim list.
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
int response_code
HTTP response code.
Definition: config_plugin.c:75
struct EgoEntry * ego_entry
IDENTITY Operation.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
Definition: gns_plugin.c:122
struct GNUNET_CRYPTO_PrivateKey priv_key
Pointer to ego private key.
void * proc_cls
The closure of the result processor.
Definition: config_plugin.c:70
struct GNUNET_RECLAIM_AttributeIterator * attr_it
Attribute iterator.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
Definition: config_plugin.c:65
struct RequestHandle * next
DLL.
Definition: config_plugin.c:50
struct GNUNET_RECLAIM_CredentialIterator * cred_it
Credential iterator.
json_t * resp_object
Response object.
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
Definition: config_plugin.c:60
char * url
The URL.
Definition: config_plugin.c:80
struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gns_plugin.c:117