diff options
Diffstat (limited to 'src/credential/credential_serialization.c')
-rw-r--r-- | src/credential/credential_serialization.c | 91 |
1 files changed, 10 insertions, 81 deletions
diff --git a/src/credential/credential_serialization.c b/src/credential/credential_serialization.c index 65a85e37e..564d9957b 100644 --- a/src/credential/credential_serialization.c +++ b/src/credential/credential_serialization.c | |||
@@ -221,11 +221,10 @@ GNUNET_CREDENTIAL_delegates_serialize ( | |||
221 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 221 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
222 | */ | 222 | */ |
223 | int | 223 | int |
224 | GNUNET_CREDENTIAL_delegates_deserialize ( | 224 | GNUNET_CREDENTIAL_delegates_deserialize (size_t len, |
225 | size_t len, | 225 | const char *src, |
226 | const char *src, | 226 | unsigned int c_count, |
227 | unsigned int c_count, | 227 | struct GNUNET_CREDENTIAL_Delegate *cd) |
228 | struct GNUNET_CREDENTIAL_Delegate *cd) | ||
229 | { | 228 | { |
230 | struct DelegateEntry c_rec; | 229 | struct DelegateEntry c_rec; |
231 | unsigned int i; | 230 | unsigned int i; |
@@ -335,9 +334,9 @@ GNUNET_CREDENTIAL_delegation_chain_serialize ( | |||
335 | off += dd[i].subject_attribute_len; | 334 | off += dd[i].subject_attribute_len; |
336 | } | 335 | } |
337 | return off + GNUNET_CREDENTIAL_delegates_serialize (c_count, | 336 | return off + GNUNET_CREDENTIAL_delegates_serialize (c_count, |
338 | cd, | 337 | cd, |
339 | dest_size - off, | 338 | dest_size - off, |
340 | &dest[off]); | 339 | &dest[off]); |
341 | } | 340 | } |
342 | 341 | ||
343 | 342 | ||
@@ -386,79 +385,9 @@ GNUNET_CREDENTIAL_delegation_chain_deserialize ( | |||
386 | off += dd[i].subject_attribute_len; | 385 | off += dd[i].subject_attribute_len; |
387 | } | 386 | } |
388 | return GNUNET_CREDENTIAL_delegates_deserialize (len - off, | 387 | return GNUNET_CREDENTIAL_delegates_deserialize (len - off, |
389 | &src[off], | 388 | &src[off], |
390 | c_count, | 389 | c_count, |
391 | cd); | 390 | cd); |
392 | } | ||
393 | |||
394 | int | ||
395 | GNUNET_CREDENTIAL_credential_serialize ( | ||
396 | struct GNUNET_CREDENTIAL_Credential *cred, | ||
397 | char **data) | ||
398 | { | ||
399 | size_t size; | ||
400 | struct CredentialEntry *cdata; | ||
401 | |||
402 | size = sizeof (struct CredentialEntry) + strlen (cred->issuer_attribute) + 1; | ||
403 | *data = GNUNET_malloc (size); | ||
404 | cdata = (struct CredentialEntry *) *data; | ||
405 | cdata->subject_key = cred->subject_key; | ||
406 | cdata->issuer_key = cred->issuer_key; | ||
407 | cdata->expiration = GNUNET_htonll (cred->expiration.abs_value_us); | ||
408 | cdata->signature = cred->signature; | ||
409 | cdata->issuer_attribute_len = htonl (strlen (cred->issuer_attribute) + 1); | ||
410 | cdata->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL); | ||
411 | cdata->purpose.size = | ||
412 | htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | ||
413 | GNUNET_memcpy (&cdata[1], | ||
414 | cred->issuer_attribute, | ||
415 | strlen (cred->issuer_attribute)); | ||
416 | |||
417 | if (GNUNET_OK != | ||
418 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, | ||
419 | &cdata->purpose, | ||
420 | &cdata->signature, | ||
421 | &cdata->issuer_key)) | ||
422 | { | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n"); | ||
424 | //return NULL; | ||
425 | } | ||
426 | return size; | ||
427 | } | ||
428 | |||
429 | struct GNUNET_CREDENTIAL_Credential * | ||
430 | GNUNET_CREDENTIAL_credential_deserialize (const char *data, size_t data_size) | ||
431 | { | ||
432 | struct GNUNET_CREDENTIAL_Credential *cred; | ||
433 | struct CredentialEntry *cdata; | ||
434 | char *issuer_attribute; | ||
435 | |||
436 | if (data_size < sizeof (struct CredentialEntry)) | ||
437 | return NULL; | ||
438 | cdata = (struct CredentialEntry *) data; | ||
439 | if (GNUNET_OK != | ||
440 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, | ||
441 | &cdata->purpose, | ||
442 | &cdata->signature, | ||
443 | &cdata->issuer_key)) | ||
444 | { | ||
445 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential\n"); | ||
446 | //return NULL; | ||
447 | } | ||
448 | issuer_attribute = (char *) &cdata[1]; | ||
449 | |||
450 | cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + | ||
451 | ntohl (cdata->issuer_attribute_len)); | ||
452 | |||
453 | cred->issuer_key = cdata->issuer_key; | ||
454 | cred->subject_key = cdata->subject_key; | ||
455 | GNUNET_memcpy (&cred[1], | ||
456 | issuer_attribute, | ||
457 | ntohl (cdata->issuer_attribute_len)); | ||
458 | cred->signature = cdata->signature; | ||
459 | cred->issuer_attribute = (char *) &cred[1]; | ||
460 | cred->expiration.abs_value_us = GNUNET_ntohll (cdata->expiration); | ||
461 | return cred; | ||
462 | } | 391 | } |
463 | 392 | ||
464 | int | 393 | int |