GNUnet  0.10.x
Functions
credential_serialization.c File Reference

API to serialize and deserialize delegation chains and credentials. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_credential_service.h"
#include "gnunet_signatures.h"
#include "credential.h"
Include dependency graph for credential_serialization.c:

Go to the source code of this file.

Functions

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. More...
 
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. More...
 
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. More...
 
size_t GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count, const struct GNUNET_CREDENTIAL_Credential *cd)
 Calculate how many bytes we will need to serialize the credentials. More...
 
ssize_t GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count, const struct GNUNET_CREDENTIAL_Credential *cd, size_t dest_size, char *dest)
 Serizalize the given credentials. More...
 
int GNUNET_CREDENTIAL_credentials_deserialize (size_t len, const char *src, unsigned int c_count, struct GNUNET_CREDENTIAL_Credential *cd)
 Deserialize the given destination. More...
 
size_t GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count, const struct GNUNET_CREDENTIAL_Delegation *dd, unsigned int c_count, const struct GNUNET_CREDENTIAL_Credential *cd)
 Calculate how many bytes we will need to serialize the given delegation chain and credential. More...
 
ssize_t GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count, const struct GNUNET_CREDENTIAL_Delegation *dd, unsigned int c_count, const struct GNUNET_CREDENTIAL_Credential *cd, size_t dest_size, char *dest)
 Serizalize the given delegation chain entries and credential. More...
 
int GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len, const char *src, unsigned int d_count, struct GNUNET_CREDENTIAL_Delegation *dd, unsigned int c_count, struct GNUNET_CREDENTIAL_Credential *cd)
 Deserialize the given destination. More...
 
int GNUNET_CREDENTIAL_credential_serialize (struct GNUNET_CREDENTIAL_Credential *cred, char **data)
 
struct GNUNET_CREDENTIAL_CredentialGNUNET_CREDENTIAL_credential_deserialize (const char *data, size_t data_size)
 

Detailed Description

API to serialize and deserialize delegation chains and credentials.

Author
Martin Schanzenbach

Definition in file credential_serialization.c.

Function Documentation

◆ GNUNET_CREDENTIAL_delegation_set_get_size()

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.

Calculate how many bytes we will need to serialize the given delegation record.

Parameters
ds_countnumber of delegation chain entries
dsrarray of GNUNET_CREDENTIAL_DelegationSet
Returns
the required size to serialize

Definition at line 44 of file credential_serialization.c.

References GNUNET_assert, ret, GNUNET_CREDENTIAL_DelegationSet::subject_attribute_len, and DelegationRecordData::subject_attribute_len.

Referenced by credential_string_to_value().

