GNUnet  0.20.0
plugin_rest_reclaim.c File Reference

GNUnet reclaim REST plugin. More...

#include "platform.h"
#include "microhttpd.h"
#include <inttypes.h>
#include <jansson.h>
#include "gnunet_gns_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_identity_service.h"
#include "gnunet_reclaim_lib.h"
#include "gnunet_reclaim_service.h"
#include "gnunet_rest_lib.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_signatures.h"
#include "json_reclaim.h"
Include dependency graph for plugin_rest_reclaim.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  EgoEntry
 The ego list. More...
 
struct  RequestHandle
 The request handle. More...
 

Macros

#define GNUNET_REST_API_NS_RECLAIM   "/reclaim"
 REST root namespace. More...
 
#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES   "/reclaim/attributes"
 Attribute namespace. More...
 
#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL   "/reclaim/credential"
 Credential namespace. More...
 
#define GNUNET_REST_API_NS_IDENTITY_TICKETS   "/reclaim/tickets"
 Ticket namespace. More...
 
#define GNUNET_REST_API_NS_IDENTITY_REVOKE   "/reclaim/revoke"
 Revoke namespace. More...
 
#define GNUNET_REST_API_NS_IDENTITY_CONSUME   "/reclaim/consume"
 Revoke namespace. More...
 
#define ID_REST_STATE_INIT   0
 State while collecting all egos. More...
 
#define ID_REST_STATE_POST_INIT   1
 Done collecting egos. More...
 

Functions

static void cleanup_handle (void *cls)
 Cleanup lookup handle. More...
 
static void do_error (void *cls)
 Task run on error, sends error message. More...
 
static void do_timeout (void *cls)
 Task run on timeout, sends error message. More...
 
static void collect_error_cb (void *cls)
 
static void finished_cont (void *cls, int32_t success, const char *emsg)
 
static void delete_finished_cb (void *cls, int32_t success, const char *emsg)
 
static void return_response (void *cls)
 Return attributes for identity. More...
 
static void collect_finished_cb (void *cls)
 
static void ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
 Collect all attributes for an ego. More...
 
static void add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, 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. More...
 
static void list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Lists credential for identity request. More...
 
static void delete_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Deletes credential from an identity. More...
 
static void list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 List tickets for identity request. More...
 
static void add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 
struct GNUNET_RECLAIM_Attributeparse_jwt (const struct GNUNET_RECLAIM_Credential *cred, const char *claim)
 Parse a JWT and return the respective claim value as Attribute. More...
 
static void attr_collect (void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr)
 Collect all attributes for an ego. More...
 
static void list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 List attributes for identity request. More...
 
static void delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 List attributes for identity request. More...
 
static void revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 
static void consume_cont (void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr, const struct GNUNET_RECLAIM_Presentation *presentation)
 
static void consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 
static void options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Respond to OPTIONS request. More...
 
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. More...
 
static enum GNUNET_GenericReturnValue rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
 
void * libgnunet_plugin_rest_reclaim_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_rest_reclaim_done (void *cls)
 Exit point from the plugin. More...
 

Variables

const struct GNUNET_CONFIGURATION_Handlecfg
 The configuration handle. More...
 
static char * allow_methods
 HTTP methods allows for this plugin. More...
 
static struct EgoEntryego_head
 Ego list. More...
 
static struct EgoEntryego_tail
 Ego list. More...
 
static int state
 The processing state. More...
 
static struct GNUNET_IDENTITY_Handleidentity_handle
 Handle to Identity service. More...
 
static struct GNUNET_RECLAIM_Handleidp
 Identity Provider. More...
 
static struct RequestHandlerequests_head
 DLL. More...
 
static struct RequestHandlerequests_tail
 DLL. More...
 

Detailed Description

GNUnet reclaim REST plugin.

Author
Martin Schanzenbach
Philippe Buschmann

Definition in file plugin_rest_reclaim.c.

Macro Definition Documentation

◆ GNUNET_REST_API_NS_RECLAIM

#define GNUNET_REST_API_NS_RECLAIM   "/reclaim"

REST root namespace.

Definition at line 43 of file plugin_rest_reclaim.c.

◆ GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES

#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES   "/reclaim/attributes"

Attribute namespace.

Definition at line 48 of file plugin_rest_reclaim.c.

◆ GNUNET_REST_API_NS_RECLAIM_CREDENTIAL

#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL   "/reclaim/credential"

Credential namespace.

Definition at line 53 of file plugin_rest_reclaim.c.

◆ GNUNET_REST_API_NS_IDENTITY_TICKETS

#define GNUNET_REST_API_NS_IDENTITY_TICKETS   "/reclaim/tickets"

Ticket namespace.

Definition at line 58 of file plugin_rest_reclaim.c.

◆ GNUNET_REST_API_NS_IDENTITY_REVOKE

#define GNUNET_REST_API_NS_IDENTITY_REVOKE   "/reclaim/revoke"

Revoke namespace.

Definition at line 63 of file plugin_rest_reclaim.c.

◆ GNUNET_REST_API_NS_IDENTITY_CONSUME

#define GNUNET_REST_API_NS_IDENTITY_CONSUME   "/reclaim/consume"

Revoke namespace.

Definition at line 68 of file plugin_rest_reclaim.c.

◆ ID_REST_STATE_INIT

#define ID_REST_STATE_INIT   0

State while collecting all egos.

Definition at line 73 of file plugin_rest_reclaim.c.

◆ ID_REST_STATE_POST_INIT

#define ID_REST_STATE_POST_INIT   1

Done collecting egos.

Definition at line 78 of file plugin_rest_reclaim.c.

Function Documentation

◆ cleanup_handle()

static void cleanup_handle ( void *  cls)
static

Cleanup lookup handle.

Parameters
handleHandle to clean up

Definition at line 274 of file plugin_rest_reclaim.c.

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 }
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_RECLAIM_attribute_list_destroy(struct GNUNET_RECLAIM_AttributeList *attrs)
Destroy claim list.
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_stop(struct GNUNET_RECLAIM_CredentialIterator *ait)
Stops iteration and releases the handle for further calls.
Definition: reclaim_api.c:1469
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
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
static struct RequestHandle * requests_head
DLL.
static struct RequestHandle * requests_tail
DLL.
The request handle.

References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_RECLAIM_attribute_list_destroy(), GNUNET_RECLAIM_get_attributes_stop(), GNUNET_RECLAIM_get_credentials_stop(), GNUNET_RECLAIM_ticket_iteration_stop(), GNUNET_SCHEDULER_cancel(), handle, requests_head, and requests_tail.

Referenced by delete_finished_cb(), do_error(), finished_cont(), options_cont(), and return_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_error()

static void do_error ( void *  cls)
static

Task run on error, sends error message.

Cleans up everything.

Parameters
clsthe struct RequestHandle

Definition at line 308 of file plugin_rest_reclaim.c.

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 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:44
@ MHD_HTTP_BAD_REQUEST
Bad Request [RFC7231, Section 6.5.1].
static void cleanup_handle(void *cls)
Cleanup lookup handle.

References cleanup_handle(), GNUNET_asprintf(), GNUNET_assert, GNUNET_free, GNUNET_REST_create_response(), handle, and MHD_HTTP_BAD_REQUEST.

Referenced by add_attribute_cont(), add_credential_cont(), collect_error_cb(), consume_ticket_cont(), delete_attribute_cont(), delete_credential_cont(), delete_finished_cb(), do_timeout(), finished_cont(), libgnunet_plugin_rest_reclaim_done(), list_attribute_cont(), list_credential_cont(), list_tickets_cont(), and revoke_ticket_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_timeout()

static void do_timeout ( void *  cls)
static

Task run on timeout, sends error message.

Cleans up everything.

Parameters
clsthe struct RequestHandle

Definition at line 333 of file plugin_rest_reclaim.c.

334 {
335  struct RequestHandle *handle = cls;
336 
337  handle->timeout_task = NULL;
338  do_error (handle);
339 }
static void do_error(void *cls)
Task run on error, sends error message.

References do_error(), and handle.

Here is the call graph for this function:

◆ collect_error_cb()

static void collect_error_cb ( void *  cls)
static

Definition at line 343 of file plugin_rest_reclaim.c.

344 {
346 }
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

References do_error(), and GNUNET_SCHEDULER_add_now().

Referenced by list_attribute_cont(), list_credential_cont(), and list_tickets_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finished_cont()

