GNUnet  0.19.4
plugin_rest_reclaim.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"
32 #include "gnunet_gnsrecord_lib.h"
34 #include "gnunet_reclaim_lib.h"
35 #include "gnunet_reclaim_service.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 
88 static char *allow_methods;
89 
93 static struct EgoEntry *ego_head;
94 
98 static struct EgoEntry *ego_tail;
99 
103 static int state;
104 
109 
113 static struct GNUNET_RECLAIM_Handle *idp;
114 
118 struct Plugin
119 {
120  const struct GNUNET_CONFIGURATION_Handle *cfg;
121 };
122 
126 struct 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 
155 struct 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 
273 static void
274 cleanup_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 
307 static void
308 do_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", "application/json"));
321  handle->proc (handle->proc_cls, resp, handle->response_code);
323  GNUNET_free (json_error);
324 }
325 
326 
332 static void
333 do_timeout (void *cls)
334 {
335  struct RequestHandle *handle = cls;
336 
337  handle->timeout_task = NULL;
338  do_error (handle);
339 }
340 
341 
342 static void
343 collect_error_cb (void *cls)
344 {
346 }
347 
348 
349 static void
350 finished_cont (void *cls, int32_t success, const char *emsg)
351 {
352  struct RequestHandle *handle = cls;
353  struct MHD_Response *resp;
354 
355  handle->idp_op = NULL;
356  if (GNUNET_OK != success)
357  {
359  return;
360  }
361  resp = GNUNET_REST_create_response (emsg);
362  GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
363  "Content-Type",
364  "application/json"));
365  GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
366  "Access-Control-Allow-Methods",
367  allow_methods));
368  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
370 }
371 
372 
373 static void
374 delete_finished_cb (void *cls, int32_t success, const char *emsg)
375 {
376  struct RequestHandle *handle = cls;
377  struct MHD_Response *resp;
378 
379  if (GNUNET_OK != success)
380  {
382  return;
383  }
384  resp = GNUNET_REST_create_response (emsg);
385  GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
386  "Access-Control-Allow-Methods",
387  allow_methods));
388  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
390 }
391 
392 
398 static void
399 return_response (void *cls)
400 {
401  char *result_str;
402  struct RequestHandle *handle = cls;
403  struct MHD_Response *resp;
404 
405  result_str = json_dumps (handle->resp_object, 0);
406  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
407  resp = GNUNET_REST_create_response (result_str);
408  GNUNET_assert (MHD_NO !=
409  MHD_add_response_header (resp,
410  "Access-Control-Allow-Methods",
411  allow_methods));
412  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
413  GNUNET_free (result_str);
415 }
416 
417 
418 static void
420 {
421  struct RequestHandle *handle = cls;
422 
423  // Done
424  handle->attr_it = NULL;
425  handle->cred_it = NULL;
426  handle->ticket_it = NULL;
428 }
429 
430 
435 static void
436 ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
437 {
438  json_t *json_resource;
439  struct RequestHandle *handle = cls;
440  json_t *value;
441  char *tmp;
442 
443  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n");
445  json_resource = json_object ();
446  GNUNET_free (tmp);
447  json_array_append (handle->resp_object, json_resource);
448 
449  tmp =
451  sizeof(struct
453  value = json_string (tmp);
454  json_object_set_new (json_resource, "issuer", value);
455  GNUNET_free (tmp);
456  tmp =
458  sizeof(struct
460  value = json_string (tmp);
461  json_object_set_new (json_resource, "audience", value);
462  GNUNET_free (tmp);
464  value = json_string (tmp);
465  json_object_set_new (json_resource, "rnd", value);
466  GNUNET_free (tmp);
468 }
469 
470 
471 static void
473  const char *url,
474  void *cls)
475 {
476  struct RequestHandle *handle = cls;
477  const struct GNUNET_IDENTITY_PrivateKey *identity_priv;
478  const char *identity;
479  struct EgoEntry *ego_entry;
480  struct GNUNET_RECLAIM_Credential *attribute;
481  struct GNUNET_TIME_Relative exp;
482  char term_data[handle->rest_handle->data_size + 1];
483  json_t *data_json;
484  json_error_t err;
485  struct GNUNET_JSON_Specification attrspec[] =
488 
490  "Adding an credential for %s.\n",
491  handle->url);
492  if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen (
493  handle->url))
494  {
495  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
497  return;
498  }
499  identity = handle->url + strlen (
501 
502  for (ego_entry = ego_head; NULL != ego_entry;
503  ego_entry = ego_entry->next)
504  if (0 == strcmp (identity, ego_entry->identifier))
505  break;
506 
507  if (NULL == ego_entry)
508  {
509  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity);
510  return;
511  }
512  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
513 
514  if (0 >= handle->rest_handle->data_size)
515  {
517  return;
518  }
519 
520  term_data[handle->rest_handle->data_size] = '\0';
521  GNUNET_memcpy (term_data,
522  handle->rest_handle->data,
523  handle->rest_handle->data_size);
524  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
525  if (GNUNET_OK != GNUNET_JSON_parse (data_json, attrspec, NULL, NULL))
526  {
527  json_decref (data_json);
529  "Unable to parse JSON from %s\n",
530  term_data);
532  return;
533  }
534  json_decref (data_json);
535  if (NULL == attribute)
536  {
538  "Unable to parse credential from %s\n",
539  term_data);
541  return;
542  }
546  if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
547  GNUNET_RECLAIM_id_generate (&attribute->id);
550  identity_priv,
551  attribute,
552  &exp,
553  &finished_cont,
554  handle);
555  GNUNET_JSON_parse_free (attrspec);
556 }
557 
558 
563 static void
565  const struct GNUNET_IDENTITY_PublicKey *identity,
566  const struct GNUNET_RECLAIM_Credential *cred)
567 {
568  struct RequestHandle *handle = cls;
569  struct GNUNET_RECLAIM_AttributeList *attrs;
571  struct GNUNET_TIME_Absolute exp;
572  json_t *attr_obj;
573  json_t *cred_obj;
574  const char *type;
575  char *tmp_value;
576  char *id_str;
577  char *issuer;
578 
579 
580  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential: %s\n",
581  cred->name);
583  issuer = GNUNET_RECLAIM_credential_get_issuer (cred);
585  cred->data,
586  cred->data_size);
587  cred_obj = json_object ();
588  json_object_set_new (cred_obj, "value", json_string (tmp_value));
589  json_object_set_new (cred_obj, "name", json_string (cred->name));
591  json_object_set_new (cred_obj, "type", json_string (type));
592  if (NULL != issuer)
593  {
594  json_object_set_new (cred_obj, "issuer", json_string (issuer));
595  GNUNET_free (issuer);
596  }
598  &exp))
599  {
600  json_object_set_new (cred_obj, "expiration", json_integer (
601  exp.abs_value_us));
602  }
603  id_str = GNUNET_STRINGS_data_to_string_alloc (&cred->id,
604  sizeof(cred->id));
605  json_object_set_new (cred_obj, "id", json_string (id_str));
606  GNUNET_free (tmp_value);
607  GNUNET_free (id_str);
608  if (NULL != attrs)
609  {
610  json_t *attr_arr = json_array ();
611  for (ale = attrs->list_head; NULL != ale; ale = ale->next)
612  {
613  tmp_value =
615  ale->attribute->data,
616  ale->attribute->data_size);
617  attr_obj = json_object ();
618  json_object_set_new (attr_obj, "value", json_string (tmp_value));
619  json_object_set_new (attr_obj, "name", json_string (
620  ale->attribute->name));
621 
622  json_object_set_new (attr_obj, "flag", json_string ("1")); // FIXME
624  json_object_set_new (attr_obj, "type", json_string (type));
625  json_object_set_new (attr_obj, "id", json_string (""));
626  json_object_set_new (attr_obj, "credential", json_string (""));
627  json_array_append_new (attr_arr, attr_obj);
628  GNUNET_free (tmp_value);
629  }
630  json_object_set_new (cred_obj, "attributes", attr_arr);
631  }
632  json_array_append_new (handle->resp_object, cred_obj);
633  if (NULL != attrs)
636 }
637 
638 
646 static void
648  const char *url,
649  void *cls)
650 {
651  struct RequestHandle *handle = cls;
652  const struct GNUNET_IDENTITY_PrivateKey *priv_key;
653  struct EgoEntry *ego_entry;
654  char *identity;
655 
657  "Getting credentials for %s.\n",
658  handle->url);
659  if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen (
660  handle->url))
661  {
662  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
664  return;
665  }
666  identity = handle->url + strlen (
668 
669  for (ego_entry = ego_head; NULL != ego_entry;
670  ego_entry = ego_entry->next)
671  if (0 == strcmp (identity, ego_entry->identifier))
672  break;
673  handle->resp_object = json_array ();
674 
675 
676  if (NULL == ego_entry)
677  {
678  // Done
679  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
681  return;
682  }
683  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
685  priv_key,
687  handle,
688  &cred_collect,
689  handle,
690  &
692  handle);
693 }
694 
695 
703 static void
705  const char *url,
706  void *cls)
707 {
708  struct RequestHandle *handle = cls;
709  const struct GNUNET_IDENTITY_PrivateKey *priv_key;
710  struct GNUNET_RECLAIM_Credential attr;
711  struct EgoEntry *ego_entry;
712  char *identity_id_str;
713  char *identity;
714  char *id;
715 
716  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting credential.\n");
717  if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen (
718  handle->url))
719  {
720  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
722  return;
723  }
724  identity_id_str =
725  strdup (handle->url + strlen (
727  identity = strtok (identity_id_str, "/");
728  id = strtok (NULL, "/");
729  if ((NULL == identity) || (NULL == id))
730  {
731  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
732  GNUNET_free (identity_id_str);
734  return;
735  }
736 
737  for (ego_entry = ego_head; NULL != ego_entry;
738  ego_entry = ego_entry->next)
739  if (0 == strcmp (identity, ego_entry->identifier))
740  break;
741  handle->resp_object = json_array ();
742  if (NULL == ego_entry)
743  {
744  // Done
745  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
746  GNUNET_free (identity_id_str);
748  return;
749  }
750  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
751  memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Credential));
752  GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
753  attr.name = "";
755  priv_key,
756  &attr,
758  handle);
759  GNUNET_free (identity_id_str);
760 }
761 
762 
770 static void
772  const char *url,
773  void *cls)
774 {
775  const struct GNUNET_IDENTITY_PrivateKey *priv_key;
776  struct RequestHandle *handle = cls;
777  struct EgoEntry *ego_entry;
778  char *identity;
779 
781  "Getting tickets for %s.\n",
782  handle->url);
783  if (strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) >= strlen (handle->url))
784  {
785  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
787  return;
788  }
790 
791  for (ego_entry = ego_head; NULL != ego_entry;
792  ego_entry = ego_entry->next)
793  if (0 == strcmp (identity, ego_entry->identifier))
794  break;
795  handle->resp_object = json_array ();
796 
797  if (NULL == ego_entry)
798  {
799  // Done
800  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
802  return;
803  }
804  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
805  handle->ticket_it =
807  priv_key,
809  handle,
811  handle,
813  handle);
814 }
815 
816 
817 static void
819  const char *url,
820  void *cls)
821 {
822  const struct GNUNET_IDENTITY_PrivateKey *identity_priv;
823  const char *identity;
824  struct RequestHandle *handle = cls;
825  struct EgoEntry *ego_entry;
826  struct GNUNET_RECLAIM_Attribute *attribute;
827  struct GNUNET_TIME_Relative exp;
828  char term_data[handle->rest_handle->data_size + 1];
829  json_t *data_json;
830  json_error_t err;
831  struct GNUNET_JSON_Specification attrspec[] =
833 
835  "Adding an attribute for %s.\n",
836  handle->url);
837  if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
838  {
839  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
841  return;
842  }
844 
845  for (ego_entry = ego_head; NULL != ego_entry;
846  ego_entry = ego_entry->next)
847  if (0 == strcmp (identity, ego_entry->identifier))
848  break;
849 
850  if (NULL == ego_entry)
851  {
852  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity);
853  return;
854  }
855  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
856 
857  if (0 >= handle->rest_handle->data_size)
858  {
860  return;
861  }
862 
863  term_data[handle->rest_handle->data_size] = '\0';
864  GNUNET_memcpy (term_data,
865  handle->rest_handle->data,
866  handle->rest_handle->data_size);
867  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
869  GNUNET_JSON_parse (data_json, attrspec, NULL, NULL));
870  json_decref (data_json);
871  if (NULL == attribute)
872  {
874  "Unable to parse attribute from %s\n",
875  term_data);
877  return;
878  }
882  if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
883  GNUNET_RECLAIM_id_generate (&attribute->id);
886  identity_priv,
887  attribute,
888  &exp,
889  &finished_cont,
890  handle);
891  GNUNET_JSON_parse_free (attrspec);
892 }
893 
894 
905  const char *claim)
906 {
907  char *jwt_string;
908  struct GNUNET_RECLAIM_Attribute *attr;
909  char delim[] = ".";
910  const char *type_str = NULL;
911  const char *val_str = NULL;
912  char *data;
913  size_t data_size;
914  uint32_t type;
915  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
916  char *decoded_jwt;
917  json_t *json_val;
918  json_error_t *json_err = NULL;
919 
921  cred->data,
922  cred->data_size);
923  char *jwt_body = strtok (jwt_string, delim);
924  jwt_body = strtok (NULL, delim);
925  GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body),
926  (void **) &decoded_jwt);
927  json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
928  const char *key;
929  json_t *value;
930  json_object_foreach (json_val, key, value) {
931  if (0 == strcasecmp (key,claim))
932  {
933  val_str = json_dumps (value, JSON_ENCODE_ANY);
934  }
935  }
936  type_str = "String";
939  (void **) &data,
940  &data_size))
941  {
943  "Attribute value from JWT Parser invalid!\n");
945  "Error: Referenced Claim Name not Found",
946  (void **) &data,
947  &data_size);
948  attr = GNUNET_RECLAIM_attribute_new (claim, &cred->id,
949  type, data, data_size);
950  attr->id = cred->id;
951  attr->flag = 1;
952  }
953  else
954  {
955  attr = GNUNET_RECLAIM_attribute_new (claim, &cred->id,
956  type, data, data_size);
957  attr->id = cred->id;
958  attr->flag = 1;
959  }
960  return attr;
961 }
962 
963 
968 static void
969 attr_collect (void *cls,
970  const struct GNUNET_IDENTITY_PublicKey *identity,
971  const struct GNUNET_RECLAIM_Attribute *attr)
972 {
973  struct RequestHandle *handle = cls;
974  json_t *attr_obj;
975  const char *type;
976  char *id_str;
977 
978  char *tmp_value;
980  attr->data,
981  attr->data_size);
982  attr_obj = json_object ();
983  json_object_set_new (attr_obj, "value", json_string (tmp_value));
984  json_object_set_new (attr_obj, "name", json_string (attr->name));
985 
987  json_object_set_new (attr_obj, "flag", json_string ("0"));
988  else
989  json_object_set_new (attr_obj, "flag", json_string ("1"));
991  json_object_set_new (attr_obj, "type", json_string (type));
992  id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id,
993  sizeof(attr->id));
994  json_object_set_new (attr_obj, "id", json_string (id_str));
995  GNUNET_free (id_str);
997  sizeof(attr->credential));
998  json_object_set_new (attr_obj, "credential", json_string (id_str));
999  GNUNET_free (id_str);
1000  json_array_append (handle->resp_object, attr_obj);
1001  json_decref (attr_obj);
1002  GNUNET_free (tmp_value);
1004 }
1005 
1006 
1014 static void
1016  const char *url,
1017  void *cls)
1018 {
1019  const struct GNUNET_IDENTITY_PrivateKey *priv_key;
1020  struct RequestHandle *handle = cls;
1021  struct EgoEntry *ego_entry;
1022  char *identity;
1023 
1025  "Getting attributes for %s.\n",
1026  handle->url);
1027  if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
1028  {
1029  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
1031  return;
1032  }
1034 
1035  for (ego_entry = ego_head; NULL != ego_entry;
1036  ego_entry = ego_entry->next)
1037  if (0 == strcmp (identity, ego_entry->identifier))
1038  break;
1039  handle->resp_object = json_array ();
1040 
1041 
1042  if (NULL == ego_entry)
1043  {
1044  // Done
1045  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
1047  return;
1048  }
1049  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1051  priv_key,
1053  handle,
1054  &attr_collect,
1055  handle,
1057  handle);
1058 }
1059 
1060 
1068 static void
1070  const char *url,
1071  void *cls)
1072 {
1073  const struct GNUNET_IDENTITY_PrivateKey *priv_key;
1074  struct RequestHandle *handle = cls;
1075  struct GNUNET_RECLAIM_Attribute attr;
1076  struct EgoEntry *ego_entry;
1077  char *identity_id_str;
1078  char *identity;
1079  char *id;
1080 
1081  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n");
1082  if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
1083  {
1084  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
1086  return;
1087  }
1088  identity_id_str =
1089  strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1);
1090  identity = strtok (identity_id_str, "/");
1091  id = strtok (NULL, "/");
1092  if ((NULL == identity) || (NULL == id))
1093  {
1094  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
1095  GNUNET_free (identity_id_str);
1097  return;
1098  }
1099 
1100  for (ego_entry = ego_head; NULL != ego_entry;
1101  ego_entry = ego_entry->next)
1102  if (0 == strcmp (identity, ego_entry->identifier))
1103  break;
1104  handle->resp_object = json_array ();
1105  if (NULL == ego_entry)
1106  {
1107  // Done
1108  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
1109  GNUNET_free (identity_id_str);
1111  return;
1112  }
1113  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1114  memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute));
1115  GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
1116  attr.name = "";
1118  priv_key,
1119  &attr,
1121  handle);
1122  GNUNET_free (identity_id_str);
1123 }
1124 
1125 
1126 static void
1128  const char *url,
1129  void *cls)
1130 {
1131  const struct GNUNET_IDENTITY_PrivateKey *identity_priv;
1132  struct RequestHandle *handle = cls;
1133  struct EgoEntry *ego_entry;
1134  struct GNUNET_RECLAIM_Ticket *ticket = NULL;
1135  struct GNUNET_IDENTITY_PublicKey tmp_pk;
1136  char term_data[handle->rest_handle->data_size + 1];
1137  json_t *data_json;
1138  json_error_t err;
1139  struct GNUNET_JSON_Specification tktspec[] =
1141 
1142  if (0 >= handle->rest_handle->data_size)
1143  {
1145  return;
1146  }
1147 
1148  term_data[handle->rest_handle->data_size] = '\0';
1149  GNUNET_memcpy (term_data,
1150  handle->rest_handle->data,
1151  handle->rest_handle->data_size);
1152  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
1153  if ((NULL == data_json) ||
1154  (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL)))
1155  {
1156  handle->emsg = GNUNET_strdup ("Not a ticket!\n");
1158  GNUNET_JSON_parse_free (tktspec);
1159  if (NULL != data_json)
1160  json_decref (data_json);
1161  return;
1162  }
1163  json_decref (data_json);
1164  if (NULL == ticket)
1165  {
1167  "Unable to parse ticket from %s\n",
1168  term_data);
1170  return;
1171  }
1172 
1173  for (ego_entry = ego_head; NULL != ego_entry;
1174  ego_entry = ego_entry->next)
1175  {
1176  GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
1177  if (0 == memcmp (&ticket->identity,
1178  &tmp_pk,
1179  sizeof(struct GNUNET_IDENTITY_PublicKey)))
1180  break;
1181  }
1182  if (NULL == ego_entry)
1183  {
1184  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
1185  GNUNET_JSON_parse_free (tktspec);
1186  return;
1187  }
1188  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1189 
1191  identity_priv,
1192  ticket,
1193  &finished_cont,
1194  handle);
1195  GNUNET_JSON_parse_free (tktspec);
1196 }
1197 
1198 
1199 static void
1201  const struct GNUNET_IDENTITY_PublicKey *identity,
1202  const struct GNUNET_RECLAIM_Attribute *attr,
1203  const struct GNUNET_RECLAIM_Presentation *presentation)
1204 {
1205  struct RequestHandle *handle = cls;
1206  char *val_str;
1207  json_t *value;
1208 
1209  if (NULL == identity)
1210  {
1212  return;
1213  }
1214 
1215  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
1217  attr->data,
1218  attr->data_size);
1219  if (NULL == val_str)
1220  {
1222  "Failed to parse value for: %s\n",
1223  attr->name);
1224  return;
1225  }
1226  value = json_string (val_str);
1227  json_object_set_new (handle->resp_object, attr->name, value);
1228  json_decref (value);
1229  GNUNET_free (val_str);
1230 }
1231 
1232 
1233 static void
1235  const char *url,
1236  void *cls)
1237 {
1238  const struct GNUNET_IDENTITY_PrivateKey *identity_priv;
1239  struct RequestHandle *handle = cls;
1240  struct EgoEntry *ego_entry;
1241  struct GNUNET_RECLAIM_Ticket *ticket;
1242  struct GNUNET_IDENTITY_PublicKey tmp_pk;
1243  char term_data[handle->rest_handle->data_size + 1];
1244  json_t *data_json;
1245  json_error_t err;
1246  struct GNUNET_JSON_Specification tktspec[] =
1248 
1249  if (0 >= handle->rest_handle->data_size)
1250  {
1252  return;
1253  }
1254 
1255  term_data[handle->rest_handle->data_size] = '\0';
1256  GNUNET_memcpy (term_data,
1257  handle->rest_handle->data,
1258  handle->rest_handle->data_size);
1259  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
1260  if (NULL == data_json)
1261  {
1263  "Unable to parse JSON Object from %s\n",
1264  term_data);
1266  return;
1267  }
1268  if (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL))
1269  {
1270  handle->emsg = GNUNET_strdup ("Not a ticket!\n");
1272  GNUNET_JSON_parse_free (tktspec);
1273  json_decref (data_json);
1274  return;
1275  }
1276  for (ego_entry = ego_head; NULL != ego_entry;
1277  ego_entry = ego_entry->next)
1278  {
1279  GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
1280  if (0 == memcmp (&ticket->audience,
1281  &tmp_pk,
1282  sizeof(struct GNUNET_IDENTITY_PublicKey)))
1283  break;
1284  }
1285  if (NULL == ego_entry)
1286  {
1287  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
1288  GNUNET_JSON_parse_free (tktspec);
1289  return;
1290  }
1291  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1292  handle->resp_object = json_object ();
1294  identity_priv,
1295  ticket,
1296  &consume_cont,
1297  handle);
1298  GNUNET_JSON_parse_free (tktspec);
1299 }
1300 
1301 
1309 static void
1311  const char *url,
1312  void *cls)
1313 {
1314  struct MHD_Response *resp;
1315  struct RequestHandle *handle = cls;
1316 
1317  // For now, independent of path return all options
1318  resp = GNUNET_REST_create_response (NULL);
1319  GNUNET_assert (MHD_NO != MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods));
1320  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1322  return;
1323 }
1324 
1325 
1358 static void
1359 list_ego (void *cls,
1360  struct GNUNET_IDENTITY_Ego *ego,
1361  void **ctx,
1362  const char *identifier)
1363 {
1364  struct EgoEntry *ego_entry;
1366 
1367  if (NULL == ego)
1368  {
1370  return;
1371  }
1372  if (ID_REST_STATE_INIT == state)
1373  {
1374  ego_entry = GNUNET_new (struct EgoEntry);
1377  ego_entry->ego = ego;
1378  ego_entry->identifier = GNUNET_strdup (identifier);
1380  ego_tail,
1381  ego_entry);
1382  }
1383  /* Ego renamed or added */
1384  if (identifier != NULL)
1385  {
1386  for (ego_entry = ego_head; NULL != ego_entry;
1387  ego_entry = ego_entry->next)
1388  {
1389  if (ego_entry->ego == ego)
1390  {
1391  /* Rename */
1392  GNUNET_free (ego_entry->identifier);
1393  ego_entry->identifier = GNUNET_strdup (identifier);
1394  break;
1395  }
1396  }
1397  if (NULL == ego_entry)
1398  {
1399  /* Add */
1400  ego_entry = GNUNET_new (struct EgoEntry);
1403  ego_entry->ego = ego;
1404  ego_entry->identifier = GNUNET_strdup (identifier);
1406  ego_tail,
1407  ego_entry);
1408  }
1409  }
1410  else
1411  {
1412  /* Delete */
1413  for (ego_entry = ego_head; NULL != ego_entry;
1414  ego_entry = ego_entry->next)
1415  {
1416  if (ego_entry->ego == ego)
1417  break;
1418  }
1419  if (NULL == ego_entry)
1420  return; /* Not found */
1421 
1423  ego_tail,
1424  ego_entry);
1425  GNUNET_free (ego_entry->identifier);
1426  GNUNET_free (ego_entry->keystring);
1427  GNUNET_free (ego_entry);
1428  return;
1429  }
1430 
1431 }
1432 
1433 
1434 static enum GNUNET_GenericReturnValue
1437  void *proc_cls)
1438 {
1439  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1441  static const struct GNUNET_REST_RequestHandler handlers[] =
1442  { { MHD_HTTP_METHOD_GET,
1444  { MHD_HTTP_METHOD_POST,
1446  { MHD_HTTP_METHOD_DELETE,
1448  { MHD_HTTP_METHOD_GET,
1450  { MHD_HTTP_METHOD_POST,
1452  { MHD_HTTP_METHOD_DELETE,
1454  { MHD_HTTP_METHOD_GET,
1456  { MHD_HTTP_METHOD_POST,
1458  { MHD_HTTP_METHOD_POST,
1460  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
1462 
1463  handle->response_code = 0;
1465  handle->proc_cls = proc_cls;
1466  handle->proc = proc;
1467  handle->rest_handle = rest_handle;
1468 
1469  handle->url = GNUNET_strdup (rest_handle->url);
1470  if (handle->url[strlen (handle->url) - 1] == '/')
1471  handle->url[strlen (handle->url) - 1] = '\0';
1472  handle->timeout_task =
1475  requests_tail,
1476  handle);
1477  if (GNUNET_NO ==
1478  GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1479  {
1481  return GNUNET_NO;
1482  }
1483 
1484  return GNUNET_YES;
1485 }
1486 
1487 
1494 void *
1496 {
1497  static struct Plugin plugin;
1498  struct GNUNET_REST_Plugin *api;
1499 
1500  cfg = cls;
1501  if (NULL != plugin.cfg)
1502  return NULL; /* can only initialize once! */
1503  memset (&plugin, 0, sizeof(struct Plugin));
1504  plugin.cfg = cfg;
1505  api = GNUNET_new (struct GNUNET_REST_Plugin);
1506  api->cls = &plugin;
1510  "%s, %s, %s, %s, %s",
1511  MHD_HTTP_METHOD_GET,
1512  MHD_HTTP_METHOD_POST,
1513  MHD_HTTP_METHOD_PUT,
1514  MHD_HTTP_METHOD_DELETE,
1515  MHD_HTTP_METHOD_OPTIONS);
1520  _ ("Identity Provider REST API initialized\n"));
1521  return api;
1522 }
1523 
1524 
1531 void *
1533 {
1534  struct GNUNET_REST_Plugin *api = cls;
1535  struct Plugin *plugin = api->cls;
1536  struct RequestHandle *request;
1537  struct EgoEntry *ego_entry;
1538  struct EgoEntry *ego_tmp;
1539 
1540  plugin->cfg = NULL;
1541  while (NULL != (request = requests_head))
1542  do_error (request);
1543  if (NULL != idp)
1545  if (NULL != identity_handle)
1547  for (ego_entry = ego_head; NULL != ego_entry;)
1548  {
1549  ego_tmp = ego_entry;
1550  ego_entry = ego_entry->next;
1551  GNUNET_free (ego_tmp->identifier);
1552  GNUNET_free (ego_tmp->keystring);
1553  GNUNET_free (ego_tmp);
1554  }
1555 
1557  GNUNET_free (api);
1559  "Identity Provider REST plugin is finished\n");
1560  return NULL;
1561 }
1562 
1563 
1564 /* end of plugin_rest_reclaim.c */
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct TestcasePlugin * plugin
The process handle to the testbed service.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
uint32_t data
The data value.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static char * value
Value of the record to add/remove.
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_DNSSTUB_Context * ctx
Context for DNS resolution.
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_IDENTITY_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:560
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_IDENTITY_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:573
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
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:531
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:757
#define GNUNET_log(kind,...)
#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.
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.
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)
const char * GNUNET_RECLAIM_credential_number_to_typename(uint32_t type)
Convert an credential type number to the corresponding credential type string.
#define GNUNET_RECLAIM_id_is_zero(a)
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.
#define GNUNET_RECLAIM_id_generate(id)
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.
int GNUNET_RECLAIM_credential_get_expiration(const struct GNUNET_RECLAIM_Credential *cred, struct GNUNET_TIME_Absolute *exp)
const char * GNUNET_RECLAIM_attribute_number_to_typename(uint32_t type)
Convert a type number to the corresponding 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.
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:1143
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_credential_store(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_IDENTITY_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:1247
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:1641
struct GNUNET_RECLAIM_AttributeIterator * GNUNET_RECLAIM_get_attributes_start(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_IDENTITY_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:1332
void GNUNET_RECLAIM_get_attributes_stop(struct GNUNET_RECLAIM_AttributeIterator *it)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1391
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:1454
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_store(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_IDENTITY_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:1162
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_credential_delete(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const struct GNUNET_RECLAIM_Credential *cred, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
Delete a credential.
Definition: reclaim_api.c:1291
struct GNUNET_RECLAIM_CredentialIterator * GNUNET_RECLAIM_get_credentials_start(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_IDENTITY_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:1409
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:1377
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_delete(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const struct GNUNET_RECLAIM_Attribute *attr, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
Delete an attribute.
Definition: reclaim_api.c:1206
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_ticket_revoke(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *identity, const struct GNUNET_RECLAIM_Ticket *ticket, GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls)
Revoked an issued ticket.
Definition: reclaim_api.c:1692
struct GNUNET_RECLAIM_TicketIterator * GNUNET_RECLAIM_ticket_iteration_start(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_IDENTITY_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:1589
struct GNUNET_RECLAIM_Handle * GNUNET_RECLAIM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the re:claimID service.
Definition: reclaim_api.c:1111
void GNUNET_RECLAIM_get_credentials_stop(struct GNUNET_RECLAIM_CredentialIterator *ait)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1469
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_ticket_consume(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *identity, const struct GNUNET_RECLAIM_Ticket *ticket, GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls)
Consumes an issued ticket.
Definition: reclaim_api.c:1549
void GNUNET_RECLAIM_ticket_iteration_stop(struct GNUNET_RECLAIM_TicketIterator *it)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1661
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:44
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 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
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_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:763
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:788
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1695
#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:177
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)
static void attr_collect(void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr)
Collect all attributes for an ego.
void * libgnunet_plugin_rest_reclaim_done(void *cls)
Exit point from the plugin.
#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL
Credential namespace.
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.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
static void revoke_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
#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 * libgnunet_plugin_rest_reclaim_init(void *cls)
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 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.
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.
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.
static void collect_finished_cb(void *cls)
static void cred_collect(void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Credential *cred)
Collect all credentials for an ego.
static struct RequestHandle * requests_tail
DLL.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static void consume_cont(void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr, const struct GNUNET_RECLAIM_Presentation *presentation)
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)
#define ID_REST_STATE_POST_INIT
Done collecting egos.
static enum GNUNET_GenericReturnValue rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
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 ego list.
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.
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
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
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:182
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:249
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:317
Handle for an operation with the service.
Definition: reclaim_api.c:41
A credential presentation.
Handle for a ticket iterator operation.
Definition: reclaim_api.c:119
The authorization ticket.
struct GNUNET_RECLAIM_Identifier rnd
The ticket random identifier.
struct GNUNET_IDENTITY_PublicKey audience
The ticket audience (= relying party)
struct GNUNET_IDENTITY_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.
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
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.
struct GNUNET_RECLAIM_TicketIterator * ticket_it
Ticket iterator.
struct GNUNET_RECLAIM_Ticket ticket
A ticket.
char * emsg
Error response message.
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
struct RequestHandle * prev
DLL.
struct GNUNET_RECLAIM_AttributeList * attr_list
Attribute claim list.
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
int response_code
Response code.
struct EgoEntry * ego_entry
IDENTITY Operation.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
void * proc_cls
The closure of the result processor.
struct GNUNET_RECLAIM_AttributeIterator * attr_it
Attribute iterator.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
struct RequestHandle * next
DLL.
struct GNUNET_IDENTITY_PrivateKey priv_key
Pointer to ego private key.
struct GNUNET_RECLAIM_CredentialIterator * cred_it
Credential iterator.
json_t * resp_object
Response object.
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
char * url
The url.
struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model