GNUnet  0.10.x
Functions
credential_serialization.h 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 dependency graph for credential_serialization.h:
This graph shows which files directly or indirectly include this file:

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 record. 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 record entries. 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_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...
 
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...
 
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.h.

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 record.

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

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().

46 {
47  unsigned int i;
48  size_t ret;
49 
50  ret = sizeof(struct DelegationRecordData) * (ds_count);
51 
52  for (i = 0; i < ds_count; i++)
53  {
54  GNUNET_assert((ret + dsr[i].subject_attribute_len) >= ret);
55  ret += dsr[i].subject_attribute_len;
56  }
57  return ret;
58 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint32_t subject_attribute_len
Subject attributes.
Definition: credential.h:144
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 record entries.

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

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 70 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().

74 {
75  struct DelegationRecordData rec;
76  unsigned int i;
77  size_t off;
78 
79  off = 0;
80  for (i = 0; i < d_count; i++)
81  {
82  rec.subject_attribute_len = htonl((uint32_t)dsr[i].subject_attribute_len);
83  rec.subject_key = dsr[i].subject_key;
84  if (off + sizeof(rec) > dest_size)
85  return -1;
86  GNUNET_memcpy(&dest[off],
87  &rec,
88  sizeof(rec));
89  off += sizeof(rec);
90  if (0 == dsr[i].subject_attribute_len)
91  continue;
92  if (off + dsr[i].subject_attribute_len > dest_size)
93  return -1;
94  GNUNET_memcpy(&dest[off],
95  dsr[i].subject_attribute,
96  dsr[i].subject_attribute_len);
97  off += dsr[i].subject_attribute_len;
98  }
99  return off;
100 }
#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:144
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 recird
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
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 113 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().

117 {
118  struct DelegationRecordData rec;
119  unsigned int i;
120  size_t off;
121 
122  off = 0;
123  for (i = 0; i < d_count; i++)
124  {
125  if (off + sizeof(rec) > len)
126  return GNUNET_SYSERR;
127  GNUNET_memcpy(&rec, &src[off], sizeof(rec));
128  dsr[i].subject_key = rec.subject_key;
129  off += sizeof(rec);
130  dsr[i].subject_attribute_len = ntohl((uint32_t)rec.subject_attribute_len);
131  if (off + dsr[i].subject_attribute_len > len)
132  return GNUNET_SYSERR;
133  dsr[i].subject_attribute = (char*)&src[off];
134  off += dsr[i].subject_attribute_len;
135  }
136  return GNUNET_OK;
137 }
#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:144
#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_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 264 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().

268 {
269  unsigned int i;
270  size_t ret;
271 
272  ret = sizeof(struct ChainEntry) * (d_count);
273 
274  for (i = 0; i < d_count; i++)
275  {
276  GNUNET_assert((ret +
277  dd[i].issuer_attribute_len +
278  dd[i].subject_attribute_len) >= ret);
279  ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len;
280  }
281  return ret + GNUNET_CREDENTIAL_credentials_get_size(c_count, cd);
282 }
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:162
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint32_t subject_attribute_len
Subject attributes.
Definition: credential.h:167
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 296 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().

302 {
303  struct ChainEntry rec;
304  unsigned int i;
305  size_t off;
306 
307  off = 0;
308  for (i = 0; i < d_count; i++)
309  {
310  rec.issuer_attribute_len = htonl((uint32_t)dd[i].issuer_attribute_len);
311  rec.subject_attribute_len = htonl((uint32_t)dd[i].subject_attribute_len);
312  rec.issuer_key = dd[i].issuer_key;
313  rec.subject_key = dd[i].subject_key;
314  if (off + sizeof(rec) > dest_size)
315  return -1;
316  GNUNET_memcpy(&dest[off],
317  &rec,
318  sizeof(rec));
319  off += sizeof(rec);
320  if (off + dd[i].issuer_attribute_len > dest_size)
321  return -1;
322  GNUNET_memcpy(&dest[off],
323  dd[i].issuer_attribute,
324  dd[i].issuer_attribute_len);
325  off += dd[i].issuer_attribute_len;
326  if (0 == dd[i].subject_attribute_len)
327  continue;
328  if (off + dd[i].subject_attribute_len > dest_size)
329  return -1;
330  GNUNET_memcpy(&dest[off],
331  dd[i].subject_attribute,
332  dd[i].subject_attribute_len);
333  off += dd[i].subject_attribute_len;
334  }
335  return off + GNUNET_CREDENTIAL_credentials_serialize(c_count,
336  cd,
337  dest_size - off,
338  &dest[off]);
339 }
uint32_t subject_attribute_len
Length of the attribute.
uint32_t issuer_attribute_len
Issuer attributes.
Definition: credential.h:162
#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:167
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_countnumber of credential entries
cdwhere to put the credential data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error
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 354 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().

360 {
361  struct ChainEntry rec;
362  unsigned int i;
363  size_t off;
364 
365  off = 0;
366  for (i = 0; i < d_count; i++)
367  {
368  if (off + sizeof(rec) > len)
369  return GNUNET_SYSERR;
370  GNUNET_memcpy(&rec, &src[off], sizeof(rec));
371  dd[i].issuer_attribute_len = ntohl((uint32_t)rec.issuer_attribute_len);
372  dd[i].issuer_key = rec.issuer_key;
373  dd[i].subject_key = rec.subject_key;
374  off += sizeof(rec);
375  if (off + dd[i].issuer_attribute_len > len)
376  return GNUNET_SYSERR;
377  dd[i].issuer_attribute = &src[off];
378  off += dd[i].issuer_attribute_len;
379  dd[i].subject_attribute_len = ntohl((uint32_t)rec.subject_attribute_len);
380  if (off + dd[i].subject_attribute_len > len)
381  return GNUNET_SYSERR;
382  dd[i].subject_attribute = &src[off];
383  off += dd[i].subject_attribute_len;
384  }
386  &src[off],
387  c_count,
388  cd);
389 }
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:162
#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:167
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_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 149 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().

