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_claim (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_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to an attestation claim. More...
 
static void clean_attest (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_claim_attest (struct GNUNET_RECLAIM_Attestation **attr)
 JSON Specification for Reclaim attestation 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 44 of file json_reclaim.c.

References GNUNET_RECLAIM_Attribute::attestation, 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_claim().

45 {
46  struct GNUNET_RECLAIM_Attribute *attr;
47  const char *name_str = NULL;
48  const char *val_str = NULL;
49  const char *type_str = NULL;
50  const char *id_str = NULL;
51  const char *attest_str = NULL;
52  const char *flag_str = NULL;
53  char *data;
54  int unpack_state;
55  uint32_t type;
56  size_t data_size;
57 
58  GNUNET_assert (NULL != root);
59 
60  if (! json_is_object (root))
61  {
63  "Error json is not array nor object!\n");
64  return GNUNET_SYSERR;
65  }
66  // interpret single attribute
67  unpack_state = json_unpack (root,
68  "{s:s, s?s, s?s, s:s, s:s, s?s!}",
69  "name",
70  &name_str,
71  "id",
72  &id_str,
73  "attestation",
74  &attest_str,
75  "type",
76  &type_str,
77  "value",
78  &val_str,
79  "flag",
80  &flag_str);
81  if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) ||
82  (NULL == type_str))
83  {
85  "Error json object has a wrong format!\n");
86  return GNUNET_SYSERR;
87  }
89  if (GNUNET_SYSERR ==
91  val_str,
92  (void **) &data,
93  &data_size)))
94  {
95  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n");
96  return GNUNET_SYSERR;
97  }
98  attr = GNUNET_RECLAIM_attribute_new (name_str, NULL,
99  type, data, data_size);
100  if ((NULL != attest_str) && (0 != strlen (attest_str)))
101  {
102  GNUNET_STRINGS_string_to_data (attest_str,
103  strlen (attest_str),
104  &attr->attestation,
105  sizeof(attr->attestation));
106  }
107  if ((NULL == id_str) || (0 == strlen (id_str)))
108  memset (&attr->id, 0, sizeof (attr->id));
109  else
111  strlen (id_str),
112  &attr->id,
113  sizeof(attr->id));
114 
115  *(struct GNUNET_RECLAIM_Attribute **) spec->ptr = attr;
116  return GNUNET_OK;
117 }
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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
struct GNUNET_RECLAIM_Identifier attestation
Referenced ID of Attestation (may be 0 if self-attested)
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
static char * type_str
Attribute type.
void * ptr
Pointer, details specific to the parser.
struct GNUNET_RECLAIM_Attribute * GNUNET_RECLAIM_attribute_new(const char *attr_name, const struct GNUNET_RECLAIM_Identifier *attestation, uint32_t type, const void *data, size_t data_size)
Create a new attribute claim.
#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:970
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 127 of file json_reclaim.c.

References GNUNET_free, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_RECLAIM_JSON_spec_claim().

128 {
129  struct GNUNET_RECLAIM_Attribute **attr;
130 
131  attr = (struct GNUNET_RECLAIM_Attribute **) spec->ptr;
132  if (NULL != *attr)
133  {
134  GNUNET_free (*attr);
135  *attr = NULL;
136  }
137 }
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_claim()

struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_claim ( struct GNUNET_RECLAIM_Attribute **  attr)

JSON Specification for Reclaim claims.

Parameters
ticketstruct of GNUNET_RECLAIM_Attribute to fill
Returns
JSON Specification

Definition at line 147 of file json_reclaim.c.

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

Referenced by add_attribute_cont().

148 {
149  struct GNUNET_JSON_Specification ret = { .parser = &parse_attr,
150  .cleaner = &clean_attr,
151  .cls = NULL,
152  .field = NULL,
153  .ptr = attr,
154  .ptr_size = 0,
155  .size_ptr = NULL };
156 
157  *attr = NULL;
158  return ret;
159 }
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:127
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:44
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 171 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().

