GNUnet  0.10.x
Functions | Variables
plugin_gnsrecord_credential.c File Reference

gnsrecord plugin to provide the API for CREDENTIAL records More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "credential_misc.h"
#include "credential_serialization.h"
#include "gnunet_credential_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_gnsrecord_plugin.h"
#include "gnunet_signatures.h"
Include dependency graph for plugin_gnsrecord_credential.c:

Go to the source code of this file.

Functions

static char * credential_value_to_string (void *cls, uint32_t type, const void *data, size_t data_size)
 Convert the 'value' of a record to a string. More...
 
static int credential_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 a record to the binary representation. More...
 
static uint32_t credential_typename_to_number (void *cls, const char *gns_typename)
 Convert a type name (i.e. More...
 
static const char * credential_number_to_typename (void *cls, uint32_t type)
 Convert a type number (i.e. More...
 
void * libgnunet_plugin_gnsrecord_credential_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_gnsrecord_credential_done (void *cls)
 Exit point from the plugin. More...
 

Variables

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

Detailed Description

gnsrecord plugin to provide the API for CREDENTIAL records

Author
Martin Schanzenbach

Definition in file plugin_gnsrecord_credential.c.

Function Documentation

◆ credential_value_to_string()

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

Convert the 'value' of a record to a string.

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

Definition at line 46 of file plugin_gnsrecord_credential.c.

References data, GNUNET_asprintf(), GNUNET_CREDENTIAL_credential_deserialize(), GNUNET_CREDENTIAL_credential_to_string(), GNUNET_CREDENTIAL_delegation_set_deserialize(), GNUNET_CRYPTO_ecdsa_public_key_to_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNSRECORD_TYPE_CREDENTIAL, GNUNET_GNSRECORD_TYPE_POLICY, GNUNET_log, GNUNET_memcpy, GNUNET_ntohll(), GNUNET_OK, GNUNET_strndup, GNUNET_CREDENTIAL_DelegationSet::subject_attribute, GNUNET_CREDENTIAL_DelegationSet::subject_attribute_len, subject_key, and subject_pkey.

Referenced by libgnunet_plugin_gnsrecord_credential_init().

48 {
49  const char *cdata;
50 
51  switch (type)
52  {
55  char *attr_str;
56  char *subject_pkey;
57  char *tmp_str;
58  int i;
59  if (data_size < sizeof(struct GNUNET_CREDENTIAL_DelegationRecord))
60  return NULL; /* malformed */
61  GNUNET_memcpy(&sets, data, sizeof(sets));
62  cdata = data;
63  struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)];
65  GNUNET_ntohll(sets.data_size), &cdata[sizeof(sets)],
66  ntohl(sets.set_count), set))
67  return NULL;
68 
69  for (i = 0; i < ntohl(sets.set_count); i++)
70  {
71  subject_pkey =
73  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n",
74  set[i].subject_attribute_len);
75  if (0 == set[i].subject_attribute_len)
76  {
77  if (0 == i)
78  {
79  GNUNET_asprintf(&attr_str, "%s", subject_pkey);
80  }
81  else
82  {
83  GNUNET_asprintf(&tmp_str, "%s,%s", attr_str, subject_pkey);
84  GNUNET_free(attr_str);
85  attr_str = tmp_str;
86  }
87  }
88  else
89  {
90  if (0 == i)
91  {
92  GNUNET_asprintf(&attr_str, "%s %s", subject_pkey,
93  set[i].subject_attribute);
94  }
95  else
96  {
97  GNUNET_asprintf(&tmp_str, "%s,%s %s", attr_str, subject_pkey,
98  set[i].subject_attribute);
99  GNUNET_free(attr_str);
100  attr_str = tmp_str;
101  }
102  }
103  GNUNET_free(subject_pkey);
104  }
105  return attr_str;
106  }
107 
109  struct GNUNET_CREDENTIAL_Credential *cred;
110  char *cred_str;
111 
114  GNUNET_free(cred);
115  return cred_str;
116  }
117 
119  return GNUNET_strndup(data, data_size);
120  }
121 
122  default:
123  return NULL;
124  }
125 }
#define GNUNET_GNSRECORD_TYPE_POLICY
Record type for policies.
static char * subject_key
Subject pubkey string.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
int GNUNET_CREDENTIAL_delegation_set_deserialize(size_t len, const char *src, unsigned int d_count, struct GNUNET_CREDENTIAL_DelegationSet *dsr)
Deserialize the given destination.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey
Subject key.
#define GNUNET_GNSRECORD_TYPE_CREDENTIAL
65546 reserved
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
const char * subject_attribute
The subject attribute.
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:334
struct GNUNET_CREDENTIAL_Credential * GNUNET_CREDENTIAL_credential_deserialize(const char *data, size_t data_size)
char * GNUNET_CREDENTIAL_credential_to_string(const struct GNUNET_CREDENTIAL_Credential *cred)
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE
Record type for reverse lookups.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
The attribute delegation record.
The attribute delegation record.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ credential_string_to_value()