151 {
152  unsigned int i;
153  size_t ret;
154 
155  ret = sizeof(struct CredentialEntry) * (c_count);
156 
157  for (i = 0; i < c_count; i++)
158  {
159  GNUNET_assert((ret + cd[i].issuer_attribute_len) >= ret);
160  ret += cd[i].issuer_attribute_len;
161  }
162  return ret;
163 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:200
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 174 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().

178 {
179  struct CredentialEntry c_rec;
180  unsigned int i;
181  size_t off;
182 
183  off = 0;
184  for (i = 0; i < c_count; i++)
185  {
186  c_rec.issuer_attribute_len = htonl((uint32_t)cd[i].issuer_attribute_len);
187  c_rec.issuer_key = cd[i].issuer_key;
188  c_rec.subject_key = cd[i].subject_key;
189  c_rec.signature = cd[i].signature;
190  c_rec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
191  c_rec.purpose.size = htonl((sizeof(struct CredentialEntry) + cd[i].issuer_attribute_len) - sizeof(struct GNUNET_CRYPTO_EcdsaSignature));
192  c_rec.expiration = GNUNET_htonll(cd[i].expiration.abs_value_us);
193  if (off + sizeof(c_rec) > dest_size)
194  return -1;
195  GNUNET_memcpy(&dest[off],
196  &c_rec,
197  sizeof(c_rec));
198  off += sizeof(c_rec);
199  if (off + cd[i].issuer_attribute_len > dest_size)
200  return -1;
201  GNUNET_memcpy(&dest[off],
202  cd[i].issuer_attribute,
203  cd[i].issuer_attribute_len);
204  off += cd[i].issuer_attribute_len;
205  }
206 
207  return off;
208 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:200
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 222 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().

226 {
227  struct CredentialEntry c_rec;
228  unsigned int i;
229  size_t off;
230 
231  off = 0;
232  for (i = 0; i < c_count; i++)
233  {
234  if (off + sizeof(c_rec) > len)
235  return GNUNET_SYSERR;
236  GNUNET_memcpy(&c_rec, &src[off], sizeof(c_rec));
237  cd[i].issuer_attribute_len = ntohl((uint32_t)c_rec.issuer_attribute_len);
238  cd[i].issuer_key = c_rec.issuer_key;
239  cd[i].subject_key = c_rec.subject_key;
240  cd[i].signature = c_rec.signature;
241  cd[i].expiration.abs_value_us = GNUNET_ntohll(c_rec.expiration);
242  off += sizeof(c_rec);
243  if (off + cd[i].issuer_attribute_len > len)
244  return GNUNET_SYSERR;
245  cd[i].issuer_attribute = &src[off];
246  off += cd[i].issuer_attribute_len;
247  }
248  return GNUNET_OK;
249 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:200
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_credential_serialize()

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

Definition at line 391 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().

393 {
394  size_t size;
395  struct CredentialEntry *cdata;
396 
397  size = sizeof(struct CredentialEntry) + strlen(cred->issuer_attribute) + 1;
398  *data = GNUNET_malloc(size);
399  cdata = (struct CredentialEntry*)*data;
400  cdata->subject_key = cred->subject_key;
401  cdata->issuer_key = cred->issuer_key;
403  cdata->signature = cred->signature;
404  cdata->issuer_attribute_len = htonl(strlen(cred->issuer_attribute) + 1);
406  cdata->purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_EcdsaSignature));
407  GNUNET_memcpy(&cdata[1],
408  cred->issuer_attribute,
409  strlen(cred->issuer_attribute));
410 
412  &cdata->purpose,
413  &cdata->signature,
414  &cdata->issuer_key))
415  {
417  "Invalid credential\n");
418  //return NULL;
419  }
420  return size;
421 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:200
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:1048
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:190
#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:180
#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:185
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:66
struct GNUNET_CRYPTO_EcdsaSignature signature
The signature for this credential by the issuer.
Definition: credential.h:175
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:195
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 424 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().

426 {
427  struct GNUNET_CREDENTIAL_Credential *cred;
428  struct CredentialEntry *cdata;
429  char *issuer_attribute;
430 
431  if (data_size < sizeof(struct CredentialEntry))
432  return NULL;
433  cdata = (struct CredentialEntry*)data;
435  &cdata->purpose,
436  &cdata->signature,
437  &cdata->issuer_key))
438  {
440  "Invalid credential\n");
441  //return NULL;
442  }
443  issuer_attribute = (char*)&cdata[1];
444 
445  cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) + ntohl(cdata->issuer_attribute_len));
446 
447  cred->issuer_key = cdata->issuer_key;
448  cred->subject_key = cdata->subject_key;
449  GNUNET_memcpy(&cred[1],
450  issuer_attribute,
451  ntohl(cdata->issuer_attribute_len));
452  cred->signature = cdata->signature;
453  cred->issuer_attribute = (char*)&cred[1];
455  return cred;
456 }
uint32_t issuer_attribute_len
Issuer attribute length.
Definition: credential.h:200
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:1048
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
Definition: credential.h:190
#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:180
#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:185
struct GNUNET_CRYPTO_EcdsaSignature signature
The signature for this credential by the issuer.
Definition: credential.h:175
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:195
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: