GNUnet  0.11.x
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 
175  struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key;
176 
180  struct GNUNET_REST_RequestHandle *rest_handle;
181 
186 
191 
195  struct GNUNET_RECLAIM_Operation *idp_op;
196 
200  struct GNUNET_RECLAIM_AttributeIterator *attr_it;
201 
205  struct GNUNET_RECLAIM_CredentialIterator *cred_it;
206 
210  struct GNUNET_RECLAIM_TicketIterator *ticket_it;
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)
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)
295  GNUNET_CONTAINER_DLL_remove (requests_head,
296  requests_tail,
297  handle);
298  GNUNET_free (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  MHD_add_response_header (resp, "Content-Type", "application/json");
321  handle->proc (handle->proc_cls, resp, handle->response_code);
322  cleanup_handle (handle);
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  resp = GNUNET_REST_create_response (emsg);
357  MHD_add_response_header (resp, "Content-Type", "application/json");
358  MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
359  if (GNUNET_OK != success)
360  {
362  return;
363  }
364  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
366 }
367 
368 
369 static void
370 delete_finished_cb (void *cls, int32_t success, const char *emsg)
371 {
372  struct RequestHandle *handle = cls;
373  struct MHD_Response *resp;
374 
375  resp = GNUNET_REST_create_response (emsg);
376  MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
377  if (GNUNET_OK != success)
378  {
380  return;
381  }
382  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
384 }
385 
386 
392 static void
393 return_response (void *cls)
394 {
395  char *result_str;
396  struct RequestHandle *handle = cls;
397  struct MHD_Response *resp;
398 
399  result_str = json_dumps (handle->resp_object, 0);
400  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
401  resp = GNUNET_REST_create_response (result_str);
402  MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
403  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
404  GNUNET_free (result_str);
405  cleanup_handle (handle);
406 }
407 
408 
409 static void
411 {
412  struct RequestHandle *handle = cls;
413 
414  // Done
415  handle->attr_it = NULL;
416  handle->cred_it = NULL;
417  handle->ticket_it = NULL;
419 }
420 
421 
426 static void
427 ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
428 {
429  json_t *json_resource;
430  struct RequestHandle *handle = cls;
431  json_t *value;
432  char *tmp;
433 
434  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n");
435  tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof(ticket->rnd));
436  json_resource = json_object ();
437  GNUNET_free (tmp);
438  json_array_append (handle->resp_object, json_resource);
439 
440  tmp =
442  sizeof(struct
444  value = json_string (tmp);
445  json_object_set_new (json_resource, "issuer", value);
446  GNUNET_free (tmp);
447  tmp =
449  sizeof(struct
451  value = json_string (tmp);
452  json_object_set_new (json_resource, "audience", value);
453  GNUNET_free (tmp);
454  tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof(ticket->rnd));
455  value = json_string (tmp);
456  json_object_set_new (json_resource, "rnd", value);
457  GNUNET_free (tmp);
459 }
460 
461 
462 static void
464  const char *url,
465  void *cls)
466 {
467  struct RequestHandle *handle = cls;
468  const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
469  const char *identity;
470  struct EgoEntry *ego_entry;
471  struct GNUNET_RECLAIM_Credential *attribute;
472  struct GNUNET_TIME_Relative exp;
473  char term_data[handle->rest_handle->data_size + 1];
474  json_t *data_json;
475  json_error_t err;
476  struct GNUNET_JSON_Specification attrspec[] =
479 
481  "Adding an credential for %s.\n",
482  handle->url);
483  if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen (
484  handle->url))
485  {
486  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
488  return;
489  }
490  identity = handle->url + strlen (
492 
493  for (ego_entry = ego_head; NULL != ego_entry;
494  ego_entry = ego_entry->next)
495  if (0 == strcmp (identity, ego_entry->identifier))
496  break;
497 
498  if (NULL == ego_entry)
499  {
500  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity);
501  return;
502  }
503  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
504 
505  if (0 >= handle->rest_handle->data_size)
506  {
508  return;
509  }
510 
511  term_data[handle->rest_handle->data_size] = '\0';
512  GNUNET_memcpy (term_data,
513  handle->rest_handle->data,
514  handle->rest_handle->data_size);
515  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
516  GNUNET_JSON_parse (data_json, attrspec, NULL, NULL);
517  json_decref (data_json);
518  if (NULL == attribute)
519  {
521  "Unable to parse credential from %s\n",
522  term_data);
524  return;
525  }
529  if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
530  GNUNET_RECLAIM_id_generate (&attribute->id);
533  identity_priv,
534  attribute,
535  &exp,
536  &finished_cont,
537  handle);
538  GNUNET_JSON_parse_free (attrspec);
539 }
540 
541 
546 static void
549  const struct GNUNET_RECLAIM_Credential *cred)
550 {
551  struct RequestHandle *handle = cls;
552  struct GNUNET_RECLAIM_AttributeList *attrs;
554  struct GNUNET_TIME_Absolute exp;
555  json_t *attr_obj;
556  json_t *cred_obj;
557  const char *type;
558  char *tmp_value;
559  char *id_str;
560  char *issuer;
561 
562 
563  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential: %s\n",
564  cred->name);
566  issuer = GNUNET_RECLAIM_credential_get_issuer (cred);
568  cred->data,
569  cred->data_size);
570  cred_obj = json_object ();
571  json_object_set_new (cred_obj, "value", json_string (tmp_value));
572  json_object_set_new (cred_obj, "name", json_string (cred->name));
574  json_object_set_new (cred_obj, "type", json_string (type));
575  if (NULL != issuer)
576  {
577  json_object_set_new (cred_obj, "issuer", json_string (issuer));
578  GNUNET_free (issuer);
579  }
581  &exp))
582  {
583  json_object_set_new (cred_obj, "expiration", json_integer (
584  exp.abs_value_us));
585  }
586  id_str = GNUNET_STRINGS_data_to_string_alloc (&cred->id,
587  sizeof(cred->id));
588  json_object_set_new (cred_obj, "id", json_string (id_str));
589  GNUNET_free (tmp_value);
590  GNUNET_free (id_str);
591  if (NULL != attrs)
592  {
593  json_t *attr_arr = json_array ();
594  for (ale = attrs->list_head; NULL != ale; ale = ale->next)
595  {
596  tmp_value =
598  ale->attribute->data,
599  ale->attribute->data_size);
600  attr_obj = json_object ();
601  json_object_set_new (attr_obj, "value", json_string (tmp_value));
602  json_object_set_new (attr_obj, "name", json_string (
603  ale->attribute->name));
604 
605  json_object_set_new (attr_obj, "flag", json_string ("1")); // FIXME
607  json_object_set_new (attr_obj, "type", json_string (type));
608  json_object_set_new (attr_obj, "id", json_string (""));
609  json_object_set_new (attr_obj, "credential", json_string (""));
610  json_array_append_new (attr_arr, attr_obj);
611  GNUNET_free (tmp_value);
612  }
613  json_object_set_new (cred_obj, "attributes", attr_arr);
614  }
615  json_array_append_new (handle->resp_object, cred_obj);
618 }
619 
620 
628 static void
630  const char *url,
631  void *cls)
632 {
633  struct RequestHandle *handle = cls;
634  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
635  struct EgoEntry *ego_entry;
636  char *identity;
637 
639  "Getting credentials for %s.\n",
640  handle->url);
641  if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen (
642  handle->url))
643  {
644  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
646  return;
647  }
648  identity = handle->url + strlen (
650 
651  for (ego_entry = ego_head; NULL != ego_entry;
652  ego_entry = ego_entry->next)
653  if (0 == strcmp (identity, ego_entry->identifier))
654  break;
655  handle->resp_object = json_array ();
656 
657 
658  if (NULL == ego_entry)
659  {
660  // Done
661  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
663  return;
664  }
665  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
667  priv_key,
669  handle,
670  &cred_collect,
671  handle,
672  &
674  handle);
675 }
676 
677 
685 static void
687  const char *url,
688  void *cls)
689 {
690  struct RequestHandle *handle = cls;
691  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
692  struct GNUNET_RECLAIM_Credential attr;
693  struct EgoEntry *ego_entry;
694  char *identity_id_str;
695  char *identity;
696  char *id;
697 
698  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting credential.\n");
699  if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen (
700  handle->url))
701  {
702  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
704  return;
705  }
706  identity_id_str =
707  strdup (handle->url + strlen (
709  identity = strtok (identity_id_str, "/");
710  id = strtok (NULL, "/");
711  if ((NULL == identity) || (NULL == id))
712  {
713  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
714  GNUNET_free (identity_id_str);
716  return;
717  }
718 
719  for (ego_entry = ego_head; NULL != ego_entry;
720  ego_entry = ego_entry->next)
721  if (0 == strcmp (identity, ego_entry->identifier))
722  break;
723  handle->resp_object = json_array ();
724  if (NULL == ego_entry)
725  {
726  // Done
727  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
728  GNUNET_free (identity_id_str);
730  return;
731  }
732  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
733  memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Credential));
734  GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
735  attr.name = "";
737  priv_key,
738  &attr,
740  handle);
741  GNUNET_free (identity_id_str);
742 }
743 
744 
752 static void
754  const char *url,
755  void *cls)
756 {
757  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
758  struct RequestHandle *handle = cls;
759  struct EgoEntry *ego_entry;
760  char *identity;
761 
763  "Getting tickets for %s.\n",
764  handle->url);
765  if (strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) >= strlen (handle->url))
766  {
767  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
769  return;
770  }
771  identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1;
772 
773  for (ego_entry = ego_head; NULL != ego_entry;
774  ego_entry = ego_entry->next)
775  if (0 == strcmp (identity, ego_entry->identifier))
776  break;
777  handle->resp_object = json_array ();
778 
779  if (NULL == ego_entry)
780  {
781  // Done
782  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
784  return;
785  }
786  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
787  handle->ticket_it =
789  priv_key,
791  handle,
793  handle,
795  handle);
796 }
797 
798 
799 static void
801  const char *url,
802  void *cls)
803 {
804  const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
805  const char *identity;
806  struct RequestHandle *handle = cls;
807  struct EgoEntry *ego_entry;
808  struct GNUNET_RECLAIM_Attribute *attribute;
809  struct GNUNET_TIME_Relative exp;
810  char term_data[handle->rest_handle->data_size + 1];
811  json_t *data_json;
812  json_error_t err;
813  struct GNUNET_JSON_Specification attrspec[] =
815 
817  "Adding an attribute for %s.\n",
818  handle->url);
819  if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
820  {
821  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
823  return;
824  }
825  identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
826 
827  for (ego_entry = ego_head; NULL != ego_entry;
828  ego_entry = ego_entry->next)
829  if (0 == strcmp (identity, ego_entry->identifier))
830  break;
831 
832  if (NULL == ego_entry)
833  {
834  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity);
835  return;
836  }
837  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
838 
839  if (0 >= handle->rest_handle->data_size)
840  {
842  return;
843  }
844 
845  term_data[handle->rest_handle->data_size] = '\0';
846  GNUNET_memcpy (term_data,
847  handle->rest_handle->data,
848  handle->rest_handle->data_size);
849  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
851  GNUNET_JSON_parse (data_json, attrspec, NULL, NULL));
852  json_decref (data_json);
853  if (NULL == attribute)
854  {
856  "Unable to parse attribute from %s\n",
857  term_data);
859  return;
860  }
864  if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
865  GNUNET_RECLAIM_id_generate (&attribute->id);
867  handle->idp_op = GNUNET_RECLAIM_attribute_store (idp,
868  identity_priv,
869  attribute,
870  &exp,
871  &finished_cont,
872  handle);
873  GNUNET_JSON_parse_free (attrspec);
874 }
875 
876 
887  const char *claim)
888 {
889  char *jwt_string;
890  struct GNUNET_RECLAIM_Attribute *attr;
891  char delim[] = ".";
892  const char *type_str = NULL;
893  const char *val_str = NULL;
894  char *data;
895  size_t data_size;
896  uint32_t type;
897  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
898  char *decoded_jwt;
899  json_t *json_val;
900  json_error_t *json_err = NULL;
901 
903  cred->data,
904  cred->data_size);
905  char *jwt_body = strtok (jwt_string, delim);
906  jwt_body = strtok (NULL, delim);
907  GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body),
908  (void **) &decoded_jwt);
909  json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
910  const char *key;
911  json_t *value;
912  json_object_foreach (json_val, key, value) {
913  if (0 == strcasecmp (key,claim))
914  {
915  val_str = json_dumps (value, JSON_ENCODE_ANY);
916  }
917  }
918  type_str = "String";
921  (void **) &data,
922  &data_size))
923  {
925  "Attribute value from JWT Parser invalid!\n");
927  "Error: Referenced Claim Name not Found",
928  (void **) &data,
929  &data_size);
930  attr = GNUNET_RECLAIM_attribute_new (claim, &cred->id,
931  type, data, data_size);
932  attr->id = cred->id;
933  attr->flag = 1;
934  }
935  else
936  {
937  attr = GNUNET_RECLAIM_attribute_new (claim, &cred->id,
938  type, data, data_size);
939  attr->id = cred->id;
940  attr->flag = 1;
941  }
942  return attr;
943 }
944 
945 
950 static void
951 attr_collect (void *cls,
953  const struct GNUNET_RECLAIM_Attribute *attr)
954 {
955  struct RequestHandle *handle = cls;
956  json_t *attr_obj;
957  const char *type;
958  char *id_str;
959 
960  char *tmp_value;
962  attr->data,
963  attr->data_size);
964  attr_obj = json_object ();
965  json_object_set_new (attr_obj, "value", json_string (tmp_value));
966  json_object_set_new (attr_obj, "name", json_string (attr->name));
967 
969  json_object_set_new (attr_obj, "flag", json_string ("0"));
970  else
971  json_object_set_new (attr_obj, "flag", json_string ("1"));
973  json_object_set_new (attr_obj, "type", json_string (type));
974  id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id,
975  sizeof(attr->id));
976  json_object_set_new (attr_obj, "id", json_string (id_str));
978  sizeof(attr->credential));
979  json_object_set_new (attr_obj, "credential", json_string (id_str));
980  json_array_append (handle->resp_object, attr_obj);
981  json_decref (attr_obj);
982  GNUNET_free (tmp_value);
984 }
985 
986 
994 static void
996  const char *url,
997  void *cls)
998 {
999  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
1000  struct RequestHandle *handle = cls;
1001  struct EgoEntry *ego_entry;
1002  char *identity;
1003 
1005  "Getting attributes for %s.\n",
1006  handle->url);
1007  if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
1008  {
1009  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
1011  return;
1012  }
1013  identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
1014 
1015  for (ego_entry = ego_head; NULL != ego_entry;
1016  ego_entry = ego_entry->next)
1017  if (0 == strcmp (identity, ego_entry->identifier))
1018  break;
1019  handle->resp_object = json_array ();
1020 
1021 
1022  if (NULL == ego_entry)
1023  {
1024  // Done
1025  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
1027  return;
1028  }
1029  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1031  priv_key,
1033  handle,
1034  &attr_collect,
1035  handle,
1037  handle);
1038 }
1039 
1040 
1048 static void
1050  const char *url,
1051  void *cls)
1052 {
1053  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
1054  struct RequestHandle *handle = cls;
1055  struct GNUNET_RECLAIM_Attribute attr;
1056  struct EgoEntry *ego_entry;
1057  char *identity_id_str;
1058  char *identity;
1059  char *id;
1060 
1061  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n");
1062  if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
1063  {
1064  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
1066  return;
1067  }
1068  identity_id_str =
1069  strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1);
1070  identity = strtok (identity_id_str, "/");
1071  id = strtok (NULL, "/");
1072  if ((NULL == identity) || (NULL == id))
1073  {
1074  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
1075  GNUNET_free (identity_id_str);
1077  return;
1078  }
1079 
1080  for (ego_entry = ego_head; NULL != ego_entry;
1081  ego_entry = ego_entry->next)
1082  if (0 == strcmp (identity, ego_entry->identifier))
1083  break;
1084  handle->resp_object = json_array ();
1085  if (NULL == ego_entry)
1086  {
1087  // Done
1088  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
1089  GNUNET_free (identity_id_str);
1091  return;
1092  }
1093  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1094  memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute));
1095  GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
1096  attr.name = "";
1097  handle->idp_op = GNUNET_RECLAIM_attribute_delete (idp,
1098  priv_key,
1099  &attr,
1101  handle);
1102  GNUNET_free (identity_id_str);
1103 }
1104 
1105 
1106 static void
1108  const char *url,
1109  void *cls)
1110 {
1111  const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
1112  struct RequestHandle *handle = cls;
1113  struct EgoEntry *ego_entry;
1114  struct GNUNET_RECLAIM_Ticket *ticket = NULL;
1115  struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk;
1116  char term_data[handle->rest_handle->data_size + 1];
1117  json_t *data_json;
1118  json_error_t err;
1119  struct GNUNET_JSON_Specification tktspec[] =
1121 
1122  if (0 >= handle->rest_handle->data_size)
1123  {
1125  return;
1126  }
1127 
1128  term_data[handle->rest_handle->data_size] = '\0';
1129  GNUNET_memcpy (term_data,
1130  handle->rest_handle->data,
1131  handle->rest_handle->data_size);
1132  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
1133  if ((NULL == data_json) ||
1134  (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL)))
1135  {
1136  handle->emsg = GNUNET_strdup ("Not a ticket!\n");
1138  GNUNET_JSON_parse_free (tktspec);
1139  if (NULL != data_json)
1140  json_decref (data_json);
1141  return;
1142  }
1143  json_decref (data_json);
1144  if (NULL == ticket)
1145  {
1147  "Unable to parse ticket from %s\n",
1148  term_data);
1150  return;
1151  }
1152 
1153  for (ego_entry = ego_head; NULL != ego_entry;
1154  ego_entry = ego_entry->next)
1155  {
1156  GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
1157  if (0 == memcmp (&ticket->identity,
1158  &tmp_pk,
1159  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
1160  break;
1161  }
1162  if (NULL == ego_entry)
1163  {
1164  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
1165  GNUNET_JSON_parse_free (tktspec);
1166  return;
1167  }
1168  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1169 
1170  handle->idp_op = GNUNET_RECLAIM_ticket_revoke (idp,
1171  identity_priv,
1172  ticket,
1173  &finished_cont,
1174  handle);
1175  GNUNET_JSON_parse_free (tktspec);
1176 }
1177 
1178 
1179 static void
1181  const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
1182  const struct GNUNET_RECLAIM_Attribute *attr,
1183  const struct GNUNET_RECLAIM_Presentation *pres)
1184 {
1185  struct RequestHandle *handle = cls;
1186  char *val_str;
1187  json_t *value;
1188 
1189  if (NULL == identity)
1190  {
1192  return;
1193  }
1194 
1195  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
1197  attr->data,
1198  attr->data_size);
1199  if (NULL == val_str)
1200  {
1202  "Failed to parse value for: %s\n",
1203  attr->name);
1204  return;
1205  }
1206  value = json_string (val_str);
1207  json_object_set_new (handle->resp_object, attr->name, value);
1208  json_decref (value);
1209  GNUNET_free (val_str);
1210 }
1211 
1212 
1213 static void
1215  const char *url,
1216  void *cls)
1217 {
1218  const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
1219  struct RequestHandle *handle = cls;
1220  struct EgoEntry *ego_entry;
1221  struct GNUNET_RECLAIM_Ticket *ticket;
1222  struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk;
1223  char term_data[handle->rest_handle->data_size + 1];
1224  json_t *data_json;
1225  json_error_t err;
1226  struct GNUNET_JSON_Specification tktspec[] =
1228 
1229  if (0 >= handle->rest_handle->data_size)
1230  {
1232  return;
1233  }
1234 
1235  term_data[handle->rest_handle->data_size] = '\0';
1236  GNUNET_memcpy (term_data,
1237  handle->rest_handle->data,
1238  handle->rest_handle->data_size);
1239  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
1240  if (NULL == data_json)
1241  {
1243  "Unable to parse JSON Object from %s\n",
1244  term_data);
1246  return;
1247  }
1248  if (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL))
1249  {
1250  handle->emsg = GNUNET_strdup ("Not a ticket!\n");
1252  GNUNET_JSON_parse_free (tktspec);
1253  json_decref (data_json);
1254  return;
1255  }
1256  for (ego_entry = ego_head; NULL != ego_entry;
1257  ego_entry = ego_entry->next)
1258  {
1259  GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
1260  if (0 == memcmp (&ticket->audience,
1261  &tmp_pk,
1262  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
1263  break;
1264  }
1265  if (NULL == ego_entry)
1266  {
1267  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
1268  GNUNET_JSON_parse_free (tktspec);
1269  return;
1270  }
1271  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1272  handle->resp_object = json_object ();
1273  handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp,
1274  identity_priv,
1275  ticket,
1276  &consume_cont,
1277  handle);
1278  GNUNET_JSON_parse_free (tktspec);
1279 }
1280 
1281 
1289 static void
1291  const char *url,
1292  void *cls)
1293 {
1294  struct MHD_Response *resp;
1295  struct RequestHandle *handle = cls;
1296 
1297  // For now, independent of path return all options
1298  resp = GNUNET_REST_create_response (NULL);
1299  MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
1300  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1301  cleanup_handle (handle);
1302  return;
1303 }
1304 
1305 
1339 static void
1340 list_ego (void *cls,
1341  struct GNUNET_IDENTITY_Ego *ego,
1342  void **ctx,
1343  const char *identifier)
1344 {
1345  struct EgoEntry *ego_entry;
1346  struct GNUNET_CRYPTO_EcdsaPublicKey pk;
1347 
1348  if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1349  {
1351  return;
1352  }
1353  if (ID_REST_STATE_INIT == state)
1354  {
1355  ego_entry = GNUNET_new (struct EgoEntry);
1358  ego_entry->ego = ego;
1359  ego_entry->identifier = GNUNET_strdup (identifier);
1361  ego_tail,
1362  ego_entry);
1363  }
1364  /* Ego renamed or added */
1365  if (identifier != NULL)
1366  {
1367  for (ego_entry = ego_head; NULL != ego_entry;
1368  ego_entry = ego_entry->next)
1369  {
1370  if (ego_entry->ego == ego)
1371  {
1372  /* Rename */
1373  GNUNET_free (ego_entry->identifier);
1374  ego_entry->identifier = GNUNET_strdup (identifier);
1375  break;
1376  }
1377  }
1378  if (NULL == ego_entry)
1379  {
1380  /* Add */
1381  ego_entry = GNUNET_new (struct EgoEntry);
1384  ego_entry->ego = ego;
1385  ego_entry->identifier = GNUNET_strdup (identifier);
1387  ego_tail,
1388  ego_entry);
1389  }
1390  }
1391  else
1392  {
1393  /* Delete */
1394  for (ego_entry = ego_head; NULL != ego_entry;
1395  ego_entry = ego_entry->next)
1396  {
1397  if (ego_entry->ego == ego)
1398  break;
1399  }
1400  if (NULL == ego_entry)
1401  return; /* Not found */
1402 
1403  GNUNET_CONTAINER_DLL_remove (ego_head,
1404  ego_tail,
1405  ego_entry);
1406  GNUNET_free (ego_entry->identifier);
1407  GNUNET_free (ego_entry->keystring);
1408  GNUNET_free (ego_entry);
1409  return;
1410  }
1411 
1412 }
1413 
1414 
1415 static enum GNUNET_GenericReturnValue
1418  void *proc_cls)
1419 {
1420  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1422  static const struct GNUNET_REST_RequestHandler handlers[] =
1423  { { MHD_HTTP_METHOD_GET,
1425  { MHD_HTTP_METHOD_POST,
1427  { MHD_HTTP_METHOD_DELETE,
1429  { MHD_HTTP_METHOD_GET,
1431  { MHD_HTTP_METHOD_POST,
1433  { MHD_HTTP_METHOD_DELETE,
1435  { MHD_HTTP_METHOD_GET,
1437  { MHD_HTTP_METHOD_POST,
1439  { MHD_HTTP_METHOD_POST,
1441  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
1443  };
1444 
1445  handle->response_code = 0;
1447  handle->proc_cls = proc_cls;
1448  handle->proc = proc;
1449  handle->rest_handle = rest_handle;
1450 
1451  handle->url = GNUNET_strdup (rest_handle->url);
1452  if (handle->url[strlen (handle->url) - 1] == '/')
1453  handle->url[strlen (handle->url) - 1] = '\0';
1454  handle->timeout_task =
1455  GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
1456  GNUNET_CONTAINER_DLL_insert (requests_head,
1457  requests_tail,
1458  handle);
1459  if (GNUNET_NO ==
1460  GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1461  {
1462  cleanup_handle (handle);
1463  return GNUNET_NO;
1464  }
1465 
1466  return GNUNET_YES;
1467 }
1468 
1469 
1476 void *
1478 {
1479  static struct Plugin plugin;
1480  struct GNUNET_REST_Plugin *api;
1481 
1482  cfg = cls;
1483  if (NULL != plugin.cfg)
1484  return NULL; /* can only initialize once! */
1485  memset (&plugin, 0, sizeof(struct Plugin));
1486  plugin.cfg = cfg;
1487  api = GNUNET_new (struct GNUNET_REST_Plugin);
1488  api->cls = &plugin;
1492  "%s, %s, %s, %s, %s",
1493  MHD_HTTP_METHOD_GET,
1494  MHD_HTTP_METHOD_POST,
1495  MHD_HTTP_METHOD_PUT,
1496  MHD_HTTP_METHOD_DELETE,
1497  MHD_HTTP_METHOD_OPTIONS);
1498  identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL);
1500  idp = GNUNET_RECLAIM_connect (cfg);
1502  _ ("Identity Provider REST API initialized\n"));
1503  return api;
1504 }
1505 
1506 
1513 void *
1515 {
1516  struct GNUNET_REST_Plugin *api = cls;
1517  struct Plugin *plugin = api->cls;
1518  struct RequestHandle *request;
1519  struct EgoEntry *ego_entry;
1520  struct EgoEntry *ego_tmp;
1521 
1522  plugin->cfg = NULL;
1523  while (NULL != (request = requests_head))
1524  do_error (request);
1525  if (NULL != idp)
1527  if (NULL != identity_handle)
1528  GNUNET_IDENTITY_disconnect (identity_handle);
1529  for (ego_entry = ego_head; NULL != ego_entry;)
1530  {
1531  ego_tmp = ego_entry;
1532  ego_entry = ego_entry->next;
1533  GNUNET_free (ego_tmp->identifier);
1534  GNUNET_free (ego_tmp->keystring);
1535  GNUNET_free (ego_tmp);
1536  }
1537 
1539  GNUNET_free (api);
1541  "Identity Provider REST plugin is finished\n");
1542  return NULL;
1543 }
1544 
1545 
1546 /* end of plugin_rest_reclaim.c */
static void list_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List attributes for identity request.
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:566
void * cls
Closure for parser and cleaner.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES
Attribute namespace.
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:1487
Handle to the service.
Definition: reclaim_api.c:317
The authorization ticket.
void(* GNUNET_REST_ResultProcessor)(void *cls, struct MHD_Response *resp, int status)
Iterator called on obtained result for a REST result.
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.
static void consume_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
struct GNUNET_RECLAIM_AttributeIterator * GNUNET_RECLAIM_get_attributes_start(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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:1331
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
#define GNUNET_TIME_UNIT_HOURS
One hour.
struct GNUNET_RECLAIM_Identifier id
ID.
uint32_t type
Type/Format of Claim.
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_ticket_consume(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, const struct GNUNET_RECLAIM_Ticket *ticket, GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls)
Consumes an issued ticket.
Definition: reclaim_api.c:1591
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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.
void GNUNET_RECLAIM_get_credentials_stop(struct GNUNET_RECLAIM_CredentialIterator *ait)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1509
struct GNUNET_RECLAIM_TicketIterator * GNUNET_RECLAIM_ticket_iteration_start(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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:1637
void GNUNET_RECLAIM_attribute_list_destroy(struct GNUNET_RECLAIM_AttributeList *attrs)
Destroy claim list.
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_delete(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const struct GNUNET_RECLAIM_Attribute *attr, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
Delete an attribute.
Definition: reclaim_api.c:1182
void * cls
The closure of the plugin.
size_t data_size
The POST data size.
struct GNUNET_RECLAIM_Attribute * claim
Claim to store.
static void collect_error_cb(void *cls)
struct GNUNET_RECLAIM_AttributeIterator * attr_it
Attribute iterator.
static struct EgoEntry * ego_tail
Ego list.
const char * name
The name of the attribute.
static void add_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
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:45
GNUNET_REST_ResultProcessor proc
The plugin result processor.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_RECLAIM_credential_get_expiration(const struct GNUNET_RECLAIM_Credential *cred, struct GNUNET_TIME_Absolute *exp)
#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL
Credential namespace.
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:100
size_t data_size
Number of bytes in data.
#define GNUNET_REST_API_NS_IDENTITY_CONSUME
Revoke namespace.
char * key
TLS key.
static void finished_cont(void *cls, int32_t success, const char *emsg)
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:595
void GNUNET_RECLAIM_disconnect(struct GNUNET_RECLAIM_Handle *h)
Disconnect from identity provider service.
Definition: reclaim_api.c:1104
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct returned by the initialization function of the plugin
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
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:1681
A list of GNUNET_RECLAIM_Attribute structures.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
Entry in parser specification for GNUNET_JSON_parse().
void GNUNET_RECLAIM_ticket_iteration_stop(struct GNUNET_RECLAIM_TicketIterator *it)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1701
const void * data
Binary value stored as credential value.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Private ECC key encoded for transmission.
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
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
Handle for an operation with the service.
Definition: reclaim_api.c:41
struct GNUNET_RECLAIM_Identifier credential
Referenced ID of credential (may be GNUNET_RECLAIM_ID_ZERO if self-creded)
struct GNUNET_RECLAIM_CredentialIterator * GNUNET_RECLAIM_get_credentials_start(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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:1440
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
static void collect_finished_cb(void *cls)
uint64_t abs_value_us
The actual value.
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_credential(struct GNUNET_RECLAIM_Credential **cred)
JSON Specification for credential claims.
Definition: json_reclaim.c:379
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
Handle for an operation with the identity service.
Definition: identity_api.c:39
#define GNUNET_REST_HANDLER_END
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
struct GNUNET_RECLAIM_Attribute * attribute
The attribute claim.
The request handle.
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
The ego list.
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_attribute(struct GNUNET_RECLAIM_Attribute **attr)
JSON Specification for Reclaim claims.
Definition: json_reclaim.c:145
const char * GNUNET_RECLAIM_credential_number_to_typename(uint32_t type)
Convert an credential type number to the corresponding credential type string.
static void delete_credential_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Deletes credential from an identity.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
#define ID_REST_STATE_INIT
State while collecting all egos.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * GNUNET_RECLAIM_credential_get_issuer(const struct GNUNET_RECLAIM_Credential *cred)
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:1269
Handle for an ego.
Definition: identity.h:245
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_ticket_revoke(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, const struct GNUNET_RECLAIM_Ticket *ticket, GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls)
Revoked an issued ticket.
Definition: reclaim_api.c:1732
Handle for a attribute iterator operation.
Definition: reclaim_api.c:182
static char * allow_methods
HTTP methods allows for this plugin.
json_t * resp_object
Response object.
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static char * value
Value of the record to add/remove.
char * emsg
Error response message.
const char * url
The url as string.
Handle for the service.
Definition: identity_api.c:95
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:1296
char * name
Plugin name.
static struct RequestHandle * requests_tail
DLL.
struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
struct GNUNET_RECLAIM_TicketIterator * ticket_it
Ticket iterator.
uint32_t GNUNET_RECLAIM_attribute_typename_to_number(const char *typename)
Convert a type name to the corresponding number.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void list_tickets_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List tickets for identity request.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:884
#define ID_REST_STATE_POST_INIT
Done collecting egos.
struct GNUNET_RECLAIM_Identifier id
ID.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
size_t data_size
Number of bytes in data.
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_attribute_store(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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:1135
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:77
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
int response_code
Response code.
#define GNUNET_REST_API_NS_RECLAIM
REST root namespace.
static void ticket_collect(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
Collect all attributes for an ego.
static char * plugin
Solver plugin name as string.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1977
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 &#39;claim&#39; of an attribute to the binary representation.
static void delete_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List attributes for identity request.
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:232
static void return_response(void *cls)
Return attributes for identity.
const char * data
The POST data.
struct RequestHandle * next
DLL.
struct GNUNET_CRYPTO_EcdsaPublicKey identity
The ticket issuer (= the user)
char * keystring
Public key string.
A credential presentation.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
void * libgnunet_plugin_rest_reclaim_done(void *cls)
Exit point from the plugin.
struct GNUNET_RECLAIM_AttributeList * attr_list
Attribute claim list.
#define GNUNET_REST_API_NS_IDENTITY_REVOKE
Revoke namespace.
const char * name
The name of the credential.
struct GNUNET_RECLAIM_AttributeListEntry * next
DLL.
static char * type_str
Attribute type.
struct RequestHandle * prev
DLL.
struct GNUNET_RECLAIM_CredentialIterator * cred_it
Credential iterator.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
static void delete_finished_cb(void *cls, int32_t success, const char *emsg)
static struct GNUNET_SCHEDULER_Task * timeout_task
Task to be run on timeout.
Definition: gnunet-arm.c:124
static void do_error(void *cls)
Task run on error, sends error message.
char * identifier
Ego Identifier.
static struct EgoEntry * ego_head
Ego list.
const char * GNUNET_RECLAIM_attribute_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string.
static void revoke_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
static void attr_collect(void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr)
Collect all attributes for an ego.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
configuration data
Definition: configuration.c:84
Handle for a plugin.
Definition: block.c:37
void GNUNET_RECLAIM_get_attributes_stop(struct GNUNET_RECLAIM_AttributeIterator *it)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1398
static void cred_collect(void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_Credential *cred)
Collect all credentials for an ego.
struct GNUNET_RECLAIM_Identifier rnd
The ticket random identifier.
struct GNUNET_CRYPTO_EcdsaPublicKey audience
The ticket audience (= relying party)
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
static void do_timeout(void *cls)
Task run on timeout, sends error message.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
static struct RequestHandle * requests_head
DLL.
Handle for a ticket iterator operation.
Definition: reclaim_api.c:119
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
const void * data
Binary value stored as attribute value.
void * libgnunet_plugin_rest_reclaim_init(void *cls)
Entry point for the plugin.
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
char * GNUNET_RECLAIM_attribute_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;claim&#39; of an attribute to a string.
uint32_t type
Type of Claim.
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_credential_delete(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const struct GNUNET_RECLAIM_Credential *cred, GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls)
Delete a credential.
Definition: reclaim_api.c:1274
static void consume_cont(void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr, const struct GNUNET_RECLAIM_Presentation *pres)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Time for absolute times used by GNUnet, in microseconds.
static int state
The processing state.
struct GNUNET_RECLAIM_Operation * GNUNET_RECLAIM_credential_store(struct GNUNET_RECLAIM_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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:1227
struct EgoEntry * prev
DLL.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end(void)
End of a parser specification.
Definition: json_helper.c:35
char * GNUNET_RECLAIM_credential_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;claim&#39; of an credential to a string.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:936
#define GNUNET_RECLAIM_id_generate(id)
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static void cleanup_handle(void *cls)
Cleanup lookup handle.
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
struct GNUNET_RECLAIM_Handle * GNUNET_RECLAIM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the re:claimID service.
Definition: reclaim_api.c:1064
uint32_t data
The data value.
static void list_credential_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Lists credential for identity request.
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:608
struct EgoEntry * next
DLL.
Handle for a credential iterator operation.
Definition: reclaim_api.c:249
struct GNUNET_RECLAIM_AttributeListEntry * list_head
List head.
int 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:971
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 add_credential_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
#define GNUNET_REST_API_NS_IDENTITY_TICKETS
Ticket namespace.
static enum GNUNET_GenericReturnValue rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
#define GNUNET_RECLAIM_id_is_zero(a)
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_ticket(struct GNUNET_RECLAIM_Ticket **ticket)
JSON Specification for Reclaim tickets.
Definition: json_reclaim.c:266
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
struct GNUNET_RECLAIM_AttributeList * GNUNET_RECLAIM_credential_get_attributes(const struct GNUNET_RECLAIM_Credential *cred)
Convert an credential type name to the corresponding number.
char * url
The url.