diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2016-12-14 07:52:23 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2016-12-14 07:52:23 +0100 |
commit | 80bdda1c79efb648cb56bdfb63da0c2c0db3ff45 (patch) | |
tree | 6b6b99779062dbe1325974acb5c4ea19b78e63e8 /src/credential/gnunet-service-credential.c | |
parent | 12a3d957faa3932db31ffea0497dd083fd381b86 (diff) | |
download | gnunet-80bdda1c79efb648cb56bdfb63da0c2c0db3ff45.tar.gz gnunet-80bdda1c79efb648cb56bdfb63da0c2c0db3ff45.zip |
-add serializer
Diffstat (limited to 'src/credential/gnunet-service-credential.c')
-rw-r--r-- | src/credential/gnunet-service-credential.c | 114 |
1 files changed, 75 insertions, 39 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c index 38d74e2ab..74e1e1cd2 100644 --- a/src/credential/gnunet-service-credential.c +++ b/src/credential/gnunet-service-credential.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "gnunet_credential_service.h" | 27 | #include "gnunet_credential_service.h" |
28 | #include "gnunet_statistics_service.h" | 28 | #include "gnunet_statistics_service.h" |
29 | #include "credential.h" | 29 | #include "credential.h" |
30 | #include "credential_serialization.h" | ||
30 | #include "gnunet_protocols.h" | 31 | #include "gnunet_protocols.h" |
31 | #include "gnunet_signatures.h" | 32 | #include "gnunet_signatures.h" |
32 | 33 | ||
@@ -165,6 +166,11 @@ struct DelegationQueueEntry | |||
165 | * The delegation chain entry | 166 | * The delegation chain entry |
166 | */ | 167 | */ |
167 | struct GNUNET_CREDENTIAL_DelegationChainEntry *delegation_chain_entry; | 168 | struct GNUNET_CREDENTIAL_DelegationChainEntry *delegation_chain_entry; |
169 | |||
170 | /** | ||
171 | * Delegation chain length until now | ||
172 | */ | ||
173 | uint32_t d_count; | ||
168 | }; | 174 | }; |
169 | 175 | ||
170 | 176 | ||
@@ -221,11 +227,6 @@ struct VerifyRequestHandle | |||
221 | struct CredentialRecordEntry *cred_chain_tail; | 227 | struct CredentialRecordEntry *cred_chain_tail; |
222 | 228 | ||
223 | /** | 229 | /** |
224 | * Number of chain entries | ||
225 | */ | ||
226 | uint32_t cred_chain_entries; | ||
227 | |||
228 | /** | ||
229 | * Delegation Queue | 230 | * Delegation Queue |
230 | */ | 231 | */ |
231 | struct DelegationQueueEntry *chain_start; | 232 | struct DelegationQueueEntry *chain_start; |
@@ -251,6 +252,11 @@ struct VerifyRequestHandle | |||
251 | uint32_t credential_size; | 252 | uint32_t credential_size; |
252 | 253 | ||
253 | /** | 254 | /** |
255 | * Length of found delegation chain | ||
256 | */ | ||
257 | uint32_t d_count; | ||
258 | |||
259 | /** | ||
254 | * request id | 260 | * request id |
255 | */ | 261 | */ |
256 | uint32_t request_id; | 262 | uint32_t request_id; |
@@ -439,65 +445,92 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
439 | struct GNUNET_MQ_Envelope *env; | 445 | struct GNUNET_MQ_Envelope *env; |
440 | struct VerifyResultMessage *rmsg; | 446 | struct VerifyResultMessage *rmsg; |
441 | struct DelegationQueueEntry *dq_entry; | 447 | struct DelegationQueueEntry *dq_entry; |
442 | char *write_ptr; | ||
443 | size_t size = vrh->credential_size; | 448 | size_t size = vrh->credential_size; |
449 | struct GNUNET_CREDENTIAL_Delegation dd[vrh->d_count]; | ||
450 | struct GNUNET_CREDENTIAL_Credential cred; | ||
444 | 451 | ||
445 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 452 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
446 | "Sending response\n"); | 453 | "Sending response\n"); |
447 | 454 | dq_entry = vrh->chain_end; | |
448 | for (dq_entry = vrh->chain_end; NULL != dq_entry; dq_entry = dq_entry->parent) | 455 | for (int i=0; i<vrh->d_count; i++) |
449 | { | 456 | { |
450 | if (NULL == dq_entry->delegation_chain_entry) | 457 | dd[i].issuer_key = dq_entry->delegation_chain_entry->issuer_key; |
451 | break; | 458 | dd[i].subject_key = dq_entry->delegation_chain_entry->subject_key; |
452 | size += sizeof (struct GNUNET_CREDENTIAL_DelegationChainEntry); | 459 | dd[i].issuer_attribute = dq_entry->delegation_chain_entry->issuer_attribute; |
460 | dd[i].issuer_attribute_len = strlen (dq_entry->delegation_chain_entry->issuer_attribute); | ||
461 | dd[i].subject_attribute_len = 0; | ||
453 | if (NULL != dq_entry->delegation_chain_entry->subject_attribute) | 462 | if (NULL != dq_entry->delegation_chain_entry->subject_attribute) |
454 | size += strlen (dq_entry->delegation_chain_entry->subject_attribute) + 1; | 463 | { |
455 | size += strlen(dq_entry->delegation_chain_entry->issuer_attribute) + 1; | 464 | dd[i].subject_attribute = dq_entry->delegation_chain_entry->subject_attribute; |
465 | dd[i].subject_attribute_len = strlen(dq_entry->delegation_chain_entry->subject_attribute); | ||
466 | } | ||
467 | dq_entry = dq_entry->parent; | ||
456 | } | 468 | } |
457 | 469 | ||
470 | /** | ||
471 | * Get serialized record data | ||
472 | * Append at the end of rmsg | ||
473 | */ | ||
474 | cred.issuer_key = vrh->credential->issuer_key; | ||
475 | cred.subject_key = vrh->credential->issuer_key; | ||
476 | cred.issuer_attribute_len = strlen((char*)&vrh->credential[1]); | ||
477 | cred.issuer_attribute = (char*)&vrh->credential[1]; | ||
478 | size = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->d_count, | ||
479 | dd, | ||
480 | &cred); | ||
458 | env = GNUNET_MQ_msg_extra (rmsg, | 481 | env = GNUNET_MQ_msg_extra (rmsg, |
459 | size, | 482 | size, |
460 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); | 483 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); |
461 | //Assign id so that client can find associated request | 484 | //Assign id so that client can find associated request |
462 | rmsg->id = vrh->request_id; | 485 | rmsg->id = vrh->request_id; |
463 | rmsg->cd_count = htonl (vrh->cred_chain_entries); | 486 | rmsg->d_count = htonl (vrh->d_count); |
464 | |||
465 | /** | ||
466 | * Get serialized record data | ||
467 | * Append at the end of rmsg | ||
468 | */ | ||
469 | rmsg->cred_found = htonl (GNUNET_NO); | ||
470 | 487 | ||
471 | if (NULL != vrh->credential) | 488 | if (NULL != vrh->credential) |
472 | { | ||
473 | memcpy (&rmsg[1], | ||
474 | vrh->credential, | ||
475 | vrh->credential_size); | ||
476 | rmsg->cred_found = htonl (GNUNET_YES); | 489 | rmsg->cred_found = htonl (GNUNET_YES); |
477 | } | 490 | else |
491 | rmsg->cred_found = htonl (GNUNET_NO); | ||
492 | |||
493 | GNUNET_assert (-1 != GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->d_count, | ||
494 | dd, | ||
495 | &cred, | ||
496 | size, | ||
497 | (char*)&rmsg[1])); | ||
498 | |||
499 | |||
500 | /*for (dq_entry = vrh->chain_end; NULL != dq_entry; dq_entry = dq_entry->parent) | ||
501 | { | ||
502 | if (NULL == dq_entry->delegation_chain_entry) | ||
503 | break; | ||
504 | size += sizeof (struct GNUNET_CREDENTIAL_DelegationChainEntry); | ||
505 | if (NULL != dq_entry->delegation_chain_entry->subject_attribute) | ||
506 | size += strlen (dq_entry->delegation_chain_entry->subject_attribute) + 1; | ||
507 | size += strlen(dq_entry->delegation_chain_entry->issuer_attribute) + 1; | ||
508 | d_count++; | ||
509 | }*/ | ||
510 | |||
478 | //TODO refactor into serializer module | 511 | //TODO refactor into serializer module |
479 | write_ptr = (char*)&rmsg[1] + vrh->credential_size; | 512 | /*write_ptr = (char*)&rmsg[1] + vrh->credential_size; |
480 | for (dq_entry = vrh->chain_end; NULL != dq_entry; dq_entry = dq_entry->parent) | 513 | for (dq_entry = vrh->chain_end; NULL != dq_entry; dq_entry = dq_entry->parent) |
481 | { | 514 | { |
482 | if (NULL == dq_entry->delegation_chain_entry) | 515 | if (NULL == dq_entry->delegation_chain_entry) |
483 | break; | 516 | break; |
484 | memcpy (write_ptr, | 517 | memcpy (write_ptr, |
485 | dq_entry->delegation_chain_entry, | 518 | dq_entry->delegation_chain_entry, |
486 | sizeof (struct GNUNET_CREDENTIAL_DelegationChainEntry)); | 519 | sizeof (struct GNUNET_CREDENTIAL_DelegationChainEntry)); |
487 | write_ptr += sizeof (struct GNUNET_CREDENTIAL_DelegationChainEntry); | 520 | write_ptr += sizeof (struct GNUNET_CREDENTIAL_DelegationChainEntry); |
488 | if (NULL != dq_entry->delegation_chain_entry->subject_attribute) | 521 | if (NULL != dq_entry->delegation_chain_entry->subject_attribute) |
489 | { | 522 | { |
490 | GNUNET_snprintf (write_ptr, | 523 | GNUNET_snprintf (write_ptr, |
491 | strlen (dq_entry->delegation_chain_entry->subject_attribute) + 2, | 524 | strlen (dq_entry->delegation_chain_entry->subject_attribute) + 2, |
492 | "%s;", | 525 | "%s;", |
493 | dq_entry->delegation_chain_entry->subject_attribute); | 526 | dq_entry->delegation_chain_entry->subject_attribute); |
494 | write_ptr += strlen (dq_entry->delegation_chain_entry->subject_attribute) + 1; | 527 | write_ptr += strlen (dq_entry->delegation_chain_entry->subject_attribute) + 1; |
495 | } | 528 | } |
496 | memcpy (write_ptr, | 529 | memcpy (write_ptr, |
497 | dq_entry->delegation_chain_entry->issuer_attribute, | 530 | dq_entry->delegation_chain_entry->issuer_attribute, |
498 | strlen(dq_entry->delegation_chain_entry->issuer_attribute)); | 531 | strlen(dq_entry->delegation_chain_entry->issuer_attribute)); |
499 | write_ptr += strlen(dq_entry->delegation_chain_entry->issuer_attribute) + 1; | 532 | write_ptr += strlen(dq_entry->delegation_chain_entry->issuer_attribute) + 1; |
500 | } | 533 | }*/ |
501 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client), | 534 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client), |
502 | env); | 535 | env); |
503 | GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); | 536 | GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); |
@@ -580,6 +613,7 @@ backward_resolution (void* cls, | |||
580 | dq_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (current_delegation->lookup_attribute); | 613 | dq_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (current_delegation->lookup_attribute); |
581 | 614 | ||
582 | dq_entry->parent = current_delegation; | 615 | dq_entry->parent = current_delegation; |
616 | dq_entry->d_count = current_delegation->d_count + 1; | ||
583 | GNUNET_CONTAINER_DLL_insert (current_delegation->children_head, | 617 | GNUNET_CONTAINER_DLL_insert (current_delegation->children_head, |
584 | current_delegation->children_tail, | 618 | current_delegation->children_tail, |
585 | dq_entry); | 619 | dq_entry); |
@@ -608,6 +642,7 @@ backward_resolution (void* cls, | |||
608 | vrh->credential = GNUNET_malloc (cred_pointer->data_size); | 642 | vrh->credential = GNUNET_malloc (cred_pointer->data_size); |
609 | vrh->credential_size = cred_pointer->data_size; | 643 | vrh->credential_size = cred_pointer->data_size; |
610 | vrh->chain_end = dq_entry; | 644 | vrh->chain_end = dq_entry; |
645 | vrh->d_count = dq_entry->d_count; | ||
611 | //Found match | 646 | //Found match |
612 | send_lookup_response (vrh); | 647 | send_lookup_response (vrh); |
613 | return; | 648 | return; |
@@ -743,6 +778,7 @@ handle_credential_query (void* cls, | |||
743 | dq_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); | 778 | dq_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); |
744 | dq_entry->handle = vrh; | 779 | dq_entry->handle = vrh; |
745 | dq_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute); | 780 | dq_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute); |
781 | dq_entry->d_count = 0; | ||
746 | vrh->chain_start = dq_entry; | 782 | vrh->chain_start = dq_entry; |
747 | vrh->pending_lookups = 1; | 783 | vrh->pending_lookups = 1; |
748 | //Start with backward resolution | 784 | //Start with backward resolution |