static void finished_cont ( void *  cls,
int32_t  success,
const char *  emsg 
)
static

Definition at line 350 of file plugin_rest_reclaim.c.

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 }
@ GNUNET_OK
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].
static char * allow_methods
HTTP methods allows for this plugin.

References allow_methods, cleanup_handle(), do_error(), GNUNET_assert, GNUNET_OK, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and MHD_HTTP_OK.

Referenced by add_attribute_cont(), add_credential_cont(), and revoke_ticket_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_finished_cb()

static void delete_finished_cb ( void *  cls,
int32_t  success,
const char *  emsg 
)
static

Definition at line 374 of file plugin_rest_reclaim.c.

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 }

References allow_methods, cleanup_handle(), do_error(), GNUNET_assert, GNUNET_OK, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and MHD_HTTP_OK.

Referenced by delete_attribute_cont(), and delete_credential_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ return_response()

static void return_response ( void *  cls)
static

Return attributes for identity.

Parameters
clsthe request handle

Definition at line 399 of file plugin_rest_reclaim.c.

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 }

References allow_methods, cleanup_handle(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_REST_create_response(), handle, and MHD_HTTP_OK.

Referenced by collect_finished_cb(), consume_cont(), delete_attribute_cont(), delete_credential_cont(), list_attribute_cont(), list_credential_cont(), and list_tickets_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ collect_finished_cb()

static void collect_finished_cb ( void *  cls)
static

Definition at line 419 of file plugin_rest_reclaim.c.

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 }
static void return_response(void *cls)
Return attributes for identity.

References GNUNET_SCHEDULER_add_now(), handle, and return_response().

Referenced by list_attribute_cont(), list_credential_cont(), and list_tickets_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ticket_collect()

static void ticket_collect ( void *  cls,
const struct GNUNET_RECLAIM_Ticket ticket 
)
static

Collect all attributes for an ego.

Definition at line 436 of file plugin_rest_reclaim.c.

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 }
static char * value
Value of the record to add/remove.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
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
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
An identity key as per LSD0001.
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)

References GNUNET_RECLAIM_Ticket::audience, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_RECLAIM_ticket_iteration_next(), GNUNET_STRINGS_data_to_string_alloc(), handle, GNUNET_RECLAIM_Ticket::identity, GNUNET_RECLAIM_Ticket::rnd, ticket, and value.

Referenced by list_tickets_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_credential_cont()

static void add_credential_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

New ID for attribute

Definition at line 472 of file plugin_rest_reclaim.c.

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 }
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
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
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
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_RECLAIM_id_is_zero(a)
#define GNUNET_RECLAIM_id_generate(id)
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
#define GNUNET_TIME_UNIT_HOURS
One hour.
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_credential(struct GNUNET_RECLAIM_Credential **cred)
JSON Specification for credential claims.
Definition: json_reclaim.c:385
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
static void finished_cont(void *cls, int32_t success, const char *emsg)
#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL
Credential namespace.
static struct EgoEntry * ego_head
Ego list.
The ego list.
char * identifier
Ego Identifier.
struct EgoEntry * next
DLL.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
A private key for an identity as per LSD0001.
Entry in parser specification for GNUNET_JSON_parse().
struct GNUNET_RECLAIM_Identifier id
ID.
Time for relative time used by GNUnet, in microseconds.

References do_error(), EgoEntry::ego, ego_head, finished_cont(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_JSON_parse(), GNUNET_JSON_parse_free(), GNUNET_JSON_spec_end(), GNUNET_log, GNUNET_memcpy, GNUNET_OK, GNUNET_RECLAIM_credential_store(), GNUNET_RECLAIM_id_generate, GNUNET_RECLAIM_id_is_zero, GNUNET_RECLAIM_JSON_spec_credential(), GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, GNUNET_SCHEDULER_add_now(), GNUNET_TIME_UNIT_HOURS, GNUNET_YES, handle, GNUNET_RECLAIM_Credential::id, EgoEntry::identifier, identity, idp, and EgoEntry::next.

Here is the call graph for this function:

◆ cred_collect()

static void cred_collect ( void *  cls,
const struct GNUNET_IDENTITY_PublicKey identity,
const struct GNUNET_RECLAIM_Credential cred 
)
static

Collect all credentials for an ego.

Definition at line 564 of file plugin_rest_reclaim.c.

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 }
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.
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.
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.
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.
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_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.
uint32_t type
Type of Claim.
const void * data
Binary value stored as attribute value.
size_t data_size
Number of bytes in data.
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.
Time for absolute times used by GNUnet, in microseconds.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_RECLAIM_AttributeListEntry::attribute, GNUNET_RECLAIM_Attribute::data, GNUNET_RECLAIM_Credential::data, GNUNET_RECLAIM_Attribute::data_size, GNUNET_RECLAIM_Credential::data_size, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_RECLAIM_attribute_list_destroy(), GNUNET_RECLAIM_attribute_number_to_typename(), GNUNET_RECLAIM_attribute_value_to_string(), GNUNET_RECLAIM_credential_get_attributes(), GNUNET_RECLAIM_credential_get_expiration(), GNUNET_RECLAIM_credential_get_issuer(), GNUNET_RECLAIM_credential_number_to_typename(), GNUNET_RECLAIM_credential_value_to_string(), GNUNET_RECLAIM_get_credentials_next(), GNUNET_STRINGS_data_to_string_alloc(), handle, GNUNET_RECLAIM_Credential::id, GNUNET_RECLAIM_AttributeList::list_head, GNUNET_RECLAIM_Attribute::name, GNUNET_RECLAIM_Credential::name, GNUNET_RECLAIM_AttributeListEntry::next, GNUNET_RECLAIM_Attribute::type, GNUNET_RECLAIM_Credential::type, and type.

Referenced by list_credential_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_credential_cont()

static void list_credential_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

Lists credential for identity request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 647 of file plugin_rest_reclaim.c.

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 }
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
static void collect_error_cb(void *cls)
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.

References collect_error_cb(), collect_finished_cb(), cred_collect(), do_error(), EgoEntry::ego, ego_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_RECLAIM_get_credentials_start(), GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, GNUNET_SCHEDULER_add_now(), handle, EgoEntry::identifier, identity, idp, EgoEntry::next, and return_response().

Here is the call graph for this function:

◆ delete_credential_cont()

static void delete_credential_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

Deletes credential from an identity.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 704 of file plugin_rest_reclaim.c.

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 }
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
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
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
static void delete_finished_cb(void *cls, int32_t success, const char *emsg)

References delete_finished_cb(), do_error(), EgoEntry::ego, ego_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_RECLAIM_credential_delete(), GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_string_to_data(), handle, id, GNUNET_RECLAIM_Credential::id, EgoEntry::identifier, identity, idp, GNUNET_RECLAIM_Credential::name, EgoEntry::next, and return_response().

Here is the call graph for this function:

◆ list_tickets_cont()

static void list_tickets_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

List tickets for identity request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 771 of file plugin_rest_reclaim.c.

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 }
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
#define GNUNET_REST_API_NS_IDENTITY_TICKETS
Ticket namespace.
static void ticket_collect(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
Collect all attributes for an ego.

References collect_error_cb(), collect_finished_cb(), do_error(), EgoEntry::ego, ego_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_RECLAIM_ticket_iteration_start(), GNUNET_REST_API_NS_IDENTITY_TICKETS, GNUNET_SCHEDULER_add_now(), handle, EgoEntry::identifier, identity, idp, EgoEntry::next, return_response(), and ticket_collect().

Here is the call graph for this function:

◆ add_attribute_cont()

static void add_attribute_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

New ID for attribute

Definition at line 818 of file plugin_rest_reclaim.c.

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 }
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_JSON_Specification GNUNET_RECLAIM_JSON_spec_attribute(struct GNUNET_RECLAIM_Attribute **attr)
JSON Specification for Reclaim claims.
Definition: json_reclaim.c:146
#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES
Attribute namespace.
struct GNUNET_RECLAIM_Identifier id
ID.

References do_error(), EgoEntry::ego, ego_head, finished_cont(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_JSON_parse(), GNUNET_JSON_parse_free(), GNUNET_JSON_spec_end(), GNUNET_log, GNUNET_memcpy, GNUNET_OK, GNUNET_RECLAIM_attribute_store(), GNUNET_RECLAIM_id_generate, GNUNET_RECLAIM_id_is_zero, GNUNET_RECLAIM_JSON_spec_attribute(), GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, GNUNET_SCHEDULER_add_now(), GNUNET_TIME_UNIT_HOURS, GNUNET_YES, handle, GNUNET_RECLAIM_Attribute::id, EgoEntry::identifier, identity, idp, and EgoEntry::next.

Here is the call graph for this function:

◆ parse_jwt()

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.

Parameters
credthe jwt credential
claimthe name of the claim in the JWT
Returns
a GNUNET_RECLAIM_Attribute, containing the new value

Definition at line 904 of file plugin_rest_reclaim.c.

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 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
struct GNUNET_HashCode key
The key used in the DHT.
uint32_t data
The data value.
struct GNUNET_RECLAIM_Attribute * claim
Claim to store.
static char * type_str
Attribute type.
@ GNUNET_SYSERR
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.
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.
uint32_t GNUNET_RECLAIM_attribute_typename_to_number(const char *typename)
Convert a type name to the corresponding number.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1695

References claim, GNUNET_RECLAIM_Credential::data, data, data_size, GNUNET_RECLAIM_Credential::data_size, GNUNET_RECLAIM_Attribute::flag, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_RECLAIM_attribute_new(), GNUNET_RECLAIM_attribute_string_to_value(), GNUNET_RECLAIM_attribute_typename_to_number(), GNUNET_RECLAIM_credential_value_to_string(), GNUNET_STRINGS_base64_decode(), GNUNET_SYSERR, GNUNET_RECLAIM_Attribute::id, GNUNET_RECLAIM_Credential::id, key, GNUNET_RECLAIM_Credential::type, type, type_str, and value.

Here is the call graph for this function:

◆ attr_collect()

static void attr_collect ( void *  cls,
const struct GNUNET_IDENTITY_PublicKey identity,
const struct GNUNET_RECLAIM_Attribute attr 
)
static

Collect all attributes for an ego.

Definition at line 969 of file plugin_rest_reclaim.c.

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 }
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_Identifier credential
Referenced ID of credential (may be GNUNET_RECLAIM_ID_ZERO if self-creded)

References GNUNET_RECLAIM_Attribute::credential, GNUNET_RECLAIM_Attribute::data, GNUNET_RECLAIM_Attribute::data_size, GNUNET_free, GNUNET_RECLAIM_attribute_number_to_typename(), GNUNET_RECLAIM_attribute_value_to_string(), GNUNET_RECLAIM_get_attributes_next(), GNUNET_RECLAIM_id_is_zero, GNUNET_STRINGS_data_to_string_alloc(), handle, GNUNET_RECLAIM_Attribute::id, GNUNET_RECLAIM_Attribute::name, GNUNET_RECLAIM_Attribute::type, and type.

Referenced by list_attribute_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_attribute_cont()

static void list_attribute_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

List attributes for identity request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 1015 of file plugin_rest_reclaim.c.

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 }
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
static void attr_collect(void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr)
Collect all attributes for an ego.

References attr_collect(), collect_error_cb(), collect_finished_cb(), do_error(), EgoEntry::ego, ego_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_RECLAIM_get_attributes_start(), GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, GNUNET_SCHEDULER_add_now(), handle, EgoEntry::identifier, identity, idp, EgoEntry::next, and return_response().

Here is the call graph for this function:

◆ delete_attribute_cont()

static void delete_attribute_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

List attributes for identity request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 1069 of file plugin_rest_reclaim.c.

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 }
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

References delete_finished_cb(), do_error(), EgoEntry::ego, ego_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_RECLAIM_attribute_delete(), GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_string_to_data(), handle, id, GNUNET_RECLAIM_Attribute::id, EgoEntry::identifier, identity, idp, GNUNET_RECLAIM_Attribute::name, EgoEntry::next, and return_response().

Here is the call graph for this function:

◆ revoke_ticket_cont()

static void revoke_ticket_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

Definition at line 1127 of file plugin_rest_reclaim.c.

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 }
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
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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_JSON_Specification GNUNET_RECLAIM_JSON_spec_ticket(struct GNUNET_RECLAIM_Ticket **ticket)
JSON Specification for Reclaim tickets.
Definition: json_reclaim.c:265
The authorization ticket.

References do_error(), EgoEntry::ego, ego_head, finished_cont(), GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_IDENTITY_ego_get_public_key(), GNUNET_JSON_parse(), GNUNET_JSON_parse_free(), GNUNET_JSON_spec_end(), GNUNET_log, GNUNET_memcpy, GNUNET_OK, GNUNET_RECLAIM_JSON_spec_ticket(), GNUNET_RECLAIM_ticket_revoke(), GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, GNUNET_RECLAIM_Ticket::identity, idp, EgoEntry::next, and ticket.

Here is the call graph for this function:

◆ consume_cont()

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

Definition at line 1200 of file plugin_rest_reclaim.c.

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 }

References GNUNET_RECLAIM_Attribute::data, GNUNET_RECLAIM_Attribute::data_size, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_RECLAIM_attribute_value_to_string(), GNUNET_SCHEDULER_add_now(), handle, identity, GNUNET_RECLAIM_Attribute::name, return_response(), GNUNET_RECLAIM_Attribute::type, and value.

Referenced by consume_ticket_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consume_ticket_cont()

static void consume_ticket_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

Definition at line 1234 of file plugin_rest_reclaim.c.

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 }
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
static void consume_cont(void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr, const struct GNUNET_RECLAIM_Presentation *presentation)

References GNUNET_RECLAIM_Ticket::audience, consume_cont(), do_error(), EgoEntry::ego, ego_head, GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_IDENTITY_ego_get_public_key(), GNUNET_JSON_parse(), GNUNET_JSON_parse_free(), GNUNET_JSON_spec_end(), GNUNET_log, GNUNET_memcpy, GNUNET_OK, GNUNET_RECLAIM_JSON_spec_ticket(), GNUNET_RECLAIM_ticket_consume(), GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, idp, EgoEntry::next, and ticket.

Here is the call graph for this function:

◆ options_cont()

static void options_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

Respond to OPTIONS request.

Parameters
con_handlethe connection handle
urlthe url
clsthe RequestHandle

Definition at line 1310 of file plugin_rest_reclaim.c.

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 }

References allow_methods, cleanup_handle(), GNUNET_assert, GNUNET_REST_create_response(), handle, and MHD_HTTP_OK.

Here is the call graph for this function:

◆ list_ego()

static void list_ego ( void *  cls,
struct GNUNET_IDENTITY_Ego ego,
void **  ctx,
const char *  identifier 
)
static

If listing is enabled, prints information about the egos.

This function is initially called for all egos and then again whenever a ego's identifier changes or if it is deleted. At the end of the initial pass over all egos, the function is once called with 'NULL' for 'ego'. That does NOT mean that the callback won't be invoked in the future or that there was an error.

When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get', this function is only called ONCE, and 'NULL' being passed in 'ego' does indicate an error (for example because name is taken or no default value is known). If 'ego' is non-NULL and if '*ctx' is set in those callbacks, the value WILL be passed to a subsequent call to the identity callback of 'GNUNET_IDENTITY_connect' (if that one was not NULL).

When an identity is renamed, this function is called with the (known) ego but the NEW identifier.

When an identity is deleted, this function is called with the (known) ego and "NULL" for the 'identifier'. In this case, the 'ego' is henceforth invalid (and the 'ctx' should also be cleaned up).

Parameters
clsclosure
egoego handle
ctxcontext for application to store data for this ego (during the lifetime of this process, initially NULL)
identifieridentifier assigned by the user for this ego, NULL if the user just deleted the ego and it must thus no longer be used

Definition at line 1359 of file plugin_rest_reclaim.c.

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 }
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct EgoEntry * ego_tail
Ego list.
#define ID_REST_STATE_INIT
State while collecting all egos.
static int state
The processing state.
#define ID_REST_STATE_POST_INIT
Done collecting egos.
char * keystring
Public key string.

References EgoEntry::ego, ego_head, ego_tail, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_IDENTITY_ego_get_public_key(), GNUNET_IDENTITY_public_key_to_string(), GNUNET_new, GNUNET_strdup, ID_REST_STATE_INIT, ID_REST_STATE_POST_INIT, EgoEntry::identifier, EgoEntry::keystring, EgoEntry::next, pk, and state.

Referenced by libgnunet_plugin_rest_reclaim_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rest_identity_process_request()

static enum GNUNET_GenericReturnValue rest_identity_process_request ( struct GNUNET_REST_RequestHandle rest_handle,
GNUNET_REST_ResultProcessor  proc,
void *  proc_cls 
)
static

Definition at line 1359 of file plugin_rest_reclaim.c.

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 }
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
@ GNUNET_NO
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
#define GNUNET_REST_HANDLER_END
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
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_REST_API_NS_IDENTITY_REVOKE
Revoke namespace.
static void do_timeout(void *cls)
Task run on timeout, sends error message.
#define GNUNET_REST_API_NS_IDENTITY_CONSUME
Revoke namespace.
static void delete_credential_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Deletes credential from an identity.
static void revoke_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
#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.
static void list_tickets_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List tickets for identity request.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
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 void add_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
static void list_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List attributes for identity request.
static void consume_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
const char * url
The url as string.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.

Referenced by libgnunet_plugin_rest_reclaim_init().

Here is the caller graph for this function:

◆ libgnunet_plugin_rest_reclaim_init()

void* libgnunet_plugin_rest_reclaim_init ( void *  cls)

Entry point for the plugin.

Parameters
clsConfig info
Returns
NULL on error, otherwise the plugin context

Definition at line 1495 of file plugin_rest_reclaim.c.

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 }
struct TestcasePlugin * plugin
The process handle to the testbed service.
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
struct GNUNET_RECLAIM_Handle * GNUNET_RECLAIM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the re:claimID service.
Definition: reclaim_api.c:1111
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
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 struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static enum GNUNET_GenericReturnValue rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
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.
Handle for a plugin.
Definition: block.c:38

References _, allow_methods, cfg, GNUNET_REST_Plugin::cls, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_connect(), GNUNET_log, GNUNET_new, GNUNET_RECLAIM_connect(), GNUNET_REST_API_NS_RECLAIM, ID_REST_STATE_INIT, identity_handle, idp, list_ego(), GNUNET_REST_Plugin::name, plugin, GNUNET_REST_Plugin::process_request, rest_identity_process_request(), and state.

Here is the call graph for this function:

◆ libgnunet_plugin_rest_reclaim_done()

void* libgnunet_plugin_rest_reclaim_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe plugin context (as returned by "init")
Returns
always NULL

Definition at line 1532 of file plugin_rest_reclaim.c.

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 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:40
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:757
void GNUNET_RECLAIM_disconnect(struct GNUNET_RECLAIM_Handle *h)
Disconnect from identity provider service.
Definition: reclaim_api.c:1143
void * cls
Closure for all of the callbacks.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References allow_methods, Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_REST_Plugin::cls, do_error(), ego_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_disconnect(), GNUNET_log, GNUNET_RECLAIM_disconnect(), EgoEntry::identifier, identity_handle, idp, EgoEntry::keystring, EgoEntry::next, plugin, request, and requests_head.

Here is the call graph for this function:

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg

The configuration handle.

Handle to our configuration.

Definition at line 83 of file plugin_rest_reclaim.c.

Referenced by libgnunet_plugin_rest_reclaim_init().

◆ allow_methods

char* allow_methods
static

◆ ego_head

◆ ego_tail

struct EgoEntry* ego_tail
static

Ego list.

Definition at line 98 of file plugin_rest_reclaim.c.

Referenced by list_ego().

◆ state

int state
static

The processing state.

Definition at line 103 of file plugin_rest_reclaim.c.

Referenced by libgnunet_plugin_rest_reclaim_init(), and list_ego().

◆ identity_handle

struct GNUNET_IDENTITY_Handle* identity_handle
static

Handle to Identity service.

Definition at line 108 of file plugin_rest_reclaim.c.

Referenced by libgnunet_plugin_rest_reclaim_done(), and libgnunet_plugin_rest_reclaim_init().

◆ idp

◆ requests_head

struct RequestHandle* requests_head
static

DLL.

Definition at line 261 of file plugin_rest_reclaim.c.

Referenced by cleanup_handle(), and libgnunet_plugin_rest_reclaim_done().

◆ requests_tail

struct RequestHandle* requests_tail
static

DLL.

Definition at line 266 of file plugin_rest_reclaim.c.

Referenced by cleanup_handle().