static int credential_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 a record to the binary representation.

Parameters
clsclosure, unused
typetype of the record
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 140 of file plugin_gnsrecord_credential.c.

References _, entries, GNUNET_CREDENTIAL_credential_from_string(), GNUNET_CREDENTIAL_credential_serialize(), GNUNET_CREDENTIAL_delegation_set_get_size(), GNUNET_CREDENTIAL_delegation_set_serialize(), GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNSRECORD_TYPE_CREDENTIAL, GNUNET_GNSRECORD_TYPE_POLICY, GNUNET_htonll(), GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, GNUNET_CREDENTIAL_DelegationSet::subject_attribute, GNUNET_CREDENTIAL_DelegationSet::subject_attribute_len, subject_key, and subject_pkey.

Referenced by libgnunet_plugin_gnsrecord_credential_init().

142 {
143  if (NULL == s)
144  return GNUNET_SYSERR;
145  switch (type)
146  {
149  char attr_str[253 + 1];
150  char subject_pkey[52 + 1];
151  char *token;
152  char *tmp_str;
153  int matches = 0;
154  int entries;
155  size_t tmp_data_size;
156  int i;
157 
158  tmp_str = GNUNET_strdup(s);
159  token = strtok(tmp_str, ",");
160  entries = 0;
161  tmp_data_size = 0;
163  while (NULL != token)
164  {
165  matches = sscanf(token, "%s %s", subject_pkey, attr_str);
166  if (0 == matches)
167  {
169  _("Unable to parse ATTR record string `%s'\n"), s);
170  GNUNET_free(tmp_str);
171  return GNUNET_SYSERR;
172  }
173  if (1 == matches)
174  {
175  tmp_data_size += sizeof(struct GNUNET_CREDENTIAL_DelegationRecordSet);
176  }
177  else if (2 == matches)
178  {
179  tmp_data_size += sizeof(struct GNUNET_CREDENTIAL_DelegationRecordSet) +
180  strlen(attr_str) + 1;
181  }
182  entries++;
183  token = strtok(NULL, ",");
184  }
185  GNUNET_free(tmp_str);
186  tmp_str = GNUNET_strdup(s);
187  token = strtok(tmp_str, ",");
188  if (NULL == token)
189  {
190  GNUNET_free(tmp_str);
191  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s);
192  return GNUNET_SYSERR;
193  }
194  struct GNUNET_CREDENTIAL_DelegationSet set[entries];
195  memset(set, 0, sizeof(struct GNUNET_CREDENTIAL_DelegationSet) * entries);
196  for (i = 0; i < entries; i++)
197  {
198  matches = sscanf(token, "%s %s", subject_pkey, attr_str);
200  subject_pkey, strlen(subject_pkey), &set[i].subject_key);
201  if (2 == matches)
202  {
203  set[i].subject_attribute_len = strlen(attr_str) + 1;
204  set[i].subject_attribute = GNUNET_strdup(attr_str);
205  }
206  token = strtok(NULL, ",");
207  }
208  tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size(entries, set);
209 
210  if (-1 == tmp_data_size)
211  {
212  GNUNET_free(tmp_str);
213  return GNUNET_SYSERR;
214  }
215  *data_size += tmp_data_size;
216  *data = sets = GNUNET_malloc(*data_size);
217  GNUNET_CREDENTIAL_delegation_set_serialize(entries, set, tmp_data_size,
218  (char *)&sets[1]);
219  for (i = 0; i < entries; i++)
220  {
221  if (0 != set[i].subject_attribute_len)
222  GNUNET_free((char *)set[i].subject_attribute);
223  }
224  sets->set_count = htonl(entries);
225  sets->data_size = GNUNET_htonll(tmp_data_size);
226 
227  GNUNET_free(tmp_str);
228  return GNUNET_OK;
229  }
230 
232  struct GNUNET_CREDENTIAL_Credential *cred;
234 
236  return GNUNET_OK;
237  }
238 
240  *data_size = strlen(s);
241  *data = GNUNET_strdup(s);
242  return GNUNET_OK;
243  }
244 
245  default:
246  return GNUNET_SYSERR;
247  }
248 }
struct GNUNET_CREDENTIAL_Credential * GNUNET_CREDENTIAL_credential_from_string(const char *s)
int GNUNET_CREDENTIAL_credential_serialize(struct GNUNET_CREDENTIAL_Credential *cred, char **data)
ssize_t GNUNET_CREDENTIAL_delegation_set_serialize(unsigned int d_count, const struct GNUNET_CREDENTIAL_DelegationSet *dsr, size_t dest_size, char *dest)
Serizalize the given delegation chain entries and credential.
#define GNUNET_GNSRECORD_TYPE_POLICY
Record type for policies.
static char * subject_key
Subject pubkey string.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey
Subject key.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint32_t set_count
Number of delegation sets in this record.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
#define GNUNET_GNSRECORD_TYPE_CREDENTIAL
65546 reserved
struct ListEntry * entries
List of peers in the list.
size_t GNUNET_CREDENTIAL_delegation_set_get_size(unsigned int ds_count, const struct GNUNET_CREDENTIAL_DelegationSet *dsr)
Calculate how many bytes we will need to serialize the given delegation chain.
const char * subject_attribute
The subject attribute.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
uint64_t data_size
Length of delegation sets.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:468
The attribute delegation record.
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE
Record type for reverse lookups.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
The attribute delegation record.
#define GNUNET_malloc(size)
Wrapper around malloc.
The attribute delegation record.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ credential_typename_to_number()

static uint32_t credential_typename_to_number ( void *  cls,
const char *  gns_typename 
)
static

Convert a type name (i.e.

"AAAA") to the corresponding number.

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

Definition at line 272 of file plugin_gnsrecord_credential.c.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_credential_init().

273 {
274  unsigned int i;
275 
276  i = 0;
277  while ((name_map[i].name != NULL) &&
278  (0 != strcasecmp(gns_typename, name_map[i].name)))
279  i++;
280  return name_map[i].number;
281 }
static struct @10 name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name
Here is the caller graph for this function:

◆ credential_number_to_typename()

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

Convert a type number (i.e.

1) to the corresponding type string (i.e. "A")

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

Definition at line 292 of file plugin_gnsrecord_credential.c.

References name, name_map, and number.

Referenced by libgnunet_plugin_gnsrecord_credential_init().

293 {
294  unsigned int i;
295 
296  i = 0;
297  while ((name_map[i].name != NULL) && (type != name_map[i].number))
298  i++;
299  return name_map[i].name;
300 }
static struct @10 name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t number
Here is the caller graph for this function:

◆ libgnunet_plugin_gnsrecord_credential_init()

void* libgnunet_plugin_gnsrecord_credential_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 310 of file plugin_gnsrecord_credential.c.

References credential_number_to_typename(), credential_string_to_value(), credential_typename_to_number(), credential_value_to_string(), GNUNET_new, GNUNET_GNSRECORD_PluginFunctions::number_to_typename, GNUNET_GNSRECORD_PluginFunctions::string_to_value, GNUNET_GNSRECORD_PluginFunctions::typename_to_number, and GNUNET_GNSRECORD_PluginFunctions::value_to_string.

311 {
313 
319  return api;
320 }
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
static uint32_t credential_typename_to_number(void *cls, const char *gns_typename)
Convert a type name (i.e.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
static int credential_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 a record to the binary representation.
static const char * credential_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
static char * credential_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Here is the call graph for this function:

◆ libgnunet_plugin_gnsrecord_credential_done()

void* libgnunet_plugin_gnsrecord_credential_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init
Returns
NULL

Definition at line 330 of file plugin_gnsrecord_credential.c.

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

331 {
333 
334  GNUNET_free(api);
335  return NULL;
336 }
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 257 of file plugin_gnsrecord_credential.c.

Referenced by credential_number_to_typename().

◆ name_map

struct { ... } name_map[]
Initial value:
{ NULL, UINT32_MAX } }
#define GNUNET_GNSRECORD_TYPE_POLICY
Record type for policies.
#define GNUNET_GNSRECORD_TYPE_CREDENTIAL
65546 reserved
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE
Record type for reverse lookups.

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

Referenced by credential_number_to_typename(), and credential_typename_to_number().