GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
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 *pres)
 
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.

Referenced by libgnunet_plugin_rest_reclaim_init(), and rest_identity_process_request().

◆ GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES

#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES   "/reclaim/attributes"

◆ GNUNET_REST_API_NS_RECLAIM_CREDENTIAL

#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL   "/reclaim/credential"

◆ 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.

Referenced by list_tickets_cont(), and rest_identity_process_request().

◆ 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.

Referenced by rest_identity_process_request().

◆ 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.

Referenced by rest_identity_process_request().

◆ 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.

Referenced by libgnunet_plugin_rest_reclaim_init(), and list_ego().

◆ 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.

Referenced by list_ego().

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.

References RequestHandle::attr_it, RequestHandle::attr_list, RequestHandle::cred_it, RequestHandle::emsg, 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, RequestHandle::resp_object, RequestHandle::ticket_it, RequestHandle::timeout_task, and RequestHandle::url.

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

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)
297  handle);
298  GNUNET_free (handle);
299 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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
void GNUNET_RECLAIM_attribute_list_destroy(struct GNUNET_RECLAIM_AttributeList *attrs)
Destroy claim list.
struct GNUNET_RECLAIM_AttributeIterator * attr_it
Attribute iterator.
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
The request handle.
json_t * resp_object
Response object.
char * emsg
Error response message.
static struct RequestHandle * requests_tail
DLL.
struct GNUNET_RECLAIM_TicketIterator * ticket_it
Ticket iterator.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_RECLAIM_AttributeList * attr_list
Attribute claim list.
struct GNUNET_RECLAIM_CredentialIterator * cred_it
Credential iterator.
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
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
static struct RequestHandle * requests_head
DLL.
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
char * url
The url.
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.

References cleanup_handle(), RequestHandle::emsg, GNUNET_asprintf(), GNUNET_free, GNUNET_REST_create_response(), handle, RequestHandle::proc, RequestHandle::proc_cls, and RequestHandle::response_code.

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().

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 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
char * emsg
Error response message.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
Response code.
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:57
static void cleanup_handle(void *cls)
Cleanup lookup handle.
#define GNUNET_free(ptr)
Wrapper around free.
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.

References do_error(), handle, and RequestHandle::timeout_task.

Referenced by rest_identity_process_request().

334 {
335  struct RequestHandle *handle = cls;
336 
337  handle->timeout_task = NULL;
338  do_error (handle);
339 }
The request handle.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void do_error(void *cls)
Task run on error, sends error message.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
Here is the call graph for this function:
Here is the caller 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.

References do_error(), and GNUNET_SCHEDULER_add_now().

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

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:1296
static void do_error(void *cls)
Task run on error, sends error message.
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.

References allow_methods, cleanup_handle(), do_error(), GNUNET_OK, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, RequestHandle::idp_op, RequestHandle::proc, and RequestHandle::proc_cls.

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

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 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
static char * allow_methods
HTTP methods allows for this plugin.
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void do_error(void *cls)
Task run on error, sends error message.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
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 370 of file plugin_rest_reclaim.c.

References allow_methods, cleanup_handle(), do_error(), GNUNET_OK, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, RequestHandle::proc, and RequestHandle::proc_cls.

Referenced by delete_attribute_cont(), and delete_credential_cont().

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 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
static char * allow_methods
HTTP methods allows for this plugin.
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void do_error(void *cls)
Task run on error, sends error message.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
static void cleanup_handle(void *cls)
Cleanup lookup handle.
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 393 of file plugin_rest_reclaim.c.

References allow_methods, cleanup_handle(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_REST_create_response(), handle, RequestHandle::proc, RequestHandle::proc_cls, and RequestHandle::resp_object.

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

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 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
static char * allow_methods
HTTP methods allows for this plugin.
json_t * resp_object
Response object.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
#define GNUNET_log(kind,...)
static void cleanup_handle(void *cls)
Cleanup lookup handle.
#define GNUNET_free(ptr)
Wrapper around free.
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 410 of file plugin_rest_reclaim.c.

References RequestHandle::attr_it, RequestHandle::cred_it, GNUNET_SCHEDULER_add_now(), handle, return_response(), and RequestHandle::ticket_it.

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

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 }
struct GNUNET_RECLAIM_AttributeIterator * attr_it
Attribute iterator.
The request handle.
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
struct GNUNET_RECLAIM_TicketIterator * ticket_it
Ticket iterator.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void return_response(void *cls)
Return attributes for identity.
struct GNUNET_RECLAIM_CredentialIterator * cred_it
Credential iterator.
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 427 of file plugin_rest_reclaim.c.

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, RequestHandle::resp_object, GNUNET_RECLAIM_Ticket::rnd, RequestHandle::ticket_it, and value.

