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 
50  const char *cdata;
51 
52  switch (type) {
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  subject_pkey =
72  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n",
73  set[i].subject_attribute_len);
74  if (0 == set[i].subject_attribute_len) {
75  if (0 == i) {
76  GNUNET_asprintf (&attr_str, "%s", subject_pkey);
77  } else {
78  GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey);
79  GNUNET_free (attr_str);
80  attr_str = tmp_str;
81  }
82  } else {
83  if (0 == i) {
84  GNUNET_asprintf (&attr_str, "%s %s", subject_pkey,
85  set[i].subject_attribute);
86  } else {
87  GNUNET_asprintf (&tmp_str, "%s,%s %s", attr_str, subject_pkey,
88  set[i].subject_attribute);
89  GNUNET_free (attr_str);
90  attr_str = tmp_str;
91  }
92  }
93  GNUNET_free (subject_pkey);
94  }
95  return attr_str;
96  }
98  struct GNUNET_CREDENTIAL_Credential *cred;
99  char *cred_str;
100 
102  cred_str = GNUNET_CREDENTIAL_credential_to_string (cred);
103  GNUNET_free (cred);
104  return cred_str;
105  }
107  return GNUNET_strndup (data, data_size);
108  }
109  default:
110  return NULL;
111  }
112 }
#define GNUNET_GNSRECORD_TYPE_POLICY
Record type for policies.
static char * subject_key
Subject pubkey string.
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:78
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.
#define GNUNET_memcpy(dst, src, n)
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 127 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, SSCANF, GNUNET_CREDENTIAL_DelegationSet::subject_attribute, GNUNET_CREDENTIAL_DelegationSet::subject_attribute_len, subject_key, and subject_pkey.

Referenced by libgnunet_plugin_gnsrecord_credential_init().

129 {
130  if (NULL == s)
131  return GNUNET_SYSERR;
132  switch (type) {
135  char attr_str[253 + 1];
136  char subject_pkey[52 + 1];
137  char *token;
138  char *tmp_str;
139  int matches = 0;
140  int entries;
141  size_t tmp_data_size;
142  int i;
143 
144  tmp_str = GNUNET_strdup (s);
145  token = strtok (tmp_str, ",");
146  entries = 0;
147  tmp_data_size = 0;
149  while (NULL != token) {
150  matches = SSCANF (token, "%s %s", subject_pkey, attr_str);
151  if (0 == matches) {
153  _ ("Unable to parse ATTR record string `%s'\n"), s);
154  GNUNET_free (tmp_str);
155  return GNUNET_SYSERR;
156  }
157  if (1 == matches) {
158  tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet);
159  } else if (2 == matches) {
160  tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet) +
161  strlen (attr_str) + 1;
162  }
163  entries++;
164  token = strtok (NULL, ",");
165  }
166  GNUNET_free (tmp_str);
167  tmp_str = GNUNET_strdup (s);
168  token = strtok (tmp_str, ",");
169  if (NULL == token) {
170  GNUNET_free (tmp_str);
171  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s);
172  return GNUNET_SYSERR;
173  }
174  struct GNUNET_CREDENTIAL_DelegationSet set[entries];
175  memset (set, 0, sizeof (struct GNUNET_CREDENTIAL_DelegationSet) * entries);
176  for (i = 0; i < entries; i++) {
177  matches = SSCANF (token, "%s %s", subject_pkey, attr_str);
179  subject_pkey, strlen (subject_pkey), &set[i].subject_key);
180  if (2 == matches) {
181  set[i].subject_attribute_len = strlen (attr_str) + 1;
182  set[i].subject_attribute = GNUNET_strdup (attr_str);
183  }
184  token = strtok (NULL, ",");
185  }
186  tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set);
187 
188  if (-1 == tmp_data_size) {
189  GNUNET_free (tmp_str);
190  return GNUNET_SYSERR;
191  }
192  *data_size += tmp_data_size;
193  *data = sets = GNUNET_malloc (*data_size);
194  GNUNET_CREDENTIAL_delegation_set_serialize (entries, set, tmp_data_size,
195  (char *)&sets[1]);
196  for (i = 0; i < entries; i++) {
197  if (0 != set[i].subject_attribute_len)
198  GNUNET_free ((char *)set[i].subject_attribute);
199  }
200  sets->set_count = htonl (entries);
201  sets->data_size = GNUNET_htonll (tmp_data_size);
202 
203  GNUNET_free (tmp_str);
204  return GNUNET_OK;
205  }
207  struct GNUNET_CREDENTIAL_Credential *cred;
209 
211  return GNUNET_OK;
212  }
214  *data_size = strlen (s);
215  *data = GNUNET_strdup (s);
216  return GNUNET_OK;
217  }
218  default:
219  return GNUNET_SYSERR;
220  }
221 }
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:78
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:208
#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:79
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
#define SSCANF
Definition: plibc.h:691
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 246 of file plugin_gnsrecord_credential.c.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_credential_init().

247 {
248  unsigned int i;
249 
250  i = 0;
251  while ((name_map[i].name != NULL) &&
252  (0 != strcasecmp (gns_typename, name_map[i].name)))
253  i++;
254  return name_map[i].number;
255 }
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 266 of file plugin_gnsrecord_credential.c.

References name, name_map, and number.

Referenced by libgnunet_plugin_gnsrecord_credential_init().

267 {
268  unsigned int i;
269 
270  i = 0;
271  while ((name_map[i].name != NULL) && (type != name_map[i].number))
272  i++;
273  return name_map[i].name;
274 }
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 284 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.

285 {
287 
293  return api;
294 }
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 304 of file plugin_gnsrecord_credential.c.

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

305 {
307 
308  GNUNET_free (api);
309  return NULL;
310 }
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 231 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().