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.c520
1 files changed, 320 insertions, 200 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index 8f7d71b28..8843abfd6 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -46,9 +46,22 @@
46 46
47struct VerifyRequestHandle; 47struct VerifyRequestHandle;
48 48
49struct GNUNET_CREDENTIAL_DelegationChainEntry 49struct DelegationSetEntry;
50
51
52struct DelegationChainEntry
50{ 53{
51 /** 54 /**
55 * DLL
56 */
57 struct DelegationChainEntry *next;
58
59 /**
60 * DLL
61 */
62 struct DelegationChainEntry *prev;
63
64 /**
52 * The issuer 65 * The issuer
53 */ 66 */
54 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key; 67 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
@@ -97,8 +110,8 @@ struct CredentialRecordEntry
97}; 110};
98 111
99/** 112/**
100 * DLL for delegations - Used as a queue 113 * DLL used for delegations
101 * Insert tail - Pop head 114 * Used for OR delegations
102 */ 115 */
103struct DelegationQueueEntry 116struct DelegationQueueEntry
104{ 117{
@@ -113,16 +126,43 @@ struct DelegationQueueEntry
113 struct DelegationQueueEntry *prev; 126 struct DelegationQueueEntry *prev;
114 127
115 /** 128 /**
116 * Children of this attribute 129 * Sets under this Queue
117 */ 130 */
118 struct DelegationQueueEntry *children_head; 131 struct DelegationSetEntry *set_entries_head;
119 132
120 /** 133 /**
121 * Children of this attribute 134 * Sets under this Queue
122 */ 135 */
123 struct DelegationQueueEntry *children_tail; 136 struct DelegationSetEntry *set_entries_tail;
124 137
125 /** 138 /**
139 * Parent set
140 */
141 struct DelegationSetEntry *parent_set;
142
143 /**
144 * Required solutions
145 */
146 uint32_t required_solutions;
147};
148
149/**
150 * DLL for delegation sets
151 * Used for AND delegation set
152 */
153struct DelegationSetEntry
154{
155 /**
156 * DLL
157 */
158 struct DelegationSetEntry *next;
159
160 /**
161 * DLL
162 */
163 struct DelegationSetEntry *prev;
164
165 /**
126 * GNS handle 166 * GNS handle
127 */ 167 */
128 struct GNUNET_GNS_LookupRequest *lookup_request; 168 struct GNUNET_GNS_LookupRequest *lookup_request;
@@ -143,6 +183,21 @@ struct DelegationQueueEntry
143 struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key; 183 struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key;
144 184
145 /** 185 /**
186 * Queue entries of this set
187 */
188 struct DelegationQueueEntry *queue_entries_head;
189
190 /**
191 * Queue entries of this set
192 */
193 struct DelegationQueueEntry *queue_entries_tail;
194
195 /**
196 * Parent QueueEntry
197 */
198 struct DelegationQueueEntry *parent_queue_entry;
199
200 /**
146 * Issuer attribute delegated to 201 * Issuer attribute delegated to
147 */ 202 */
148 char *issuer_attribute; 203 char *issuer_attribute;
@@ -161,16 +216,12 @@ struct DelegationQueueEntry
161 * Still to resolve delegation as string 216 * Still to resolve delegation as string
162 */ 217 */
163 char *unresolved_attribute_delegation; 218 char *unresolved_attribute_delegation;
164 219
165 /** 220 /**
166 * The delegation chain entry 221 * The delegation chain entry
167 */ 222 */
168 struct GNUNET_CREDENTIAL_DelegationChainEntry *delegation_chain_entry; 223 struct DelegationChainEntry *delegation_chain_entry;
169 224
170 /**
171 * Delegation chain length until now
172 */
173 uint32_t d_count;
174}; 225};
175 226
176 227
@@ -194,18 +245,32 @@ struct VerifyRequestHandle
194 * Handle to the requesting client 245 * Handle to the requesting client
195 */ 246 */
196 struct GNUNET_SERVICE_Client *client; 247 struct GNUNET_SERVICE_Client *client;
197 248
198 /** 249 /**
199 * GNS handle 250 * GNS handle
200 */ 251 */
201 struct GNUNET_GNS_LookupRequest *lookup_request; 252 struct GNUNET_GNS_LookupRequest *lookup_request;
202 253
254 /**
255 * Size of delegation tree
256 */
257 uint32_t delegation_chain_size;
258
259 /**
260 * Children of this attribute
261 */
262 struct DelegationChainEntry *delegation_chain_head;
263
264 /**
265 * Children of this attribute
266 */
267 struct DelegationChainEntry *delegation_chain_tail;
203 268
204 /** 269 /**
205 * Issuer public key 270 * Issuer public key
206 */ 271 */
207 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key; 272 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
208 273
209 /** 274 /**
210 * Issuer attribute 275 * Issuer attribute
211 */ 276 */
@@ -227,15 +292,10 @@ struct VerifyRequestHandle
227 struct CredentialRecordEntry *cred_chain_tail; 292 struct CredentialRecordEntry *cred_chain_tail;
228 293
229 /** 294 /**
230 * Delegation Queue 295 * Root Delegation Set
231 */ 296 */
232 struct DelegationQueueEntry *chain_start; 297 struct DelegationSetEntry *root_set;
233 298
234 /**
235 * Delegation Queue
236 */
237 struct DelegationQueueEntry *chain_end;
238
239 /** 299 /**
240 * Current Delegation Pointer 300 * Current Delegation Pointer
241 */ 301 */
@@ -252,11 +312,6 @@ struct VerifyRequestHandle
252 uint32_t credential_size; 312 uint32_t credential_size;
253 313
254 /** 314 /**
255 * Length of found delegation chain
256 */
257 uint32_t d_count;
258
259 /**
260 * request id 315 * request id
261 */ 316 */
262 uint32_t request_id; 317 uint32_t request_id;
@@ -291,43 +346,56 @@ static struct GNUNET_GNS_Handle *gns;
291 346
292 347
293static void 348static void
294cleanup_delegation_queue (struct DelegationQueueEntry *dq_entry) 349cleanup_delegation_set (struct DelegationSetEntry *ds_entry)
295{ 350{
296 struct DelegationQueueEntry *child; 351 struct DelegationQueueEntry *dq_entry;
297 if (NULL == dq_entry) 352 struct DelegationSetEntry *child;
353
354 if (NULL == ds_entry)
298 return; 355 return;
299 356
300 for (child = dq_entry->children_head; NULL != child; child = dq_entry->children_head) 357 for (dq_entry = ds_entry->queue_entries_head;
358 NULL != dq_entry;
359 dq_entry = ds_entry->queue_entries_head)
301 { 360 {
302 GNUNET_CONTAINER_DLL_remove (dq_entry->children_head, 361 GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head,
303 dq_entry->children_tail, 362 ds_entry->queue_entries_tail,
304 child); 363 dq_entry);
305 cleanup_delegation_queue (child); 364 for (child = dq_entry->set_entries_head;
365 NULL != child;
366 child = dq_entry->set_entries_head)
367 {
368 GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head,
369 dq_entry->set_entries_tail,
370 child);
371 cleanup_delegation_set (child);
372 }
373 GNUNET_free (dq_entry);
306 } 374 }
307 if (NULL != dq_entry->issuer_key) 375 if (NULL != ds_entry->issuer_key)
308 GNUNET_free (dq_entry->issuer_key); 376 GNUNET_free (ds_entry->issuer_key);
309 if (NULL != dq_entry->lookup_attribute) 377 if (NULL != ds_entry->lookup_attribute)
310 GNUNET_free (dq_entry->lookup_attribute); 378 GNUNET_free (ds_entry->lookup_attribute);
311 if (NULL != dq_entry->issuer_attribute) 379 if (NULL != ds_entry->issuer_attribute)
312 GNUNET_free (dq_entry->issuer_attribute); 380 GNUNET_free (ds_entry->issuer_attribute);
313 if (NULL != dq_entry->unresolved_attribute_delegation) 381 if (NULL != ds_entry->unresolved_attribute_delegation)
314 GNUNET_free (dq_entry->unresolved_attribute_delegation); 382 GNUNET_free (ds_entry->unresolved_attribute_delegation);
315 if (NULL != dq_entry->attr_trailer) 383 if (NULL != ds_entry->attr_trailer)
316 GNUNET_free (dq_entry->attr_trailer); 384 GNUNET_free (ds_entry->attr_trailer);
317 if (NULL != dq_entry->lookup_request) 385 if (NULL != ds_entry->lookup_request)
318 { 386 {
319 GNUNET_GNS_lookup_cancel (dq_entry->lookup_request); 387 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request);
320 dq_entry->lookup_request = NULL; 388 ds_entry->lookup_request = NULL;
321 } 389 }
322 if (NULL != dq_entry->delegation_chain_entry) 390 if (NULL != ds_entry->delegation_chain_entry)
323 { 391 {
324 if (NULL != dq_entry->delegation_chain_entry->subject_attribute) 392 if (NULL != ds_entry->delegation_chain_entry->subject_attribute)
325 GNUNET_free (dq_entry->delegation_chain_entry->subject_attribute); 393 GNUNET_free (ds_entry->delegation_chain_entry->subject_attribute);
326 if (NULL != dq_entry->delegation_chain_entry->issuer_attribute) 394 if (NULL != ds_entry->delegation_chain_entry->issuer_attribute)
327 GNUNET_free (dq_entry->delegation_chain_entry->issuer_attribute); 395 GNUNET_free (ds_entry->delegation_chain_entry->issuer_attribute);
328 GNUNET_free (dq_entry->delegation_chain_entry); 396 GNUNET_free (ds_entry->delegation_chain_entry);
329 } 397 }
330 GNUNET_free (dq_entry); 398 GNUNET_free (ds_entry);
331} 399}
332 400
333static void 401static void
@@ -343,7 +411,7 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
343 } 411 }
344 if (NULL != vrh->credential) 412 if (NULL != vrh->credential)
345 GNUNET_free (vrh->credential); 413 GNUNET_free (vrh->credential);
346 cleanup_delegation_queue (vrh->chain_start); 414 cleanup_delegation_set (vrh->root_set);
347 if (NULL != vrh->issuer_attribute) 415 if (NULL != vrh->issuer_attribute)
348 GNUNET_free (vrh->issuer_attribute); 416 GNUNET_free (vrh->issuer_attribute);
349 for (cr_entry = vrh->cred_chain_head; 417 for (cr_entry = vrh->cred_chain_head;
@@ -444,57 +512,63 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
444{ 512{
445 struct GNUNET_MQ_Envelope *env; 513 struct GNUNET_MQ_Envelope *env;
446 struct VerifyResultMessage *rmsg; 514 struct VerifyResultMessage *rmsg;
447 struct DelegationQueueEntry *dq_entry; 515 struct DelegationChainEntry *dce;
448 size_t size = vrh->credential_size; 516 size_t size = vrh->credential_size;
449 struct GNUNET_CREDENTIAL_Delegation dd[vrh->d_count]; 517 struct GNUNET_CREDENTIAL_Delegation dd[vrh->delegation_chain_size];
450 struct GNUNET_CREDENTIAL_Credential cred; 518 struct GNUNET_CREDENTIAL_Credential cred;
519 int i;
451 520
452 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 521 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
453 "Sending response\n"); 522 "Sending response\n");
454 dq_entry = vrh->chain_end; 523 i = 0;
455 for (int i=0; i<vrh->d_count; i++) 524 for (dce = vrh->delegation_chain_head;
525 NULL != dce;
526 dce = dce->next)
456 { 527 {
457 dd[i].issuer_key = dq_entry->delegation_chain_entry->issuer_key; 528 dd[i].issuer_key = dce->issuer_key;
458 dd[i].subject_key = dq_entry->delegation_chain_entry->subject_key; 529 dd[i].subject_key = dce->subject_key;
459 dd[i].issuer_attribute = dq_entry->delegation_chain_entry->issuer_attribute; 530 dd[i].issuer_attribute = dce->issuer_attribute;
460 dd[i].issuer_attribute_len = strlen (dq_entry->delegation_chain_entry->issuer_attribute)+1; 531 dd[i].issuer_attribute_len = strlen (dce->issuer_attribute)+1;
461 dd[i].subject_attribute_len = 0; 532 dd[i].subject_attribute_len = 0;
462 if (NULL != dq_entry->delegation_chain_entry->subject_attribute) 533 if (NULL != dce->subject_attribute)
463 { 534 {
464 dd[i].subject_attribute = dq_entry->delegation_chain_entry->subject_attribute; 535 dd[i].subject_attribute = dce->subject_attribute;
465 dd[i].subject_attribute_len = strlen(dq_entry->delegation_chain_entry->subject_attribute)+1; 536 dd[i].subject_attribute_len = strlen(dce->subject_attribute)+1;
466 } 537 }
467 dq_entry = dq_entry->parent; 538 i++;
468 } 539 }
469 540
470 /** 541 /**
471 * Get serialized record data 542 * Get serialized record data
472 * Append at the end of rmsg 543 * Append at the end of rmsg
473 */ 544 */
474 cred.issuer_key = vrh->credential->issuer_key; 545 cred.issuer_key = vrh->credential->issuer_key;
475 cred.subject_key = vrh->credential->subject_key; 546 cred.subject_key = vrh->credential->subject_key;
476 cred.issuer_attribute_len = strlen((char*)&vrh->credential[1]); 547 cred.issuer_attribute_len = strlen((char*)&vrh->credential[1])+1;
477 cred.issuer_attribute = (char*)&vrh->credential[1]; 548 cred.issuer_attribute = (char*)&vrh->credential[1];
478 size = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->d_count, 549 size = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size,
479 dd, 550 dd,
480 &cred); 551 &cred);
552 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
553 "SIZE; %llu count: %d\n",size,vrh->delegation_chain_size);
481 env = GNUNET_MQ_msg_extra (rmsg, 554 env = GNUNET_MQ_msg_extra (rmsg,
482 size, 555 size,
483 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); 556 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT);
484 //Assign id so that client can find associated request 557 //Assign id so that client can find associated request
485 rmsg->id = vrh->request_id; 558 rmsg->id = vrh->request_id;
486 rmsg->d_count = htonl (vrh->d_count); 559 rmsg->d_count = htonl (vrh->delegation_chain_size);
487 560
488 if (NULL != vrh->credential) 561 if (NULL != vrh->credential)
489 rmsg->cred_found = htonl (GNUNET_YES); 562 rmsg->cred_found = htonl (GNUNET_YES);
490 else 563 else
491 rmsg->cred_found = htonl (GNUNET_NO); 564 rmsg->cred_found = htonl (GNUNET_NO);
492 565
493 GNUNET_assert (-1 != GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->d_count, 566 GNUNET_assert (-1 !=
494 dd, 567 GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size,
495 &cred, 568 dd,
496 size, 569 &cred,
497 (char*)&rmsg[1])); 570 size,
571 (char*)&rmsg[1]));
498 572
499 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client), 573 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client),
500 env); 574 env);
@@ -515,146 +589,194 @@ backward_resolution (void* cls,
515 589
516 struct VerifyRequestHandle *vrh; 590 struct VerifyRequestHandle *vrh;
517 struct GNUNET_CREDENTIAL_CredentialRecordData *cred; 591 struct GNUNET_CREDENTIAL_CredentialRecordData *cred;
518 const struct GNUNET_CREDENTIAL_AttributeRecordData *attr; 592 const struct GNUNET_CREDENTIAL_DelegationRecordData *sets;
519 struct CredentialRecordEntry *cred_pointer; 593 struct CredentialRecordEntry *cred_pointer;
520 struct DelegationQueueEntry *current_delegation; 594 struct DelegationSetEntry *current_set;
595 struct DelegationSetEntry *ds_entry;
596 struct DelegationSetEntry *tmp_set;
521 struct DelegationQueueEntry *dq_entry; 597 struct DelegationQueueEntry *dq_entry;
522 char *expanded_attr; 598 char *expanded_attr;
523 char *lookup_attribute; 599 char *lookup_attribute;
524 int i; 600 int i;
601 int j;
525 602
526 603
527 current_delegation = cls; 604 current_set = cls;
528 current_delegation->lookup_request = NULL; 605 current_set->lookup_request = NULL;
529 vrh = current_delegation->handle; 606 vrh = current_set->handle;
530 vrh->pending_lookups--; 607 vrh->pending_lookups--;
531 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 608 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
532 "Got %d attrs\n", rd_count); 609 "Got %d attrs\n", rd_count);
533 610
611 // Each OR
534 for (i=0; i < rd_count; i++) 612 for (i=0; i < rd_count; i++)
535 { 613 {
536 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) 614 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
537 continue; 615 continue;
538 616
617 sets = rd[i].data;
618 struct GNUNET_CREDENTIAL_DelegationSetRecord set[ntohl(sets->set_count)];
539 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 619 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
540 "Found new attribute delegation. Creating new Job...\n"); 620 "Found new attribute delegation with %d sets. Creating new Job...\n",
541 attr = rd[i].data; 621 ntohl (sets->set_count));
622
623 if (GNUNET_OK !=GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll(sets->data_size),
624 (const char*)&sets[1],
625 ntohl(sets->set_count),
626 set))
627 {
628 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
629 "Failed to deserialize!\n");
630 continue;
631 }
542 dq_entry = GNUNET_new (struct DelegationQueueEntry); 632 dq_entry = GNUNET_new (struct DelegationQueueEntry);
543 if (NULL != current_delegation->attr_trailer) 633 dq_entry->required_solutions = ntohl(sets->set_count);
634 dq_entry->parent_set = current_set;
635 GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head,
636 current_set->queue_entries_tail,
637 dq_entry);
638 // Each AND
639 for (j=0; j<ntohl(sets->set_count); j++)
544 { 640 {
545 if (rd[i].data_size == sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData)) 641 ds_entry = GNUNET_new (struct DelegationSetEntry);
642 if (NULL != current_set->attr_trailer)
546 { 643 {
547 GNUNET_asprintf (&expanded_attr, 644 if (0 == set[j].subject_attribute_len)
548 "%s", 645 {
549 current_delegation->attr_trailer); 646 GNUNET_asprintf (&expanded_attr,
550 647 "%s",
648 current_set->attr_trailer);
649
650 } else {
651 GNUNET_asprintf (&expanded_attr,
652 "%s.%s",
653 set[j].subject_attribute,
654 current_set->attr_trailer);
655 }
656 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
657 "Expanded to %s\n", expanded_attr);
658 ds_entry->unresolved_attribute_delegation = expanded_attr;
551 } else { 659 } else {
552 GNUNET_asprintf (&expanded_attr, 660 if (0 != set[j].subject_attribute_len)
553 "%s.%s", 661 {
554 (char*)&attr[1], 662 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 current_delegation->attr_trailer); 663 "Not Expanding %s\n", set[j].subject_attribute);
664 ds_entry->unresolved_attribute_delegation = GNUNET_strdup (set[j].subject_attribute);
665 }
556 } 666 }
667
668 //Add a credential chain entry
669 ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry);
670 ds_entry->delegation_chain_entry->subject_key = set[j].subject_key;
671 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
672 GNUNET_memcpy (ds_entry->issuer_key,
673 &set[j].subject_key,
674 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
675 if (0 < set[j].subject_attribute_len)
676 ds_entry->delegation_chain_entry->subject_attribute = GNUNET_strdup (set[j].subject_attribute);
677 ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
678 ds_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (current_set->lookup_attribute);
679
680 ds_entry->parent_queue_entry = dq_entry; //current_delegation;
681 GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head,
682 dq_entry->set_entries_tail,
683 ds_entry);
684
557 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 685 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
558 "Expanded to %s\n", expanded_attr); 686 "Checking for cred match\n");
559 dq_entry->unresolved_attribute_delegation = expanded_attr; 687 /**
560 } else { 688 * Check if this delegation already matches one of our credentials
561 if (rd[i].data_size > sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData)) 689 */
690 for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
691 cred_pointer = cred_pointer->next)
562 { 692 {
693 cred = cred_pointer->data;
694 if(0 != memcmp (&set->subject_key,
695 &cred_pointer->data->issuer_key,
696 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
697 continue;
563 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 698 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
564 "Not Expanding %s\n", (char*)&attr[1]); 699 "Checking if %s matches %s\n",
565 dq_entry->unresolved_attribute_delegation = GNUNET_strdup ((char*)&attr[1]); 700 ds_entry->unresolved_attribute_delegation, (char*)&cred[1]);
566 }
567 }
568 701
569 //Add a credential chain entry 702 if (0 != strcmp (ds_entry->unresolved_attribute_delegation, (char*)&cred[1]))
570 dq_entry->delegation_chain_entry = GNUNET_new (struct GNUNET_CREDENTIAL_DelegationChainEntry); 703 continue;
571 dq_entry->delegation_chain_entry->subject_key = attr->subject_key;
572 dq_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
573 GNUNET_memcpy (dq_entry->issuer_key,
574 &attr->subject_key,
575 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
576 if (rd[i].data_size > sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData))
577 dq_entry->delegation_chain_entry->subject_attribute = GNUNET_strdup ((char*)&attr[1]);
578 dq_entry->delegation_chain_entry->issuer_key = *current_delegation->issuer_key;
579 dq_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (current_delegation->lookup_attribute);
580
581 dq_entry->parent = current_delegation;
582 dq_entry->d_count = current_delegation->d_count + 1;
583 GNUNET_CONTAINER_DLL_insert (current_delegation->children_head,
584 current_delegation->children_tail,
585 dq_entry);
586 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
587 "Checking for cred match\n");
588 /**
589 * Check if this delegation already matches one of our credentials
590 */
591 for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
592 cred_pointer = cred_pointer->next)
593 {
594 cred = cred_pointer->data;
595 if(0 != memcmp (&attr->subject_key,
596 &cred_pointer->data->issuer_key,
597 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
598 continue;
599 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
600 "Checking if %s matches %s\n",
601 dq_entry->unresolved_attribute_delegation, (char*)&cred[1]);
602 704
603 if (0 != strcmp (dq_entry->unresolved_attribute_delegation, (char*)&cred[1])) 705 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
604 continue; 706 "Found issuer\n");
707
708 //Backtrack
709 for (tmp_set = ds_entry;
710 NULL != tmp_set->parent_queue_entry;
711 tmp_set = tmp_set->parent_queue_entry->parent_set)
712 {
713 tmp_set->parent_queue_entry->required_solutions--;
714 if (NULL != tmp_set->delegation_chain_entry)
715 {
716 vrh->delegation_chain_size++;
717 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
718 vrh->delegation_chain_tail,
719 tmp_set->delegation_chain_entry);
720 }
721 if (0 < tmp_set->parent_queue_entry->required_solutions)
722 break;
723 }
724
725 if (NULL == tmp_set->parent_queue_entry)
726 {
727 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
728 "All solutions found\n");
729 vrh->credential = GNUNET_malloc (cred_pointer->data_size);
730 memcpy (vrh->credential,
731 cred,
732 cred_pointer->data_size);
733 vrh->credential_size = cred_pointer->data_size;
734 //Found match
735 send_lookup_response (vrh);
736 return;
737 }
605 738
739 }
606 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 740 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
607 "Found issuer\n"); 741 "Building new lookup request from %s\n",
608 vrh->credential = GNUNET_malloc (cred_pointer->data_size); 742 ds_entry->unresolved_attribute_delegation);
609 memcpy (vrh->credential, 743 //Continue with backward resolution
610 cred, 744 char issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation)+1];
611 cred_pointer->data_size); 745 strcpy (issuer_attribute_name,
612 vrh->credential_size = cred_pointer->data_size; 746 ds_entry->unresolved_attribute_delegation);
613 vrh->chain_end = dq_entry; 747 char *next_attr = strtok (issuer_attribute_name, ".");
614 vrh->d_count = dq_entry->d_count; 748 GNUNET_asprintf (&lookup_attribute,
615 //Found match 749 "%s.gnu",
616 send_lookup_response (vrh); 750 next_attr);
617 return; 751 GNUNET_asprintf (&ds_entry->lookup_attribute,
618 752 "%s",
619 } 753 next_attr);
620 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 754 if (strlen (next_attr) == strlen (ds_entry->unresolved_attribute_delegation))
621 "Building new lookup request\n"); 755 {
622 //Continue with backward resolution 756 ds_entry->attr_trailer = NULL;
623 char issuer_attribute_name[strlen (dq_entry->unresolved_attribute_delegation)+1]; 757 } else {
624 strcpy (issuer_attribute_name, 758 next_attr += strlen (next_attr) + 1;
625 dq_entry->unresolved_attribute_delegation); 759 ds_entry->attr_trailer = GNUNET_strdup (next_attr);
626 char *next_attr = strtok (issuer_attribute_name, "."); 760 }
627 GNUNET_asprintf (&lookup_attribute,
628 "%s.gnu",
629 next_attr);
630 GNUNET_asprintf (&dq_entry->lookup_attribute,
631 "%s",
632 next_attr);
633 if (strlen (next_attr) == strlen (dq_entry->unresolved_attribute_delegation))
634 {
635 dq_entry->attr_trailer = NULL;
636 } else {
637 next_attr += strlen (next_attr) + 1;
638 dq_entry->attr_trailer = GNUNET_strdup (next_attr);
639 }
640 761
641 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
642 "Looking up %s\n", dq_entry->lookup_attribute);
643 if (NULL != dq_entry->attr_trailer)
644 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 762 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
645 "%s still to go...\n", dq_entry->attr_trailer); 763 "Looking up %s\n", ds_entry->lookup_attribute);
646 764 if (NULL != ds_entry->attr_trailer)
647 vrh->pending_lookups++; 765 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
648 dq_entry->handle = vrh; 766 "%s still to go...\n", ds_entry->attr_trailer);
649 dq_entry->lookup_request = GNUNET_GNS_lookup (gns, 767
650 lookup_attribute, 768 vrh->pending_lookups++;
651 dq_entry->issuer_key, //issuer_key, 769 ds_entry->handle = vrh;
652 GNUNET_GNSRECORD_TYPE_ATTRIBUTE, 770 ds_entry->lookup_request = GNUNET_GNS_lookup (gns,
653 GNUNET_GNS_LO_DEFAULT, 771 lookup_attribute,
654 NULL, //shorten_key, always NULL 772 ds_entry->issuer_key, //issuer_key,
655 &backward_resolution, 773 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
656 dq_entry); 774 GNUNET_GNS_LO_DEFAULT,
657 GNUNET_free (lookup_attribute); 775 NULL, //shorten_key, always NULL
776 &backward_resolution,
777 ds_entry);
778 GNUNET_free (lookup_attribute);
779 }
658 } 780 }
659 781
660 if(0 == vrh->pending_lookups) 782 if(0 == vrh->pending_lookups)
@@ -681,7 +803,7 @@ handle_credential_query (void* cls,
681 const struct GNUNET_GNSRECORD_Data *rd) 803 const struct GNUNET_GNSRECORD_Data *rd)
682{ 804{
683 struct VerifyRequestHandle *vrh = cls; 805 struct VerifyRequestHandle *vrh = cls;
684 struct DelegationQueueEntry *dq_entry; 806 struct DelegationSetEntry *ds_entry;
685 const struct GNUNET_CREDENTIAL_CredentialRecordData *crd; 807 const struct GNUNET_CREDENTIAL_CredentialRecordData *crd;
686 struct CredentialRecordEntry *cr_entry; 808 struct CredentialRecordEntry *cr_entry;
687 int cred_record_count; 809 int cred_record_count;
@@ -725,7 +847,6 @@ handle_credential_query (void* cls,
725 rd[i].data, 847 rd[i].data,
726 rd[i].data_size); 848 rd[i].data_size);
727 vrh->credential_size = rd[i].data_size; 849 vrh->credential_size = rd[i].data_size;
728 vrh->chain_end = NULL;
729 //Found match prematurely 850 //Found match prematurely
730 send_lookup_response (vrh); 851 send_lookup_response (vrh);
731 return; 852 return;
@@ -743,26 +864,25 @@ handle_credential_query (void* cls,
743 ".gnu"); 864 ".gnu");
744 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 865 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
745 "Looking up %s\n", issuer_attribute_name); 866 "Looking up %s\n", issuer_attribute_name);
746 dq_entry = GNUNET_new (struct DelegationQueueEntry); 867 ds_entry = GNUNET_new (struct DelegationSetEntry);
747 dq_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 868 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
748 memcpy (dq_entry->issuer_key, 869 memcpy (ds_entry->issuer_key,
749 &vrh->issuer_key, 870 &vrh->issuer_key,
750 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 871 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
751 dq_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); 872 ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute);
752 dq_entry->handle = vrh; 873 ds_entry->handle = vrh;
753 dq_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute); 874 ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute);
754 dq_entry->d_count = 0; 875 vrh->root_set = ds_entry;
755 vrh->chain_start = dq_entry;
756 vrh->pending_lookups = 1; 876 vrh->pending_lookups = 1;
757 //Start with backward resolution 877 //Start with backward resolution
758 dq_entry->lookup_request = GNUNET_GNS_lookup (gns, 878 ds_entry->lookup_request = GNUNET_GNS_lookup (gns,
759 issuer_attribute_name, 879 issuer_attribute_name,
760 &vrh->issuer_key, //issuer_key, 880 &vrh->issuer_key, //issuer_key,
761 GNUNET_GNSRECORD_TYPE_ATTRIBUTE, 881 GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
762 GNUNET_GNS_LO_DEFAULT, 882 GNUNET_GNS_LO_DEFAULT,
763 NULL, //shorten_key, always NULL 883 NULL, //shorten_key, always NULL
764 &backward_resolution, 884 &backward_resolution,
765 dq_entry); 885 ds_entry);
766} 886}
767 887
768 888
@@ -819,7 +939,7 @@ handle_verify (void *cls,
819 send_lookup_response (vrh); 939 send_lookup_response (vrh);
820 return; 940 return;
821 } 941 }
822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 942 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
823 "Looking up %s\n", 943 "Looking up %s\n",
824 subject_attribute); 944 subject_attribute);
825 /** 945 /**