Referenced by list_tickets_cont().

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 }
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
The request handle.
json_t * resp_object
Response object.
static char * value
Value of the record to add/remove.
struct GNUNET_IDENTITY_PublicKey identity
The ticket issuer (= the user)
struct GNUNET_RECLAIM_TicketIterator * ticket_it
Ticket iterator.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
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)
#define GNUNET_log(kind,...)
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:937
#define GNUNET_free(ptr)
Wrapper around free.
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 463 of file plugin_rest_reclaim.c.

References GNUNET_REST_RequestHandle::data, GNUNET_REST_RequestHandle::data_size, do_error(), EgoEntry::ego, 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_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, RequestHandle::idp_op, EgoEntry::next, RequestHandle::rest_handle, and RequestHandle::url.

Referenced by rest_identity_process_request().

466 {
467  struct RequestHandle *handle = cls;
468  const struct GNUNET_IDENTITY_PrivateKey *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 }
#define GNUNET_TIME_UNIT_HOURS
One hour.
struct GNUNET_RECLAIM_Identifier id
ID.
size_t data_size
The POST data size.
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
#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:106
static void finished_cont(void *cls, int32_t success, const char *emsg)
A private key for an identity as per LSD0001.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Entry in parser specification for GNUNET_JSON_parse().
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_credential(struct GNUNET_RECLAIM_Credential **cred)
JSON Specification for credential claims.
Definition: json_reclaim.c:379
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
const char * data
The POST data.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static void do_error(void *cls)
Task run on error, sends error message.
char * identifier
Ego Identifier.
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:1227
static struct EgoEntry * ego_head
Ego list.
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:639
#define GNUNET_log(kind,...)
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end(void)
End of a parser specification.
Definition: json_helper.c:35
#define GNUNET_RECLAIM_id_generate(id)
struct EgoEntry * next
DLL.
Time for relative time used by GNUnet, in microseconds.
#define GNUNET_RECLAIM_id_is_zero(a)
char * url
The url.
Here is the call graph for this function:
Here is the caller 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 547 of file plugin_rest_reclaim.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_RECLAIM_AttributeListEntry::attribute, RequestHandle::cred_it, 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, RequestHandle::resp_object, type, GNUNET_RECLAIM_Attribute::type, and GNUNET_RECLAIM_Credential::type.

Referenced by list_credential_cont().

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 }
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
struct GNUNET_RECLAIM_Identifier id
ID.
uint32_t type
Type/Format of Claim.
void GNUNET_RECLAIM_attribute_list_destroy(struct GNUNET_RECLAIM_AttributeList *attrs)
Destroy claim list.
const char * name
The name of the attribute.
int GNUNET_RECLAIM_credential_get_expiration(const struct GNUNET_RECLAIM_Credential *cred, struct GNUNET_TIME_Absolute *exp)
size_t data_size
Number of bytes in data.
A list of GNUNET_RECLAIM_Attribute structures.
const void * data
Binary value stored as credential value.
struct GNUNET_RECLAIM_Attribute * attribute
The attribute claim.
The request handle.
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_credential_get_issuer(const struct GNUNET_RECLAIM_Credential *cred)
json_t * resp_object
Response object.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
size_t data_size
Number of bytes in data.
const char * name
The name of the credential.
struct GNUNET_RECLAIM_AttributeListEntry * next
DLL.
struct GNUNET_RECLAIM_CredentialIterator * cred_it
Credential iterator.
const char * GNUNET_RECLAIM_attribute_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string.
#define GNUNET_log(kind,...)
const void * data
Binary value stored as attribute value.
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.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Time for absolute times used by GNUnet, in microseconds.
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:937
struct GNUNET_RECLAIM_AttributeListEntry * list_head
List head.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_RECLAIM_AttributeList * GNUNET_RECLAIM_credential_get_attributes(const struct GNUNET_RECLAIM_Credential *cred)
Convert an credential type name to the corresponding number.
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 629 of file plugin_rest_reclaim.c.

References collect_error_cb(), collect_finished_cb(), cred_collect(), RequestHandle::cred_it, do_error(), EgoEntry::ego, 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, EgoEntry::next, RequestHandle::resp_object, return_response(), and RequestHandle::url.

Referenced by rest_identity_process_request().

632 {
633  struct RequestHandle *handle = cls;
634  const struct GNUNET_IDENTITY_PrivateKey *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 }
static void collect_error_cb(void *cls)
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:1440
#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL
Credential namespace.
A private key for an identity as per LSD0001.
static void cred_collect(void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Credential *cred)
Collect all credentials for an ego.
static void collect_finished_cb(void *cls)
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
json_t * resp_object
Response object.
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void return_response(void *cls)
Return attributes for identity.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
struct GNUNET_RECLAIM_CredentialIterator * cred_it
Credential iterator.
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 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:639
#define GNUNET_log(kind,...)
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
struct EgoEntry * next
DLL.
char * url
The url.
Here is the call graph for this function:
Here is the caller 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 686 of file plugin_rest_reclaim.c.

References delete_finished_cb(), do_error(), EgoEntry::ego, 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, GNUNET_RECLAIM_Credential::id, id, EgoEntry::identifier, identity, RequestHandle::idp_op, GNUNET_RECLAIM_Credential::name, EgoEntry::next, RequestHandle::resp_object, return_response(), and RequestHandle::url.

Referenced by rest_identity_process_request().

689 {
690  struct RequestHandle *handle = cls;
691  const struct GNUNET_IDENTITY_PrivateKey *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 }
#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL
Credential namespace.
A private key for an identity as per LSD0001.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
json_t * resp_object
Response object.
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void return_response(void *cls)
Return attributes for identity.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static void delete_finished_cb(void *cls, int32_t success, const char *emsg)
static void do_error(void *cls)
Task run on error, sends error message.
char * identifier
Ego Identifier.
static struct EgoEntry * ego_head
Ego list.
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:1274
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:639
#define GNUNET_log(kind,...)
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
struct EgoEntry * next
DLL.
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:972
#define GNUNET_free(ptr)
Wrapper around free.
char * url
The url.
Here is the call graph for this function:
Here is the caller 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 753 of file plugin_rest_reclaim.c.

References collect_error_cb(), collect_finished_cb(), do_error(), EgoEntry::ego, 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, EgoEntry::next, RequestHandle::resp_object, return_response(), ticket_collect(), RequestHandle::ticket_it, and RequestHandle::url.

Referenced by rest_identity_process_request().

756 {
757  const struct GNUNET_IDENTITY_PrivateKey *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 }
static void collect_error_cb(void *cls)
A private key for an identity as per LSD0001.
static void collect_finished_cb(void *cls)
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
json_t * resp_object
Response object.
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
struct GNUNET_RECLAIM_TicketIterator * ticket_it
Ticket iterator.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void ticket_collect(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
Collect all attributes for an ego.
static void return_response(void *cls)
Return attributes for identity.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
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 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:639
#define GNUNET_log(kind,...)
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
struct EgoEntry * next
DLL.
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:1637
#define GNUNET_REST_API_NS_IDENTITY_TICKETS
Ticket namespace.
char * url
The url.
Here is the call graph for this function:
Here is the caller 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 800 of file plugin_rest_reclaim.c.

References GNUNET_REST_RequestHandle::data, GNUNET_REST_RequestHandle::data_size, do_error(), EgoEntry::ego, 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, RequestHandle::idp_op, EgoEntry::next, RequestHandle::rest_handle, and RequestHandle::url.

Referenced by rest_identity_process_request().

803 {
804  const struct GNUNET_IDENTITY_PrivateKey *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);
868  identity_priv,
869  attribute,
870  &exp,
871  &finished_cont,
872  handle);
873  GNUNET_JSON_parse_free (attrspec);
874 }
#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES
Attribute namespace.
#define GNUNET_TIME_UNIT_HOURS
One hour.
size_t data_size
The POST data size.
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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:106
static void finished_cont(void *cls, int32_t success, const char *emsg)
A private key for an identity as per LSD0001.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Entry in parser specification for GNUNET_JSON_parse().
The request handle.
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:146
struct GNUNET_IDENTITY_Ego * ego
The Ego.
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_RECLAIM_Identifier id
ID.
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
const char * data
The POST data.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
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 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:639
#define GNUNET_log(kind,...)
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
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:1135
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end(void)
End of a parser specification.
Definition: json_helper.c:35
#define GNUNET_RECLAIM_id_generate(id)
struct EgoEntry * next
DLL.
Time for relative time used by GNUnet, in microseconds.
#define GNUNET_RECLAIM_id_is_zero(a)
char * url
The url.
Here is the call graph for this function:
Here is the caller 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 886 of file plugin_rest_reclaim.c.

References data, GNUNET_RECLAIM_Credential::data, GNUNET_RECLAIM_Credential::data_size, 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, Plugin::key, type, GNUNET_RECLAIM_Credential::type, type_str, and value.

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 }
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.
struct GNUNET_RECLAIM_Identifier id
ID.
uint32_t type
Type/Format of Claim.
struct GNUNET_RECLAIM_Attribute * claim
Claim to store.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
size_t data_size
Number of bytes in data.
const void * data
Binary value stored as credential value.
static char * value
Value of the record to add/remove.
uint32_t GNUNET_RECLAIM_attribute_typename_to_number(const char *typename)
Convert a type name to the corresponding number.
struct GNUNET_RECLAIM_Identifier id
ID.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1978
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.
struct GNUNET_HashCode key
The key used in the DHT.
static char * type_str
Attribute type.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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.
uint32_t data
The data 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 951 of file plugin_rest_reclaim.c.

References RequestHandle::attr_it, 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, RequestHandle::resp_object, type, and GNUNET_RECLAIM_Attribute::type.

Referenced by list_attribute_cont().

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));
977  GNUNET_free (id_str);
979  sizeof(attr->credential));
980  json_object_set_new (attr_obj, "credential", json_string (id_str));
981  GNUNET_free (id_str);
982  json_array_append (handle->resp_object, attr_obj);
983  json_decref (attr_obj);
984  GNUNET_free (tmp_value);
986 }
struct GNUNET_RECLAIM_AttributeIterator * attr_it
Attribute iterator.
const char * name
The name of the attribute.
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)
The request handle.
json_t * resp_object
Response object.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_RECLAIM_Identifier id
ID.
size_t data_size
Number of bytes in data.
const char * GNUNET_RECLAIM_attribute_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string.
const void * data
Binary value stored as attribute value.
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.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:937
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_RECLAIM_id_is_zero(a)
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 997 of file plugin_rest_reclaim.c.

References attr_collect(), RequestHandle::attr_it, collect_error_cb(), collect_finished_cb(), do_error(), EgoEntry::ego, 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, EgoEntry::next, RequestHandle::resp_object, return_response(), and RequestHandle::url.

Referenced by rest_identity_process_request().

1000 {
1001  const struct GNUNET_IDENTITY_PrivateKey *priv_key;
1002  struct RequestHandle *handle = cls;
1003  struct EgoEntry *ego_entry;
1004  char *identity;
1005 
1007  "Getting attributes for %s.\n",
1008  handle->url);
1009  if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
1010  {
1011  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
1013  return;
1014  }
1015  identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
1016 
1017  for (ego_entry = ego_head; NULL != ego_entry;
1018  ego_entry = ego_entry->next)
1019  if (0 == strcmp (identity, ego_entry->identifier))
1020  break;
1021  handle->resp_object = json_array ();
1022 
1023 
1024  if (NULL == ego_entry)
1025  {
1026  // Done
1027  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
1029  return;
1030  }
1031  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1033  priv_key,
1035  handle,
1036  &attr_collect,
1037  handle,
1039  handle);
1040 }
#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES
Attribute namespace.
static void collect_error_cb(void *cls)
struct GNUNET_RECLAIM_AttributeIterator * attr_it
Attribute iterator.
A private key for an identity as per LSD0001.
static void collect_finished_cb(void *cls)
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
json_t * resp_object
Response object.
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
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:1331
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void return_response(void *cls)
Return attributes for identity.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
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 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:639
#define GNUNET_log(kind,...)
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
static void attr_collect(void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr)
Collect all attributes for an ego.
struct EgoEntry * next
DLL.
char * url
The url.
Here is the call graph for this function:
Here is the caller 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 1051 of file plugin_rest_reclaim.c.

References delete_finished_cb(), do_error(), EgoEntry::ego, 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, GNUNET_RECLAIM_Attribute::id, id, EgoEntry::identifier, identity, RequestHandle::idp_op, GNUNET_RECLAIM_Attribute::name, EgoEntry::next, RequestHandle::resp_object, return_response(), and RequestHandle::url.

Referenced by rest_identity_process_request().

1054 {
1055  const struct GNUNET_IDENTITY_PrivateKey *priv_key;
1056  struct RequestHandle *handle = cls;
1057  struct GNUNET_RECLAIM_Attribute attr;
1058  struct EgoEntry *ego_entry;
1059  char *identity_id_str;
1060  char *identity;
1061  char *id;
1062 
1063  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n");
1064  if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url))
1065  {
1066  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
1068  return;
1069  }
1070  identity_id_str =
1071  strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1);
1072  identity = strtok (identity_id_str, "/");
1073  id = strtok (NULL, "/");
1074  if ((NULL == identity) || (NULL == id))
1075  {
1076  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
1077  GNUNET_free (identity_id_str);
1079  return;
1080  }
1081 
1082  for (ego_entry = ego_head; NULL != ego_entry;
1083  ego_entry = ego_entry->next)
1084  if (0 == strcmp (identity, ego_entry->identifier))
1085  break;
1086  handle->resp_object = json_array ();
1087  if (NULL == ego_entry)
1088  {
1089  // Done
1090  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
1091  GNUNET_free (identity_id_str);
1093  return;
1094  }
1095  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1096  memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute));
1097  GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
1098  attr.name = "";
1100  priv_key,
1101  &attr,
1103  handle);
1104  GNUNET_free (identity_id_str);
1105 }
#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES
Attribute namespace.
A private key for an identity as per LSD0001.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
The request handle.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
json_t * resp_object
Response object.
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void return_response(void *cls)
Return attributes for identity.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static void delete_finished_cb(void *cls, int32_t success, const char *emsg)
static void do_error(void *cls)
Task run on error, sends error message.
char * identifier
Ego Identifier.
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:1182
static struct EgoEntry * ego_head
Ego list.
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:639
#define GNUNET_log(kind,...)
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
struct EgoEntry * next
DLL.
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:972
#define GNUNET_free(ptr)
Wrapper around free.
char * url
The url.
Here is the call graph for this function:
Here is the caller 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 1109 of file plugin_rest_reclaim.c.

References GNUNET_REST_RequestHandle::data, GNUNET_REST_RequestHandle::data_size, do_error(), EgoEntry::ego, RequestHandle::emsg, 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, RequestHandle::idp_op, EgoEntry::next, RequestHandle::rest_handle, and ticket.

Referenced by rest_identity_process_request().

1112 {
1113  const struct GNUNET_IDENTITY_PrivateKey *identity_priv;
1114  struct RequestHandle *handle = cls;
1115  struct EgoEntry *ego_entry;
1116  struct GNUNET_RECLAIM_Ticket *ticket = NULL;
1117  struct GNUNET_IDENTITY_PublicKey tmp_pk;
1118  char term_data[handle->rest_handle->data_size + 1];
1119  json_t *data_json;
1120  json_error_t err;
1121  struct GNUNET_JSON_Specification tktspec[] =
1123 
1124  if (0 >= handle->rest_handle->data_size)
1125  {
1127  return;
1128  }
1129 
1130  term_data[handle->rest_handle->data_size] = '\0';
1131  GNUNET_memcpy (term_data,
1132  handle->rest_handle->data,
1133  handle->rest_handle->data_size);
1134  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
1135  if ((NULL == data_json) ||
1136  (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL)))
1137  {
1138  handle->emsg = GNUNET_strdup ("Not a ticket!\n");
1140  GNUNET_JSON_parse_free (tktspec);
1141  if (NULL != data_json)
1142  json_decref (data_json);
1143  return;
1144  }
1145  json_decref (data_json);
1146  if (NULL == ticket)
1147  {
1149  "Unable to parse ticket from %s\n",
1150  term_data);
1152  return;
1153  }
1154 
1155  for (ego_entry = ego_head; NULL != ego_entry;
1156  ego_entry = ego_entry->next)
1157  {
1158  GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
1159  if (0 == memcmp (&ticket->identity,
1160  &tmp_pk,
1161  sizeof(struct GNUNET_IDENTITY_PublicKey)))
1162  break;
1163  }
1164  if (NULL == ego_entry)
1165  {
1166  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
1167  GNUNET_JSON_parse_free (tktspec);
1168  return;
1169  }
1170  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1171 
1173  identity_priv,
1174  ticket,
1175  &finished_cont,
1176  handle);
1177  GNUNET_JSON_parse_free (tktspec);
1178 }
The authorization ticket.
size_t data_size
The POST data size.
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
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:106
static void finished_cont(void *cls, int32_t success, const char *emsg)
A private key for an identity as per LSD0001.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Entry in parser specification for GNUNET_JSON_parse().
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:652
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
struct GNUNET_IDENTITY_PublicKey identity
The ticket issuer (= the user)
char * emsg
Error response message.
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
const char * data
The POST data.
static void do_error(void *cls)
Task run on error, sends error message.
static struct EgoEntry * ego_head
Ego list.
An identity key as per LSD0001.
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:1732
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:639
#define GNUNET_log(kind,...)
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end(void)
End of a parser specification.
Definition: json_helper.c:35
struct EgoEntry * next
DLL.
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_ticket(struct GNUNET_RECLAIM_Ticket **ticket)
JSON Specification for Reclaim tickets.
Definition: json_reclaim.c:265
Here is the call graph for this function:
Here is the caller 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 pres 
)
static

Definition at line 1182 of file plugin_rest_reclaim.c.

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, GNUNET_RECLAIM_Attribute::name, RequestHandle::resp_object, return_response(), GNUNET_RECLAIM_Attribute::type, and value.

Referenced by consume_ticket_cont().

1186 {
1187  struct RequestHandle *handle = cls;
1188  char *val_str;
1189  json_t *value;
1190 
1191  if (NULL == identity)
1192  {
1194  return;
1195  }
1196 
1197  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
1199  attr->data,
1200  attr->data_size);
1201  if (NULL == val_str)
1202  {
1204  "Failed to parse value for: %s\n",
1205  attr->name);
1206  return;
1207  }
1208  value = json_string (val_str);
1209  json_object_set_new (handle->resp_object, attr->name, value);
1210  json_decref (value);
1211  GNUNET_free (val_str);
1212 }
const char * name
The name of the attribute.
The request handle.
json_t * resp_object
Response object.
static char * value
Value of the record to add/remove.
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
size_t data_size
Number of bytes in data.
static void return_response(void *cls)
Return attributes for identity.
#define GNUNET_log(kind,...)
const void * data
Binary value stored as attribute value.
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.
#define GNUNET_free(ptr)
Wrapper around free.
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 1216 of file plugin_rest_reclaim.c.

