diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-15 20:04:06 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-15 20:04:06 +0200 |
commit | 8341c4666b341e2dae0b84f15da02e09dc7fd9e9 (patch) | |
tree | 3e093ec9add413cfc3bd64bc8cc131ffd4fbc67e /src/credential/gnunet-service-credential.c | |
parent | a61f1f4e3e755f3d9f2118201522b8130c2c5dea (diff) | |
download | gnunet-8341c4666b341e2dae0b84f15da02e09dc7fd9e9.tar.gz gnunet-8341c4666b341e2dae0b84f15da02e09dc7fd9e9.zip |
CREDENTIAL: Fix build with new APIs
Diffstat (limited to 'src/credential/gnunet-service-credential.c')
-rw-r--r-- | src/credential/gnunet-service-credential.c | 581 |
1 files changed, 221 insertions, 360 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c index 56c29b8b4..4a3002fa1 100644 --- a/src/credential/gnunet-service-credential.c +++ b/src/credential/gnunet-service-credential.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -23,19 +23,20 @@ | |||
23 | * @author Martin Schanzenbach | 23 | * @author Martin Schanzenbach |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | |||
26 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
27 | #include "gnunet_credential_service.h" | 28 | |
28 | #include "gnunet_statistics_service.h" | ||
29 | #include "credential.h" | 29 | #include "credential.h" |
30 | #include "credential_serialization.h" | 30 | #include "credential_serialization.h" |
31 | #include "gnunet_credential_service.h" | ||
31 | #include "gnunet_protocols.h" | 32 | #include "gnunet_protocols.h" |
32 | #include "gnunet_signatures.h" | 33 | #include "gnunet_signatures.h" |
33 | 34 | #include "gnunet_statistics_service.h" | |
34 | #include <gnunet_dnsparser_lib.h> | 35 | #include <gnunet_dnsparser_lib.h> |
35 | #include <gnunet_identity_service.h> | 36 | #include <gnunet_gns_service.h> |
36 | #include <gnunet_gnsrecord_lib.h> | 37 | #include <gnunet_gnsrecord_lib.h> |
38 | #include <gnunet_identity_service.h> | ||
37 | #include <gnunet_namestore_service.h> | 39 | #include <gnunet_namestore_service.h> |
38 | #include <gnunet_gns_service.h> | ||
39 | 40 | ||
40 | 41 | ||
41 | #define GNUNET_CREDENTIAL_MAX_LENGTH 255 | 42 | #define GNUNET_CREDENTIAL_MAX_LENGTH 255 |
@@ -157,7 +158,7 @@ struct DelegationSetQueueEntry | |||
157 | */ | 158 | */ |
158 | struct DelegationSetQueueEntry *prev; | 159 | struct DelegationSetQueueEntry *prev; |
159 | 160 | ||
160 | /** | 161 | /** |
161 | * GNS handle | 162 | * GNS handle |
162 | */ | 163 | */ |
163 | struct GNUNET_GNS_LookupRequest *lookup_request; | 164 | struct GNUNET_GNS_LookupRequest *lookup_request; |
@@ -216,7 +217,6 @@ struct DelegationSetQueueEntry | |||
216 | * The delegation chain entry | 217 | * The delegation chain entry |
217 | */ | 218 | */ |
218 | struct DelegationChainEntry *delegation_chain_entry; | 219 | struct DelegationChainEntry *delegation_chain_entry; |
219 | |||
220 | }; | 220 | }; |
221 | 221 | ||
222 | 222 | ||
@@ -320,7 +320,6 @@ struct VerifyRequestHandle | |||
320 | * Collect task | 320 | * Collect task |
321 | */ | 321 | */ |
322 | struct GNUNET_SCHEDULER_Task *collect_next_task; | 322 | struct GNUNET_SCHEDULER_Task *collect_next_task; |
323 | |||
324 | }; | 323 | }; |
325 | 324 | ||
326 | 325 | ||
@@ -359,20 +358,14 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry) | |||
359 | if (NULL == ds_entry) | 358 | if (NULL == ds_entry) |
360 | return; | 359 | return; |
361 | 360 | ||
362 | for (dq_entry = ds_entry->queue_entries_head; | 361 | for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry; |
363 | NULL != dq_entry; | 362 | dq_entry = ds_entry->queue_entries_head) { |
364 | dq_entry = ds_entry->queue_entries_head) | ||
365 | { | ||
366 | GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head, | 363 | GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head, |
367 | ds_entry->queue_entries_tail, | 364 | ds_entry->queue_entries_tail, dq_entry); |
368 | dq_entry); | 365 | for (child = dq_entry->set_entries_head; NULL != child; |
369 | for (child = dq_entry->set_entries_head; | 366 | child = dq_entry->set_entries_head) { |
370 | NULL != child; | ||
371 | child = dq_entry->set_entries_head) | ||
372 | { | ||
373 | GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head, | 367 | GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head, |
374 | dq_entry->set_entries_tail, | 368 | dq_entry->set_entries_tail, child); |
375 | child); | ||
376 | cleanup_delegation_set (child); | 369 | cleanup_delegation_set (child); |
377 | } | 370 | } |
378 | GNUNET_free (dq_entry); | 371 | GNUNET_free (dq_entry); |
@@ -382,13 +375,11 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry) | |||
382 | GNUNET_free_non_null (ds_entry->issuer_attribute); | 375 | GNUNET_free_non_null (ds_entry->issuer_attribute); |
383 | GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation); | 376 | GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation); |
384 | GNUNET_free_non_null (ds_entry->attr_trailer); | 377 | GNUNET_free_non_null (ds_entry->attr_trailer); |
385 | if (NULL != ds_entry->lookup_request) | 378 | if (NULL != ds_entry->lookup_request) { |
386 | { | ||
387 | GNUNET_GNS_lookup_cancel (ds_entry->lookup_request); | 379 | GNUNET_GNS_lookup_cancel (ds_entry->lookup_request); |
388 | ds_entry->lookup_request = NULL; | 380 | ds_entry->lookup_request = NULL; |
389 | } | 381 | } |
390 | if (NULL != ds_entry->delegation_chain_entry) | 382 | if (NULL != ds_entry->delegation_chain_entry) { |
391 | { | ||
392 | GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute); | 383 | GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute); |
393 | GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute); | 384 | GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute); |
394 | GNUNET_free (ds_entry->delegation_chain_entry); | 385 | GNUNET_free (ds_entry->delegation_chain_entry); |
@@ -400,21 +391,16 @@ static void | |||
400 | cleanup_handle (struct VerifyRequestHandle *vrh) | 391 | cleanup_handle (struct VerifyRequestHandle *vrh) |
401 | { | 392 | { |
402 | struct CredentialRecordEntry *cr_entry; | 393 | struct CredentialRecordEntry *cr_entry; |
403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n"); |
404 | "Cleaning up...\n"); | 395 | if (NULL != vrh->lookup_request) { |
405 | if (NULL != vrh->lookup_request) | ||
406 | { | ||
407 | GNUNET_GNS_lookup_cancel (vrh->lookup_request); | 396 | GNUNET_GNS_lookup_cancel (vrh->lookup_request); |
408 | vrh->lookup_request = NULL; | 397 | vrh->lookup_request = NULL; |
409 | } | 398 | } |
410 | cleanup_delegation_set (vrh->root_set); | 399 | cleanup_delegation_set (vrh->root_set); |
411 | GNUNET_free_non_null (vrh->issuer_attribute); | 400 | GNUNET_free_non_null (vrh->issuer_attribute); |
412 | for (cr_entry = vrh->cred_chain_head; | 401 | for (cr_entry = vrh->cred_chain_head; NULL != vrh->cred_chain_head; |
413 | NULL != vrh->cred_chain_head; | 402 | cr_entry = vrh->cred_chain_head) { |
414 | cr_entry = vrh->cred_chain_head) | 403 | GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, vrh->cred_chain_tail, |
415 | { | ||
416 | GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, | ||
417 | vrh->cred_chain_tail, | ||
418 | cr_entry); | 404 | cr_entry); |
419 | GNUNET_free_non_null (cr_entry->credential); | 405 | GNUNET_free_non_null (cr_entry->credential); |
420 | GNUNET_free (cr_entry); | 406 | GNUNET_free (cr_entry); |
@@ -427,39 +413,29 @@ shutdown_task (void *cls) | |||
427 | { | 413 | { |
428 | struct VerifyRequestHandle *vrh; | 414 | struct VerifyRequestHandle *vrh; |
429 | 415 | ||
430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n"); |
431 | "Shutting down!\n"); | 417 | |
432 | 418 | while (NULL != (vrh = vrh_head)) { | |
433 | while (NULL != (vrh = vrh_head)) | 419 | // CREDENTIAL_resolver_lookup_cancel (clh->lookup); |
434 | { | 420 | GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); |
435 | //CREDENTIAL_resolver_lookup_cancel (clh->lookup); | ||
436 | GNUNET_CONTAINER_DLL_remove (vrh_head, | ||
437 | vrh_tail, | ||
438 | vrh); | ||
439 | cleanup_handle (vrh); | 421 | cleanup_handle (vrh); |
440 | } | 422 | } |
441 | 423 | ||
442 | if (NULL != gns) | 424 | if (NULL != gns) { |
443 | { | ||
444 | GNUNET_GNS_disconnect (gns); | 425 | GNUNET_GNS_disconnect (gns); |
445 | gns = NULL; | 426 | gns = NULL; |
446 | } | 427 | } |
447 | if (NULL != namestore) | 428 | if (NULL != namestore) { |
448 | { | ||
449 | GNUNET_NAMESTORE_disconnect (namestore); | 429 | GNUNET_NAMESTORE_disconnect (namestore); |
450 | namestore = NULL; | 430 | namestore = NULL; |
451 | } | 431 | } |
452 | if (NULL != statistics) | 432 | if (NULL != statistics) { |
453 | { | 433 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); |
454 | GNUNET_STATISTICS_destroy (statistics, | ||
455 | GNUNET_NO); | ||
456 | statistics = NULL; | 434 | statistics = NULL; |
457 | } | 435 | } |
458 | |||
459 | } | 436 | } |
460 | 437 | ||
461 | 438 | ||
462 | |||
463 | static void | 439 | static void |
464 | send_lookup_response (struct VerifyRequestHandle *vrh) | 440 | send_lookup_response (struct VerifyRequestHandle *vrh) |
465 | { | 441 | { |
@@ -472,21 +448,18 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
472 | struct CredentialRecordEntry *tmp; | 448 | struct CredentialRecordEntry *tmp; |
473 | size_t size; | 449 | size_t size; |
474 | 450 | ||
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n"); |
476 | "Sending response\n"); | ||
477 | dce = vrh->delegation_chain_head; | 452 | dce = vrh->delegation_chain_head; |
478 | for (uint32_t i=0;i<vrh->delegation_chain_size;i++) | 453 | for (uint32_t i = 0; i < vrh->delegation_chain_size; i++) { |
479 | { | ||
480 | dd[i].issuer_key = dce->issuer_key; | 454 | dd[i].issuer_key = dce->issuer_key; |
481 | dd[i].subject_key = dce->subject_key; | 455 | dd[i].subject_key = dce->subject_key; |
482 | dd[i].issuer_attribute = dce->issuer_attribute; | 456 | dd[i].issuer_attribute = dce->issuer_attribute; |
483 | dd[i].issuer_attribute_len = strlen (dce->issuer_attribute)+1; | 457 | dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1; |
484 | dd[i].subject_attribute_len = 0; | 458 | dd[i].subject_attribute_len = 0; |
485 | dd[i].subject_attribute = NULL; | 459 | dd[i].subject_attribute = NULL; |
486 | if (NULL != dce->subject_attribute) | 460 | if (NULL != dce->subject_attribute) { |
487 | { | ||
488 | dd[i].subject_attribute = dce->subject_attribute; | 461 | dd[i].subject_attribute = dce->subject_attribute; |
489 | dd[i].subject_attribute_len = strlen(dce->subject_attribute)+1; | 462 | dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1; |
490 | } | 463 | } |
491 | dce = dce->next; | 464 | dce = dce->next; |
492 | } | 465 | } |
@@ -494,17 +467,14 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
494 | /** | 467 | /** |
495 | * Remove all credentials not needed | 468 | * Remove all credentials not needed |
496 | */ | 469 | */ |
497 | for (cd = vrh->cred_chain_head; NULL != cd;) | 470 | for (cd = vrh->cred_chain_head; NULL != cd;) { |
498 | { | 471 | if (cd->refcount > 0) { |
499 | if (cd->refcount > 0) | ||
500 | { | ||
501 | cd = cd->next; | 472 | cd = cd->next; |
502 | continue; | 473 | continue; |
503 | } | 474 | } |
504 | tmp = cd; | 475 | tmp = cd; |
505 | cd = cd->next; | 476 | cd = cd->next; |
506 | GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, | 477 | GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, vrh->cred_chain_tail, |
507 | vrh->cred_chain_tail, | ||
508 | tmp); | 478 | tmp); |
509 | GNUNET_free (tmp->credential); | 479 | GNUNET_free (tmp->credential); |
510 | GNUNET_free (tmp); | 480 | GNUNET_free (tmp); |
@@ -516,24 +486,21 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
516 | * Append at the end of rmsg | 486 | * Append at the end of rmsg |
517 | */ | 487 | */ |
518 | cd = vrh->cred_chain_head; | 488 | cd = vrh->cred_chain_head; |
519 | for (uint32_t i=0;i<vrh->cred_chain_size;i++) | 489 | for (uint32_t i = 0; i < vrh->cred_chain_size; i++) { |
520 | { | ||
521 | cred[i].issuer_key = cd->credential->issuer_key; | 490 | cred[i].issuer_key = cd->credential->issuer_key; |
522 | cred[i].subject_key = cd->credential->subject_key; | 491 | cred[i].subject_key = cd->credential->subject_key; |
523 | cred[i].issuer_attribute_len = strlen(cd->credential->issuer_attribute)+1; | 492 | cred[i].issuer_attribute_len = |
493 | strlen (cd->credential->issuer_attribute) + 1; | ||
524 | cred[i].issuer_attribute = cd->credential->issuer_attribute; | 494 | cred[i].issuer_attribute = cd->credential->issuer_attribute; |
525 | cred[i].expiration = cd->credential->expiration; | 495 | cred[i].expiration = cd->credential->expiration; |
526 | cred[i].signature = cd->credential->signature; | 496 | cred[i].signature = cd->credential->signature; |
527 | cd = cd->next; | 497 | cd = cd->next; |
528 | } | 498 | } |
529 | size = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size, | 499 | size = GNUNET_CREDENTIAL_delegation_chain_get_size ( |
530 | dd, | 500 | vrh->delegation_chain_size, dd, vrh->cred_chain_size, cred); |
531 | vrh->cred_chain_size, | 501 | env = GNUNET_MQ_msg_extra (rmsg, size, |
532 | cred); | ||
533 | env = GNUNET_MQ_msg_extra (rmsg, | ||
534 | size, | ||
535 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); | 502 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); |
536 | //Assign id so that client can find associated request | 503 | // Assign id so that client can find associated request |
537 | rmsg->id = vrh->request_id; | 504 | rmsg->id = vrh->request_id; |
538 | rmsg->d_count = htonl (vrh->delegation_chain_size); | 505 | rmsg->d_count = htonl (vrh->delegation_chain_size); |
539 | rmsg->c_count = htonl (vrh->cred_chain_size); | 506 | rmsg->c_count = htonl (vrh->cred_chain_size); |
@@ -543,28 +510,21 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
543 | else | 510 | else |
544 | rmsg->cred_found = htonl (GNUNET_NO); | 511 | rmsg->cred_found = htonl (GNUNET_NO); |
545 | 512 | ||
546 | GNUNET_assert (-1 != | 513 | GNUNET_assert (-1 != GNUNET_CREDENTIAL_delegation_chain_serialize ( |
547 | GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size, | 514 | vrh->delegation_chain_size, dd, vrh->cred_chain_size, |
548 | dd, | 515 | cred, size, (char *)&rmsg[1])); |
549 | vrh->cred_chain_size, | ||
550 | cred, | ||
551 | size, | ||
552 | (char*)&rmsg[1])); | ||
553 | 516 | ||
554 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client), | 517 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env); |
555 | env); | ||
556 | GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); | 518 | GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); |
557 | cleanup_handle(vrh); | 519 | cleanup_handle (vrh); |
558 | 520 | ||
559 | GNUNET_STATISTICS_update (statistics, | 521 | GNUNET_STATISTICS_update (statistics, "Completed verifications", 1, |
560 | "Completed verifications", 1, | ||
561 | GNUNET_NO); | 522 | GNUNET_NO); |
562 | } | 523 | } |
563 | 524 | ||
564 | 525 | ||
565 | static void | 526 | static void |
566 | backward_resolution (void* cls, | 527 | backward_resolution (void *cls, uint32_t rd_count, |
567 | uint32_t rd_count, | ||
568 | const struct GNUNET_GNSRECORD_Data *rd) | 528 | const struct GNUNET_GNSRECORD_Data *rd) |
569 | { | 529 | { |
570 | 530 | ||
@@ -583,97 +543,83 @@ backward_resolution (void* cls, | |||
583 | current_set->lookup_request = NULL; | 543 | current_set->lookup_request = NULL; |
584 | vrh = current_set->handle; | 544 | vrh = current_set->handle; |
585 | vrh->pending_lookups--; | 545 | vrh->pending_lookups--; |
586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %d attrs\n", rd_count); |
587 | "Got %d attrs\n", rd_count); | ||
588 | 547 | ||
589 | // Each OR | 548 | // Each OR |
590 | for (uint32_t i=0; i < rd_count; i++) | 549 | for (uint32_t i = 0; i < rd_count; i++) { |
591 | { | ||
592 | if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) | 550 | if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) |
593 | continue; | 551 | continue; |
594 | 552 | ||
595 | sets = rd[i].data; | 553 | sets = rd[i].data; |
596 | struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets->set_count)]; | 554 | struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets->set_count)]; |
597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 555 | GNUNET_log ( |
598 | "Found new attribute delegation with %d sets. Creating new Job...\n", | 556 | GNUNET_ERROR_TYPE_DEBUG, |
599 | ntohl (sets->set_count)); | 557 | "Found new attribute delegation with %d sets. Creating new Job...\n", |
600 | 558 | ntohl (sets->set_count)); | |
601 | if (GNUNET_OK !=GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll(sets->data_size), | 559 | |
602 | (const char*)&sets[1], | 560 | if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize ( |
603 | ntohl(sets->set_count), | 561 | GNUNET_ntohll (sets->data_size), |
604 | set)) | 562 | (const char *)&sets[1], ntohl (sets->set_count), |
605 | { | 563 | set)) { |
606 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 564 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n"); |
607 | "Failed to deserialize!\n"); | ||
608 | continue; | 565 | continue; |
609 | } | 566 | } |
610 | dq_entry = GNUNET_new (struct DelegationQueueEntry); | 567 | dq_entry = GNUNET_new (struct DelegationQueueEntry); |
611 | dq_entry->required_solutions = ntohl(sets->set_count); | 568 | dq_entry->required_solutions = ntohl (sets->set_count); |
612 | dq_entry->parent_set = current_set; | 569 | dq_entry->parent_set = current_set; |
613 | GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head, | 570 | GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head, |
614 | current_set->queue_entries_tail, | 571 | current_set->queue_entries_tail, dq_entry); |
615 | dq_entry); | ||
616 | // Each AND | 572 | // Each AND |
617 | for (uint32_t j=0; j<ntohl(sets->set_count); j++) | 573 | for (uint32_t j = 0; j < ntohl (sets->set_count); j++) { |
618 | { | ||
619 | ds_entry = GNUNET_new (struct DelegationSetQueueEntry); | 574 | ds_entry = GNUNET_new (struct DelegationSetQueueEntry); |
620 | if (NULL != current_set->attr_trailer) | 575 | if (NULL != current_set->attr_trailer) { |
621 | { | 576 | if (0 == set[j].subject_attribute_len) { |
622 | if (0 == set[j].subject_attribute_len) | 577 | GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer); |
623 | { | ||
624 | GNUNET_asprintf (&expanded_attr, | ||
625 | "%s", | ||
626 | current_set->attr_trailer); | ||
627 | 578 | ||
628 | } else { | 579 | } else { |
629 | GNUNET_asprintf (&expanded_attr, | 580 | GNUNET_asprintf (&expanded_attr, "%s.%s", set[j].subject_attribute, |
630 | "%s.%s", | ||
631 | set[j].subject_attribute, | ||
632 | current_set->attr_trailer); | 581 | current_set->attr_trailer); |
633 | } | 582 | } |
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 583 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr); |
635 | "Expanded to %s\n", expanded_attr); | ||
636 | ds_entry->unresolved_attribute_delegation = expanded_attr; | 584 | ds_entry->unresolved_attribute_delegation = expanded_attr; |
637 | } else { | 585 | } else { |
638 | if (0 != set[j].subject_attribute_len) | 586 | if (0 != set[j].subject_attribute_len) { |
639 | { | 587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not Expanding %s\n", |
640 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 588 | set[j].subject_attribute); |
641 | "Not Expanding %s\n", set[j].subject_attribute); | 589 | ds_entry->unresolved_attribute_delegation = |
642 | ds_entry->unresolved_attribute_delegation = GNUNET_strdup (set[j].subject_attribute); | 590 | GNUNET_strdup (set[j].subject_attribute); |
643 | } | 591 | } |
644 | } | 592 | } |
645 | 593 | ||
646 | //Add a credential chain entry | 594 | // Add a credential chain entry |
647 | ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry); | 595 | ds_entry->delegation_chain_entry = |
596 | GNUNET_new (struct DelegationChainEntry); | ||
648 | ds_entry->delegation_chain_entry->subject_key = set[j].subject_key; | 597 | ds_entry->delegation_chain_entry->subject_key = set[j].subject_key; |
649 | ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | 598 | ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); |
650 | GNUNET_memcpy (ds_entry->issuer_key, | 599 | GNUNET_memcpy (ds_entry->issuer_key, &set[j].subject_key, |
651 | &set[j].subject_key, | ||
652 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 600 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); |
653 | if (0 < set[j].subject_attribute_len) | 601 | if (0 < set[j].subject_attribute_len) |
654 | ds_entry->delegation_chain_entry->subject_attribute = GNUNET_strdup (set[j].subject_attribute); | 602 | ds_entry->delegation_chain_entry->subject_attribute = |
603 | GNUNET_strdup (set[j].subject_attribute); | ||
655 | ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key; | 604 | ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key; |
656 | ds_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (current_set->lookup_attribute); | 605 | ds_entry->delegation_chain_entry->issuer_attribute = |
606 | GNUNET_strdup (current_set->lookup_attribute); | ||
657 | 607 | ||
658 | ds_entry->parent_queue_entry = dq_entry; //current_delegation; | 608 | ds_entry->parent_queue_entry = dq_entry; // current_delegation; |
659 | GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head, | 609 | GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head, |
660 | dq_entry->set_entries_tail, | 610 | dq_entry->set_entries_tail, ds_entry); |
661 | ds_entry); | ||
662 | 611 | ||
663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n"); |
664 | "Checking for cred match\n"); | ||
665 | /** | 613 | /** |
666 | * Check if this delegation already matches one of our credentials | 614 | * Check if this delegation already matches one of our credentials |
667 | */ | 615 | */ |
668 | for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; | 616 | for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; |
669 | cred_pointer = cred_pointer->next) | 617 | cred_pointer = cred_pointer->next) { |
670 | { | 618 | if (0 != memcmp (&set->subject_key, |
671 | if(0 != memcmp (&set->subject_key, | 619 | &cred_pointer->credential->issuer_key, |
672 | &cred_pointer->credential->issuer_key, | 620 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) |
673 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
674 | continue; | 621 | continue; |
675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking if %s matches %s\n", |
676 | "Checking if %s matches %s\n", | ||
677 | ds_entry->unresolved_attribute_delegation, | 623 | ds_entry->unresolved_attribute_delegation, |
678 | cred_pointer->credential->issuer_attribute); | 624 | cred_pointer->credential->issuer_attribute); |
679 | 625 | ||
@@ -681,17 +627,13 @@ backward_resolution (void* cls, | |||
681 | cred_pointer->credential->issuer_attribute)) | 627 | cred_pointer->credential->issuer_attribute)) |
682 | continue; | 628 | continue; |
683 | 629 | ||
684 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 630 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n"); |
685 | "Found issuer\n"); | ||
686 | cred_pointer->refcount++; | 631 | cred_pointer->refcount++; |
687 | //Backtrack | 632 | // Backtrack |
688 | for (tmp_set = ds_entry; | 633 | for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry; |
689 | NULL != tmp_set->parent_queue_entry; | 634 | tmp_set = tmp_set->parent_queue_entry->parent_set) { |
690 | tmp_set = tmp_set->parent_queue_entry->parent_set) | ||
691 | { | ||
692 | tmp_set->parent_queue_entry->required_solutions--; | 635 | tmp_set->parent_queue_entry->required_solutions--; |
693 | if (NULL != tmp_set->delegation_chain_entry) | 636 | if (NULL != tmp_set->delegation_chain_entry) { |
694 | { | ||
695 | vrh->delegation_chain_size++; | 637 | vrh->delegation_chain_size++; |
696 | GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head, | 638 | GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head, |
697 | vrh->delegation_chain_tail, | 639 | vrh->delegation_chain_tail, |
@@ -701,73 +643,59 @@ backward_resolution (void* cls, | |||
701 | break; | 643 | break; |
702 | } | 644 | } |
703 | 645 | ||
704 | if (NULL == tmp_set->parent_queue_entry) | 646 | if (NULL == tmp_set->parent_queue_entry) { |
705 | { | 647 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All solutions found\n"); |
706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 648 | // Found match |
707 | "All solutions found\n"); | ||
708 | //Found match | ||
709 | send_lookup_response (vrh); | 649 | send_lookup_response (vrh); |
710 | return; | 650 | return; |
711 | } | 651 | } |
712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 652 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not all solutions found yet.\n"); |
713 | "Not all solutions found yet.\n"); | ||
714 | continue; | 653 | continue; |
715 | |||
716 | } | 654 | } |
717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 655 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
718 | "Building new lookup request from %s\n", | 656 | "Building new lookup request from %s\n", |
719 | ds_entry->unresolved_attribute_delegation); | 657 | ds_entry->unresolved_attribute_delegation); |
720 | //Continue with backward resolution | 658 | // Continue with backward resolution |
721 | char issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation)+1]; | 659 | char issuer_attribute_name |
722 | strcpy (issuer_attribute_name, | 660 | [strlen (ds_entry->unresolved_attribute_delegation) + 1]; |
723 | ds_entry->unresolved_attribute_delegation); | 661 | strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation); |
724 | char *next_attr = strtok (issuer_attribute_name, "."); | 662 | char *next_attr = strtok (issuer_attribute_name, "."); |
725 | if (NULL == next_attr) | 663 | if (NULL == next_attr) { |
726 | { | ||
727 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 664 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
728 | "Failed to parse next attribute\n"); | 665 | "Failed to parse next attribute\n"); |
729 | continue; | 666 | continue; |
730 | } | 667 | } |
731 | GNUNET_asprintf (&lookup_attribute, | 668 | GNUNET_asprintf (&lookup_attribute, "%s", next_attr); |
732 | "%s.gnu", | 669 | GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr); |
733 | next_attr); | 670 | if (strlen (next_attr) == |
734 | GNUNET_asprintf (&ds_entry->lookup_attribute, | 671 | strlen (ds_entry->unresolved_attribute_delegation)) { |
735 | "%s", | ||
736 | next_attr); | ||
737 | if (strlen (next_attr) == strlen (ds_entry->unresolved_attribute_delegation)) | ||
738 | { | ||
739 | ds_entry->attr_trailer = NULL; | 672 | ds_entry->attr_trailer = NULL; |
740 | } else { | 673 | } else { |
741 | next_attr += strlen (next_attr) + 1; | 674 | next_attr += strlen (next_attr) + 1; |
742 | ds_entry->attr_trailer = GNUNET_strdup (next_attr); | 675 | ds_entry->attr_trailer = GNUNET_strdup (next_attr); |
743 | } | 676 | } |
744 | 677 | ||
745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 678 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking up %s\n", |
746 | "Looking up %s\n", ds_entry->lookup_attribute); | 679 | ds_entry->lookup_attribute); |
747 | if (NULL != ds_entry->attr_trailer) | 680 | if (NULL != ds_entry->attr_trailer) |
748 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 681 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s still to go...\n", |
749 | "%s still to go...\n", ds_entry->attr_trailer); | 682 | ds_entry->attr_trailer); |
750 | 683 | ||
751 | vrh->pending_lookups++; | 684 | vrh->pending_lookups++; |
752 | ds_entry->handle = vrh; | 685 | ds_entry->handle = vrh; |
753 | ds_entry->lookup_request = GNUNET_GNS_lookup (gns, | 686 | ds_entry->lookup_request = GNUNET_GNS_lookup ( |
754 | lookup_attribute, | 687 | gns, lookup_attribute, |
755 | ds_entry->issuer_key, //issuer_key, | 688 | ds_entry->issuer_key, // issuer_key, |
756 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, | 689 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNS_LO_DEFAULT, |
757 | GNUNET_GNS_LO_DEFAULT, | 690 | &backward_resolution, ds_entry); |
758 | &backward_resolution, | ||
759 | ds_entry); | ||
760 | GNUNET_free (lookup_attribute); | 691 | GNUNET_free (lookup_attribute); |
761 | } | 692 | } |
762 | } | 693 | } |
763 | 694 | ||
764 | if(0 == vrh->pending_lookups) | 695 | if (0 == vrh->pending_lookups) { |
765 | { | 696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n"); |
766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
767 | "We are all out of attributes...\n"); | ||
768 | send_lookup_response (vrh); | 697 | send_lookup_response (vrh); |
769 | return; | 698 | return; |
770 | |||
771 | } | 699 | } |
772 | } | 700 | } |
773 | 701 | ||
@@ -778,89 +706,76 @@ backward_resolution (void* cls, | |||
778 | * @param cls the closure (our client lookup handle) | 706 | * @param cls the closure (our client lookup handle) |
779 | */ | 707 | */ |
780 | static void | 708 | static void |
781 | delegation_chain_resolution_start (void* cls) | 709 | delegation_chain_resolution_start (void *cls) |
782 | { | 710 | { |
783 | struct VerifyRequestHandle *vrh = cls; | 711 | struct VerifyRequestHandle *vrh = cls; |
784 | struct DelegationSetQueueEntry *ds_entry; | 712 | struct DelegationSetQueueEntry *ds_entry; |
785 | struct CredentialRecordEntry *cr_entry; | 713 | struct CredentialRecordEntry *cr_entry; |
786 | vrh->lookup_request = NULL; | 714 | vrh->lookup_request = NULL; |
787 | 715 | ||
788 | if (0 == vrh->cred_chain_size) | 716 | if (0 == vrh->cred_chain_size) { |
789 | { | 717 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No credentials found\n"); |
790 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
791 | "No credentials found\n"); | ||
792 | send_lookup_response (vrh); | 718 | send_lookup_response (vrh); |
793 | return; | 719 | return; |
794 | } | 720 | } |
795 | 721 | ||
796 | for (cr_entry = vrh->cred_chain_head; cr_entry != NULL; cr_entry = cr_entry->next) | 722 | for (cr_entry = vrh->cred_chain_head; cr_entry != NULL; |
797 | { | 723 | cr_entry = cr_entry->next) { |
798 | if (0 != memcmp (&cr_entry->credential->issuer_key, | 724 | if (0 != memcmp (&cr_entry->credential->issuer_key, &vrh->issuer_key, |
799 | &vrh->issuer_key, | ||
800 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 725 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) |
801 | continue; | 726 | continue; |
802 | if (0 != strcmp (cr_entry->credential->issuer_attribute, vrh->issuer_attribute)) | 727 | if (0 != |
728 | strcmp (cr_entry->credential->issuer_attribute, vrh->issuer_attribute)) | ||
803 | continue; | 729 | continue; |
804 | cr_entry->refcount++; | 730 | cr_entry->refcount++; |
805 | //Found match prematurely | 731 | // Found match prematurely |
806 | send_lookup_response (vrh); | 732 | send_lookup_response (vrh); |
807 | return; | 733 | return; |
808 | |||
809 | } | 734 | } |
810 | 735 | ||
811 | /** | 736 | /** |
812 | * Check for attributes from the issuer and follow the chain | 737 | * Check for attributes from the issuer and follow the chain |
813 | * till you get the required subject's attributes | 738 | * till you get the required subject's attributes |
814 | */ | 739 | */ |
815 | char issuer_attribute_name[strlen (vrh->issuer_attribute) + strlen (".gnu") + 1]; | 740 | char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1]; |
816 | strcpy (issuer_attribute_name, | 741 | strcpy (issuer_attribute_name, vrh->issuer_attribute); |
817 | vrh->issuer_attribute); | 742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up %s\n", |
818 | strcpy (issuer_attribute_name + strlen (vrh->issuer_attribute), | 743 | issuer_attribute_name); |
819 | ".gnu"); | ||
820 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
821 | "Looking up %s\n", issuer_attribute_name); | ||
822 | ds_entry = GNUNET_new (struct DelegationSetQueueEntry); | 744 | ds_entry = GNUNET_new (struct DelegationSetQueueEntry); |
823 | ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | 745 | ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); |
824 | GNUNET_memcpy (ds_entry->issuer_key, | 746 | GNUNET_memcpy (ds_entry->issuer_key, &vrh->issuer_key, |
825 | &vrh->issuer_key, | ||
826 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 747 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); |
827 | ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); | 748 | ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); |
828 | ds_entry->handle = vrh; | 749 | ds_entry->handle = vrh; |
829 | ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute); | 750 | ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute); |
830 | vrh->root_set = ds_entry; | 751 | vrh->root_set = ds_entry; |
831 | vrh->pending_lookups = 1; | 752 | vrh->pending_lookups = 1; |
832 | //Start with backward resolution | 753 | // Start with backward resolution |
833 | ds_entry->lookup_request = GNUNET_GNS_lookup (gns, | 754 | ds_entry->lookup_request = |
834 | issuer_attribute_name, | 755 | GNUNET_GNS_lookup (gns, issuer_attribute_name, |
835 | &vrh->issuer_key, //issuer_key, | 756 | &vrh->issuer_key, // issuer_key, |
836 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, | 757 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNS_LO_DEFAULT, |
837 | GNUNET_GNS_LO_DEFAULT, | 758 | &backward_resolution, ds_entry); |
838 | &backward_resolution, | ||
839 | ds_entry); | ||
840 | } | 759 | } |
841 | 760 | ||
842 | static int | 761 | static int |
843 | check_verify (void *cls, | 762 | check_verify (void *cls, const struct VerifyMessage *v_msg) |
844 | const struct VerifyMessage *v_msg) | ||
845 | { | 763 | { |
846 | size_t msg_size; | 764 | size_t msg_size; |
847 | const char* attr; | 765 | const char *attr; |
848 | 766 | ||
849 | msg_size = ntohs (v_msg->header.size); | 767 | msg_size = ntohs (v_msg->header.size); |
850 | if (msg_size < sizeof (struct VerifyMessage)) | 768 | if (msg_size < sizeof (struct VerifyMessage)) { |
851 | { | ||
852 | GNUNET_break (0); | 769 | GNUNET_break (0); |
853 | return GNUNET_SYSERR; | 770 | return GNUNET_SYSERR; |
854 | } | 771 | } |
855 | if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) | 772 | if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) { |
856 | { | ||
857 | GNUNET_break (0); | 773 | GNUNET_break (0); |
858 | return GNUNET_SYSERR; | 774 | return GNUNET_SYSERR; |
859 | } | 775 | } |
860 | attr = (const char *) &v_msg[1]; | 776 | attr = (const char *)&v_msg[1]; |
861 | 777 | ||
862 | if ( strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) | 778 | if (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) { |
863 | { | ||
864 | GNUNET_break (0); | 779 | GNUNET_break (0); |
865 | return GNUNET_SYSERR; | 780 | return GNUNET_SYSERR; |
866 | } | 781 | } |
@@ -868,8 +783,7 @@ check_verify (void *cls, | |||
868 | } | 783 | } |
869 | 784 | ||
870 | static void | 785 | static void |
871 | handle_verify (void *cls, | 786 | handle_verify (void *cls, const struct VerifyMessage *v_msg) |
872 | const struct VerifyMessage *v_msg) | ||
873 | { | 787 | { |
874 | struct VerifyRequestHandle *vrh; | 788 | struct VerifyRequestHandle *vrh; |
875 | struct GNUNET_SERVICE_Client *client = cls; | 789 | struct GNUNET_SERVICE_Client *client = cls; |
@@ -882,13 +796,10 @@ handle_verify (void *cls, | |||
882 | char *credential_data; | 796 | char *credential_data; |
883 | const char *utf_in; | 797 | const char *utf_in; |
884 | 798 | ||
885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n"); |
886 | "Received VERIFY message\n"); | 800 | utf_in = (const char *)&v_msg[1]; |
887 | utf_in = (const char *) &v_msg[1]; | ||
888 | GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); | 801 | GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); |
889 | GNUNET_memcpy (issuer_attribute, | 802 | GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len)); |
890 | attr, | ||
891 | ntohs (v_msg->issuer_attribute_len)); | ||
892 | issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0'; | 803 | issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0'; |
893 | vrh = GNUNET_new (struct VerifyRequestHandle); | 804 | vrh = GNUNET_new (struct VerifyRequestHandle); |
894 | GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh); | 805 | GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh); |
@@ -897,10 +808,9 @@ handle_verify (void *cls, | |||
897 | vrh->issuer_key = v_msg->issuer_key; | 808 | vrh->issuer_key = v_msg->issuer_key; |
898 | vrh->subject_key = v_msg->subject_key; | 809 | vrh->subject_key = v_msg->subject_key; |
899 | vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); | 810 | vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); |
900 | if (0 == strlen (issuer_attribute)) | 811 | GNUNET_SERVICE_client_continue (vrh->client); |
901 | { | 812 | if (0 == strlen (issuer_attribute)) { |
902 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 813 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); |
903 | "No issuer attribute provided!\n"); | ||
904 | send_lookup_response (vrh); | 814 | send_lookup_response (vrh); |
905 | return; | 815 | return; |
906 | } | 816 | } |
@@ -908,43 +818,36 @@ handle_verify (void *cls, | |||
908 | * First, collect credentials | 818 | * First, collect credentials |
909 | * TODO: cleanup! | 819 | * TODO: cleanup! |
910 | */ | 820 | */ |
911 | credentials_count = ntohl(v_msg->c_count); | 821 | credentials_count = ntohl (v_msg->c_count); |
912 | credential_data_size = ntohs (v_msg->header.size) | 822 | credential_data_size = ntohs (v_msg->header.size) - |
913 | - sizeof (struct VerifyMessage) | 823 | sizeof (struct VerifyMessage) - |
914 | - ntohs (v_msg->issuer_attribute_len) | 824 | ntohs (v_msg->issuer_attribute_len) - 1; |
915 | - 1; | ||
916 | struct GNUNET_CREDENTIAL_Credential credentials[credentials_count]; | 825 | struct GNUNET_CREDENTIAL_Credential credentials[credentials_count]; |
917 | credential_data = (char*)&v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1; | 826 | credential_data = (char *)&v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1; |
918 | if (GNUNET_OK != GNUNET_CREDENTIAL_credentials_deserialize (credential_data_size, | 827 | if (GNUNET_OK != GNUNET_CREDENTIAL_credentials_deserialize ( |
919 | credential_data, | 828 | credential_data_size, credential_data, credentials_count, |
920 | credentials_count, | 829 | credentials)) { |
921 | credentials)) | 830 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n"); |
922 | { | ||
923 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
924 | "Cannot deserialize credentials!\n"); | ||
925 | send_lookup_response (vrh); | 831 | send_lookup_response (vrh); |
926 | return; | 832 | return; |
927 | } | 833 | } |
928 | 834 | ||
929 | for (uint32_t i=0;i<credentials_count;i++) { | 835 | for (uint32_t i = 0; i < credentials_count; i++) { |
930 | cr_entry = GNUNET_new (struct CredentialRecordEntry); | 836 | cr_entry = GNUNET_new (struct CredentialRecordEntry); |
931 | cr_entry->credential = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + | 837 | cr_entry->credential = |
932 | credentials[i].issuer_attribute_len); | 838 | GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + |
933 | GNUNET_memcpy (cr_entry->credential, | 839 | credentials[i].issuer_attribute_len); |
934 | &credentials[i], | 840 | GNUNET_memcpy (cr_entry->credential, &credentials[i], |
935 | sizeof (struct GNUNET_CREDENTIAL_Credential)); | 841 | sizeof (struct GNUNET_CREDENTIAL_Credential)); |
936 | GNUNET_memcpy (&cr_entry->credential[1], | 842 | GNUNET_memcpy (&cr_entry->credential[1], credentials[i].issuer_attribute, |
937 | credentials[i].issuer_attribute, | ||
938 | credentials[i].issuer_attribute_len); | 843 | credentials[i].issuer_attribute_len); |
939 | cr_entry->credential->issuer_attribute = (char*)&cr_entry->credential[1]; | 844 | cr_entry->credential->issuer_attribute = (char *)&cr_entry->credential[1]; |
940 | GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, | 845 | GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, |
941 | vrh->cred_chain_tail, | 846 | vrh->cred_chain_tail, cr_entry); |
942 | cr_entry); | ||
943 | vrh->cred_chain_size++; | 847 | vrh->cred_chain_size++; |
944 | } | 848 | } |
945 | 849 | ||
946 | delegation_chain_resolution_start (vrh); | 850 | delegation_chain_resolution_start (vrh); |
947 | |||
948 | } | 851 | } |
949 | 852 | ||
950 | static void | 853 | static void |
@@ -963,16 +866,14 @@ collect_next (void *cls) | |||
963 | struct VerifyRequestHandle *vrh = cls; | 866 | struct VerifyRequestHandle *vrh = cls; |
964 | vrh->collect_next_task = NULL; | 867 | vrh->collect_next_task = NULL; |
965 | GNUNET_assert (NULL != vrh->cred_collection_iter); | 868 | GNUNET_assert (NULL != vrh->cred_collection_iter); |
966 | GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter, | 869 | GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter, 1); |
967 | 1); | ||
968 | } | 870 | } |
969 | 871 | ||
970 | 872 | ||
971 | static void | 873 | static void |
972 | handle_cred_collection_cb (void *cls, | 874 | handle_cred_collection_cb (void *cls, |
973 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 875 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
974 | const char *label, | 876 | const char *label, unsigned int rd_count, |
975 | unsigned int rd_count, | ||
976 | const struct GNUNET_GNSRECORD_Data *rd) | 877 | const struct GNUNET_GNSRECORD_Data *rd) |
977 | { | 878 | { |
978 | struct VerifyRequestHandle *vrh = cls; | 879 | struct VerifyRequestHandle *vrh = cls; |
@@ -981,43 +882,36 @@ handle_cred_collection_cb (void *cls, | |||
981 | int cred_record_count; | 882 | int cred_record_count; |
982 | 883 | ||
983 | cred_record_count = 0; | 884 | cred_record_count = 0; |
984 | for (uint32_t i=0; i < rd_count; i++) | 885 | for (uint32_t i = 0; i < rd_count; i++) { |
985 | { | ||
986 | if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) | 886 | if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) |
987 | continue; | 887 | continue; |
988 | cred_record_count++; | 888 | cred_record_count++; |
989 | crd = GNUNET_CREDENTIAL_credential_deserialize (rd[i].data, | 889 | crd = |
990 | rd[i].data_size); | 890 | GNUNET_CREDENTIAL_credential_deserialize (rd[i].data, rd[i].data_size); |
991 | if (NULL == crd) | 891 | if (NULL == crd) { |
992 | { | 892 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n"); |
993 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
994 | "Invalid credential found\n"); | ||
995 | continue; | 893 | continue; |
996 | } | 894 | } |
997 | cr_entry = GNUNET_new (struct CredentialRecordEntry); | 895 | cr_entry = GNUNET_new (struct CredentialRecordEntry); |
998 | cr_entry->credential = crd; | 896 | cr_entry->credential = crd; |
999 | GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, | 897 | GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head, |
1000 | vrh->cred_chain_tail, | 898 | vrh->cred_chain_tail, cr_entry); |
1001 | cr_entry); | ||
1002 | vrh->cred_chain_size++; | 899 | vrh->cred_chain_size++; |
1003 | } | 900 | } |
1004 | vrh->collect_next_task = GNUNET_SCHEDULER_add_now (&collect_next, | 901 | vrh->collect_next_task = GNUNET_SCHEDULER_add_now (&collect_next, vrh); |
1005 | vrh); | ||
1006 | } | 902 | } |
1007 | 903 | ||
1008 | static void | 904 | static void |
1009 | handle_cred_collection_finished_cb (void *cls) | 905 | handle_cred_collection_finished_cb (void *cls) |
1010 | { | 906 | { |
1011 | struct VerifyRequestHandle *vrh = cls; | 907 | struct VerifyRequestHandle *vrh = cls; |
1012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 908 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting credentials.\n"); |
1013 | "Done collecting credentials.\n"); | ||
1014 | vrh->cred_collection_iter = NULL; | 909 | vrh->cred_collection_iter = NULL; |
1015 | delegation_chain_resolution_start (vrh); | 910 | delegation_chain_resolution_start (vrh); |
1016 | } | 911 | } |
1017 | 912 | ||
1018 | static void | 913 | static void |
1019 | handle_collect (void *cls, | 914 | handle_collect (void *cls, const struct CollectMessage *c_msg) |
1020 | const struct CollectMessage *c_msg) | ||
1021 | { | 915 | { |
1022 | char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; | 916 | char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; |
1023 | char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; | 917 | char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; |
@@ -1026,71 +920,57 @@ handle_collect (void *cls, | |||
1026 | char *attrptr = attr; | 920 | char *attrptr = attr; |
1027 | const char *utf_in; | 921 | const char *utf_in; |
1028 | 922 | ||
1029 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 923 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n"); |
1030 | "Received COLLECT message\n"); | ||
1031 | 924 | ||
1032 | utf_in = (const char *) &c_msg[1]; | 925 | utf_in = (const char *)&c_msg[1]; |
1033 | GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); | 926 | GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); |
1034 | 927 | ||
1035 | GNUNET_memcpy (issuer_attribute, | 928 | GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len)); |
1036 | attr, | ||
1037 | ntohs (c_msg->issuer_attribute_len)); | ||
1038 | issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0'; | 929 | issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0'; |
1039 | vrh = GNUNET_new (struct VerifyRequestHandle); | 930 | vrh = GNUNET_new (struct VerifyRequestHandle); |
1040 | GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh); | 931 | GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh); |
1041 | vrh->client = client; | 932 | vrh->client = client; |
1042 | vrh->request_id = c_msg->id; | 933 | vrh->request_id = c_msg->id; |
1043 | vrh->issuer_key = c_msg->issuer_key; | 934 | vrh->issuer_key = c_msg->issuer_key; |
1044 | GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key, | 935 | GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key, &vrh->subject_key); |
1045 | &vrh->subject_key); | ||
1046 | vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); | 936 | vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); |
1047 | 937 | ||
1048 | if (0 == strlen (issuer_attribute)) | 938 | if (0 == strlen (issuer_attribute)) { |
1049 | { | 939 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n"); |
1050 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1051 | "No issuer attribute provided!\n"); | ||
1052 | send_lookup_response (vrh); | 940 | send_lookup_response (vrh); |
1053 | return; | 941 | return; |
1054 | } | 942 | } |
1055 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting credentials for subject\n"); |
1056 | "Getting credentials for subject\n"); | ||
1057 | /** | 944 | /** |
1058 | * First, get attribute from subject | 945 | * First, get attribute from subject |
1059 | */ | 946 | */ |
1060 | vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore, | 947 | vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start ( |
1061 | &c_msg->subject_key, | 948 | namestore, &c_msg->subject_key, &handle_cred_collection_error_cb, vrh, |
1062 | &handle_cred_collection_error_cb, | 949 | &handle_cred_collection_cb, vrh, &handle_cred_collection_finished_cb, |
1063 | vrh, | 950 | vrh); |
1064 | &handle_cred_collection_cb, | 951 | GNUNET_SERVICE_client_continue (vrh->client); |
1065 | vrh, | ||
1066 | &handle_cred_collection_finished_cb, | ||
1067 | vrh); | ||
1068 | } | 952 | } |
1069 | 953 | ||
1070 | 954 | ||
1071 | static int | 955 | static int |
1072 | check_collect (void *cls, | 956 | check_collect (void *cls, const struct CollectMessage *c_msg) |
1073 | const struct CollectMessage *c_msg) | ||
1074 | { | 957 | { |
1075 | size_t msg_size; | 958 | size_t msg_size; |
1076 | const char* attr; | 959 | const char *attr; |
1077 | 960 | ||
1078 | msg_size = ntohs (c_msg->header.size); | 961 | msg_size = ntohs (c_msg->header.size); |
1079 | if (msg_size < sizeof (struct CollectMessage)) | 962 | if (msg_size < sizeof (struct CollectMessage)) { |
1080 | { | ||
1081 | GNUNET_break (0); | 963 | GNUNET_break (0); |
1082 | return GNUNET_SYSERR; | 964 | return GNUNET_SYSERR; |
1083 | } | 965 | } |
1084 | if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) | 966 | if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) { |
1085 | { | ||
1086 | GNUNET_break (0); | 967 | GNUNET_break (0); |
1087 | return GNUNET_SYSERR; | 968 | return GNUNET_SYSERR; |
1088 | } | 969 | } |
1089 | attr = (const char *) &c_msg[1]; | 970 | attr = (const char *)&c_msg[1]; |
1090 | 971 | ||
1091 | if ( ('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) || | 972 | if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) || |
1092 | (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) ) | 973 | (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)) { |
1093 | { | ||
1094 | GNUNET_break (0); | 974 | GNUNET_break (0); |
1095 | return GNUNET_SYSERR; | 975 | return GNUNET_SYSERR; |
1096 | } | 976 | } |
@@ -1098,23 +978,17 @@ check_collect (void *cls, | |||
1098 | } | 978 | } |
1099 | 979 | ||
1100 | static void | 980 | static void |
1101 | client_disconnect_cb (void *cls, | 981 | client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, |
1102 | struct GNUNET_SERVICE_Client *client, | ||
1103 | void *app_ctx) | 982 | void *app_ctx) |
1104 | { | 983 | { |
1105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); |
1106 | "Client %p disconnected\n", | ||
1107 | client); | ||
1108 | } | 985 | } |
1109 | 986 | ||
1110 | static void * | 987 | static void * |
1111 | client_connect_cb (void *cls, | 988 | client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, |
1112 | struct GNUNET_SERVICE_Client *client, | ||
1113 | struct GNUNET_MQ_Handle *mq) | 989 | struct GNUNET_MQ_Handle *mq) |
1114 | { | 990 | { |
1115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); |
1116 | "Client %p connected\n", | ||
1117 | client); | ||
1118 | return client; | 992 | return client; |
1119 | } | 993 | } |
1120 | 994 | ||
@@ -1126,22 +1000,17 @@ client_connect_cb (void *cls, | |||
1126 | * @param handle service handle | 1000 | * @param handle service handle |
1127 | */ | 1001 | */ |
1128 | static void | 1002 | static void |
1129 | run (void *cls, | 1003 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, |
1130 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
1131 | struct GNUNET_SERVICE_Handle *handle) | 1004 | struct GNUNET_SERVICE_Handle *handle) |
1132 | { | 1005 | { |
1133 | 1006 | ||
1134 | gns = GNUNET_GNS_connect (c); | 1007 | gns = GNUNET_GNS_connect (c); |
1135 | if (NULL == gns) | 1008 | if (NULL == gns) { |
1136 | { | 1009 | fprintf (stderr, _ ("Failed to connect to GNS\n")); |
1137 | fprintf (stderr, | ||
1138 | _("Failed to connect to GNS\n")); | ||
1139 | } | 1010 | } |
1140 | namestore = GNUNET_NAMESTORE_connect (c); | 1011 | namestore = GNUNET_NAMESTORE_connect (c); |
1141 | if (NULL == namestore) | 1012 | if (NULL == namestore) { |
1142 | { | 1013 | fprintf (stderr, _ ("Failed to connect to namestore\n")); |
1143 | fprintf (stderr, | ||
1144 | _("Failed to connect to namestore\n")); | ||
1145 | } | 1014 | } |
1146 | 1015 | ||
1147 | statistics = GNUNET_STATISTICS_create ("credential", c); | 1016 | statistics = GNUNET_STATISTICS_create ("credential", c); |
@@ -1152,21 +1021,13 @@ run (void *cls, | |||
1152 | /** | 1021 | /** |
1153 | * Define "main" method using service macro | 1022 | * Define "main" method using service macro |
1154 | */ | 1023 | */ |
1155 | GNUNET_SERVICE_MAIN | 1024 | GNUNET_SERVICE_MAIN ( |
1156 | ("credential", | 1025 | "credential", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, |
1157 | GNUNET_SERVICE_OPTION_NONE, | 1026 | &client_disconnect_cb, NULL, |
1158 | &run, | 1027 | GNUNET_MQ_hd_var_size (verify, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY, |
1159 | &client_connect_cb, | 1028 | struct VerifyMessage, NULL), |
1160 | &client_disconnect_cb, | 1029 | GNUNET_MQ_hd_var_size (collect, GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT, |
1161 | NULL, | 1030 | struct CollectMessage, NULL), |
1162 | GNUNET_MQ_hd_var_size (verify, | 1031 | GNUNET_MQ_handler_end ()); |
1163 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY, | ||
1164 | struct VerifyMessage, | ||
1165 | NULL), | ||
1166 | GNUNET_MQ_hd_var_size (collect, | ||
1167 | GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT, | ||
1168 | struct CollectMessage, | ||
1169 | NULL), | ||
1170 | GNUNET_MQ_handler_end()); | ||
1171 | 1032 | ||
1172 | /* end of gnunet-service-credential.c */ | 1033 | /* end of gnunet-service-credential.c */ |