172 {
174  const char *rnd_str;
175  const char *aud_str;
176  const char *id_str;
177  int unpack_state;
178 
179  GNUNET_assert (NULL != root);
180 
181  if (! json_is_object (root))
182  {
184  "Error json is not array nor object!\n");
185  return GNUNET_SYSERR;
186  }
187  // interpret single ticket
188  unpack_state = json_unpack (root,
189  "{s:s, s:s, s:s!}",
190  "rnd",
191  &rnd_str,
192  "audience",
193  &aud_str,
194  "issuer",
195  &id_str);
196  if (0 != unpack_state)
197  {
199  "Error json object has a wrong format!\n");
200  return GNUNET_SYSERR;
201  }
202  ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
204  strlen (rnd_str),
205  &ticket->rnd,
206  sizeof(ticket->rnd)))
207  {
208  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n");
209  GNUNET_free (ticket);
210  return GNUNET_SYSERR;
211  }
212  if (GNUNET_OK !=
214  strlen (id_str),
215  &ticket->identity,
216  sizeof(
218  {
219  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n");
220  GNUNET_free (ticket);
221  return GNUNET_SYSERR;
222  }
223 
224  if (GNUNET_OK !=
226  strlen (aud_str),
227  &ticket->audience,
228  sizeof(struct
230  {
231  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n");
232  GNUNET_free (ticket);
233  return GNUNET_SYSERR;
234  }
235 
236  *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket;
237  return GNUNET_OK;
238 }
The authorization ticket.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#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)
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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:970
#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 248 of file json_reclaim.c.

References GNUNET_free, GNUNET_JSON_Specification::ptr, and ticket.

Referenced by GNUNET_RECLAIM_JSON_spec_ticket().

249 {
250  struct GNUNET_RECLAIM_Ticket **ticket;
251 
252  ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr;
253  if (NULL != *ticket)
254  {
255  GNUNET_free (*ticket);
256  *ticket = NULL;
257  }
258 }
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 268 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().

269 {
270  struct GNUNET_JSON_Specification ret = { .parser = &parse_ticket,
271  .cleaner = &clean_ticket,
272  .cls = NULL,
273  .field = NULL,
274  .ptr = ticket,
275  .ptr_size = 0,
276  .size_ptr = NULL };
277 
278  *ticket = NULL;
279  return ret;
280 }
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:171
static void clean_ticket(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_reclaim.c:248
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_attest()

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

Parse given JSON object to an attestation 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 291 of file json_reclaim.c.

References data, data_size, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_RECLAIM_attestation_new(), GNUNET_RECLAIM_attestation_string_to_value(), GNUNET_RECLAIM_attestation_typename_to_number(), GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_RECLAIM_Attestation::id, GNUNET_JSON_Specification::ptr, type, and type_str.

Referenced by GNUNET_RECLAIM_JSON_spec_claim_attest().

292 {
293  struct GNUNET_RECLAIM_Attestation *attr;
294  const char *name_str = NULL;
295  const char *val_str = NULL;
296  const char *type_str = NULL;
297  const char *id_str = NULL;
298  char *data;
299  int unpack_state;
300  uint32_t type;
301  size_t data_size;
302 
303  GNUNET_assert (NULL != root);
304 
305  if (! json_is_object (root))
306  {
308  "Error json is not array nor object!\n");
309  return GNUNET_SYSERR;
310  }
311  // interpret single attribute
312  unpack_state = json_unpack (root,
313  "{s:s, s?s, s:s, s:s!}",
314  "name",
315  &name_str,
316  "id",
317  &id_str,
318  "type",
319  &type_str,
320  "value",
321  &val_str);
322  if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) ||
323  (NULL == type_str))
324  {
326  "Error json object has a wrong format!\n");
327  return GNUNET_SYSERR;
328  }
330  if (GNUNET_SYSERR ==
332  val_str,
333  (void **) &data,
334  &data_size)))
335  {
336  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attestation value invalid!\n");
337  return GNUNET_SYSERR;
338  }
339  attr = GNUNET_RECLAIM_attestation_new (name_str, type, data, data_size);
340  if ((NULL == id_str) || (0 == strlen (id_str)))
341  memset (&attr->id, 0, sizeof (attr->id));
342  else
344  strlen (id_str),
345  &attr->id,
346  sizeof(attr->id));
347 
348  *(struct GNUNET_RECLAIM_Attestation **) spec->ptr = attr;
349  return GNUNET_OK;
350 }
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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
uint32_t GNUNET_RECLAIM_attestation_typename_to_number(const char *typename)
Convert an attestation type name to the corresponding number.
int GNUNET_RECLAIM_attestation_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'claim' of an attestation to the binary representation.
struct GNUNET_RECLAIM_Attestation * GNUNET_RECLAIM_attestation_new(const char *name, uint32_t type, const void *data, size_t data_size)
Create a new attestation.
struct GNUNET_RECLAIM_Identifier id
ID.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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:970
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_attest()

static void clean_attest ( 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_claim_attest().

360 {
361  struct GNUNET_RECLAIM_Attestation **attr;
362 
363  attr = (struct GNUNET_RECLAIM_Attestation **) 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_claim_attest()

struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_claim_attest ( struct GNUNET_RECLAIM_Attestation **  attr)

JSON Specification for Reclaim attestation claims.

Parameters
ticketstruct of GNUNET_RECLAIM_ATTESTATION_Claim to fill
Returns
JSON Specification

Definition at line 377 of file json_reclaim.c.

References clean_attest(), parse_attest(), GNUNET_JSON_Specification::parser, and ret.

Referenced by add_attestation_cont().

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