References GNUNET_RECLAIM_Ticket::audience, consume_cont(), GNUNET_REST_RequestHandle::data, GNUNET_REST_RequestHandle::data_size, do_error(), EgoEntry::ego, RequestHandle::emsg, 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, RequestHandle::idp_op, EgoEntry::next, RequestHandle::resp_object, RequestHandle::rest_handle, and ticket.

Referenced by rest_identity_process_request().

1219 {
1220  const struct GNUNET_IDENTITY_PrivateKey *identity_priv;
1221  struct RequestHandle *handle = cls;
1222  struct EgoEntry *ego_entry;
1223  struct GNUNET_RECLAIM_Ticket *ticket;
1224  struct GNUNET_IDENTITY_PublicKey tmp_pk;
1225  char term_data[handle->rest_handle->data_size + 1];
1226  json_t *data_json;
1227  json_error_t err;
1228  struct GNUNET_JSON_Specification tktspec[] =
1230 
1231  if (0 >= handle->rest_handle->data_size)
1232  {
1234  return;
1235  }
1236 
1237  term_data[handle->rest_handle->data_size] = '\0';
1238  GNUNET_memcpy (term_data,
1239  handle->rest_handle->data,
1240  handle->rest_handle->data_size);
1241  data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
1242  if (NULL == data_json)
1243  {
1245  "Unable to parse JSON Object from %s\n",
1246  term_data);
1248  return;
1249  }
1250  if (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL))
1251  {
1252  handle->emsg = GNUNET_strdup ("Not a ticket!\n");
1254  GNUNET_JSON_parse_free (tktspec);
1255  json_decref (data_json);
1256  return;
1257  }
1258  for (ego_entry = ego_head; NULL != ego_entry;
1259  ego_entry = ego_entry->next)
1260  {
1261  GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
1262  if (0 == memcmp (&ticket->audience,
1263  &tmp_pk,
1264  sizeof(struct GNUNET_IDENTITY_PublicKey)))
1265  break;
1266  }
1267  if (NULL == ego_entry)
1268  {
1269  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
1270  GNUNET_JSON_parse_free (tktspec);
1271  return;
1272  }
1273  identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1274  handle->resp_object = json_object ();
1276  identity_priv,
1277  ticket,
1278  &consume_cont,
1279  handle);
1280  GNUNET_JSON_parse_free (tktspec);
1281 }
The authorization ticket.
size_t data_size
The POST data size.
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
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:106
A private key for an identity as per LSD0001.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Entry in parser specification for GNUNET_JSON_parse().
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:1591
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:652
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The request handle.
The ego list.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
json_t * resp_object
Response object.
char * emsg
Error response message.
static void consume_cont(void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, const struct GNUNET_RECLAIM_Attribute *attr, const struct GNUNET_RECLAIM_Presentation *pres)
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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
const char * data
The POST data.
static void do_error(void *cls)
Task run on error, sends error message.
static struct EgoEntry * ego_head
Ego list.
An identity key as per LSD0001.
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:639
struct GNUNET_IDENTITY_PublicKey audience
The ticket audience (= relying party)
#define GNUNET_log(kind,...)
struct GNUNET_RECLAIM_Operation * idp_op
Idp Operation.
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end(void)
End of a parser specification.
Definition: json_helper.c:35
struct EgoEntry * next
DLL.
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_ticket(struct GNUNET_RECLAIM_Ticket **ticket)
JSON Specification for Reclaim tickets.
Definition: json_reclaim.c:265
Here is the call graph for this function:
Here is the caller 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 1292 of file plugin_rest_reclaim.c.

References allow_methods, cleanup_handle(), GNUNET_REST_create_response(), handle, RequestHandle::proc, and RequestHandle::proc_cls.

Referenced by rest_identity_process_request().

1295 {
1296  struct MHD_Response *resp;
1297  struct RequestHandle *handle = cls;
1298 
1299  // For now, independent of path return all options
1300  resp = GNUNET_REST_create_response (NULL);
1301  MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
1302  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1303  cleanup_handle (handle);
1304  return;
1305 }
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
static char * allow_methods
HTTP methods allows for this plugin.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
static void cleanup_handle(void *cls)
Cleanup lookup handle.
Here is the call graph for this function:
Here is the caller 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 (i.e. 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 1342 of file plugin_rest_reclaim.c.

References EgoEntry::ego, 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, and state.

Referenced by libgnunet_plugin_rest_reclaim_init().

1346 {
1347  struct EgoEntry *ego_entry;
1349 
1350  if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1351  {
1353  return;
1354  }
1355  if (ID_REST_STATE_INIT == state)
1356  {
1357  ego_entry = GNUNET_new (struct EgoEntry);
1360  ego_entry->ego = ego;
1361  ego_entry->identifier = GNUNET_strdup (identifier);
1363  ego_tail,
1364  ego_entry);
1365  }
1366  /* Ego renamed or added */
1367  if (identifier != NULL)
1368  {
1369  for (ego_entry = ego_head; NULL != ego_entry;
1370  ego_entry = ego_entry->next)
1371  {
1372  if (ego_entry->ego == ego)
1373  {
1374  /* Rename */
1375  GNUNET_free (ego_entry->identifier);
1376  ego_entry->identifier = GNUNET_strdup (identifier);
1377  break;
1378  }
1379  }
1380  if (NULL == ego_entry)
1381  {
1382  /* Add */
1383  ego_entry = GNUNET_new (struct EgoEntry);
1386  ego_entry->ego = ego;
1387  ego_entry->identifier = GNUNET_strdup (identifier);
1389  ego_tail,
1390  ego_entry);
1391  }
1392  }
1393  else
1394  {
1395  /* Delete */
1396  for (ego_entry = ego_head; NULL != ego_entry;
1397  ego_entry = ego_entry->next)
1398  {
1399  if (ego_entry->ego == ego)
1400  break;
1401  }
1402  if (NULL == ego_entry)
1403  return; /* Not found */
1404 
1406  ego_tail,
1407  ego_entry);
1408  GNUNET_free (ego_entry->identifier);
1409  GNUNET_free (ego_entry->keystring);
1410  GNUNET_free (ego_entry);
1411  return;
1412  }
1413 
1414 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct EgoEntry * ego_tail
Ego list.
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.
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:652
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The ego list.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
#define ID_REST_STATE_INIT
State while collecting all egos.
#define ID_REST_STATE_POST_INIT
Done collecting egos.
char * keystring
Public key string.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
char * identifier
Ego Identifier.
static struct EgoEntry * ego_head
Ego list.
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static int state
The processing state.
struct EgoEntry * next
DLL.
#define GNUNET_free(ptr)
Wrapper around free.
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 1418 of file plugin_rest_reclaim.c.

References add_attribute_cont(), add_credential_cont(), cleanup_handle(), consume_ticket_cont(), delete_attribute_cont(), delete_credential_cont(), do_timeout(), GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_NO, GNUNET_REST_API_NS_IDENTITY_CONSUME, GNUNET_REST_API_NS_IDENTITY_REVOKE, GNUNET_REST_API_NS_IDENTITY_TICKETS, GNUNET_REST_API_NS_RECLAIM, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, handle, list_attribute_cont(), list_credential_cont(), list_tickets_cont(), options_cont(), GNUNET_REST_RequestHandler::proc, RequestHandle::proc, RequestHandle::proc_cls, RequestHandle::response_code, RequestHandle::rest_handle, revoke_ticket_cont(), RequestHandle::timeout, RequestHandle::timeout_task, GNUNET_REST_RequestHandle::url, and RequestHandle::url.

Referenced by libgnunet_plugin_rest_reclaim_init().

1421 {
1422  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1424  static const struct GNUNET_REST_RequestHandler handlers[] =
1425  { { MHD_HTTP_METHOD_GET,
1427  { MHD_HTTP_METHOD_POST,
1429  { MHD_HTTP_METHOD_DELETE,
1431  { MHD_HTTP_METHOD_GET,
1433  { MHD_HTTP_METHOD_POST,
1435  { MHD_HTTP_METHOD_DELETE,
1437  { MHD_HTTP_METHOD_GET,
1439  { MHD_HTTP_METHOD_POST,
1441  { MHD_HTTP_METHOD_POST,
1443  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
1445  };
1446 
1447  handle->response_code = 0;
1449  handle->proc_cls = proc_cls;
1450  handle->proc = proc;
1451  handle->rest_handle = rest_handle;
1452 
1453  handle->url = GNUNET_strdup (rest_handle->url);
1454  if (handle->url[strlen (handle->url) - 1] == '/')
1455  handle->url[strlen (handle->url) - 1] = '\0';
1456  handle->timeout_task =
1457  GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
1459  requests_tail,
1460  handle);
1461  if (GNUNET_NO ==
1462  GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1463  {
1464  cleanup_handle (handle);
1465  return GNUNET_NO;
1466  }
1467 
1468  return GNUNET_YES;
1469 }
static void list_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List attributes for identity request.
#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES
Attribute namespace.
static void consume_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static void add_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
GNUNET_REST_ResultProcessor proc
The plugin result processor.
#define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL
Credential namespace.
#define GNUNET_REST_API_NS_IDENTITY_CONSUME
Revoke namespace.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
#define GNUNET_REST_HANDLER_END
The request handle.
static void delete_credential_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Deletes credential from an identity.
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
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
const char * url
The url as string.
static struct RequestHandle * requests_tail
DLL.
struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
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.
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 delete_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
List attributes for identity request.
#define GNUNET_REST_API_NS_IDENTITY_REVOKE
Revoke namespace.
static void revoke_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
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.
static struct RequestHandle * requests_head
DLL.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
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)
#define GNUNET_REST_API_NS_IDENTITY_TICKETS
Ticket namespace.
char * url
The url.
Here is the call graph for this function:
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 1479 of file plugin_rest_reclaim.c.

References _, allow_methods, Plugin::api, Plugin::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, list_ego(), GNUNET_REST_Plugin::name, plugin, GNUNET_REST_Plugin::process_request, rest_identity_process_request(), and state.

1480 {
1481  static struct Plugin plugin;
1482  struct GNUNET_REST_Plugin *api;
1483 
1484  cfg = cls;
1485  if (NULL != plugin.cfg)
1486  return NULL; /* can only initialize once! */
1487  memset (&plugin, 0, sizeof(struct Plugin));
1488  plugin.cfg = cfg;
1489  api = GNUNET_new (struct GNUNET_REST_Plugin);
1490  api->cls = &plugin;
1494  "%s, %s, %s, %s, %s",
1495  MHD_HTTP_METHOD_GET,
1496  MHD_HTTP_METHOD_POST,
1497  MHD_HTTP_METHOD_PUT,
1498  MHD_HTTP_METHOD_DELETE,
1499  MHD_HTTP_METHOD_OPTIONS);
1504  _ ("Identity Provider REST API initialized\n"));
1505  return api;
1506 }
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:610
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 * cls
The closure of the plugin.
struct returned by the initialization function of the plugin
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
#define ID_REST_STATE_INIT
State while collecting all egos.
static char * allow_methods
HTTP methods allows for this plugin.
char * name
Plugin name.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
#define GNUNET_REST_API_NS_RECLAIM
REST root namespace.
static char * plugin
Solver plugin name as string.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
static int state
The processing state.
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
static enum GNUNET_GenericReturnValue rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
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 1516 of file plugin_rest_reclaim.c.

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

1517 {
1518  struct GNUNET_REST_Plugin *api = cls;
1519  struct Plugin *plugin = api->cls;
1520  struct RequestHandle *request;
1521  struct EgoEntry *ego_entry;
1522  struct EgoEntry *ego_tmp;
1523 
1524  plugin->cfg = NULL;
1525  while (NULL != (request = requests_head))
1526  do_error (request);
1527  if (NULL != idp)
1529  if (NULL != identity_handle)
1531  for (ego_entry = ego_head; NULL != ego_entry;)
1532  {
1533  ego_tmp = ego_entry;
1534  ego_entry = ego_entry->next;
1535  GNUNET_free (ego_tmp->identifier);
1536  GNUNET_free (ego_tmp->keystring);
1537  GNUNET_free (ego_tmp);
1538  }
1539 
1541  GNUNET_free (api);
1543  "Identity Provider REST plugin is finished\n");
1544  return NULL;
1545 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
void * cls
The closure of the plugin.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
void GNUNET_RECLAIM_disconnect(struct GNUNET_RECLAIM_Handle *h)
Disconnect from identity provider service.
Definition: reclaim_api.c:1104
struct returned by the initialization function of the plugin
The request handle.
The ego list.
static char * allow_methods
HTTP methods allows for this plugin.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
static char * plugin
Solver plugin name as string.
char * keystring
Public key string.
static void do_error(void *cls)
Task run on error, sends error message.
char * identifier
Ego Identifier.
static struct EgoEntry * ego_head
Ego list.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
Handle for a plugin.
Definition: block.c:37
static struct RequestHandle * requests_head
DLL.
#define GNUNET_log(kind,...)
static struct GNUNET_RECLAIM_Handle * idp
Identity Provider.
struct EgoEntry * next
DLL.
#define GNUNET_free(ptr)
Wrapper around free.
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.

◆ allow_methods

char* allow_methods
static

◆ ego_head

struct EgoEntry* ego_head
static

Ego list.

Definition at line 93 of file plugin_rest_reclaim.c.

◆ ego_tail

struct EgoEntry* ego_tail
static

Ego list.

Definition at line 98 of file plugin_rest_reclaim.c.

◆ 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.

◆ idp

struct GNUNET_RECLAIM_Handle* idp
static

Identity Provider.

Definition at line 113 of file plugin_rest_reclaim.c.

◆ requests_head

struct RequestHandle* requests_head
static

DLL.

Definition at line 261 of file plugin_rest_reclaim.c.

◆ requests_tail

struct RequestHandle* requests_tail
static

DLL.

Definition at line 266 of file plugin_rest_reclaim.c.