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.c116
1 files changed, 19 insertions, 97 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index be75e485e..be88839e9 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -18,9 +18,9 @@
18 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
19*/ 19*/
20/** 20/**
21 * @file gns/gnunet-service-credential.c 21 * @file credential/gnunet-service-credential.c
22 * @brief GNU Credential Service (main service) 22 * @brief GNUnet Credential Service (main service)
23 * @author Adnan Husain 23 * @author Martin Schanzenbach
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
@@ -377,16 +377,11 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
377 } 377 }
378 GNUNET_free (dq_entry); 378 GNUNET_free (dq_entry);
379 } 379 }
380 if (NULL != ds_entry->issuer_key) 380 GNUNET_free_non_null (ds_entry->issuer_key);
381 GNUNET_free (ds_entry->issuer_key); 381 GNUNET_free_non_null (ds_entry->lookup_attribute);
382 if (NULL != ds_entry->lookup_attribute) 382 GNUNET_free_non_null (ds_entry->issuer_attribute);
383 GNUNET_free (ds_entry->lookup_attribute); 383 GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation);
384 if (NULL != ds_entry->issuer_attribute) 384 GNUNET_free_non_null (ds_entry->attr_trailer);
385 GNUNET_free (ds_entry->issuer_attribute);
386 if (NULL != ds_entry->unresolved_attribute_delegation)
387 GNUNET_free (ds_entry->unresolved_attribute_delegation);
388 if (NULL != ds_entry->attr_trailer)
389 GNUNET_free (ds_entry->attr_trailer);
390 if (NULL != ds_entry->lookup_request) 385 if (NULL != ds_entry->lookup_request)
391 { 386 {
392 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request); 387 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request);
@@ -394,10 +389,8 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
394 } 389 }
395 if (NULL != ds_entry->delegation_chain_entry) 390 if (NULL != ds_entry->delegation_chain_entry)
396 { 391 {
397 if (NULL != ds_entry->delegation_chain_entry->subject_attribute) 392 GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute);
398 GNUNET_free (ds_entry->delegation_chain_entry->subject_attribute); 393 GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute);
399 if (NULL != ds_entry->delegation_chain_entry->issuer_attribute)
400 GNUNET_free (ds_entry->delegation_chain_entry->issuer_attribute);
401 GNUNET_free (ds_entry->delegation_chain_entry); 394 GNUNET_free (ds_entry->delegation_chain_entry);
402 } 395 }
403 GNUNET_free (ds_entry); 396 GNUNET_free (ds_entry);
@@ -415,8 +408,7 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
415 vrh->lookup_request = NULL; 408 vrh->lookup_request = NULL;
416 } 409 }
417 cleanup_delegation_set (vrh->root_set); 410 cleanup_delegation_set (vrh->root_set);
418 if (NULL != vrh->issuer_attribute) 411 GNUNET_free_non_null (vrh->issuer_attribute);
419 GNUNET_free (vrh->issuer_attribute);
420 for (cr_entry = vrh->cred_chain_head; 412 for (cr_entry = vrh->cred_chain_head;
421 NULL != vrh->cred_chain_head; 413 NULL != vrh->cred_chain_head;
422 cr_entry = vrh->cred_chain_head) 414 cr_entry = vrh->cred_chain_head)
@@ -424,19 +416,12 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
424 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, 416 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head,
425 vrh->cred_chain_tail, 417 vrh->cred_chain_tail,
426 cr_entry); 418 cr_entry);
427 if (NULL != cr_entry->credential); 419 GNUNET_free_non_null (cr_entry->credential);
428 GNUNET_free (cr_entry->credential);
429 GNUNET_free (cr_entry); 420 GNUNET_free (cr_entry);
430 } 421 }
431 GNUNET_free (vrh); 422 GNUNET_free (vrh);
432} 423}
433 424
434/**
435 * Task run during shutdown.
436 *
437 * @param cls unused
438 * @param tc unused
439 */
440static void 425static void
441shutdown_task (void *cls) 426shutdown_task (void *cls)
442{ 427{
@@ -475,11 +460,6 @@ shutdown_task (void *cls)
475 460
476 461
477 462
478/**
479 * Send.
480 *
481 * @param handle the handle to the request
482 */
483static void 463static void
484send_lookup_response (struct VerifyRequestHandle *vrh) 464send_lookup_response (struct VerifyRequestHandle *vrh)
485{ 465{
@@ -491,12 +471,11 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
491 struct CredentialRecordEntry *cd; 471 struct CredentialRecordEntry *cd;
492 struct CredentialRecordEntry *tmp; 472 struct CredentialRecordEntry *tmp;
493 size_t size; 473 size_t size;
494 int i;
495 474
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497 "Sending response\n"); 476 "Sending response\n");
498 dce = vrh->delegation_chain_head; 477 dce = vrh->delegation_chain_head;
499 for (i=0;i<vrh->delegation_chain_size;i++) 478 for (uint32_t i=0;i<vrh->delegation_chain_size;i++)
500 { 479 {
501 dd[i].issuer_key = dce->issuer_key; 480 dd[i].issuer_key = dce->issuer_key;
502 dd[i].subject_key = dce->subject_key; 481 dd[i].subject_key = dce->subject_key;
@@ -537,7 +516,7 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
537 * Append at the end of rmsg 516 * Append at the end of rmsg
538 */ 517 */
539 cd = vrh->cred_chain_head; 518 cd = vrh->cred_chain_head;
540 for (i=0;i<vrh->cred_chain_size;i++) 519 for (uint32_t i=0;i<vrh->cred_chain_size;i++)
541 { 520 {
542 cred[i].issuer_key = cd->credential->issuer_key; 521 cred[i].issuer_key = cd->credential->issuer_key;
543 cred[i].subject_key = cd->credential->subject_key; 522 cred[i].subject_key = cd->credential->subject_key;
@@ -598,8 +577,6 @@ backward_resolution (void* cls,
598 struct DelegationQueueEntry *dq_entry; 577 struct DelegationQueueEntry *dq_entry;
599 char *expanded_attr; 578 char *expanded_attr;
600 char *lookup_attribute; 579 char *lookup_attribute;
601 int i;
602 int j;
603 580
604 581
605 current_set = cls; 582 current_set = cls;
@@ -610,7 +587,7 @@ backward_resolution (void* cls,
610 "Got %d attrs\n", rd_count); 587 "Got %d attrs\n", rd_count);
611 588
612 // Each OR 589 // Each OR
613 for (i=0; i < rd_count; i++) 590 for (uint32_t i=0; i < rd_count; i++)
614 { 591 {
615 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) 592 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
616 continue; 593 continue;
@@ -637,7 +614,7 @@ backward_resolution (void* cls,
637 current_set->queue_entries_tail, 614 current_set->queue_entries_tail,
638 dq_entry); 615 dq_entry);
639 // Each AND 616 // Each AND
640 for (j=0; j<ntohl(sets->set_count); j++) 617 for (uint32_t j=0; j<ntohl(sets->set_count); j++)
641 { 618 {
642 ds_entry = GNUNET_new (struct DelegationSetQueueEntry); 619 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
643 if (NULL != current_set->attr_trailer) 620 if (NULL != current_set->attr_trailer)
@@ -793,8 +770,6 @@ backward_resolution (void* cls,
793 * Result from GNS lookup. 770 * Result from GNS lookup.
794 * 771 *
795 * @param cls the closure (our client lookup handle) 772 * @param cls the closure (our client lookup handle)
796 * @param rd_count the number of records in @a rd
797 * @param rd the record data
798 */ 773 */
799static void 774static void
800delegation_chain_resolution_start (void* cls) 775delegation_chain_resolution_start (void* cls)
@@ -858,13 +833,6 @@ delegation_chain_resolution_start (void* cls)
858 ds_entry); 833 ds_entry);
859} 834}
860 835
861/**
862 * Checks a #GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY message
863 *
864 * @param cls client sending the message
865 * @param v_msg message of type `struct VerifyMessage`
866 * @return #GNUNET_OK if @a v_msg is well-formed
867 */
868static int 836static int
869check_verify (void *cls, 837check_verify (void *cls,
870 const struct VerifyMessage *v_msg) 838 const struct VerifyMessage *v_msg)
@@ -893,13 +861,6 @@ check_verify (void *cls,
893 return GNUNET_OK; 861 return GNUNET_OK;
894} 862}
895 863
896/**
897 * Handle Credential verification requests from client
898 *
899 * @param cls the closure
900 * @param client the client
901 * @param message the message
902 */
903static void 864static void
904handle_verify (void *cls, 865handle_verify (void *cls,
905 const struct VerifyMessage *v_msg) 866 const struct VerifyMessage *v_msg)
@@ -909,7 +870,6 @@ handle_verify (void *cls,
909 struct CredentialRecordEntry *cr_entry; 870 struct CredentialRecordEntry *cr_entry;
910 uint32_t credentials_count; 871 uint32_t credentials_count;
911 uint32_t credential_data_size; 872 uint32_t credential_data_size;
912 int i;
913 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 873 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
914 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 874 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
915 char *attrptr = attr; 875 char *attrptr = attr;
@@ -958,7 +918,7 @@ handle_verify (void *cls,
958 return; 918 return;
959 } 919 }
960 920
961 for (i=0;i<credentials_count;i++) { 921 for (uint32_t i=0;i<credentials_count;i++) {
962 cr_entry = GNUNET_new (struct CredentialRecordEntry); 922 cr_entry = GNUNET_new (struct CredentialRecordEntry);
963 cr_entry->credential = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + 923 cr_entry->credential = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) +
964 credentials[i].issuer_attribute_len); 924 credentials[i].issuer_attribute_len);
@@ -979,9 +939,6 @@ handle_verify (void *cls,
979 939
980} 940}
981 941
982/**
983 * We encountered an error while collecting
984 */
985static void 942static void
986handle_cred_collection_error_cb (void *cls) 943handle_cred_collection_error_cb (void *cls)
987{ 944{
@@ -1001,9 +958,6 @@ collect_next (void *cls)
1001 GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter); 958 GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter);
1002} 959}
1003 960
1004/**
1005 * Store credential
1006 */
1007static void 961static void
1008handle_cred_collection_cb (void *cls, 962handle_cred_collection_cb (void *cls,
1009 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 963 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
@@ -1015,10 +969,9 @@ handle_cred_collection_cb (void *cls,
1015 struct GNUNET_CREDENTIAL_Credential *crd; 969 struct GNUNET_CREDENTIAL_Credential *crd;
1016 struct CredentialRecordEntry *cr_entry; 970 struct CredentialRecordEntry *cr_entry;
1017 int cred_record_count; 971 int cred_record_count;
1018 int i;
1019 972
1020 cred_record_count = 0; 973 cred_record_count = 0;
1021 for (i=0; i < rd_count; i++) 974 for (uint32_t i=0; i < rd_count; i++)
1022 { 975 {
1023 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) 976 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type)
1024 continue; 977 continue;
@@ -1042,9 +995,6 @@ handle_cred_collection_cb (void *cls,
1042 vrh); 995 vrh);
1043} 996}
1044 997
1045/**
1046 * We encountered an error while collecting
1047 */
1048static void 998static void
1049handle_cred_collection_finished_cb (void *cls) 999handle_cred_collection_finished_cb (void *cls)
1050{ 1000{
@@ -1055,13 +1005,6 @@ handle_cred_collection_finished_cb (void *cls)
1055 delegation_chain_resolution_start (vrh); 1005 delegation_chain_resolution_start (vrh);
1056} 1006}
1057 1007
1058/**
1059 * Handle Credential collection requests from client
1060 *
1061 * @param cls the closure
1062 * @param client the client
1063 * @param message the message
1064 */
1065static void 1008static void
1066handle_collect (void *cls, 1009handle_collect (void *cls,
1067 const struct CollectMessage *c_msg) 1010 const struct CollectMessage *c_msg)
@@ -1113,13 +1056,6 @@ handle_collect (void *cls,
1113} 1056}
1114 1057
1115 1058
1116/**
1117 * Checks a #GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT message
1118 *
1119 * @param cls client sending the message
1120 * @param v_msg message of type `struct CollectMessage`
1121 * @return #GNUNET_OK if @a v_msg is well-formed
1122 */
1123static int 1059static int
1124check_collect (void *cls, 1060check_collect (void *cls,
1125 const struct CollectMessage *c_msg) 1061 const struct CollectMessage *c_msg)
@@ -1149,12 +1085,6 @@ check_collect (void *cls,
1149 return GNUNET_OK; 1085 return GNUNET_OK;
1150} 1086}
1151 1087
1152/**
1153 * One of our clients disconnected, clean up after it.
1154 *
1155 * @param cls NULL
1156 * @param client the client that disconnected
1157 */
1158static void 1088static void
1159client_disconnect_cb (void *cls, 1089client_disconnect_cb (void *cls,
1160 struct GNUNET_SERVICE_Client *client, 1090 struct GNUNET_SERVICE_Client *client,
@@ -1165,14 +1095,6 @@ client_disconnect_cb (void *cls,
1165 client); 1095 client);
1166} 1096}
1167 1097
1168/**
1169 * Add a client to our list of active clients.
1170 *
1171 * @param cls NULL
1172 * @param client client to add
1173 * @param mq message queue for @a client
1174 * @return this client
1175 */
1176static void * 1098static void *
1177client_connect_cb (void *cls, 1099client_connect_cb (void *cls,
1178 struct GNUNET_SERVICE_Client *client, 1100 struct GNUNET_SERVICE_Client *client,
@@ -1188,8 +1110,8 @@ client_connect_cb (void *cls,
1188 * Process Credential requests. 1110 * Process Credential requests.
1189 * 1111 *
1190 * @param cls closure 1112 * @param cls closure
1191 * @param server the initialized server
1192 * @param c configuration to use 1113 * @param c configuration to use
1114 * @param handle service handle
1193 */ 1115 */
1194static void 1116static void
1195run (void *cls, 1117run (void *cls,