47 {
48  unsigned int i;
49  size_t ret;
50 
51  ret = sizeof(struct DelegationRecordData) * (ds_count);
52 
53  for (i = 0; i < ds_count; i++)
54  {
55  GNUNET_assert ((ret + dsr[i].subject_attribute_len) >= ret);
56  ret += dsr[i].subject_attribute_len;
57  }
58  return ret;
59 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Final status code.
Definition: gnunet-arm.c:94
uint32_t subject_attribute_len
Subject attributes.
Definition: credential.h:148
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_delegation_set_serialize()

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.

Serizalize the given delegation record entries.

Parameters
d_countnumber of delegation chain entries
dsrarray of GNUNET_CREDENTIAL_DelegationSet
dest_sizesize of the destination
destwhere to store the result
Returns
the size of the data, -1 on failure

Definition at line 71 of file credential_serialization.c.

References GNUNET_memcpy, GNUNET_CREDENTIAL_DelegationSet::subject_attribute_len, DelegationRecordData::subject_attribute_len, GNUNET_CREDENTIAL_DelegationSet::subject_key, and DelegationRecordData::subject_key.

Referenced by credential_string_to_value().

76 {
77  struct DelegationRecordData rec;
78  unsigned int i;
79  size_t off;
80 
81  off = 0;
82  for (i = 0; i < d_count; i++)
83  {
84  rec.subject_attribute_len = htonl ((uint32_t) dsr[i].subject_attribute_len);
85  rec.subject_key = dsr[i].subject_key;
86  if (off + sizeof(rec) > dest_size)
87  return -1;
88  GNUNET_memcpy (&dest[off],
89  &rec,
90  sizeof(rec));
91  off += sizeof(rec);
92  if (0 == dsr[i].subject_attribute_len)
93  continue;
94  if (off + dsr[i].subject_attribute_len > dest_size)
95  return -1;
96  GNUNET_memcpy (&dest[off],
97  dsr[i].subject_attribute,
98  dsr[i].subject_attribute_len);
99  off += dsr[i].subject_attribute_len;
100  }
101  return off;
102 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint32_t subject_attribute_len
Subject attributes.
Definition: credential.h:148
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_delegation_set_deserialize()

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.

Parameters
lensize of the serialized delegation chain and cred
srcthe serialized data
d_countthe number of delegation chain entries
dsrwhere to put the delegation chain entries
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 115 of file credential_serialization.c.

References GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_CREDENTIAL_DelegationSet::subject_attribute, GNUNET_CREDENTIAL_DelegationSet::subject_attribute_len, DelegationRecordData::subject_attribute_len, GNUNET_CREDENTIAL_DelegationSet::subject_key, and DelegationRecordData::subject_key.

Referenced by backward_resolution(), and credential_value_to_string().

121 {
122  struct DelegationRecordData rec;
123  unsigned int i;
124  size_t off;
125 
126  off = 0;
127  for (i = 0; i < d_count; i++)
128  {
129  if (off + sizeof(rec) > len)
130  return GNUNET_SYSERR;
131  GNUNET_memcpy (&rec, &src[off], sizeof(rec));
132  dsr[i].subject_key = rec.subject_key;
133  off += sizeof(rec);
134  dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len);
135  if (off + dsr[i].subject_attribute_len > len)
136  return GNUNET_SYSERR;
137  dsr[i].subject_attribute = (char*) &src[off];
138  off += dsr[i].subject_attribute_len;
139  }
140  return GNUNET_OK;
141 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const char * subject_attribute
The subject attribute.
uint32_t subject_attribute_len
Subject attributes.
Definition: credential.h:148
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_credentials_get_size()

size_t GNUNET_CREDENTIAL_credentials_get_size ( unsigned int  c_count,
const struct GNUNET_CREDENTIAL_Credential cd 
)

Calculate how many bytes we will need to serialize the credentials.

Parameters
c_countnumber of credential entries
cda GNUNET_CREDENTIAL_Credential
Returns
the required size to serialize

Definition at line 153 of file credential_serialization.c.

References GNUNET_assert, GNUNET_CREDENTIAL_Credential::issuer_attribute_len, CredentialEntry::issuer_attribute_len, and ret.

Referenced by GNUNET_CREDENTIAL_delegation_chain_get_size(), and GNUNET_CREDENTIAL_verify().

156 {
157  unsigned int i;
158  size_t ret;
159 
160  ret = sizeof(struct CredentialEntry) * (c_count);
161 
162  for (i = 0; i < c_count; i++)
163  {
164  GNUNET_assert ((ret + cd[i].issuer_attribute_len) >= ret);
165  ret += cd[i].issuer_attribute_len;
166  }
167  return ret;
168 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:206
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Final status code.
Definition: gnunet-arm.c:94
uint32_t issuer_attribute_len
Length of the attribute.
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_credentials_serialize()

ssize_t GNUNET_CREDENTIAL_credentials_serialize ( unsigned int  c_count,
const struct GNUNET_CREDENTIAL_Credential cd,
size_t  dest_size,
char *  dest 
)

Serizalize the given credentials.

Parameters
c_countnumber of credential entries
cda GNUNET_CREDENTIAL_Credential
dest_sizesize of the destination
destwhere to store the result
Returns
the size of the data, -1 on failure

Definition at line 179 of file credential_serialization.c.

References expiration, CredentialEntry::expiration, GNUNET_htonll(), GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, GNUNET_CREDENTIAL_Credential::issuer_attribute_len, CredentialEntry::issuer_attribute_len, GNUNET_CREDENTIAL_Credential::issuer_key, CredentialEntry::issuer_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, CredentialEntry::purpose, GNUNET_CREDENTIAL_Credential::signature, CredentialEntry::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_CREDENTIAL_Credential::subject_key, and CredentialEntry::subject_key.

Referenced by GNUNET_CREDENTIAL_delegation_chain_serialize(), and GNUNET_CREDENTIAL_verify().

184 {
185  struct CredentialEntry c_rec;
186  unsigned int i;
187  size_t off;
188 
189  off = 0;
190  for (i = 0; i < c_count; i++)
191  {
192  c_rec.issuer_attribute_len = htonl ((uint32_t) cd[i].issuer_attribute_len);
193  c_rec.issuer_key = cd[i].issuer_key;
194  c_rec.subject_key = cd[i].subject_key;
195  c_rec.signature = cd[i].signature;
196  c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
197  c_rec.purpose.size = htonl ((sizeof(struct CredentialEntry)
198  + cd[i].issuer_attribute_len) - sizeof(struct
200  c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us);
201  if (off + sizeof(c_rec) > dest_size)
202  return -1;
203  GNUNET_memcpy (&dest[off],
204  &c_rec,
205  sizeof(c_rec));
206  off += sizeof(c_rec);
207  if (off + cd[i].issuer_attribute_len > dest_size)
208  return -1;
209  GNUNET_memcpy (&dest[off],
210  cd[i].issuer_attribute,
211  cd[i].issuer_attribute_len);
212  off += cd[i].issuer_attribute_len;
213  }
214 
215  return off;
216 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:206
static char * expiration
Credential TTL.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
#define GNUNET_SIGNATURE_PURPOSE_CREDENTIAL
Signature for a GNUnet credential.
an ECC signature using ECDSA
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
uint32_t issuer_attribute_len
Length of the attribute.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_credentials_deserialize()

int GNUNET_CREDENTIAL_credentials_deserialize ( size_t  len,
const char *  src,
unsigned int  c_count,
struct GNUNET_CREDENTIAL_Credential cd 
)

Deserialize the given destination.

Parameters
lensize of the serialized creds
srcthe serialized data
c_countthe number of credential entries
cdwhere to put the credential data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 230 of file credential_serialization.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CREDENTIAL_Credential::expiration, CredentialEntry::expiration, GNUNET_memcpy, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, GNUNET_CREDENTIAL_Credential::issuer_attribute, GNUNET_CREDENTIAL_Credential::issuer_attribute_len, CredentialEntry::issuer_attribute_len, GNUNET_CREDENTIAL_Credential::issuer_key, CredentialEntry::issuer_key, GNUNET_CREDENTIAL_Credential::signature, CredentialEntry::signature, GNUNET_CREDENTIAL_Credential::subject_key, and CredentialEntry::subject_key.

Referenced by GNUNET_CREDENTIAL_delegation_chain_deserialize(), and handle_verify().

235 {
236  struct CredentialEntry c_rec;
237  unsigned int i;
238  size_t off;
239 
240  off = 0;
241  for (i = 0; i < c_count; i++)
242  {
243  if (off + sizeof(c_rec) > len)
244  return GNUNET_SYSERR;
245  GNUNET_memcpy (&c_rec, &src[off], sizeof(c_rec));
246  cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len);
247  cd[i].issuer_key = c_rec.issuer_key;
248  cd[i].subject_key = c_rec.subject_key;
249  cd[i].signature = c_rec.signature;
250  cd[i].expiration.abs_value_us = GNUNET_ntohll (c_rec.expiration);
251  off += sizeof(c_rec);
252  if (off + cd[i].issuer_attribute_len > len)
253  return GNUNET_SYSERR;
254  cd[i].issuer_attribute = &src[off];
255  off += cd[i].issuer_attribute_len;
256  }
257  return GNUNET_OK;
258 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:206
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
uint64_t abs_value_us
The actual value.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
const char * issuer_attribute
The attribute.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
uint32_t issuer_attribute_len
Length of the attribute.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_delegation_chain_get_size()

size_t GNUNET_CREDENTIAL_delegation_chain_get_size ( unsigned int  d_count,
const struct GNUNET_CREDENTIAL_Delegation dd,
unsigned int  c_count,
const struct GNUNET_CREDENTIAL_Credential cd 
)

Calculate how many bytes we will need to serialize the given delegation chain and credential.

Parameters
d_countnumber of delegation chain entries
ddarray of GNUNET_CREDENTIAL_Delegation
c_countnumber of credential entries
cda GNUNET_CREDENTIAL_Credential
Returns
the required size to serialize

Definition at line 273 of file credential_serialization.c.

References GNUNET_assert, GNUNET_CREDENTIAL_credentials_get_size(), GNUNET_CREDENTIAL_Delegation::issuer_attribute_len, ChainEntry::issuer_attribute_len, ret, GNUNET_CREDENTIAL_Delegation::subject_attribute_len, and ChainEntry::subject_attribute_len.

Referenced by send_lookup_response().

279 {
280  unsigned int i;
281  size_t ret;
282 
283  ret = sizeof(struct ChainEntry) * (d_count);
284 
285  for (i = 0; i < d_count; i++)
286  {
287  GNUNET_assert ((ret
288  + dd[i].issuer_attribute_len
289  + dd[i].subject_attribute_len) >= ret);
290  ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len;
291  }
292  return ret + GNUNET_CREDENTIAL_credentials_get_size (c_count, cd);
293 }
uint32_t subject_attribute_len
Length of the attribute.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t issuer_attribute_len
Issuer attributes.
Definition: credential.h:167
static int ret
Final status code.
Definition: gnunet-arm.c:94
uint32_t subject_attribute_len
Subject attributes.
Definition: credential.h:172
uint32_t issuer_attribute_len
Length of the attribute.
size_t GNUNET_CREDENTIAL_credentials_get_size(unsigned int c_count, const struct GNUNET_CREDENTIAL_Credential *cd)
Calculate how many bytes we will need to serialize the credentials.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_delegation_chain_serialize()

ssize_t GNUNET_CREDENTIAL_delegation_chain_serialize ( unsigned int  d_count,
const struct GNUNET_CREDENTIAL_Delegation dd,
unsigned int  c_count,
const struct GNUNET_CREDENTIAL_Credential cd,
size_t  dest_size,
char *  dest 
)

Serizalize the given delegation chain entries and credential.

Parameters
d_countnumber of delegation chain entries
ddarray of GNUNET_CREDENTIAL_Delegation
c_countnumber of credential entries
cda GNUNET_CREDENTIAL_Credential
dest_sizesize of the destination
destwhere to store the result
Returns
the size of the data, -1 on failure

Definition at line 307 of file credential_serialization.c.

References GNUNET_CREDENTIAL_credentials_serialize(), GNUNET_memcpy, GNUNET_CREDENTIAL_Delegation::issuer_attribute_len, ChainEntry::issuer_attribute_len, GNUNET_CREDENTIAL_Delegation::issuer_key, ChainEntry::issuer_key, GNUNET_CREDENTIAL_Delegation::subject_attribute_len, ChainEntry::subject_attribute_len, GNUNET_CREDENTIAL_Delegation::subject_key, and ChainEntry::subject_key.

Referenced by send_lookup_response().

315 {
316  struct ChainEntry rec;
317  unsigned int i;
318  size_t off;
319 
320  off = 0;
321  for (i = 0; i < d_count; i++)
322  {
323  rec.issuer_attribute_len = htonl ((uint32_t) dd[i].issuer_attribute_len);
324  rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len);
325  rec.issuer_key = dd[i].issuer_key;
326  rec.subject_key = dd[i].subject_key;
327  if (off + sizeof(rec) > dest_size)
328  return -1;
329  GNUNET_memcpy (&dest[off],
330  &rec,
331  sizeof(rec));
332  off += sizeof(rec);
333  if (off + dd[i].issuer_attribute_len > dest_size)
334  return -1;
335  GNUNET_memcpy (&dest[off],
336  dd[i].issuer_attribute,
337  dd[i].issuer_attribute_len);
338  off += dd[i].issuer_attribute_len;
339  if (0 == dd[i].subject_attribute_len)
340  continue;
341  if (off + dd[i].subject_attribute_len > dest_size)
342  return -1;
343  GNUNET_memcpy (&dest[off],
344  dd[i].subject_attribute,
345  dd[i].subject_attribute_len);
346  off += dd[i].subject_attribute_len;
347  }
348  return off + GNUNET_CREDENTIAL_credentials_serialize (c_count,
349  cd,
350  dest_size - off,
351  &dest[off]);
352 }
uint32_t subject_attribute_len
Length of the attribute.
uint32_t issuer_attribute_len
Issuer attributes.
Definition: credential.h:167
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
ssize_t GNUNET_CREDENTIAL_credentials_serialize(unsigned int c_count, const struct GNUNET_CREDENTIAL_Credential *cd, size_t dest_size, char *dest)
Serizalize the given credentials.
uint32_t subject_attribute_len
Subject attributes.
Definition: credential.h:172
uint32_t issuer_attribute_len
Length of the attribute.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the delegation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_delegation_chain_deserialize()

int GNUNET_CREDENTIAL_delegation_chain_deserialize ( size_t  len,
const char *  src,
unsigned int  d_count,
struct GNUNET_CREDENTIAL_Delegation dd,
unsigned int  c_count,
struct GNUNET_CREDENTIAL_Credential cd 
)

Deserialize the given destination.

Parameters
lensize of the serialized delegation chain and cred
srcthe serialized data
d_countthe number of delegation chain entries
ddwhere to put the delegation chain entries
c_countthe number of credential entries
cdwhere to put the credential data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 367 of file credential_serialization.c.

References GNUNET_CREDENTIAL_credentials_deserialize(), GNUNET_memcpy, GNUNET_SYSERR, GNUNET_CREDENTIAL_Delegation::issuer_attribute, GNUNET_CREDENTIAL_Delegation::issuer_attribute_len, ChainEntry::issuer_attribute_len, GNUNET_CREDENTIAL_Delegation::issuer_key, ChainEntry::issuer_key, GNUNET_CREDENTIAL_Delegation::subject_attribute, GNUNET_CREDENTIAL_Delegation::subject_attribute_len, ChainEntry::subject_attribute_len, GNUNET_CREDENTIAL_Delegation::subject_key, and ChainEntry::subject_key.

Referenced by handle_result().

375 {
376  struct ChainEntry rec;
377  unsigned int i;
378  size_t off;
379 
380  off = 0;
381  for (i = 0; i < d_count; i++)
382  {
383  if (off + sizeof(rec) > len)
384  return GNUNET_SYSERR;
385  GNUNET_memcpy (&rec, &src[off], sizeof(rec));
386  dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len);
387  dd[i].issuer_key = rec.issuer_key;
388  dd[i].subject_key = rec.subject_key;
389  off += sizeof(rec);
390  if (off + dd[i].issuer_attribute_len > len)
391  return GNUNET_SYSERR;
392  dd[i].issuer_attribute = &src[off];
393  off += dd[i].issuer_attribute_len;
394  dd[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len);
395  if (off + dd[i].subject_attribute_len > len)
396  return GNUNET_SYSERR;
397  dd[i].subject_attribute = &src[off];
398  off += dd[i].subject_attribute_len;
399  }
401  &src[off],
402  c_count,
403  cd);
404 }
uint32_t subject_attribute_len
Length of the attribute.
const char * subject_attribute
The attribute.
const char * issuer_attribute
The attribute.
int GNUNET_CREDENTIAL_credentials_deserialize(size_t len, const char *src, unsigned int c_count, struct GNUNET_CREDENTIAL_Credential *cd)
Deserialize the given destination.
uint32_t issuer_attribute_len
Issuer attributes.
Definition: credential.h:167
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint32_t subject_attribute_len
Subject attributes.
Definition: credential.h:172
uint32_t issuer_attribute_len
Length of the attribute.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the delegation.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_credential_serialize()

int GNUNET_CREDENTIAL_credential_serialize ( struct GNUNET_CREDENTIAL_Credential cred,
char **  data 
)

Definition at line 406 of file credential_serialization.c.

References CredentialEntry::expiration, GNUNET_CRYPTO_ecdsa_verify(), GNUNET_ERROR_TYPE_WARNING, GNUNET_htonll(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, CredentialEntry::issuer_attribute_len, CredentialEntry::issuer_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, CredentialEntry::purpose, CredentialEntry::signature, size, GNUNET_CRYPTO_EccSignaturePurpose::size, and CredentialEntry::subject_key.

Referenced by credential_string_to_value().

409 {
410  size_t size;
411  struct CredentialEntry *cdata;
412 
413  size = sizeof(struct CredentialEntry) + strlen (cred->issuer_attribute) + 1;
414  *data = GNUNET_malloc (size);
415  cdata = (struct CredentialEntry*) *data;
416  cdata->subject_key = cred->subject_key;
417  cdata->issuer_key = cred->issuer_key;
419  cdata->signature = cred->signature;
420  cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1);
422  cdata->purpose.size = htonl (size - sizeof(struct
424  GNUNET_memcpy (&cdata[1],
425  cred->issuer_attribute,
426  strlen (cred->issuer_attribute));
427 
430  &cdata->purpose,
431  &cdata->signature,
432  &cdata->issuer_key))
433  {
435  "Invalid credential\n");
436  // return NULL;
437  }
438  return size;
439 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:206
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
int GNUNET_CRYPTO_ecdsa_verify(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition: crypto_ecc.c:1046
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
Definition: credential.h:196
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
uint64_t abs_value_us
The actual value.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Signature meta.
Definition: credential.h:186
#define GNUNET_SIGNATURE_PURPOSE_CREDENTIAL
Signature for a GNUnet credential.
an ECC signature using ECDSA
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
Public key of the issuer.
Definition: credential.h:191
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_CRYPTO_EcdsaSignature signature
The signature for this credential by the issuer.
Definition: credential.h:181
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
const char * issuer_attribute
The attribute.
#define GNUNET_log(kind,...)
uint64_t expiration
Expiration time of this credential.
Definition: credential.h:201
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CREDENTIAL_credential_deserialize()

struct GNUNET_CREDENTIAL_Credential* GNUNET_CREDENTIAL_credential_deserialize ( const char *  data,
size_t  data_size 
)

Definition at line 442 of file credential_serialization.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CREDENTIAL_Credential::expiration, CredentialEntry::expiration, GNUNET_CRYPTO_ecdsa_verify(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_ntohll(), GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, GNUNET_CREDENTIAL_Credential::issuer_attribute, CredentialEntry::issuer_attribute_len, GNUNET_CREDENTIAL_Credential::issuer_key, CredentialEntry::issuer_key, CredentialEntry::purpose, GNUNET_CREDENTIAL_Credential::signature, CredentialEntry::signature, GNUNET_CREDENTIAL_Credential::subject_key, and CredentialEntry::subject_key.

Referenced by credential_value_to_string(), and handle_cred_collection_cb().

444 {
445  struct GNUNET_CREDENTIAL_Credential *cred;
446  struct CredentialEntry *cdata;
447  char *issuer_attribute;
448 
449  if (data_size < sizeof(struct CredentialEntry))
450  return NULL;
451  cdata = (struct CredentialEntry*) data;
454  &cdata->purpose,
455  &cdata->signature,
456  &cdata->issuer_key))
457  {
459  "Invalid credential\n");
460  // return NULL;
461  }
462  issuer_attribute = (char*) &cdata[1];
463 
464  cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + ntohl (
465  cdata->issuer_attribute_len));
466 
467  cred->issuer_key = cdata->issuer_key;
468  cred->subject_key = cdata->subject_key;
469  GNUNET_memcpy (&cred[1],
470  issuer_attribute,
471  ntohl (cdata->issuer_attribute_len));
472  cred->signature = cdata->signature;
473  cred->issuer_attribute = (char*) &cred[1];
475  return cred;
476 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:206
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
int GNUNET_CRYPTO_ecdsa_verify(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition: crypto_ecc.c:1046
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
Definition: credential.h:196
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
uint64_t abs_value_us
The actual value.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Signature meta.
Definition: credential.h:186
#define GNUNET_SIGNATURE_PURPOSE_CREDENTIAL
Signature for a GNUnet credential.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
Public key of the issuer.
Definition: credential.h:191
struct GNUNET_CRYPTO_EcdsaSignature signature
The signature for this credential by the issuer.
Definition: credential.h:181
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
const char * issuer_attribute
The attribute.
#define GNUNET_log(kind,...)
uint64_t expiration
Expiration time of this credential.
Definition: credential.h:201
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
#define GNUNET_malloc(size)
Wrapper around malloc.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
Here is the call graph for this function:
Here is the caller graph for this function: