aboutsummaryrefslogtreecommitdiff
path: root/src/credential/gnunet-service-credential.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2016-12-18 16:52:59 +0100
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2016-12-18 16:52:59 +0100
commit33e847bf4edc06be68589467d0f6a31c07d911ac (patch)
treed635352dbea2aa448395d52703351ec8c7242fe4 /src/credential/gnunet-service-credential.c
parent9c5ecc381458c941fdb70f1f4a47e76daac4eda5 (diff)
downloadgnunet-33e847bf4edc06be68589467d0f6a31c07d911ac.tar.gz
gnunet-33e847bf4edc06be68589467d0f6a31c07d911ac.zip
-fixes
Diffstat (limited to 'src/credential/gnunet-service-credential.c')
-rw-r--r--src/credential/gnunet-service-credential.c150
1 files changed, 57 insertions, 93 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index 2b3eb8b4c..55907e0d7 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -46,7 +46,7 @@
46 46
47struct VerifyRequestHandle; 47struct VerifyRequestHandle;
48 48
49struct DelegationSetEntry; 49struct DelegationSetQueueEntry;
50 50
51 51
52struct DelegationChainEntry 52struct DelegationChainEntry
@@ -101,12 +101,7 @@ struct CredentialRecordEntry
101 /** 101 /**
102 * Payload 102 * Payload
103 */ 103 */
104 struct GNUNET_CREDENTIAL_CredentialRecordData *data; 104 struct GNUNET_CREDENTIAL_Credential *credential;
105
106 /**
107 * Size
108 */
109 uint64_t data_size;
110}; 105};
111 106
112/** 107/**
@@ -128,17 +123,17 @@ struct DelegationQueueEntry
128 /** 123 /**
129 * Sets under this Queue 124 * Sets under this Queue
130 */ 125 */
131 struct DelegationSetEntry *set_entries_head; 126 struct DelegationSetQueueEntry *set_entries_head;
132 127
133 /** 128 /**
134 * Sets under this Queue 129 * Sets under this Queue
135 */ 130 */
136 struct DelegationSetEntry *set_entries_tail; 131 struct DelegationSetQueueEntry *set_entries_tail;
137 132
138 /** 133 /**
139 * Parent set 134 * Parent set
140 */ 135 */
141 struct DelegationSetEntry *parent_set; 136 struct DelegationSetQueueEntry *parent_set;
142 137
143 /** 138 /**
144 * Required solutions 139 * Required solutions
@@ -150,17 +145,17 @@ struct DelegationQueueEntry
150 * DLL for delegation sets 145 * DLL for delegation sets
151 * Used for AND delegation set 146 * Used for AND delegation set
152 */ 147 */
153struct DelegationSetEntry 148struct DelegationSetQueueEntry
154{ 149{
155 /** 150 /**
156 * DLL 151 * DLL
157 */ 152 */
158 struct DelegationSetEntry *next; 153 struct DelegationSetQueueEntry *next;
159 154
160 /** 155 /**
161 * DLL 156 * DLL
162 */ 157 */
163 struct DelegationSetEntry *prev; 158 struct DelegationSetQueueEntry *prev;
164 159
165 /** 160 /**
166 * GNS handle 161 * GNS handle
@@ -299,7 +294,7 @@ struct VerifyRequestHandle
299 /** 294 /**
300 * Root Delegation Set 295 * Root Delegation Set
301 */ 296 */
302 struct DelegationSetEntry *root_set; 297 struct DelegationSetQueueEntry *root_set;
303 298
304 /** 299 /**
305 * Current Delegation Pointer 300 * Current Delegation Pointer
@@ -307,16 +302,6 @@ struct VerifyRequestHandle
307 struct DelegationQueueEntry *current_delegation; 302 struct DelegationQueueEntry *current_delegation;
308 303
309 /** 304 /**
310 * The found credential
311 */
312 struct GNUNET_CREDENTIAL_CredentialRecordData *credential;
313
314 /**
315 * Length of the credential
316 */
317 uint32_t credential_size;
318
319 /**
320 * request id 305 * request id
321 */ 306 */
322 uint32_t request_id; 307 uint32_t request_id;
@@ -351,10 +336,10 @@ static struct GNUNET_GNS_Handle *gns;
351 336
352 337
353static void 338static void
354cleanup_delegation_set (struct DelegationSetEntry *ds_entry) 339cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
355{ 340{
356 struct DelegationQueueEntry *dq_entry; 341 struct DelegationQueueEntry *dq_entry;
357 struct DelegationSetEntry *child; 342 struct DelegationSetQueueEntry *child;
358 343
359 if (NULL == ds_entry) 344 if (NULL == ds_entry)
360 return; 345 return;
@@ -414,8 +399,6 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
414 GNUNET_GNS_lookup_cancel (vrh->lookup_request); 399 GNUNET_GNS_lookup_cancel (vrh->lookup_request);
415 vrh->lookup_request = NULL; 400 vrh->lookup_request = NULL;
416 } 401 }
417 if (NULL != vrh->credential)
418 GNUNET_free (vrh->credential);
419 cleanup_delegation_set (vrh->root_set); 402 cleanup_delegation_set (vrh->root_set);
420 if (NULL != vrh->issuer_attribute) 403 if (NULL != vrh->issuer_attribute)
421 GNUNET_free (vrh->issuer_attribute); 404 GNUNET_free (vrh->issuer_attribute);
@@ -426,8 +409,8 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
426 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, 409 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head,
427 vrh->cred_chain_tail, 410 vrh->cred_chain_tail,
428 cr_entry); 411 cr_entry);
429 if (NULL != cr_entry->data) 412 if (NULL != cr_entry->credential);
430 GNUNET_free (cr_entry->data); 413 GNUNET_free (cr_entry->credential);
431 GNUNET_free (cr_entry); 414 GNUNET_free (cr_entry);
432 } 415 }
433 GNUNET_free (vrh); 416 GNUNET_free (vrh);
@@ -518,48 +501,45 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
518 struct GNUNET_MQ_Envelope *env; 501 struct GNUNET_MQ_Envelope *env;
519 struct VerifyResultMessage *rmsg; 502 struct VerifyResultMessage *rmsg;
520 struct DelegationChainEntry *dce; 503 struct DelegationChainEntry *dce;
521 size_t size = vrh->credential_size;
522 struct GNUNET_CREDENTIAL_Delegation dd[vrh->delegation_chain_size]; 504 struct GNUNET_CREDENTIAL_Delegation dd[vrh->delegation_chain_size];
523 struct GNUNET_CREDENTIAL_Credential cred[vrh->cred_chain_size]; 505 struct GNUNET_CREDENTIAL_Credential cred[vrh->cred_chain_size];
524 struct GNUNET_CREDENTIAL_CredentialRecordData *crd;
525 struct CredentialRecordEntry *cd; 506 struct CredentialRecordEntry *cd;
507 size_t size;
526 int i; 508 int i;
527 509
528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
529 "Sending response\n"); 511 "Sending response\n");
530 i = 0; 512 dce = vrh->delegation_chain_head;
531 for (dce = vrh->delegation_chain_head; 513 for (i=0;i<vrh->delegation_chain_size;i++)
532 NULL != dce;
533 dce = dce->next)
534 { 514 {
535 dd[i].issuer_key = dce->issuer_key; 515 dd[i].issuer_key = dce->issuer_key;
536 dd[i].subject_key = dce->subject_key; 516 dd[i].subject_key = dce->subject_key;
537 dd[i].issuer_attribute = dce->issuer_attribute; 517 dd[i].issuer_attribute = dce->issuer_attribute;
538 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute)+1; 518 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute)+1;
539 dd[i].subject_attribute_len = 0; 519 dd[i].subject_attribute_len = 0;
520 dd[i].subject_attribute = NULL;
540 if (NULL != dce->subject_attribute) 521 if (NULL != dce->subject_attribute)
541 { 522 {
542 dd[i].subject_attribute = dce->subject_attribute; 523 dd[i].subject_attribute = dce->subject_attribute;
543 dd[i].subject_attribute_len = strlen(dce->subject_attribute)+1; 524 dd[i].subject_attribute_len = strlen(dce->subject_attribute)+1;
544 } 525 }
545 i++; 526 dce = dce->next;
546 } 527 }
547 528
548 /** 529 /**
549 * Get serialized record data 530 * Get serialized record data
550 * Append at the end of rmsg 531 * Append at the end of rmsg
551 */ 532 */
552 i = 0; 533 cd = vrh->cred_chain_head;
553 for (cd = vrh->cred_chain_head; 534 for (i=0;i<vrh->cred_chain_size;i++)
554 NULL != cd;
555 cd = cd->next)
556 { 535 {
557 crd = cd->data; 536 cred[i].issuer_key = cd->credential->issuer_key;
558 cred[i].issuer_key = crd->issuer_key; 537 cred[i].subject_key = cd->credential->subject_key;
559 cred[i].subject_key = crd->subject_key; 538 cred[i].issuer_attribute_len = strlen(cd->credential->issuer_attribute)+1;
560 cred[i].issuer_attribute_len = strlen((char*)&crd[1])+1; 539 cred[i].issuer_attribute = cd->credential->issuer_attribute;
561 cred[i].issuer_attribute = (char*)&crd[1]; 540 cred[i].expiration = cd->credential->expiration;
562 i++; 541 cred[i].signature = cd->credential->signature;
542 cd = cd->next;
563 } 543 }
564 size = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size, 544 size = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size,
565 dd, 545 dd,
@@ -573,18 +553,18 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
573 rmsg->d_count = htonl (vrh->delegation_chain_size); 553 rmsg->d_count = htonl (vrh->delegation_chain_size);
574 rmsg->c_count = htonl (vrh->cred_chain_size); 554 rmsg->c_count = htonl (vrh->cred_chain_size);
575 555
576 if (NULL != vrh->credential) 556 if (0 < vrh->cred_chain_size)
577 rmsg->cred_found = htonl (GNUNET_YES); 557 rmsg->cred_found = htonl (GNUNET_YES);
578 else 558 else
579 rmsg->cred_found = htonl (GNUNET_NO); 559 rmsg->cred_found = htonl (GNUNET_NO);
580 560
581 GNUNET_assert (-1 != 561 GNUNET_assert (-1 !=
582 GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size, 562 GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size,
583 dd, 563 dd,
584 vrh->cred_chain_size, 564 vrh->cred_chain_size,
585 cred, 565 cred,
586 size, 566 size,
587 (char*)&rmsg[1])); 567 (char*)&rmsg[1]));
588 568
589 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client), 569 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client),
590 env); 570 env);
@@ -604,12 +584,11 @@ backward_resolution (void* cls,
604{ 584{
605 585
606 struct VerifyRequestHandle *vrh; 586 struct VerifyRequestHandle *vrh;
607 struct GNUNET_CREDENTIAL_CredentialRecordData *cred; 587 const struct GNUNET_CREDENTIAL_DelegationRecord *sets;
608 const struct GNUNET_CREDENTIAL_DelegationRecordData *sets;
609 struct CredentialRecordEntry *cred_pointer; 588 struct CredentialRecordEntry *cred_pointer;
610 struct DelegationSetEntry *current_set; 589 struct DelegationSetQueueEntry *current_set;
611 struct DelegationSetEntry *ds_entry; 590 struct DelegationSetQueueEntry *ds_entry;
612 struct DelegationSetEntry *tmp_set; 591 struct DelegationSetQueueEntry *tmp_set;
613 struct DelegationQueueEntry *dq_entry; 592 struct DelegationQueueEntry *dq_entry;
614 char *expanded_attr; 593 char *expanded_attr;
615 char *lookup_attribute; 594 char *lookup_attribute;
@@ -631,15 +610,15 @@ backward_resolution (void* cls,
631 continue; 610 continue;
632 611
633 sets = rd[i].data; 612 sets = rd[i].data;
634 struct GNUNET_CREDENTIAL_DelegationSetRecord set[ntohl(sets->set_count)]; 613 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets->set_count)];
635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636 "Found new attribute delegation with %d sets. Creating new Job...\n", 615 "Found new attribute delegation with %d sets. Creating new Job...\n",
637 ntohl (sets->set_count)); 616 ntohl (sets->set_count));
638 617
639 if (GNUNET_OK !=GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll(sets->data_size), 618 if (GNUNET_OK !=GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll(sets->data_size),
640 (const char*)&sets[1], 619 (const char*)&sets[1],
641 ntohl(sets->set_count), 620 ntohl(sets->set_count),
642 set)) 621 set))
643 { 622 {
644 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 623 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
645 "Failed to deserialize!\n"); 624 "Failed to deserialize!\n");
@@ -654,7 +633,7 @@ backward_resolution (void* cls,
654 // Each AND 633 // Each AND
655 for (j=0; j<ntohl(sets->set_count); j++) 634 for (j=0; j<ntohl(sets->set_count); j++)
656 { 635 {
657 ds_entry = GNUNET_new (struct DelegationSetEntry); 636 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
658 if (NULL != current_set->attr_trailer) 637 if (NULL != current_set->attr_trailer)
659 { 638 {
660 if (0 == set[j].subject_attribute_len) 639 if (0 == set[j].subject_attribute_len)
@@ -706,16 +685,17 @@ backward_resolution (void* cls,
706 for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; 685 for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
707 cred_pointer = cred_pointer->next) 686 cred_pointer = cred_pointer->next)
708 { 687 {
709 cred = cred_pointer->data;
710 if(0 != memcmp (&set->subject_key, 688 if(0 != memcmp (&set->subject_key,
711 &cred_pointer->data->issuer_key, 689 &cred_pointer->credential->issuer_key,
712 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) 690 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
713 continue; 691 continue;
714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
715 "Checking if %s matches %s\n", 693 "Checking if %s matches %s\n",
716 ds_entry->unresolved_attribute_delegation, (char*)&cred[1]); 694 ds_entry->unresolved_attribute_delegation,
695 cred_pointer->credential->issuer_attribute);
717 696
718 if (0 != strcmp (ds_entry->unresolved_attribute_delegation, (char*)&cred[1])) 697 if (0 != strcmp (ds_entry->unresolved_attribute_delegation,
698 cred_pointer->credential->issuer_attribute))
719 continue; 699 continue;
720 700
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -742,11 +722,6 @@ backward_resolution (void* cls,
742 { 722 {
743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
744 "All solutions found\n"); 724 "All solutions found\n");
745 vrh->credential = GNUNET_malloc (cred_pointer->data_size);
746 memcpy (vrh->credential,
747 cred,
748 cred_pointer->data_size);
749 vrh->credential_size = cred_pointer->data_size;
750 //Found match 725 //Found match
751 send_lookup_response (vrh); 726 send_lookup_response (vrh);
752 return; 727 return;
@@ -822,8 +797,8 @@ handle_credential_query (void* cls,
822 const struct GNUNET_GNSRECORD_Data *rd) 797 const struct GNUNET_GNSRECORD_Data *rd)
823{ 798{
824 struct VerifyRequestHandle *vrh = cls; 799 struct VerifyRequestHandle *vrh = cls;
825 struct DelegationSetEntry *ds_entry; 800 struct DelegationSetQueueEntry *ds_entry;
826 const struct GNUNET_CREDENTIAL_CredentialRecordData *crd; 801 struct GNUNET_CREDENTIAL_Credential *crd;
827 struct CredentialRecordEntry *cr_entry; 802 struct CredentialRecordEntry *cr_entry;
828 int cred_record_count; 803 int cred_record_count;
829 int i; 804 int i;
@@ -835,22 +810,16 @@ handle_credential_query (void* cls,
835 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) 810 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type)
836 continue; 811 continue;
837 cred_record_count++; 812 cred_record_count++;
838 crd = rd[i].data; 813 crd = GNUNET_CREDENTIAL_credential_deserialize (rd[i].data,
839 if(GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CREDENTIAL, 814 rd[i].data_size);
840 &crd->purpose, 815 if (NULL == crd)
841 &crd->signature,
842 &crd->issuer_key))
843 { 816 {
844 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 817 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
845 "Invalid credential found\n"); 818 "Invalid credential found\n");
846 continue; 819 continue;
847 } 820 }
848 cr_entry = GNUNET_new (struct CredentialRecordEntry); 821 cr_entry = GNUNET_new (struct CredentialRecordEntry);
849 cr_entry->data = GNUNET_malloc (rd[i].data_size); 822 cr_entry->credential = crd;
850 memcpy (cr_entry->data,
851 crd,
852 rd[i].data_size);
853 cr_entry->data_size = rd[i].data_size;
854 GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, 823 GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head,
855 vrh->cred_chain_tail, 824 vrh->cred_chain_tail,
856 cr_entry); 825 cr_entry);
@@ -860,13 +829,8 @@ handle_credential_query (void* cls,
860 &vrh->issuer_key, 829 &vrh->issuer_key,
861 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 830 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
862 continue; 831 continue;
863 if (0 != strcmp ((char*)&crd[1], vrh->issuer_attribute)) 832 if (0 != strcmp (crd->issuer_attribute, vrh->issuer_attribute))
864 continue; 833 continue;
865 vrh->credential = GNUNET_malloc (rd[i].data_size);
866 memcpy (vrh->credential,
867 rd[i].data,
868 rd[i].data_size);
869 vrh->credential_size = rd[i].data_size;
870 //Found match prematurely 834 //Found match prematurely
871 send_lookup_response (vrh); 835 send_lookup_response (vrh);
872 return; 836 return;
@@ -884,7 +848,7 @@ handle_credential_query (void* cls,
884 ".gnu"); 848 ".gnu");
885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
886 "Looking up %s\n", issuer_attribute_name); 850 "Looking up %s\n", issuer_attribute_name);
887 ds_entry = GNUNET_new (struct DelegationSetEntry); 851 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
888 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 852 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
889 memcpy (ds_entry->issuer_key, 853 memcpy (ds_entry->issuer_key,
890 &vrh->issuer_key, 854 &vrh->issuer_key,