aboutsummaryrefslogtreecommitdiff
path: root/src/credential/gnunet-service-credential.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/credential/gnunet-service-credential.c')
-rw-r--r--src/credential/gnunet-service-credential.c1044
1 files changed, 525 insertions, 519 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index 4c001af1b..f4a96014f 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -46,7 +46,8 @@ struct VerifyRequestHandle;
46struct DelegationSetQueueEntry; 46struct DelegationSetQueueEntry;
47 47
48 48
49struct DelegationChainEntry { 49struct DelegationChainEntry
50{
50 /** 51 /**
51 * DLL 52 * DLL
52 */ 53 */
@@ -81,7 +82,8 @@ struct DelegationChainEntry {
81/** 82/**
82 * DLL for record 83 * DLL for record
83 */ 84 */
84struct CredentialRecordEntry { 85struct CredentialRecordEntry
86{
85 /** 87 /**
86 * DLL 88 * DLL
87 */ 89 */
@@ -107,7 +109,8 @@ struct CredentialRecordEntry {
107 * DLL used for delegations 109 * DLL used for delegations
108 * Used for OR delegations 110 * Used for OR delegations
109 */ 111 */
110struct DelegationQueueEntry { 112struct DelegationQueueEntry
113{
111 /** 114 /**
112 * DLL 115 * DLL
113 */ 116 */
@@ -143,7 +146,8 @@ struct DelegationQueueEntry {
143 * DLL for delegation sets 146 * DLL for delegation sets
144 * Used for AND delegation set 147 * Used for AND delegation set
145 */ 148 */
146struct DelegationSetQueueEntry { 149struct DelegationSetQueueEntry
150{
147 /** 151 /**
148 * DLL 152 * DLL
149 */ 153 */
@@ -219,7 +223,8 @@ struct DelegationSetQueueEntry {
219/** 223/**
220 * Handle to a lookup operation from api 224 * Handle to a lookup operation from api
221 */ 225 */
222struct VerifyRequestHandle { 226struct VerifyRequestHandle
227{
223 /** 228 /**
224 * We keep these in a DLL. 229 * We keep these in a DLL.
225 */ 230 */
@@ -344,7 +349,7 @@ static struct GNUNET_GNS_Handle *gns;
344static struct GNUNET_NAMESTORE_Handle *namestore; 349static struct GNUNET_NAMESTORE_Handle *namestore;
345 350
346static void 351static void
347cleanup_delegation_set(struct DelegationSetQueueEntry *ds_entry) 352cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
348{ 353{
349 struct DelegationQueueEntry *dq_entry; 354 struct DelegationQueueEntry *dq_entry;
350 struct DelegationSetQueueEntry *child; 355 struct DelegationSetQueueEntry *child;
@@ -354,98 +359,98 @@ cleanup_delegation_set(struct DelegationSetQueueEntry *ds_entry)
354 359
355 for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry; 360 for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry;
356 dq_entry = ds_entry->queue_entries_head) 361 dq_entry = ds_entry->queue_entries_head)
362 {
363 GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head,
364 ds_entry->queue_entries_tail,
365 dq_entry);
366 for (child = dq_entry->set_entries_head; NULL != child;
367 child = dq_entry->set_entries_head)
357 { 368 {
358 GNUNET_CONTAINER_DLL_remove(ds_entry->queue_entries_head, 369 GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head,
359 ds_entry->queue_entries_tail, 370 dq_entry->set_entries_tail,
360 dq_entry); 371 child);
361 for (child = dq_entry->set_entries_head; NULL != child; 372 cleanup_delegation_set (child);
362 child = dq_entry->set_entries_head)
363 {
364 GNUNET_CONTAINER_DLL_remove(dq_entry->set_entries_head,
365 dq_entry->set_entries_tail,
366 child);
367 cleanup_delegation_set(child);
368 }
369 GNUNET_free(dq_entry);
370 } 373 }
371 GNUNET_free_non_null(ds_entry->issuer_key); 374 GNUNET_free (dq_entry);
372 GNUNET_free_non_null(ds_entry->lookup_attribute); 375 }
373 GNUNET_free_non_null(ds_entry->issuer_attribute); 376 GNUNET_free_non_null (ds_entry->issuer_key);
374 GNUNET_free_non_null(ds_entry->unresolved_attribute_delegation); 377 GNUNET_free_non_null (ds_entry->lookup_attribute);
375 GNUNET_free_non_null(ds_entry->attr_trailer); 378 GNUNET_free_non_null (ds_entry->issuer_attribute);
379 GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation);
380 GNUNET_free_non_null (ds_entry->attr_trailer);
376 if (NULL != ds_entry->lookup_request) 381 if (NULL != ds_entry->lookup_request)
377 { 382 {
378 GNUNET_GNS_lookup_cancel(ds_entry->lookup_request); 383 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request);
379 ds_entry->lookup_request = NULL; 384 ds_entry->lookup_request = NULL;
380 } 385 }
381 if (NULL != ds_entry->delegation_chain_entry) 386 if (NULL != ds_entry->delegation_chain_entry)
382 { 387 {
383 GNUNET_free_non_null(ds_entry->delegation_chain_entry->subject_attribute); 388 GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute);
384 GNUNET_free_non_null(ds_entry->delegation_chain_entry->issuer_attribute); 389 GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute);
385 GNUNET_free(ds_entry->delegation_chain_entry); 390 GNUNET_free (ds_entry->delegation_chain_entry);
386 } 391 }
387 GNUNET_free(ds_entry); 392 GNUNET_free (ds_entry);
388} 393}
389 394
390static void 395static void
391cleanup_handle(struct VerifyRequestHandle *vrh) 396cleanup_handle (struct VerifyRequestHandle *vrh)
392{ 397{
393 struct CredentialRecordEntry *cr_entry; 398 struct CredentialRecordEntry *cr_entry;
394 399
395 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n"); 400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n");
396 if (NULL != vrh->lookup_request) 401 if (NULL != vrh->lookup_request)
397 { 402 {
398 GNUNET_GNS_lookup_cancel(vrh->lookup_request); 403 GNUNET_GNS_lookup_cancel (vrh->lookup_request);
399 vrh->lookup_request = NULL; 404 vrh->lookup_request = NULL;
400 } 405 }
401 cleanup_delegation_set(vrh->root_set); 406 cleanup_delegation_set (vrh->root_set);
402 GNUNET_free_non_null(vrh->issuer_attribute); 407 GNUNET_free_non_null (vrh->issuer_attribute);
403 for (cr_entry = vrh->cred_chain_head; NULL != vrh->cred_chain_head; 408 for (cr_entry = vrh->cred_chain_head; NULL != vrh->cred_chain_head;
404 cr_entry = vrh->cred_chain_head) 409 cr_entry = vrh->cred_chain_head)
405 { 410 {
406 GNUNET_CONTAINER_DLL_remove(vrh->cred_chain_head, 411 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head,
407 vrh->cred_chain_tail, 412 vrh->cred_chain_tail,
408 cr_entry); 413 cr_entry);
409 GNUNET_free_non_null(cr_entry->credential); 414 GNUNET_free_non_null (cr_entry->credential);
410 GNUNET_free(cr_entry); 415 GNUNET_free (cr_entry);
411 } 416 }
412 GNUNET_free(vrh); 417 GNUNET_free (vrh);
413} 418}
414 419
415static void 420static void
416shutdown_task(void *cls) 421shutdown_task (void *cls)
417{ 422{
418 struct VerifyRequestHandle *vrh; 423 struct VerifyRequestHandle *vrh;
419 424
420 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n"); 425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n");
421 426
422 while (NULL != (vrh = vrh_head)) 427 while (NULL != (vrh = vrh_head))
423 { 428 {
424 // CREDENTIAL_resolver_lookup_cancel (clh->lookup); 429 // CREDENTIAL_resolver_lookup_cancel (clh->lookup);
425 GNUNET_CONTAINER_DLL_remove(vrh_head, vrh_tail, vrh); 430 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
426 cleanup_handle(vrh); 431 cleanup_handle (vrh);
427 } 432 }
428 433
429 if (NULL != gns) 434 if (NULL != gns)
430 { 435 {
431 GNUNET_GNS_disconnect(gns); 436 GNUNET_GNS_disconnect (gns);
432 gns = NULL; 437 gns = NULL;
433 } 438 }
434 if (NULL != namestore) 439 if (NULL != namestore)
435 { 440 {
436 GNUNET_NAMESTORE_disconnect(namestore); 441 GNUNET_NAMESTORE_disconnect (namestore);
437 namestore = NULL; 442 namestore = NULL;
438 } 443 }
439 if (NULL != statistics) 444 if (NULL != statistics)
440 { 445 {
441 GNUNET_STATISTICS_destroy(statistics, GNUNET_NO); 446 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
442 statistics = NULL; 447 statistics = NULL;
443 } 448 }
444} 449}
445 450
446 451
447static void 452static void
448send_lookup_response(struct VerifyRequestHandle *vrh) 453send_lookup_response (struct VerifyRequestHandle *vrh)
449{ 454{
450 struct GNUNET_MQ_Envelope *env; 455 struct GNUNET_MQ_Envelope *env;
451 struct DelegationChainResultMessage *rmsg; 456 struct DelegationChainResultMessage *rmsg;
@@ -456,43 +461,43 @@ send_lookup_response(struct VerifyRequestHandle *vrh)
456 struct CredentialRecordEntry *tmp; 461 struct CredentialRecordEntry *tmp;
457 size_t size; 462 size_t size;
458 463
459 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending response\n"); 464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n");
460 dce = vrh->delegation_chain_head; 465 dce = vrh->delegation_chain_head;
461 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++) 466 for (uint32_t i = 0; i < vrh->delegation_chain_size; i++)
467 {
468 dd[i].issuer_key = dce->issuer_key;
469 dd[i].subject_key = dce->subject_key;
470 dd[i].issuer_attribute = dce->issuer_attribute;
471 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1;
472 dd[i].subject_attribute_len = 0;
473 dd[i].subject_attribute = NULL;
474 if (NULL != dce->subject_attribute)
462 { 475 {
463 dd[i].issuer_key = dce->issuer_key; 476 dd[i].subject_attribute = dce->subject_attribute;
464 dd[i].subject_key = dce->subject_key; 477 dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1;
465 dd[i].issuer_attribute = dce->issuer_attribute;
466 dd[i].issuer_attribute_len = strlen(dce->issuer_attribute) + 1;
467 dd[i].subject_attribute_len = 0;
468 dd[i].subject_attribute = NULL;
469 if (NULL != dce->subject_attribute)
470 {
471 dd[i].subject_attribute = dce->subject_attribute;
472 dd[i].subject_attribute_len = strlen(dce->subject_attribute) + 1;
473 }
474 dce = dce->next;
475 } 478 }
479 dce = dce->next;
480 }
476 481
477 /** 482 /**
478 * Remove all credentials not needed 483 * Remove all credentials not needed
479 */ 484 */
480 for (cd = vrh->cred_chain_head; NULL != cd;) 485 for (cd = vrh->cred_chain_head; NULL != cd;)
486 {
487 if (cd->refcount > 0)
481 { 488 {
482 if (cd->refcount > 0)
483 {
484 cd = cd->next;
485 continue;
486 }
487 tmp = cd;
488 cd = cd->next; 489 cd = cd->next;
489 GNUNET_CONTAINER_DLL_remove(vrh->cred_chain_head, 490 continue;
490 vrh->cred_chain_tail,
491 tmp);
492 GNUNET_free(tmp->credential);
493 GNUNET_free(tmp);
494 vrh->cred_chain_size--;
495 } 491 }
492 tmp = cd;
493 cd = cd->next;
494 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head,
495 vrh->cred_chain_tail,
496 tmp);
497 GNUNET_free (tmp->credential);
498 GNUNET_free (tmp);
499 vrh->cred_chain_size--;
500 }
496 501
497 /** 502 /**
498 * Get serialized record data 503 * Get serialized record data
@@ -500,58 +505,58 @@ send_lookup_response(struct VerifyRequestHandle *vrh)
500 */ 505 */
501 cd = vrh->cred_chain_head; 506 cd = vrh->cred_chain_head;
502 for (uint32_t i = 0; i < vrh->cred_chain_size; i++) 507 for (uint32_t i = 0; i < vrh->cred_chain_size; i++)
503 { 508 {
504 cred[i].issuer_key = cd->credential->issuer_key; 509 cred[i].issuer_key = cd->credential->issuer_key;
505 cred[i].subject_key = cd->credential->subject_key; 510 cred[i].subject_key = cd->credential->subject_key;
506 cred[i].issuer_attribute_len 511 cred[i].issuer_attribute_len
507 = strlen(cd->credential->issuer_attribute) + 1; 512 = strlen (cd->credential->issuer_attribute) + 1;
508 cred[i].issuer_attribute = cd->credential->issuer_attribute; 513 cred[i].issuer_attribute = cd->credential->issuer_attribute;
509 cred[i].expiration = cd->credential->expiration; 514 cred[i].expiration = cd->credential->expiration;
510 cred[i].signature = cd->credential->signature; 515 cred[i].signature = cd->credential->signature;
511 cd = cd->next; 516 cd = cd->next;
512 } 517 }
513 size 518 size
514 = GNUNET_CREDENTIAL_delegation_chain_get_size(vrh->delegation_chain_size, 519 = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size,
515 dd, 520 dd,
516 vrh->cred_chain_size, 521 vrh->cred_chain_size,
517 cred); 522 cred);
518 env = GNUNET_MQ_msg_extra(rmsg, 523 env = GNUNET_MQ_msg_extra (rmsg,
519 size, 524 size,
520 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); 525 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT);
521 // Assign id so that client can find associated request 526 // Assign id so that client can find associated request
522 rmsg->id = vrh->request_id; 527 rmsg->id = vrh->request_id;
523 rmsg->d_count = htonl(vrh->delegation_chain_size); 528 rmsg->d_count = htonl (vrh->delegation_chain_size);
524 rmsg->c_count = htonl(vrh->cred_chain_size); 529 rmsg->c_count = htonl (vrh->cred_chain_size);
525 530
526 if (0 < vrh->cred_chain_size) 531 if (0 < vrh->cred_chain_size)
527 rmsg->cred_found = htonl(GNUNET_YES); 532 rmsg->cred_found = htonl (GNUNET_YES);
528 else 533 else
529 rmsg->cred_found = htonl(GNUNET_NO); 534 rmsg->cred_found = htonl (GNUNET_NO);
530 535
531 GNUNET_assert( 536 GNUNET_assert (
532 -1 537 -1
533 != GNUNET_CREDENTIAL_delegation_chain_serialize(vrh->delegation_chain_size, 538 != GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size,
534 dd, 539 dd,
535 vrh->cred_chain_size, 540 vrh->cred_chain_size,
536 cred, 541 cred,
537 size, 542 size,
538 (char *)&rmsg[1])); 543 (char *) &rmsg[1]));
539 544
540 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(vrh->client), env); 545 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env);
541 GNUNET_CONTAINER_DLL_remove(vrh_head, vrh_tail, vrh); 546 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
542 cleanup_handle(vrh); 547 cleanup_handle (vrh);
543 548
544 GNUNET_STATISTICS_update(statistics, 549 GNUNET_STATISTICS_update (statistics,
545 "Completed verifications", 550 "Completed verifications",
546 1, 551 1,
547 GNUNET_NO); 552 GNUNET_NO);
548} 553}
549 554
550 555
551static void 556static void
552backward_resolution(void *cls, 557backward_resolution (void *cls,
553 uint32_t rd_count, 558 uint32_t rd_count,
554 const struct GNUNET_GNSRECORD_Data *rd) 559 const struct GNUNET_GNSRECORD_Data *rd)
555{ 560{
556 struct VerifyRequestHandle *vrh; 561 struct VerifyRequestHandle *vrh;
557 const struct GNUNET_CREDENTIAL_DelegationRecord *sets; 562 const struct GNUNET_CREDENTIAL_DelegationRecord *sets;
@@ -568,194 +573,194 @@ backward_resolution(void *cls,
568 current_set->lookup_request = NULL; 573 current_set->lookup_request = NULL;
569 vrh = current_set->handle; 574 vrh = current_set->handle;
570 vrh->pending_lookups--; 575 vrh->pending_lookups--;
571 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %d attrs\n", rd_count); 576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %d attrs\n", rd_count);
572 577
573 // Each OR 578 // Each OR
574 for (uint32_t i = 0; i < rd_count; i++) 579 for (uint32_t i = 0; i < rd_count; i++)
580 {
581 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
582 continue;
583
584 sets = rd[i].data;
585 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets->set_count)];
586 GNUNET_log (
587 GNUNET_ERROR_TYPE_DEBUG,
588 "Found new attribute delegation with %d sets. Creating new Job...\n",
589 ntohl (sets->set_count));
590
591 if (GNUNET_OK
592 != GNUNET_CREDENTIAL_delegation_set_deserialize (
593 GNUNET_ntohll (sets->data_size),
594 (const char *) &sets[1],
595 ntohl (sets->set_count),
596 set))
575 { 597 {
576 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) 598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n");
577 continue; 599 continue;
578 600 }
579 sets = rd[i].data; 601 dq_entry = GNUNET_new (struct DelegationQueueEntry);
580 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets->set_count)]; 602 dq_entry->required_solutions = ntohl (sets->set_count);
581 GNUNET_log( 603 dq_entry->parent_set = current_set;
582 GNUNET_ERROR_TYPE_DEBUG, 604 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head,
583 "Found new attribute delegation with %d sets. Creating new Job...\n", 605 current_set->queue_entries_tail,
584 ntohl(sets->set_count)); 606 dq_entry);
585 607 // Each AND
586 if (GNUNET_OK 608 for (uint32_t j = 0; j < ntohl (sets->set_count); j++)
587 != GNUNET_CREDENTIAL_delegation_set_deserialize( 609 {
588 GNUNET_ntohll(sets->data_size), 610 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
589 (const char *)&sets[1], 611 if (NULL != current_set->attr_trailer)
590 ntohl(sets->set_count), 612 {
591 set)) 613 if (0 == set[j].subject_attribute_len)
614 {
615 GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer);
616 }
617 else
592 { 618 {
593 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n"); 619 GNUNET_asprintf (&expanded_attr,
620 "%s.%s",
621 set[j].subject_attribute,
622 current_set->attr_trailer);
623 }
624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
625 ds_entry->unresolved_attribute_delegation = expanded_attr;
626 }
627 else
628 {
629 if (0 != set[j].subject_attribute_len)
630 {
631 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
632 "Not Expanding %s\n",
633 set[j].subject_attribute);
634 ds_entry->unresolved_attribute_delegation
635 = GNUNET_strdup (set[j].subject_attribute);
636 }
637 }
638
639 // Add a credential chain entry
640 ds_entry->delegation_chain_entry
641 = GNUNET_new (struct DelegationChainEntry);
642 ds_entry->delegation_chain_entry->subject_key = set[j].subject_key;
643 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
644 GNUNET_memcpy (ds_entry->issuer_key,
645 &set[j].subject_key,
646 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
647 if (0 < set[j].subject_attribute_len)
648 ds_entry->delegation_chain_entry->subject_attribute
649 = GNUNET_strdup (set[j].subject_attribute);
650 ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
651 ds_entry->delegation_chain_entry->issuer_attribute
652 = GNUNET_strdup (current_set->lookup_attribute);
653
654 ds_entry->parent_queue_entry = dq_entry; // current_delegation;
655 GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head,
656 dq_entry->set_entries_tail,
657 ds_entry);
658
659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
660 /**
661 * Check if this delegation already matches one of our credentials
662 */
663 for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
664 cred_pointer = cred_pointer->next)
665 {
666 if (0
667 != GNUNET_memcmp (&set->subject_key,
668 &cred_pointer->credential->issuer_key))
594 continue; 669 continue;
670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
671 "Checking if %s matches %s\n",
672 ds_entry->unresolved_attribute_delegation,
673 cred_pointer->credential->issuer_attribute);
674
675 if (0
676 != strcmp (ds_entry->unresolved_attribute_delegation,
677 cred_pointer->credential->issuer_attribute))
678 continue;
679
680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n");
681 cred_pointer->refcount++;
682 // Backtrack
683 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
684 tmp_set = tmp_set->parent_queue_entry->parent_set)
685 {
686 tmp_set->parent_queue_entry->required_solutions--;
687 if (NULL != tmp_set->delegation_chain_entry)
688 {
689 vrh->delegation_chain_size++;
690 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
691 vrh->delegation_chain_tail,
692 tmp_set->delegation_chain_entry);
693 }
694 if (0 < tmp_set->parent_queue_entry->required_solutions)
695 break;
595 } 696 }
596 dq_entry = GNUNET_new(struct DelegationQueueEntry); 697
597 dq_entry->required_solutions = ntohl(sets->set_count); 698 if (NULL == tmp_set->parent_queue_entry)
598 dq_entry->parent_set = current_set;
599 GNUNET_CONTAINER_DLL_insert(current_set->queue_entries_head,
600 current_set->queue_entries_tail,
601 dq_entry);
602 // Each AND
603 for (uint32_t j = 0; j < ntohl(sets->set_count); j++)
604 { 699 {
605 ds_entry = GNUNET_new(struct DelegationSetQueueEntry); 700 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All solutions found\n");
606 if (NULL != current_set->attr_trailer) 701 // Found match
607 { 702 send_lookup_response (vrh);
608 if (0 == set[j].subject_attribute_len) 703 return;
609 {
610 GNUNET_asprintf(&expanded_attr, "%s", current_set->attr_trailer);
611 }
612 else
613 {
614 GNUNET_asprintf(&expanded_attr,
615 "%s.%s",
616 set[j].subject_attribute,
617 current_set->attr_trailer);
618 }
619 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
620 ds_entry->unresolved_attribute_delegation = expanded_attr;
621 }
622 else
623 {
624 if (0 != set[j].subject_attribute_len)
625 {
626 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
627 "Not Expanding %s\n",
628 set[j].subject_attribute);
629 ds_entry->unresolved_attribute_delegation
630 = GNUNET_strdup(set[j].subject_attribute);
631 }
632 }
633
634 // Add a credential chain entry
635 ds_entry->delegation_chain_entry
636 = GNUNET_new(struct DelegationChainEntry);
637 ds_entry->delegation_chain_entry->subject_key = set[j].subject_key;
638 ds_entry->issuer_key = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPublicKey);
639 GNUNET_memcpy(ds_entry->issuer_key,
640 &set[j].subject_key,
641 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
642 if (0 < set[j].subject_attribute_len)
643 ds_entry->delegation_chain_entry->subject_attribute
644 = GNUNET_strdup(set[j].subject_attribute);
645 ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
646 ds_entry->delegation_chain_entry->issuer_attribute
647 = GNUNET_strdup(current_set->lookup_attribute);
648
649 ds_entry->parent_queue_entry = dq_entry; // current_delegation;
650 GNUNET_CONTAINER_DLL_insert(dq_entry->set_entries_head,
651 dq_entry->set_entries_tail,
652 ds_entry);
653
654 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
655 /**
656 * Check if this delegation already matches one of our credentials
657 */
658 for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
659 cred_pointer = cred_pointer->next)
660 {
661 if (0
662 != GNUNET_memcmp(&set->subject_key,
663 &cred_pointer->credential->issuer_key))
664 continue;
665 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
666 "Checking if %s matches %s\n",
667 ds_entry->unresolved_attribute_delegation,
668 cred_pointer->credential->issuer_attribute);
669
670 if (0
671 != strcmp(ds_entry->unresolved_attribute_delegation,
672 cred_pointer->credential->issuer_attribute))
673 continue;
674
675 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n");
676 cred_pointer->refcount++;
677 // Backtrack
678 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
679 tmp_set = tmp_set->parent_queue_entry->parent_set)
680 {
681 tmp_set->parent_queue_entry->required_solutions--;
682 if (NULL != tmp_set->delegation_chain_entry)
683 {
684 vrh->delegation_chain_size++;
685 GNUNET_CONTAINER_DLL_insert(vrh->delegation_chain_head,
686 vrh->delegation_chain_tail,
687 tmp_set->delegation_chain_entry);
688 }
689 if (0 < tmp_set->parent_queue_entry->required_solutions)
690 break;
691 }
692
693 if (NULL == tmp_set->parent_queue_entry)
694 {
695 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "All solutions found\n");
696 // Found match
697 send_lookup_response(vrh);
698 return;
699 }
700 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not all solutions found yet.\n");
701 continue;
702 }
703 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
704 "Building new lookup request from %s\n",
705 ds_entry->unresolved_attribute_delegation);
706 // Continue with backward resolution
707 char
708 issuer_attribute_name[strlen(ds_entry->unresolved_attribute_delegation)
709 + 1];
710 strcpy(issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
711 char *next_attr = strtok(issuer_attribute_name, ".");
712 if (NULL == next_attr)
713 {
714 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
715 "Failed to parse next attribute\n");
716 continue;
717 }
718 GNUNET_asprintf(&lookup_attribute, "%s", next_attr);
719 GNUNET_asprintf(&ds_entry->lookup_attribute, "%s", next_attr);
720 if (strlen(next_attr)
721 == strlen(ds_entry->unresolved_attribute_delegation))
722 {
723 ds_entry->attr_trailer = NULL;
724 }
725 else
726 {
727 next_attr += strlen(next_attr) + 1;
728 ds_entry->attr_trailer = GNUNET_strdup(next_attr);
729 }
730
731 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
732 "Looking up %s\n",
733 ds_entry->lookup_attribute);
734 if (NULL != ds_entry->attr_trailer)
735 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
736 "%s still to go...\n",
737 ds_entry->attr_trailer);
738
739 vrh->pending_lookups++;
740 ds_entry->handle = vrh;
741 ds_entry->lookup_request
742 = GNUNET_GNS_lookup(gns,
743 lookup_attribute,
744 ds_entry->issuer_key, // issuer_key,
745 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
746 GNUNET_GNS_LO_DEFAULT,
747 &backward_resolution,
748 ds_entry);
749 GNUNET_free(lookup_attribute);
750 } 704 }
705 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not all solutions found yet.\n");
706 continue;
707 }
708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
709 "Building new lookup request from %s\n",
710 ds_entry->unresolved_attribute_delegation);
711 // Continue with backward resolution
712 char
713 issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation)
714 + 1];
715 strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
716 char *next_attr = strtok (issuer_attribute_name, ".");
717 if (NULL == next_attr)
718 {
719 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
720 "Failed to parse next attribute\n");
721 continue;
722 }
723 GNUNET_asprintf (&lookup_attribute, "%s", next_attr);
724 GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr);
725 if (strlen (next_attr)
726 == strlen (ds_entry->unresolved_attribute_delegation))
727 {
728 ds_entry->attr_trailer = NULL;
729 }
730 else
731 {
732 next_attr += strlen (next_attr) + 1;
733 ds_entry->attr_trailer = GNUNET_strdup (next_attr);
734 }
735
736 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
737 "Looking up %s\n",
738 ds_entry->lookup_attribute);
739 if (NULL != ds_entry->attr_trailer)
740 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
741 "%s still to go...\n",
742 ds_entry->attr_trailer);
743
744 vrh->pending_lookups++;
745 ds_entry->handle = vrh;
746 ds_entry->lookup_request
747 = GNUNET_GNS_lookup (gns,
748 lookup_attribute,
749 ds_entry->issuer_key, // issuer_key,
750 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
751 GNUNET_GNS_LO_DEFAULT,
752 &backward_resolution,
753 ds_entry);
754 GNUNET_free (lookup_attribute);
751 } 755 }
756 }
752 757
753 if (0 == vrh->pending_lookups) 758 if (0 == vrh->pending_lookups)
754 { 759 {
755 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n"); 760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
756 send_lookup_response(vrh); 761 send_lookup_response (vrh);
757 return; 762 return;
758 } 763 }
759} 764}
760 765
761 766
@@ -765,7 +770,7 @@ backward_resolution(void *cls,
765 * @param cls the closure (our client lookup handle) 770 * @param cls the closure (our client lookup handle)
766 */ 771 */
767static void 772static void
768delegation_chain_resolution_start(void *cls) 773delegation_chain_resolution_start (void *cls)
769{ 774{
770 struct VerifyRequestHandle *vrh = cls; 775 struct VerifyRequestHandle *vrh = cls;
771 struct DelegationSetQueueEntry *ds_entry; 776 struct DelegationSetQueueEntry *ds_entry;
@@ -774,87 +779,87 @@ delegation_chain_resolution_start(void *cls)
774 vrh->lookup_request = NULL; 779 vrh->lookup_request = NULL;
775 780
776 if (0 == vrh->cred_chain_size) 781 if (0 == vrh->cred_chain_size)
777 { 782 {
778 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No credentials found\n"); 783 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No credentials found\n");
779 send_lookup_response(vrh); 784 send_lookup_response (vrh);
780 return; 785 return;
781 } 786 }
782 787
783 for (cr_entry = vrh->cred_chain_head; cr_entry != NULL; 788 for (cr_entry = vrh->cred_chain_head; cr_entry != NULL;
784 cr_entry = cr_entry->next) 789 cr_entry = cr_entry->next)
785 { 790 {
786 if (0 791 if (0
787 != GNUNET_memcmp(&cr_entry->credential->issuer_key, 792 != GNUNET_memcmp (&cr_entry->credential->issuer_key,
788 &vrh->issuer_key)) 793 &vrh->issuer_key))
789 continue; 794 continue;
790 if (0 795 if (0
791 != strcmp(cr_entry->credential->issuer_attribute, 796 != strcmp (cr_entry->credential->issuer_attribute,
792 vrh->issuer_attribute)) 797 vrh->issuer_attribute))
793 continue; 798 continue;
794 cr_entry->refcount++; 799 cr_entry->refcount++;
795 // Found match prematurely 800 // Found match prematurely
796 send_lookup_response(vrh); 801 send_lookup_response (vrh);
797 return; 802 return;
798 } 803 }
799 804
800 /** 805 /**
801 * Check for attributes from the issuer and follow the chain 806 * Check for attributes from the issuer and follow the chain
802 * till you get the required subject's attributes 807 * till you get the required subject's attributes
803 */ 808 */
804 char issuer_attribute_name[strlen(vrh->issuer_attribute) + 1]; 809 char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1];
805 strcpy(issuer_attribute_name, vrh->issuer_attribute); 810 strcpy (issuer_attribute_name, vrh->issuer_attribute);
806 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
807 "Looking up %s\n", 812 "Looking up %s\n",
808 issuer_attribute_name); 813 issuer_attribute_name);
809 ds_entry = GNUNET_new(struct DelegationSetQueueEntry); 814 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
810 ds_entry->issuer_key = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPublicKey); 815 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
811 GNUNET_memcpy(ds_entry->issuer_key, 816 GNUNET_memcpy (ds_entry->issuer_key,
812 &vrh->issuer_key, 817 &vrh->issuer_key,
813 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 818 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
814 ds_entry->issuer_attribute = GNUNET_strdup(vrh->issuer_attribute); 819 ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute);
815 ds_entry->handle = vrh; 820 ds_entry->handle = vrh;
816 ds_entry->lookup_attribute = GNUNET_strdup(vrh->issuer_attribute); 821 ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute);
817 vrh->root_set = ds_entry; 822 vrh->root_set = ds_entry;
818 vrh->pending_lookups = 1; 823 vrh->pending_lookups = 1;
819 // Start with backward resolution 824 // Start with backward resolution
820 ds_entry->lookup_request = GNUNET_GNS_lookup(gns, 825 ds_entry->lookup_request = GNUNET_GNS_lookup (gns,
821 issuer_attribute_name, 826 issuer_attribute_name,
822 &vrh->issuer_key, // issuer_key, 827 &vrh->issuer_key, // issuer_key,
823 GNUNET_GNSRECORD_TYPE_ATTRIBUTE, 828 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
824 GNUNET_GNS_LO_DEFAULT, 829 GNUNET_GNS_LO_DEFAULT,
825 &backward_resolution, 830 &backward_resolution,
826 ds_entry); 831 ds_entry);
827} 832}
828 833
829static int 834static int
830check_verify(void *cls, const struct VerifyMessage *v_msg) 835check_verify (void *cls, const struct VerifyMessage *v_msg)
831{ 836{
832 size_t msg_size; 837 size_t msg_size;
833 const char *attr; 838 const char *attr;
834 839
835 msg_size = ntohs(v_msg->header.size); 840 msg_size = ntohs (v_msg->header.size);
836 if (msg_size < sizeof(struct VerifyMessage)) 841 if (msg_size < sizeof(struct VerifyMessage))
837 { 842 {
838 GNUNET_break(0); 843 GNUNET_break (0);
839 return GNUNET_SYSERR; 844 return GNUNET_SYSERR;
840 } 845 }
841 if (ntohs(v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) 846 if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH)
842 { 847 {
843 GNUNET_break(0); 848 GNUNET_break (0);
844 return GNUNET_SYSERR; 849 return GNUNET_SYSERR;
845 } 850 }
846 attr = (const char *)&v_msg[1]; 851 attr = (const char *) &v_msg[1];
847 852
848 if (strlen(attr) > GNUNET_CREDENTIAL_MAX_LENGTH) 853 if (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)
849 { 854 {
850 GNUNET_break(0); 855 GNUNET_break (0);
851 return GNUNET_SYSERR; 856 return GNUNET_SYSERR;
852 } 857 }
853 return GNUNET_OK; 858 return GNUNET_OK;
854} 859}
855 860
856static void 861static void
857handle_verify(void *cls, const struct VerifyMessage *v_msg) 862handle_verify (void *cls, const struct VerifyMessage *v_msg)
858{ 863{
859 struct VerifyRequestHandle *vrh; 864 struct VerifyRequestHandle *vrh;
860 struct GNUNET_SERVICE_Client *client = cls; 865 struct GNUNET_SERVICE_Client *client = cls;
@@ -867,101 +872,102 @@ handle_verify(void *cls, const struct VerifyMessage *v_msg)
867 char *credential_data; 872 char *credential_data;
868 const char *utf_in; 873 const char *utf_in;
869 874
870 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n"); 875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n");
871 utf_in = (const char *)&v_msg[1]; 876 utf_in = (const char *) &v_msg[1];
872 GNUNET_STRINGS_utf8_tolower(utf_in, attrptr); 877 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
873 GNUNET_memcpy(issuer_attribute, attr, ntohs(v_msg->issuer_attribute_len)); 878 GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len));
874 issuer_attribute[ntohs(v_msg->issuer_attribute_len)] = '\0'; 879 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
875 vrh = GNUNET_new(struct VerifyRequestHandle); 880 vrh = GNUNET_new (struct VerifyRequestHandle);
876 GNUNET_CONTAINER_DLL_insert(vrh_head, vrh_tail, vrh); 881 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
877 vrh->client = client; 882 vrh->client = client;
878 vrh->request_id = v_msg->id; 883 vrh->request_id = v_msg->id;
879 vrh->issuer_key = v_msg->issuer_key; 884 vrh->issuer_key = v_msg->issuer_key;
880 vrh->subject_key = v_msg->subject_key; 885 vrh->subject_key = v_msg->subject_key;
881 vrh->issuer_attribute = GNUNET_strdup(issuer_attribute); 886 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
882 GNUNET_SERVICE_client_continue(vrh->client); 887 GNUNET_SERVICE_client_continue (vrh->client);
883 if (0 == strlen(issuer_attribute)) 888 if (0 == strlen (issuer_attribute))
884 { 889 {
885 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); 890 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
886 send_lookup_response(vrh); 891 send_lookup_response (vrh);
887 return; 892 return;
888 } 893 }
889 /** 894 /**
890 * First, collect credentials 895 * First, collect credentials
891 * TODO: cleanup! 896 * TODO: cleanup!
892 */ 897 */
893 credentials_count = ntohl(v_msg->c_count); 898 credentials_count = ntohl (v_msg->c_count);
894 credential_data_size = ntohs(v_msg->header.size) 899 credential_data_size = ntohs (v_msg->header.size)
895 - sizeof(struct VerifyMessage) 900 - sizeof(struct VerifyMessage)
896 - ntohs(v_msg->issuer_attribute_len) - 1; 901 - ntohs (v_msg->issuer_attribute_len) - 1;
897 struct GNUNET_CREDENTIAL_Credential credentials[credentials_count]; 902 struct GNUNET_CREDENTIAL_Credential credentials[credentials_count];
898 memset(credentials, 903 memset (credentials,
899 0, 904 0,
900 sizeof(struct GNUNET_CREDENTIAL_Credential) * credentials_count); 905 sizeof(struct GNUNET_CREDENTIAL_Credential) * credentials_count);
901 credential_data = (char *)&v_msg[1] + ntohs(v_msg->issuer_attribute_len) + 1; 906 credential_data = (char *) &v_msg[1] + ntohs (v_msg->issuer_attribute_len)
907 + 1;
902 if (GNUNET_OK 908 if (GNUNET_OK
903 != GNUNET_CREDENTIAL_credentials_deserialize(credential_data_size, 909 != GNUNET_CREDENTIAL_credentials_deserialize (credential_data_size,
904 credential_data, 910 credential_data,
905 credentials_count, 911 credentials_count,
906 credentials)) 912 credentials))
907 { 913 {
908 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n"); 914 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n");
909 send_lookup_response(vrh); 915 send_lookup_response (vrh);
910 return; 916 return;
911 } 917 }
912 918
913 for (uint32_t i = 0; i < credentials_count; i++) 919 for (uint32_t i = 0; i < credentials_count; i++)
914 { 920 {
915 cr_entry = GNUNET_new(struct CredentialRecordEntry); 921 cr_entry = GNUNET_new (struct CredentialRecordEntry);
916 cr_entry->credential 922 cr_entry->credential
917 = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) 923 = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential)
918 + credentials[i].issuer_attribute_len + 1); 924 + credentials[i].issuer_attribute_len + 1);
919 GNUNET_memcpy(cr_entry->credential, 925 GNUNET_memcpy (cr_entry->credential,
920 &credentials[i], 926 &credentials[i],
921 sizeof(struct GNUNET_CREDENTIAL_Credential)); 927 sizeof(struct GNUNET_CREDENTIAL_Credential));
922 GNUNET_memcpy(&cr_entry->credential[1], 928 GNUNET_memcpy (&cr_entry->credential[1],
923 credentials[i].issuer_attribute, 929 credentials[i].issuer_attribute,
924 credentials[i].issuer_attribute_len); 930 credentials[i].issuer_attribute_len);
925 cr_entry->credential->issuer_attribute_len 931 cr_entry->credential->issuer_attribute_len
926 = credentials[i].issuer_attribute_len; 932 = credentials[i].issuer_attribute_len;
927 cr_entry->credential->issuer_attribute = (char *)&cr_entry->credential[1]; 933 cr_entry->credential->issuer_attribute = (char *) &cr_entry->credential[1];
928 GNUNET_CONTAINER_DLL_insert_tail(vrh->cred_chain_head, 934 GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head,
929 vrh->cred_chain_tail, 935 vrh->cred_chain_tail,
930 cr_entry); 936 cr_entry);
931 vrh->cred_chain_size++; 937 vrh->cred_chain_size++;
932 } 938 }
933 939
934 delegation_chain_resolution_start(vrh); 940 delegation_chain_resolution_start (vrh);
935} 941}
936 942
937static void 943static void
938handle_cred_collection_error_cb(void *cls) 944handle_cred_collection_error_cb (void *cls)
939{ 945{
940 struct VerifyRequestHandle *vrh = cls; 946 struct VerifyRequestHandle *vrh = cls;
941 947
942 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
943 "Got disconnected from namestore database.\n"); 949 "Got disconnected from namestore database.\n");
944 vrh->cred_collection_iter = NULL; 950 vrh->cred_collection_iter = NULL;
945 send_lookup_response(vrh); 951 send_lookup_response (vrh);
946} 952}
947 953
948static void 954static void
949collect_next(void *cls) 955collect_next (void *cls)
950{ 956{
951 struct VerifyRequestHandle *vrh = cls; 957 struct VerifyRequestHandle *vrh = cls;
952 958
953 vrh->collect_next_task = NULL; 959 vrh->collect_next_task = NULL;
954 GNUNET_assert(NULL != vrh->cred_collection_iter); 960 GNUNET_assert (NULL != vrh->cred_collection_iter);
955 GNUNET_NAMESTORE_zone_iterator_next(vrh->cred_collection_iter, 1); 961 GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter, 1);
956} 962}
957 963
958 964
959static void 965static void
960handle_cred_collection_cb(void *cls, 966handle_cred_collection_cb (void *cls,
961 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 967 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
962 const char *label, 968 const char *label,
963 unsigned int rd_count, 969 unsigned int rd_count,
964 const struct GNUNET_GNSRECORD_Data *rd) 970 const struct GNUNET_GNSRECORD_Data *rd)
965{ 971{
966 struct VerifyRequestHandle *vrh = cls; 972 struct VerifyRequestHandle *vrh = cls;
967 struct GNUNET_CREDENTIAL_Credential *crd; 973 struct GNUNET_CREDENTIAL_Credential *crd;
@@ -970,39 +976,39 @@ handle_cred_collection_cb(void *cls,
970 976
971 cred_record_count = 0; 977 cred_record_count = 0;
972 for (uint32_t i = 0; i < rd_count; i++) 978 for (uint32_t i = 0; i < rd_count; i++)
979 {
980 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type)
981 continue;
982 cred_record_count++;
983 crd
984 = GNUNET_CREDENTIAL_credential_deserialize (rd[i].data, rd[i].data_size);
985 if (NULL == crd)
973 { 986 {
974 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) 987 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n");
975 continue; 988 continue;
976 cred_record_count++;
977 crd
978 = GNUNET_CREDENTIAL_credential_deserialize(rd[i].data, rd[i].data_size);
979 if (NULL == crd)
980 {
981 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n");
982 continue;
983 }
984 cr_entry = GNUNET_new(struct CredentialRecordEntry);
985 cr_entry->credential = crd;
986 GNUNET_CONTAINER_DLL_insert_tail(vrh->cred_chain_head,
987 vrh->cred_chain_tail,
988 cr_entry);
989 vrh->cred_chain_size++;
990 } 989 }
991 vrh->collect_next_task = GNUNET_SCHEDULER_add_now(&collect_next, vrh); 990 cr_entry = GNUNET_new (struct CredentialRecordEntry);
991 cr_entry->credential = crd;
992 GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head,
993 vrh->cred_chain_tail,
994 cr_entry);
995 vrh->cred_chain_size++;
996 }
997 vrh->collect_next_task = GNUNET_SCHEDULER_add_now (&collect_next, vrh);
992} 998}
993 999
994static void 1000static void
995handle_cred_collection_finished_cb(void *cls) 1001handle_cred_collection_finished_cb (void *cls)
996{ 1002{
997 struct VerifyRequestHandle *vrh = cls; 1003 struct VerifyRequestHandle *vrh = cls;
998 1004
999 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Done collecting credentials.\n"); 1005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting credentials.\n");
1000 vrh->cred_collection_iter = NULL; 1006 vrh->cred_collection_iter = NULL;
1001 delegation_chain_resolution_start(vrh); 1007 delegation_chain_resolution_start (vrh);
1002} 1008}
1003 1009
1004static void 1010static void
1005handle_collect(void *cls, const struct CollectMessage *c_msg) 1011handle_collect (void *cls, const struct CollectMessage *c_msg)
1006{ 1012{
1007 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 1013 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
1008 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 1014 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
@@ -1011,32 +1017,32 @@ handle_collect(void *cls, const struct CollectMessage *c_msg)
1011 char *attrptr = attr; 1017 char *attrptr = attr;
1012 const char *utf_in; 1018 const char *utf_in;
1013 1019
1014 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n"); 1020 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n");
1015 1021
1016 utf_in = (const char *)&c_msg[1]; 1022 utf_in = (const char *) &c_msg[1];
1017 GNUNET_STRINGS_utf8_tolower(utf_in, attrptr); 1023 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1018 1024
1019 GNUNET_memcpy(issuer_attribute, attr, ntohs(c_msg->issuer_attribute_len)); 1025 GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len));
1020 issuer_attribute[ntohs(c_msg->issuer_attribute_len)] = '\0'; 1026 issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0';
1021 vrh = GNUNET_new(struct VerifyRequestHandle); 1027 vrh = GNUNET_new (struct VerifyRequestHandle);
1022 GNUNET_CONTAINER_DLL_insert(vrh_head, vrh_tail, vrh); 1028 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
1023 vrh->client = client; 1029 vrh->client = client;
1024 vrh->request_id = c_msg->id; 1030 vrh->request_id = c_msg->id;
1025 vrh->issuer_key = c_msg->issuer_key; 1031 vrh->issuer_key = c_msg->issuer_key;
1026 GNUNET_CRYPTO_ecdsa_key_get_public(&c_msg->subject_key, &vrh->subject_key); 1032 GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key, &vrh->subject_key);
1027 vrh->issuer_attribute = GNUNET_strdup(issuer_attribute); 1033 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1028 1034
1029 if (0 == strlen(issuer_attribute)) 1035 if (0 == strlen (issuer_attribute))
1030 { 1036 {
1031 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); 1037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
1032 send_lookup_response(vrh); 1038 send_lookup_response (vrh);
1033 return; 1039 return;
1034 } 1040 }
1035 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Getting credentials for subject\n"); 1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting credentials for subject\n");
1036 /** 1042 /**
1037 * First, get attribute from subject 1043 * First, get attribute from subject
1038 */ 1044 */
1039 vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start( 1045 vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start (
1040 namestore, 1046 namestore,
1041 &c_msg->subject_key, 1047 &c_msg->subject_key,
1042 &handle_cred_collection_error_cb, 1048 &handle_cred_collection_error_cb,
@@ -1045,52 +1051,52 @@ handle_collect(void *cls, const struct CollectMessage *c_msg)
1045 vrh, 1051 vrh,
1046 &handle_cred_collection_finished_cb, 1052 &handle_cred_collection_finished_cb,
1047 vrh); 1053 vrh);
1048 GNUNET_SERVICE_client_continue(vrh->client); 1054 GNUNET_SERVICE_client_continue (vrh->client);
1049} 1055}
1050 1056
1051 1057
1052static int 1058static int
1053check_collect(void *cls, const struct CollectMessage *c_msg) 1059check_collect (void *cls, const struct CollectMessage *c_msg)
1054{ 1060{
1055 size_t msg_size; 1061 size_t msg_size;
1056 const char *attr; 1062 const char *attr;
1057 1063
1058 msg_size = ntohs(c_msg->header.size); 1064 msg_size = ntohs (c_msg->header.size);
1059 if (msg_size < sizeof(struct CollectMessage)) 1065 if (msg_size < sizeof(struct CollectMessage))
1060 { 1066 {
1061 GNUNET_break(0); 1067 GNUNET_break (0);
1062 return GNUNET_SYSERR; 1068 return GNUNET_SYSERR;
1063 } 1069 }
1064 if (ntohs(c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) 1070 if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH)
1065 { 1071 {
1066 GNUNET_break(0); 1072 GNUNET_break (0);
1067 return GNUNET_SYSERR; 1073 return GNUNET_SYSERR;
1068 } 1074 }
1069 attr = (const char *)&c_msg[1]; 1075 attr = (const char *) &c_msg[1];
1070 1076
1071 if (('\0' != attr[msg_size - sizeof(struct CollectMessage) - 1]) 1077 if (('\0' != attr[msg_size - sizeof(struct CollectMessage) - 1])
1072 || (strlen(attr) > GNUNET_CREDENTIAL_MAX_LENGTH)) 1078 || (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH))
1073 { 1079 {
1074 GNUNET_break(0); 1080 GNUNET_break (0);
1075 return GNUNET_SYSERR; 1081 return GNUNET_SYSERR;
1076 } 1082 }
1077 return GNUNET_OK; 1083 return GNUNET_OK;
1078} 1084}
1079 1085
1080static void 1086static void
1081client_disconnect_cb(void *cls, 1087client_disconnect_cb (void *cls,
1082 struct GNUNET_SERVICE_Client *client, 1088 struct GNUNET_SERVICE_Client *client,
1083 void *app_ctx) 1089 void *app_ctx)
1084{ 1090{
1085 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); 1091 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
1086} 1092}
1087 1093
1088static void * 1094static void *
1089client_connect_cb(void *cls, 1095client_connect_cb (void *cls,
1090 struct GNUNET_SERVICE_Client *client, 1096 struct GNUNET_SERVICE_Client *client,
1091 struct GNUNET_MQ_Handle *mq) 1097 struct GNUNET_MQ_Handle *mq)
1092{ 1098{
1093 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); 1099 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
1094 return client; 1100 return client;
1095} 1101}
1096 1102
@@ -1102,44 +1108,44 @@ client_connect_cb(void *cls,
1102 * @param handle service handle 1108 * @param handle service handle
1103 */ 1109 */
1104static void 1110static void
1105run(void *cls, 1111run (void *cls,
1106 const struct GNUNET_CONFIGURATION_Handle *c, 1112 const struct GNUNET_CONFIGURATION_Handle *c,
1107 struct GNUNET_SERVICE_Handle *handle) 1113 struct GNUNET_SERVICE_Handle *handle)
1108{ 1114{
1109 gns = GNUNET_GNS_connect(c); 1115 gns = GNUNET_GNS_connect (c);
1110 if (NULL == gns) 1116 if (NULL == gns)
1111 { 1117 {
1112 fprintf(stderr, _("Failed to connect to GNS\n")); 1118 fprintf (stderr, _ ("Failed to connect to GNS\n"));
1113 } 1119 }
1114 namestore = GNUNET_NAMESTORE_connect(c); 1120 namestore = GNUNET_NAMESTORE_connect (c);
1115 if (NULL == namestore) 1121 if (NULL == namestore)
1116 { 1122 {
1117 fprintf(stderr, _("Failed to connect to namestore\n")); 1123 fprintf (stderr, _ ("Failed to connect to namestore\n"));
1118 } 1124 }
1119 1125
1120 statistics = GNUNET_STATISTICS_create("credential", c); 1126 statistics = GNUNET_STATISTICS_create ("credential", c);
1121 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 1127 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1122} 1128}
1123 1129
1124 1130
1125/** 1131/**
1126 * Define "main" method using service macro 1132 * Define "main" method using service macro
1127 */ 1133 */
1128GNUNET_SERVICE_MAIN( 1134GNUNET_SERVICE_MAIN (
1129 "credential", 1135 "credential",
1130 GNUNET_SERVICE_OPTION_NONE, 1136 GNUNET_SERVICE_OPTION_NONE,
1131 &run, 1137 &run,
1132 &client_connect_cb, 1138 &client_connect_cb,
1133 &client_disconnect_cb, 1139 &client_disconnect_cb,
1134 NULL, 1140 NULL,
1135 GNUNET_MQ_hd_var_size(verify, 1141 GNUNET_MQ_hd_var_size (verify,
1136 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY, 1142 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY,
1137 struct VerifyMessage, 1143 struct VerifyMessage,
1138 NULL), 1144 NULL),
1139 GNUNET_MQ_hd_var_size(collect, 1145 GNUNET_MQ_hd_var_size (collect,
1140 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT, 1146 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT,
1141 struct CollectMessage, 1147 struct CollectMessage,
1142 NULL), 1148 NULL),
1143 GNUNET_MQ_handler_end()); 1149 GNUNET_MQ_handler_end ());
1144 1150
1145/* end of gnunet-service-credential.c */ 1151/* end of gnunet-service-credential.c */