GNUnet  0.11.x
Functions
json_reclaim.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_json_lib.h"
#include "gnunet_reclaim_lib.h"
#include "gnunet_reclaim_service.h"
Include dependency graph for json_reclaim.c:

Go to the source code of this file.

Functions

static int parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a claim. More...
 
static void clean_attr (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_attribute (struct GNUNET_RECLAIM_Attribute **attr)
 JSON Specification for Reclaim claims. More...
 
static int parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a ticket. More...
 
static void clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket)
 JSON Specification for Reclaim tickets. More...
 
static int parse_credential (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a credential claim. More...
 
static void clean_credential (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_credential (struct GNUNET_RECLAIM_Credential **cred)
 JSON Specification for credential claims. More...
 

Function Documentation

◆ parse_attr()

static int parse_attr ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a claim.

Parameters
clsclosure, NULL
rootthe json object representing data
specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 42 of file json_reclaim.c.

References GNUNET_RECLAIM_Attribute::credential, data, data_size, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_RECLAIM_attribute_new(), GNUNET_RECLAIM_attribute_string_to_value(), GNUNET_RECLAIM_attribute_typename_to_number(), GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_RECLAIM_Attribute::id, GNUNET_JSON_Specification::ptr, type, and type_str.

Referenced by GNUNET_RECLAIM_JSON_spec_attribute().

43 {
44  struct GNUNET_RECLAIM_Attribute *attr;
45  const char *name_str = NULL;
46  const char *val_str = NULL;
47  const char *type_str = NULL;
48  const char *id_str = NULL;
49  const char *cred_str = NULL;
50  const char *flag_str = NULL;
51  char *data;
52  int unpack_state;
53  uint32_t type;
54  size_t data_size;
55 
56  GNUNET_assert (NULL != root);
57 
58  if (! json_is_object (root))
59  {
61  "Error json is not array nor object!\n");
62  return GNUNET_SYSERR;
63  }
64  // interpret single attribute
65  unpack_state = json_unpack (root,
66  "{s:s, s?s, s?s, s:s, s:s, s?s!}",
67  "name",
68  &name_str,
69  "id",
70  &id_str,
71  "credential",
72  &cred_str,
73  "type",
74  &type_str,
75  "value",
76  &val_str,
77  "flag",
78  &flag_str);
79  if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) ||
80  (NULL == type_str))
81  {
83  "Error json object has a wrong format!\n");
84  return GNUNET_SYSERR;
85  }
87  if (GNUNET_SYSERR ==
89  val_str,
90  (void **) &data,
91  &data_size)))
92  {
93  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n");
94  return GNUNET_SYSERR;
95  }
96  attr = GNUNET_RECLAIM_attribute_new (name_str, NULL,
97  type, data, data_size);
98  if ((NULL != cred_str) && (0 != strlen (cred_str)))
99  {
101  strlen (cred_str),
102  &attr->credential,
103  sizeof(attr->credential));
104  }
105  if ((NULL == id_str) || (0 == strlen (id_str)))
106  memset (&attr->id, 0, sizeof (attr->id));
107  else
109  strlen (id_str),
110  &attr->id,
111  sizeof(attr->id));
112 
113  *(struct GNUNET_RECLAIM_Attribute **) spec->ptr = attr;
114  return GNUNET_OK;
115 }
struct GNUNET_RECLAIM_Attribute * GNUNET_RECLAIM_attribute_new(const char *attr_name, const struct GNUNET_RECLAIM_Identifier *credential, uint32_t type, const void *data, size_t data_size)
Create a new attribute claim.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_RECLAIM_Identifier credential
Referenced ID of credential (may be GNUNET_RECLAIM_ID_ZERO if self-creded)
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.
int GNUNET_RECLAIM_attribute_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'claim' of an attribute to the binary representation.
static char * type_str
Attribute type.
void * ptr
Pointer, details specific to the parser.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:971
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_attr()

static void clean_attr ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing RSA public key.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 125 of file json_reclaim.c.

References GNUNET_free, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_RECLAIM_JSON_spec_attribute().

126 {
127  struct GNUNET_RECLAIM_Attribute **attr;
128 
129  attr = (struct GNUNET_RECLAIM_Attribute **) spec->ptr;
130  if (NULL != *attr)
131  {
132  GNUNET_free (*attr);
133  *attr = NULL;
134  }
135 }
void * ptr
Pointer, details specific to the parser.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_RECLAIM_JSON_spec_attribute()

struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_attribute ( struct GNUNET_RECLAIM_Attribute **  attr)

JSON Specification for Reclaim claims.

Parameters
ticketstruct of GNUNET_RECLAIM_Attribute to fill
Returns
JSON Specification

Definition at line 145 of file json_reclaim.c.

References clean_attr(), parse_attr(), GNUNET_JSON_Specification::parser, and ret.

Referenced by add_attribute_cont().

146 {
147  struct GNUNET_JSON_Specification ret = { .parser = &parse_attr,
148  .cleaner = &clean_attr,
149  .cls = NULL,
150  .field = NULL,
151  .ptr = attr,
152  .ptr_size = 0,
153  .size_ptr = NULL };
154 
155  *attr = NULL;
156  return ret;
157 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static void clean_attr(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_reclaim.c:125
static int parse_attr(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a claim.
Definition: json_reclaim.c:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_ticket()

static int parse_ticket ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a ticket.

Parameters
clsclosure, NULL
rootthe json object representing data
specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 169 of file json_reclaim.c.

References GNUNET_RECLAIM_Ticket::audience, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_RECLAIM_Ticket::identity, GNUNET_JSON_Specification::ptr, GNUNET_RECLAIM_Ticket::rnd, and ticket.

Referenced by GNUNET_RECLAIM_JSON_spec_ticket().

170 {
172  const char *rnd_str;
173  const char *aud_str;
174  const char *id_str;
175  int unpack_state;
176 
177  GNUNET_assert (NULL != root);
178 
179  if (! json_is_object (root))
180  {
182  "Error json is not array nor object!\n");
183  return GNUNET_SYSERR;
184  }
185  // interpret single ticket
186  unpack_state = json_unpack (root,
187  "{s:s, s:s, s:s!}",
188  "rnd",
189  &rnd_str,
190  "audience",
191  &aud_str,
192  "issuer",
193  &id_str);
194  if (0 != unpack_state)
195  {
197  "Error json object has a wrong format!\n");
198  return GNUNET_SYSERR;
199  }
200  ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
202  strlen (rnd_str),
203  &ticket->rnd,
204  sizeof(ticket->rnd)))
205  {
206  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n");
207  GNUNET_free (ticket);
208  return GNUNET_SYSERR;
209  }
210  if (GNUNET_OK !=
212  strlen (id_str),
213  &ticket->identity,
214  sizeof(
216  {
217  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n");
218  GNUNET_free (ticket);
219  return GNUNET_SYSERR;
220  }
221 
222  if (GNUNET_OK !=
224  strlen (aud_str),
225  &ticket->audience,
226  sizeof(struct
228  {
229  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n");
230  GNUNET_free (ticket);
231  return GNUNET_SYSERR;
232  }
233 
234  *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket;
235  return GNUNET_OK;
236 }
The authorization ticket.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
struct GNUNET_CRYPTO_EcdsaPublicKey identity
The ticket issuer (= the user)
void * ptr
Pointer, details specific to the parser.
struct GNUNET_RECLAIM_Identifier rnd
The ticket random identifier.
struct GNUNET_CRYPTO_EcdsaPublicKey audience
The ticket audience (= relying party)
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:971
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_ticket()

static void clean_ticket ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing RSA public key.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 246 of file json_reclaim.c.

References GNUNET_free, GNUNET_JSON_Specification::ptr, and ticket.

Referenced by GNUNET_RECLAIM_JSON_spec_ticket().

247 {
248  struct GNUNET_RECLAIM_Ticket **ticket;
249 
250  ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr;
251  if (NULL != *ticket)
252  {
253  GNUNET_free (*ticket);
254  *ticket = NULL;
255  }
256 }
The authorization ticket.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
void * ptr
Pointer, details specific to the parser.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_RECLAIM_JSON_spec_ticket()

struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_ticket ( struct GNUNET_RECLAIM_Ticket **  ticket)

JSON Specification for Reclaim tickets.

Parameters
ticketstruct of GNUNET_RECLAIM_Ticket to fill
Returns
JSON Specification

Definition at line 266 of file json_reclaim.c.

References clean_ticket(), parse_ticket(), GNUNET_JSON_Specification::parser, ret, and ticket.

Referenced by consume_ticket_cont(), and revoke_ticket_cont().

267 {
268  struct GNUNET_JSON_Specification ret = { .parser = &parse_ticket,
269  .cleaner = &clean_ticket,
270  .cls = NULL,
271  .field = NULL,
272  .ptr = ticket,
273  .ptr_size = 0,
274  .size_ptr = NULL };
275 
276  *ticket = NULL;
277  return ret;
278 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
static int parse_ticket(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a ticket.
Definition: json_reclaim.c:169
static void clean_ticket(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_reclaim.c:246
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_credential()

static int parse_credential ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a credential claim.

Parameters
clsclosure, NULL
rootthe json object representing data
specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 290 of file json_reclaim.c.

References data, data_size, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_RECLAIM_credential_new(), GNUNET_RECLAIM_credential_string_to_value(), GNUNET_RECLAIM_credential_typename_to_number(), GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_RECLAIM_Credential::id, GNUNET_JSON_Specification::ptr, type, and type_str.

Referenced by GNUNET_RECLAIM_JSON_spec_credential().

291 {
292  struct GNUNET_RECLAIM_Credential *cred;
293  const char *name_str = NULL;
294  const char *val_str = NULL;
295  const char *type_str = NULL;
296  const char *id_str = NULL;
297  char *data;
298  int unpack_state;
299  uint32_t type;
300  size_t data_size;
301 
302  GNUNET_assert (NULL != root);
303 
304  if (! json_is_object (root))
305  {
307  "Error json is not array nor object!\n");
308  return GNUNET_SYSERR;
309  }
310  // interpret single attribute
311  unpack_state = json_unpack (root,
312  "{s:s, s?s, s:s, s:s!}",
313  "name",
314  &name_str,
315  "id",
316  &id_str,
317  "type",
318  &type_str,
319  "value",
320  &val_str);
321  if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) ||
322  (NULL == type_str))
323  {
325  "Error json object has a wrong format!\n");
326  return GNUNET_SYSERR;
327  }
329  if (GNUNET_SYSERR ==
331  val_str,
332  (void **) &data,
333  &data_size)))
334  {
335  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Credential value invalid!\n");
336  return GNUNET_SYSERR;
337  }
338  cred = GNUNET_RECLAIM_credential_new (name_str, type, data, data_size);
339  if ((NULL == id_str) || (0 == strlen (id_str)))
340  memset (&cred->id, 0, sizeof (cred->id));
341  else
343  strlen (id_str),
344  &cred->id,
345  sizeof(cred->id));
346 
347  *(struct GNUNET_RECLAIM_Credential **) spec->ptr = cred;
348  return GNUNET_OK;
349 }
uint32_t GNUNET_RECLAIM_credential_typename_to_number(const char *typename)
Convert an credential type name to the corresponding number.
struct GNUNET_RECLAIM_Identifier id
ID.
int GNUNET_RECLAIM_credential_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'claim' of an credential to the binary representation.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static char * type_str
Attribute type.
void * ptr
Pointer, details specific to the parser.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct GNUNET_RECLAIM_Credential * GNUNET_RECLAIM_credential_new(const char *name, uint32_t type, const void *data, size_t data_size)
Create a new credential.
uint32_t data
The data value.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:971
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_credential()

static void clean_credential ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing RSA public key.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 359 of file json_reclaim.c.

References GNUNET_free, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_RECLAIM_JSON_spec_credential().

360 {
361  struct GNUNET_RECLAIM_Credential **attr;
362 
363  attr = (struct GNUNET_RECLAIM_Credential **) spec->ptr;
364  if (NULL != *attr)
365  {
366  GNUNET_free (*attr);
367  *attr = NULL;
368  }
369 }
void * ptr
Pointer, details specific to the parser.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_RECLAIM_JSON_spec_credential()

struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_credential ( struct GNUNET_RECLAIM_Credential **  cred)

JSON Specification for credential claims.

JSON Specification for credentials.

Parameters
attrstruct of GNUNET_RECLAIM_Credential to fill
Returns
JSON Specification

Definition at line 379 of file json_reclaim.c.

References clean_credential(), parse_credential(), GNUNET_JSON_Specification::parser, and ret.

Referenced by add_credential_cont().

381 {
382  struct GNUNET_JSON_Specification ret = { .parser = &parse_credential,
383  .cleaner = &clean_credential,
384  .cls = NULL,
385  .field = NULL,
386  .ptr = cred,
387  .ptr_size = 0,
388  .size_ptr = NULL };
389 
390  *cred = NULL;
391  return ret;
392 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static void clean_credential(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_reclaim.c:359
static int parse_credential(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a credential claim.
Definition: json_reclaim.c:290
Here is the call graph for this function:
Here is the caller graph for this function: