GNUnet  0.11.x
Functions | Variables
plugin_reclaim_attestation_jwt.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_reclaim_plugin.h"
#include <inttypes.h>
#include <jansson.h>
Include dependency graph for plugin_reclaim_attestation_jwt.c:

Go to the source code of this file.

Functions

static char * jwt_value_to_string (void *cls, uint32_t type, const void *data, size_t data_size)
 Convert the 'value' of an attestation to a string. More...
 
static int jwt_string_to_value (void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
 Convert human-readable version of a 'value' of an attestation to the binary representation. More...
 
static uint32_t jwt_typename_to_number (void *cls, const char *jwt_typename)
 Convert a type name to the corresponding number. More...
 
static const char * jwt_number_to_typename (void *cls, uint32_t type)
 Convert a type number (i.e. More...
 
struct GNUNET_RECLAIM_AttributeListjwt_parse_attributes (void *cls, const struct GNUNET_RECLAIM_Attestation *attest)
 Parse a JWT and return the respective claim value as Attribute. More...
 
char * jwt_get_issuer (void *cls, const struct GNUNET_RECLAIM_Attestation *attest)
 Parse a JWT and return the issuer. More...
 
int jwt_get_expiration (void *cls, const struct GNUNET_RECLAIM_Attestation *attest, struct GNUNET_TIME_Absolute *exp)
 Parse a JWT and return the expiration. More...
 
void * libgnunet_plugin_reclaim_attestation_jwt_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_reclaim_attestation_jwt_done (void *cls)
 Exit point from the plugin. More...
 

Variables

struct {
   const char *   name
 
   uint32_t   number
 
jwt_attest_name_map []
 Mapping of attestation type numbers to human-readable attestation type names. More...
 

Function Documentation

◆ jwt_value_to_string()

static char* jwt_value_to_string ( void *  cls,
uint32_t  type,
const void *  data,
size_t  data_size 
)
static

Convert the 'value' of an attestation to a string.

Parameters
clsclosure, unused
typetype of the attestation
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Definition at line 45 of file plugin_reclaim_attestation_jwt.c.

References GNUNET_RECLAIM_ATTESTATION_TYPE_JWT, and GNUNET_strndup.

Referenced by libgnunet_plugin_reclaim_attestation_jwt_init().

49 {
50  switch (type)
51  {
53  return GNUNET_strndup (data, data_size);
54 
55  default:
56  return NULL;
57  }
58 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT
A JSON Web Token attestation.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
Here is the caller graph for this function:

◆ jwt_string_to_value()

static int jwt_string_to_value ( void *  cls,
uint32_t  type,
const char *  s,
void **  data,
size_t *  data_size 
)
static

Convert human-readable version of a 'value' of an attestation to the binary representation.

Parameters
clsclosure, unused
typetype of the attestation
shuman-readable string
dataset to value in binary encoding (will be allocated)
data_sizeset to number of bytes in data
Returns
GNUNET_OK on success

Definition at line 73 of file plugin_reclaim_attestation_jwt.c.

References GNUNET_OK, GNUNET_RECLAIM_ATTESTATION_TYPE_JWT, GNUNET_strdup, and GNUNET_SYSERR.

Referenced by libgnunet_plugin_reclaim_attestation_jwt_init().

78 {
79  if (NULL == s)
80  return GNUNET_SYSERR;
81  switch (type)
82  {
84  *data = GNUNET_strdup (s);
85  *data_size = strlen (s);
86  return GNUNET_OK;
87 
88  default:
89  return GNUNET_SYSERR;
90  }
91 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT
A JSON Web Token attestation.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
Here is the caller graph for this function:

◆ jwt_typename_to_number()

static uint32_t jwt_typename_to_number ( void *  cls,
const char *  jwt_typename 
)
static

Convert a type name to the corresponding number.

Parameters
clsclosure, unused
jwt_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 113 of file plugin_reclaim_attestation_jwt.c.

References jwt_attest_name_map, and name.

Referenced by libgnunet_plugin_reclaim_attestation_jwt_init().

114 {
115  unsigned int i;
116 
117  i = 0;
118  while ((NULL != jwt_attest_name_map[i].name) &&
119  (0 != strcasecmp (jwt_typename, jwt_attest_name_map[i].name)))
120  i++;
121  return jwt_attest_name_map[i].number;
122 }
const char * name
static struct @65 jwt_attest_name_map[]
Mapping of attestation type numbers to human-readable attestation type names.
Here is the caller graph for this function:

◆ jwt_number_to_typename()

static const char* jwt_number_to_typename ( void *  cls,
uint32_t  type 
)
static

Convert a type number (i.e.

1) to the corresponding type string

Parameters
clsclosure, unused
typenumber of a type to convert
Returns
corresponding typestring, NULL on error

Definition at line 133 of file plugin_reclaim_attestation_jwt.c.

References jwt_attest_name_map, name, and number.

Referenced by libgnunet_plugin_reclaim_attestation_jwt_init().

134 {
135  unsigned int i;
136 
137  i = 0;
138  while ((NULL != jwt_attest_name_map[i].name) && (type !=
140  number))
141  i++;
142  return jwt_attest_name_map[i].name;
143 }
const char * name
static struct @65 jwt_attest_name_map[]
Mapping of attestation type numbers to human-readable attestation type names.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Here is the caller graph for this function:

◆ jwt_parse_attributes()

struct GNUNET_RECLAIM_AttributeList* jwt_parse_attributes ( void *  cls,
const struct GNUNET_RECLAIM_Attestation attest 
)

Parse a JWT and return the respective claim value as Attribute.

Parameters
clsthe plugin
attestthe jwt attestation
Returns
a GNUNET_RECLAIM_Attribute, containing the new value

Definition at line 154 of file plugin_reclaim_attestation_jwt.c.

References GNUNET_RECLAIM_Attestation::data, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_RECLAIM_ATTESTATION_TYPE_JWT, GNUNET_RECLAIM_attribute_list_add(), GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, GNUNET_strdup, GNUNET_STRINGS_base64url_decode(), key, GNUNET_RECLAIM_Attestation::type, and value.

Referenced by libgnunet_plugin_reclaim_attestation_jwt_init().

156 {
157  char *jwt_string;
158  struct GNUNET_RECLAIM_AttributeList *attrs;
159  char delim[] = ".";
160  char *val_str = NULL;
161  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
162  char *decoded_jwt;
163  json_t *json_val;
164  json_error_t *json_err = NULL;
165 
166  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", attest->data);
168  return NULL;
169  attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
170 
171  jwt_string = GNUNET_strdup (attest->data);
172  const char *jwt_body = strtok (jwt_string, delim);
173  jwt_body = strtok (NULL, delim);
174  GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body),
175  (void **) &decoded_jwt);
176  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", decoded_jwt);
177  GNUNET_assert (NULL != decoded_jwt);
178  json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
179  const char *key;
180  json_t *value;
181  json_object_foreach (json_val, key, value) {
182  if (0 == strcmp ("iss", key))
183  continue;
184  if (0 == strcmp ("exp", key))
185  continue;
186  if (0 == strcmp ("iat", key))
187  continue;
188  if (0 == strcmp ("nbf", key))
189  continue;
190  if (0 == strcmp ("aud", key))
191  continue;
192  val_str = json_dumps (value, JSON_ENCODE_ANY);
194  key,
195  NULL,
197  val_str,
198  strlen (val_str));
199  GNUNET_free (val_str);
200  }
201  GNUNET_free (jwt_string);
202  return attrs;
203 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A list of GNUNET_RECLAIM_Attribute structures.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void GNUNET_RECLAIM_attribute_list_add(struct GNUNET_RECLAIM_AttributeList *attrs, const char *attr_name, const struct GNUNET_RECLAIM_Identifier *attestation, uint32_t type, const void *data, size_t data_size)
Add a new attribute to a claim list.
static char * value
Value of the record to add/remove.
#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING
String attribute.
uint32_t type
Type/Format of Claim.
#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT
A JSON Web Token attestation.
struct GNUNET_HashCode key
The key used in the DHT.
const void * data
Binary value stored as attribute value.
#define GNUNET_log(kind,...)
size_t GNUNET_STRINGS_base64url_decode(const char *data, size_t len, void **out)
Decode from Base64url.
Definition: strings.c:2026
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ jwt_get_issuer()

char* jwt_get_issuer ( void *  cls,
const struct GNUNET_RECLAIM_Attestation attest 
)

Parse a JWT and return the issuer.

Parameters
clsthe plugin
attestthe jwt attestation
Returns
a string, containing the isser

Definition at line 214 of file plugin_reclaim_attestation_jwt.c.

References GNUNET_RECLAIM_Attestation::data, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_RECLAIM_ATTESTATION_TYPE_JWT, GNUNET_strdup, GNUNET_STRINGS_base64url_decode(), and GNUNET_RECLAIM_Attestation::type.

Referenced by libgnunet_plugin_reclaim_attestation_jwt_init().

216 {
217  const char *jwt_body;
218  char *jwt_string;
219  char delim[] = ".";
220  char *issuer = NULL;
221  char *decoded_jwt;
222  json_t *issuer_json;
223  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
224  json_t *json_val;
225  json_error_t *json_err = NULL;
226 
228  return NULL;
229  jwt_string = GNUNET_strdup (attest->data);
230  jwt_body = strtok (jwt_string, delim);
231  jwt_body = strtok (NULL, delim);
232  GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body),
233  (void **) &decoded_jwt);
234  json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
235  issuer_json = json_object_get (json_val, "iss");
236  if ((NULL == issuer_json) || (! json_is_string (issuer_json)))
237  return NULL;
238  issuer = GNUNET_strdup (json_string_value (issuer_json));
239  GNUNET_free (jwt_string);
240  return issuer;
241 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint32_t type
Type/Format of Claim.
#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT
A JSON Web Token attestation.
const void * data
Binary value stored as attribute value.
#define GNUNET_log(kind,...)
size_t GNUNET_STRINGS_base64url_decode(const char *data, size_t len, void **out)
Decode from Base64url.
Definition: strings.c:2026
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ jwt_get_expiration()

int jwt_get_expiration ( void *  cls,
const struct GNUNET_RECLAIM_Attestation attest,
struct GNUNET_TIME_Absolute exp 
)

Parse a JWT and return the expiration.

Parameters
clsthe plugin
attestthe jwt attestation
Returns
a string, containing the isser

Definition at line 252 of file plugin_reclaim_attestation_jwt.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_RECLAIM_Attestation::data, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_RECLAIM_ATTESTATION_TYPE_JWT, GNUNET_strdup, GNUNET_STRINGS_base64url_decode(), GNUNET_SYSERR, and GNUNET_RECLAIM_Attestation::type.

Referenced by libgnunet_plugin_reclaim_attestation_jwt_init().

255 {
256  const char *jwt_body;
257  char *jwt_string;
258  char delim[] = ".";
259  char *decoded_jwt;
260  json_t *exp_json;
261  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
262  json_t *json_val;
263  json_error_t *json_err = NULL;
264 
266  return GNUNET_NO;
267  jwt_string = GNUNET_strdup (attest->data);
268  jwt_body = strtok (jwt_string, delim);
269  jwt_body = strtok (NULL, delim);
270  GNUNET_STRINGS_base64url_decode (jwt_body, strlen (jwt_body),
271  (void **) &decoded_jwt);
272  json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
273  exp_json = json_object_get (json_val, "exp");
274  if ((NULL == exp_json) || (! json_is_integer (exp_json)))
275  return GNUNET_SYSERR;
276  exp->abs_value_us = json_integer_value (exp_json) * 1000 * 1000;
277  GNUNET_free (jwt_string);
278  return GNUNET_OK;
279 }
#define GNUNET_NO
Definition: gnunet_common.h:86
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint64_t abs_value_us
The actual value.
uint32_t type
Type/Format of Claim.
#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT
A JSON Web Token attestation.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
const void * data
Binary value stored as attribute value.
#define GNUNET_log(kind,...)
size_t GNUNET_STRINGS_base64url_decode(const char *data, size_t len, void **out)
Decode from Base64url.
Definition: strings.c:2026
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_reclaim_attestation_jwt_init()

void* libgnunet_plugin_reclaim_attestation_jwt_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 289 of file plugin_reclaim_attestation_jwt.c.

References GNUNET_RECLAIM_AttestationPluginFunctions::get_attributes, GNUNET_RECLAIM_AttestationPluginFunctions::get_expiration, GNUNET_RECLAIM_AttestationPluginFunctions::get_issuer, GNUNET_new, jwt_get_expiration(), jwt_get_issuer(), jwt_number_to_typename(), jwt_parse_attributes(), jwt_string_to_value(), jwt_typename_to_number(), jwt_value_to_string(), GNUNET_RECLAIM_AttestationPluginFunctions::number_to_typename, GNUNET_RECLAIM_AttestationPluginFunctions::string_to_value, GNUNET_RECLAIM_AttestationPluginFunctions::typename_to_number, and GNUNET_RECLAIM_AttestationPluginFunctions::value_to_string.

290 {
292 
299  api->get_issuer = &jwt_get_issuer;
301  return api;
302 }
static char * jwt_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of an attestation to a string.
static const char * jwt_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
static uint32_t jwt_typename_to_number(void *cls, const char *jwt_typename)
Convert a type name to the corresponding number.
struct GNUNET_RECLAIM_AttributeList * jwt_parse_attributes(void *cls, const struct GNUNET_RECLAIM_Attestation *attest)
Parse a JWT and return the respective claim value as Attribute.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_RECLAIM_AttestationTypenameToNumberFunction typename_to_number
Typename to number.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_RECLAIM_AttestationGetIssuerFunction get_issuer
Attesation issuer.
GNUNET_RECLAIM_AttestationStringToValueFunction string_to_value
Conversion to binary.
GNUNET_RECLAIM_AttestationGetAttributesFunction get_attributes
Attesation attributes.
static int jwt_string_to_value(void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a &#39;value&#39; of an attestation to the binary representation.
char * jwt_get_issuer(void *cls, const struct GNUNET_RECLAIM_Attestation *attest)
Parse a JWT and return the issuer.
GNUNET_RECLAIM_AttestationNumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_RECLAIM_AttestationGetExpirationFunction get_expiration
Expiration.
int jwt_get_expiration(void *cls, const struct GNUNET_RECLAIM_Attestation *attest, struct GNUNET_TIME_Absolute *exp)
Parse a JWT and return the expiration.
GNUNET_RECLAIM_AttestationValueToStringFunction value_to_string
Conversion to string.
Here is the call graph for this function:

◆ libgnunet_plugin_reclaim_attestation_jwt_done()

void* libgnunet_plugin_reclaim_attestation_jwt_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init()
Returns
NULL

Definition at line 312 of file plugin_reclaim_attestation_jwt.c.

References GNUNET_RECLAIM_AttestationPluginFunctions::cls, and GNUNET_free.

313 {
315 
316  GNUNET_free (api);
317  return NULL;
318 }
void * cls
Closure for all of the callbacks.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_free(ptr)
Wrapper around free.

Variable Documentation

◆ name

const char* name

◆ number

uint32_t number

Definition at line 101 of file plugin_reclaim_attestation_jwt.c.

Referenced by jwt_number_to_typename().

◆ jwt_attest_name_map

struct { ... } jwt_attest_name_map[]
Initial value:
{ NULL, UINT32_MAX } }
#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT
A JSON Web Token attestation.

Mapping of attestation type numbers to human-readable attestation type names.

Referenced by jwt_number_to_typename(), and jwt_typename_to_number().