diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2016-12-13 20:11:14 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2016-12-13 20:11:14 +0100 |
commit | 490a5b6451470aef6a5a963e4ccef3b2ca5cd326 (patch) | |
tree | 5fda56e93fa53b073b4951544936f6cdc6ac743b /src/credential | |
parent | d03ce063cf660a1f9f37b917eab3747a40937d68 (diff) | |
download | gnunet-490a5b6451470aef6a5a963e4ccef3b2ca5cd326.tar.gz gnunet-490a5b6451470aef6a5a963e4ccef3b2ca5cd326.zip |
-add parallel delegationr resolution
Diffstat (limited to 'src/credential')
-rw-r--r-- | src/credential/gnunet-service-credential.c | 460 |
1 files changed, 301 insertions, 159 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c index e0e845468..ea74bd7d2 100644 --- a/src/credential/gnunet-service-credential.c +++ b/src/credential/gnunet-service-credential.c | |||
@@ -43,6 +43,31 @@ | |||
43 | 43 | ||
44 | #define GNUNET_CREDENTIAL_MAX_LENGTH 255 | 44 | #define GNUNET_CREDENTIAL_MAX_LENGTH 255 |
45 | 45 | ||
46 | struct VerifyRequestHandle; | ||
47 | |||
48 | struct GNUNET_CREDENTIAL_DelegationChainEntry | ||
49 | { | ||
50 | /** | ||
51 | * The issuer | ||
52 | */ | ||
53 | struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key; | ||
54 | |||
55 | /** | ||
56 | * The subject | ||
57 | */ | ||
58 | struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; | ||
59 | |||
60 | /** | ||
61 | * The issued attribute | ||
62 | */ | ||
63 | char *issuer_attribute; | ||
64 | |||
65 | /** | ||
66 | * The delegated attribute | ||
67 | */ | ||
68 | char *subject_attribute; | ||
69 | }; | ||
70 | |||
46 | /** | 71 | /** |
47 | * DLL for record | 72 | * DLL for record |
48 | */ | 73 | */ |
@@ -71,40 +96,75 @@ struct CredentialRecordEntry | |||
71 | }; | 96 | }; |
72 | 97 | ||
73 | /** | 98 | /** |
74 | * DLL for attributes - Used as a queue | 99 | * DLL for delegations - Used as a queue |
75 | * Insert tail - Pop head | 100 | * Insert tail - Pop head |
76 | */ | 101 | */ |
77 | struct AttributeQueueEntry | 102 | struct DelegationQueueEntry |
78 | { | 103 | { |
79 | /** | 104 | /** |
80 | * DLL | 105 | * DLL |
81 | */ | 106 | */ |
82 | struct AttributeQueueEntry *next; | 107 | struct DelegationQueueEntry *next; |
83 | 108 | ||
84 | /** | 109 | /** |
85 | * DLL | 110 | * DLL |
86 | */ | 111 | */ |
87 | struct AttributeQueueEntry *prev; | 112 | struct DelegationQueueEntry *prev; |
88 | 113 | ||
89 | /** | 114 | /** |
90 | * Payload | 115 | * Children of this attribute |
91 | */ | 116 | */ |
92 | struct GNUNET_CREDENTIAL_AttributeRecordData *data; | 117 | struct DelegationQueueEntry *children_head; |
93 | 118 | ||
94 | /** | 119 | /** |
95 | * Size | 120 | * Children of this attribute |
96 | */ | 121 | */ |
97 | uint64_t data_size; | 122 | struct DelegationQueueEntry *children_tail; |
123 | |||
124 | /** | ||
125 | * GNS handle | ||
126 | */ | ||
127 | struct GNUNET_GNS_LookupRequest *lookup_request; | ||
128 | |||
129 | /** | ||
130 | * Verify handle | ||
131 | */ | ||
132 | struct VerifyRequestHandle *handle; | ||
98 | 133 | ||
99 | /** | 134 | /** |
100 | * Parent attribute delegation | 135 | * Parent attribute delegation |
101 | */ | 136 | */ |
102 | struct AttributeQueueEntry *parent; | 137 | struct DelegationQueueEntry *parent; |
138 | |||
139 | /** | ||
140 | * Issuer key | ||
141 | */ | ||
142 | struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key; | ||
143 | |||
144 | /** | ||
145 | * Issuer attribute delegated to | ||
146 | */ | ||
147 | char *issuer_attribute; | ||
148 | |||
149 | /** | ||
150 | * The current attribute to look up | ||
151 | */ | ||
152 | char *lookup_attribute; | ||
103 | 153 | ||
104 | /** | 154 | /** |
105 | * Trailing attribute context | 155 | * Trailing attribute context |
106 | */ | 156 | */ |
107 | char *attr_trailer; | 157 | char *attr_trailer; |
158 | |||
159 | /** | ||
160 | * Still to resolve delegation as string | ||
161 | */ | ||
162 | char *unresolved_attribute_delegation; | ||
163 | |||
164 | /** | ||
165 | * The delegation chain entry | ||
166 | */ | ||
167 | struct GNUNET_CREDENTIAL_DelegationChainEntry *delegation_chain_entry; | ||
108 | }; | 168 | }; |
109 | 169 | ||
110 | 170 | ||
@@ -128,12 +188,13 @@ struct VerifyRequestHandle | |||
128 | * Handle to the requesting client | 188 | * Handle to the requesting client |
129 | */ | 189 | */ |
130 | struct GNUNET_SERVICE_Client *client; | 190 | struct GNUNET_SERVICE_Client *client; |
131 | 191 | ||
132 | /** | 192 | /** |
133 | * Handle to GNS lookup | 193 | * GNS handle |
134 | */ | 194 | */ |
135 | struct GNUNET_GNS_LookupRequest *lookup_request; | 195 | struct GNUNET_GNS_LookupRequest *lookup_request; |
136 | 196 | ||
197 | |||
137 | /** | 198 | /** |
138 | * Issuer public key | 199 | * Issuer public key |
139 | */ | 200 | */ |
@@ -165,19 +226,19 @@ struct VerifyRequestHandle | |||
165 | uint32_t cred_chain_entries; | 226 | uint32_t cred_chain_entries; |
166 | 227 | ||
167 | /** | 228 | /** |
168 | * Attribute Queue | 229 | * Delegation Queue |
169 | */ | 230 | */ |
170 | struct AttributeQueueEntry *attr_queue_head; | 231 | struct DelegationQueueEntry *chain_start; |
171 | 232 | ||
172 | /** | 233 | /** |
173 | * Attribute Queue | 234 | * Delegation Queue |
174 | */ | 235 | */ |
175 | struct AttributeQueueEntry *attr_queue_tail; | 236 | struct DelegationQueueEntry *chain_end; |
176 | 237 | ||
177 | /** | 238 | /** |
178 | * Current Attribute Pointer | 239 | * Current Delegation Pointer |
179 | */ | 240 | */ |
180 | struct AttributeQueueEntry *current_attribute; | 241 | struct DelegationQueueEntry *current_delegation; |
181 | 242 | ||
182 | /** | 243 | /** |
183 | * The found credential | 244 | * The found credential |
@@ -194,6 +255,11 @@ struct VerifyRequestHandle | |||
194 | */ | 255 | */ |
195 | uint32_t request_id; | 256 | uint32_t request_id; |
196 | 257 | ||
258 | /** | ||
259 | * Pending lookups | ||
260 | */ | ||
261 | uint64_t pending_lookups; | ||
262 | |||
197 | }; | 263 | }; |
198 | 264 | ||
199 | 265 | ||
@@ -212,13 +278,58 @@ static struct VerifyRequestHandle *vrh_tail; | |||
212 | */ | 278 | */ |
213 | static struct GNUNET_STATISTICS_Handle *statistics; | 279 | static struct GNUNET_STATISTICS_Handle *statistics; |
214 | 280 | ||
215 | |||
216 | |||
217 | /** | 281 | /** |
218 | * Handle to GNS service. | 282 | * Handle to GNS service. |
219 | */ | 283 | */ |
220 | static struct GNUNET_GNS_Handle *gns; | 284 | static struct GNUNET_GNS_Handle *gns; |
221 | 285 | ||
286 | |||
287 | static void | ||
288 | cleanup_delegation_queue (struct DelegationQueueEntry *dq_entry) | ||
289 | { | ||
290 | struct DelegationQueueEntry *child; | ||
291 | if (NULL == dq_entry) | ||
292 | return; | ||
293 | |||
294 | for (child = dq_entry->children_head; NULL != child; child = dq_entry->children_head) | ||
295 | { | ||
296 | GNUNET_CONTAINER_DLL_remove (dq_entry->children_head, | ||
297 | dq_entry->children_tail, | ||
298 | child); | ||
299 | cleanup_delegation_queue (child); | ||
300 | } | ||
301 | if (NULL != dq_entry->lookup_request) | ||
302 | { | ||
303 | GNUNET_GNS_lookup_cancel (dq_entry->lookup_request); | ||
304 | dq_entry->lookup_request = NULL; | ||
305 | } | ||
306 | if (NULL != dq_entry->delegation_chain_entry) | ||
307 | { | ||
308 | if (NULL != dq_entry->delegation_chain_entry->subject_attribute) | ||
309 | GNUNET_free (dq_entry->delegation_chain_entry->subject_attribute); | ||
310 | if (NULL != dq_entry->delegation_chain_entry->issuer_attribute) | ||
311 | GNUNET_free (dq_entry->delegation_chain_entry->issuer_attribute); | ||
312 | GNUNET_free (dq_entry->delegation_chain_entry); | ||
313 | } | ||
314 | GNUNET_free (dq_entry); | ||
315 | } | ||
316 | |||
317 | static void | ||
318 | cleanup_handle (struct VerifyRequestHandle *vrh) | ||
319 | { | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
321 | "Cleaning up...\n"); | ||
322 | if (NULL != vrh->lookup_request) | ||
323 | { | ||
324 | GNUNET_GNS_lookup_cancel (vrh->lookup_request); | ||
325 | vrh->lookup_request = NULL; | ||
326 | } | ||
327 | cleanup_delegation_queue (vrh->chain_start); | ||
328 | if (NULL != vrh->issuer_attribute) | ||
329 | GNUNET_free (vrh->issuer_attribute); | ||
330 | GNUNET_free (vrh); | ||
331 | } | ||
332 | |||
222 | /** | 333 | /** |
223 | * Task run during shutdown. | 334 | * Task run during shutdown. |
224 | * | 335 | * |
@@ -229,16 +340,17 @@ static void | |||
229 | shutdown_task (void *cls) | 340 | shutdown_task (void *cls) |
230 | { | 341 | { |
231 | struct VerifyRequestHandle *vrh; | 342 | struct VerifyRequestHandle *vrh; |
232 | 343 | ||
233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 344 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
234 | "Shutting down!\n"); | 345 | "Shutting down!\n"); |
346 | |||
235 | while (NULL != (vrh = vrh_head)) | 347 | while (NULL != (vrh = vrh_head)) |
236 | { | 348 | { |
237 | //CREDENTIAL_resolver_lookup_cancel (clh->lookup); | 349 | //CREDENTIAL_resolver_lookup_cancel (clh->lookup); |
238 | GNUNET_CONTAINER_DLL_remove (vrh_head, | 350 | GNUNET_CONTAINER_DLL_remove (vrh_head, |
239 | vrh_tail, | 351 | vrh_tail, |
240 | vrh); | 352 | vrh); |
241 | GNUNET_free (vrh); | 353 | cleanup_handle (vrh); |
242 | } | 354 | } |
243 | 355 | ||
244 | if (NULL != gns) | 356 | if (NULL != gns) |
@@ -252,7 +364,7 @@ shutdown_task (void *cls) | |||
252 | GNUNET_NO); | 364 | GNUNET_NO); |
253 | statistics = NULL; | 365 | statistics = NULL; |
254 | } | 366 | } |
255 | 367 | ||
256 | } | 368 | } |
257 | 369 | ||
258 | /** | 370 | /** |
@@ -264,7 +376,7 @@ shutdown_task (void *cls) | |||
264 | */ | 376 | */ |
265 | static int | 377 | static int |
266 | check_verify (void *cls, | 378 | check_verify (void *cls, |
267 | const struct VerifyMessage *v_msg) | 379 | const struct VerifyMessage *v_msg) |
268 | { | 380 | { |
269 | size_t msg_size; | 381 | size_t msg_size; |
270 | const char* attrs; | 382 | const char* attrs; |
@@ -282,7 +394,7 @@ check_verify (void *cls, | |||
282 | return GNUNET_SYSERR; | 394 | return GNUNET_SYSERR; |
283 | } | 395 | } |
284 | attrs = (const char *) &v_msg[1]; | 396 | attrs = (const char *) &v_msg[1]; |
285 | 397 | ||
286 | if ( ('\0' != attrs[ntohs(v_msg->header.size) - sizeof (struct VerifyMessage) - 1]) || | 398 | if ( ('\0' != attrs[ntohs(v_msg->header.size) - sizeof (struct VerifyMessage) - 1]) || |
287 | (strlen (attrs) > GNUNET_CREDENTIAL_MAX_LENGTH * 2) ) | 399 | (strlen (attrs) > GNUNET_CREDENTIAL_MAX_LENGTH * 2) ) |
288 | { | 400 | { |
@@ -300,21 +412,27 @@ check_verify (void *cls, | |||
300 | static void | 412 | static void |
301 | send_lookup_response (struct VerifyRequestHandle *vrh) | 413 | send_lookup_response (struct VerifyRequestHandle *vrh) |
302 | { | 414 | { |
303 | size_t len; | ||
304 | struct GNUNET_MQ_Envelope *env; | 415 | struct GNUNET_MQ_Envelope *env; |
305 | struct VerifyResultMessage *rmsg; | 416 | struct VerifyResultMessage *rmsg; |
417 | struct DelegationQueueEntry *dq_entry; | ||
418 | char *write_ptr; | ||
419 | size_t size = vrh->credential_size; | ||
306 | 420 | ||
307 | /** | 421 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
308 | * Get serialized record data size | 422 | "Sending response\n"); |
309 | */ | 423 | |
310 | len = vrh->credential_size; //TODO max length of attr | 424 | for (dq_entry = vrh->chain_end; NULL != dq_entry; dq_entry = dq_entry->parent) |
425 | { | ||
426 | if (NULL == dq_entry->delegation_chain_entry) | ||
427 | break; | ||
428 | size += sizeof (struct GNUNET_CREDENTIAL_DelegationChainEntry); | ||
429 | if (NULL != dq_entry->delegation_chain_entry->subject_attribute) | ||
430 | size += strlen (dq_entry->delegation_chain_entry->subject_attribute) + 1; | ||
431 | size += strlen(dq_entry->delegation_chain_entry->issuer_attribute) + 1; | ||
432 | } | ||
311 | 433 | ||
312 | //TODO add attr chain | ||
313 | /** | ||
314 | * Prepare a lookup result response message for the client | ||
315 | */ | ||
316 | env = GNUNET_MQ_msg_extra (rmsg, | 434 | env = GNUNET_MQ_msg_extra (rmsg, |
317 | len, | 435 | size, |
318 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); | 436 | GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT); |
319 | //Assign id so that client can find associated request | 437 | //Assign id so that client can find associated request |
320 | rmsg->id = vrh->request_id; | 438 | rmsg->id = vrh->request_id; |
@@ -325,6 +443,7 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
325 | * Append at the end of rmsg | 443 | * Append at the end of rmsg |
326 | */ | 444 | */ |
327 | rmsg->cred_found = htonl (GNUNET_NO); | 445 | rmsg->cred_found = htonl (GNUNET_NO); |
446 | |||
328 | if (NULL != vrh->credential) | 447 | if (NULL != vrh->credential) |
329 | { | 448 | { |
330 | memcpy (&rmsg[1], | 449 | memcpy (&rmsg[1], |
@@ -332,26 +451,33 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
332 | vrh->credential_size); | 451 | vrh->credential_size); |
333 | rmsg->cred_found = htonl (GNUNET_YES); | 452 | rmsg->cred_found = htonl (GNUNET_YES); |
334 | } | 453 | } |
335 | 454 | //TODO refactor into serializer module | |
336 | /*char* tmp_entry = (char*)&rmsg[1]; | 455 | write_ptr = (char*)&rmsg[1] + vrh->credential_size; |
337 | for (cr_entry = vrh->cred_chain_head; NULL != cr_entry; cr_entry = cr_entry->next) | 456 | for (dq_entry = vrh->chain_end; NULL != dq_entry; dq_entry = dq_entry->parent) |
457 | { | ||
458 | if (NULL == dq_entry->delegation_chain_entry) | ||
459 | break; | ||
460 | memcpy (write_ptr, | ||
461 | dq_entry->delegation_chain_entry, | ||
462 | sizeof (struct GNUNET_CREDENTIAL_DelegationChainEntry)); | ||
463 | write_ptr += sizeof (struct GNUNET_CREDENTIAL_DelegationChainEntry); | ||
464 | if (NULL != dq_entry->delegation_chain_entry->subject_attribute) | ||
338 | { | 465 | { |
339 | memcpy (tmp_entry, | 466 | GNUNET_snprintf (write_ptr, |
340 | &cr_entry->record_data, | 467 | strlen (dq_entry->delegation_chain_entry->subject_attribute) + 2, |
341 | cr_entry->record_data_size); | 468 | "%s;", |
342 | tmp_entry += cr_entry->record_data_size; | 469 | dq_entry->delegation_chain_entry->subject_attribute); |
343 | }*/ | 470 | write_ptr += strlen (dq_entry->delegation_chain_entry->subject_attribute) + 1; |
471 | } | ||
472 | memcpy (write_ptr, | ||
473 | dq_entry->delegation_chain_entry->issuer_attribute, | ||
474 | strlen(dq_entry->delegation_chain_entry->issuer_attribute)); | ||
475 | write_ptr += strlen(dq_entry->delegation_chain_entry->issuer_attribute) + 1; | ||
476 | } | ||
344 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client), | 477 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client), |
345 | env); | 478 | env); |
346 | |||
347 | GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); | 479 | GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); |
348 | 480 | cleanup_handle(vrh); | |
349 | /** | ||
350 | * TODO: | ||
351 | * - Free DLL | ||
352 | * - Refactor into cleanup_handle() function for this | ||
353 | */ | ||
354 | GNUNET_free (vrh); | ||
355 | 481 | ||
356 | GNUNET_STATISTICS_update (statistics, | 482 | GNUNET_STATISTICS_update (statistics, |
357 | "Completed verifications", 1, | 483 | "Completed verifications", 1, |
@@ -360,20 +486,26 @@ send_lookup_response (struct VerifyRequestHandle *vrh) | |||
360 | 486 | ||
361 | 487 | ||
362 | static void | 488 | static void |
363 | start_backward_resolution (void* cls, | 489 | backward_resolution (void* cls, |
364 | uint32_t rd_count, | 490 | uint32_t rd_count, |
365 | const struct GNUNET_GNSRECORD_Data *rd) | 491 | const struct GNUNET_GNSRECORD_Data *rd) |
366 | { | 492 | { |
367 | struct VerifyRequestHandle *vrh = cls; | 493 | |
494 | struct VerifyRequestHandle *vrh; | ||
368 | struct GNUNET_CREDENTIAL_CredentialRecordData *cred; | 495 | struct GNUNET_CREDENTIAL_CredentialRecordData *cred; |
369 | const struct GNUNET_CREDENTIAL_AttributeRecordData *attr; | 496 | const struct GNUNET_CREDENTIAL_AttributeRecordData *attr; |
370 | struct CredentialRecordEntry *cred_pointer; | 497 | struct CredentialRecordEntry *cred_pointer; |
371 | struct AttributeQueueEntry *attr_entry; | 498 | struct DelegationQueueEntry *current_delegation; |
499 | struct DelegationQueueEntry *dq_entry; | ||
372 | char *expanded_attr; | 500 | char *expanded_attr; |
373 | char *check_attr; | ||
374 | int i; | 501 | int i; |
375 | 502 | ||
376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 503 | |
504 | current_delegation = cls; | ||
505 | current_delegation->lookup_request = NULL; | ||
506 | vrh = current_delegation->handle; | ||
507 | vrh->pending_lookups--; | ||
508 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
377 | "Got %d attrs\n", rd_count); | 509 | "Got %d attrs\n", rd_count); |
378 | 510 | ||
379 | for (i=0; i < rd_count; i++) | 511 | for (i=0; i < rd_count; i++) |
@@ -381,131 +513,129 @@ start_backward_resolution (void* cls, | |||
381 | if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) | 513 | if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) |
382 | continue; | 514 | continue; |
383 | 515 | ||
516 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
517 | "Found new attribute delegation. Creating new Job...\n"); | ||
384 | attr = rd[i].data; | 518 | attr = rd[i].data; |
385 | attr_entry = GNUNET_new (struct AttributeQueueEntry); | 519 | dq_entry = GNUNET_new (struct DelegationQueueEntry); |
386 | attr_entry->data_size = rd[i].data_size; | 520 | if (NULL != current_delegation->attr_trailer) |
387 | if (NULL != vrh->current_attribute && | ||
388 | NULL != vrh->current_attribute->attr_trailer) | ||
389 | { | 521 | { |
390 | if (rd[i].data_size == sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData)) | 522 | if (rd[i].data_size == sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData)) |
391 | { | 523 | { |
392 | GNUNET_asprintf (&expanded_attr, | 524 | GNUNET_asprintf (&expanded_attr, |
393 | "%s", | 525 | "%s", |
394 | vrh->current_attribute->attr_trailer); | 526 | current_delegation->attr_trailer); |
395 | 527 | ||
396 | } else { | 528 | } else { |
397 | GNUNET_asprintf (&expanded_attr, | 529 | GNUNET_asprintf (&expanded_attr, |
398 | "%s.%s", | 530 | "%s.%s", |
399 | (char*)&attr[1], | 531 | (char*)&attr[1], |
400 | vrh->current_attribute->attr_trailer); | 532 | current_delegation->attr_trailer); |
401 | } | 533 | } |
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 534 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
403 | "Expanded to %s\n", expanded_attr); | 535 | "Expanded to %s\n", expanded_attr); |
404 | attr_entry->data_size += strlen (vrh->current_attribute->attr_trailer) + 1; | 536 | dq_entry->unresolved_attribute_delegation = expanded_attr; |
405 | } else { | 537 | } else { |
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 538 | if (rd[i].data_size > sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData)) |
407 | "Not Expanding %s\n", (char*)&attr[1]); | 539 | { |
540 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
541 | "Not Expanding %s\n", (char*)&attr[1]); | ||
542 | dq_entry->unresolved_attribute_delegation = GNUNET_strdup ((char*)&attr[1]); | ||
543 | } | ||
408 | } | 544 | } |
409 | attr_entry->data = GNUNET_malloc (attr_entry->data_size); | 545 | |
410 | memcpy (attr_entry->data, | 546 | //Add a credential chain entry |
411 | rd[i].data, | 547 | dq_entry->delegation_chain_entry = GNUNET_new (struct GNUNET_CREDENTIAL_DelegationChainEntry); |
412 | rd[i].data_size); | 548 | dq_entry->delegation_chain_entry->subject_key = attr->subject_key; |
413 | if (NULL != vrh->current_attribute && NULL != vrh->current_attribute->attr_trailer) | 549 | dq_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); |
414 | { | 550 | GNUNET_memcpy (dq_entry->issuer_key, |
415 | memcpy ((char*)&attr_entry->data[1], | 551 | &attr->subject_key, |
416 | expanded_attr, | 552 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); |
417 | strlen (expanded_attr)); | 553 | if (rd[i].data_size > sizeof (struct GNUNET_CREDENTIAL_AttributeRecordData)) |
418 | } | 554 | dq_entry->delegation_chain_entry->subject_attribute = GNUNET_strdup ((char*)&attr[1]); |
419 | check_attr = (char*)&attr_entry->data[1]; | 555 | dq_entry->delegation_chain_entry->issuer_key = *current_delegation->issuer_key; |
420 | check_attr[attr_entry->data_size] = '\0'; | 556 | dq_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (current_delegation->lookup_attribute); |
421 | attr_entry->parent = vrh->current_attribute; | 557 | |
422 | 558 | dq_entry->parent = current_delegation; | |
423 | GNUNET_CONTAINER_DLL_insert (vrh->attr_queue_head, | 559 | GNUNET_CONTAINER_DLL_insert (current_delegation->children_head, |
424 | vrh->attr_queue_tail, | 560 | current_delegation->children_tail, |
425 | attr_entry); | 561 | dq_entry); |
562 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
563 | "Checking for cred match\n"); | ||
564 | /** | ||
565 | * Check if this delegation already matches one of our credentials | ||
566 | */ | ||
426 | for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; | 567 | for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; |
427 | cred_pointer = cred_pointer->next){ | 568 | cred_pointer = cred_pointer->next) |
569 | { | ||
428 | cred = cred_pointer->data; | 570 | cred = cred_pointer->data; |
429 | if(0 != memcmp (&attr->subject_key, | 571 | if(0 != memcmp (&attr->subject_key, |
430 | &cred_pointer->data->issuer_key, | 572 | &cred_pointer->data->issuer_key, |
431 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | 573 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) |
432 | continue; | 574 | continue; |
433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 575 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
434 | "Checking if %s matches %s\n", | 576 | "Checking if %s matches %s\n", |
435 | (char*)&attr_entry->data[1], (char*)&cred[1]); | 577 | dq_entry->unresolved_attribute_delegation, (char*)&cred[1]); |
436 | 578 | ||
437 | if (0 != strcmp ((char*)&attr_entry->data[1], (char*)&cred[1])) | 579 | if (0 != strcmp (dq_entry->unresolved_attribute_delegation, (char*)&cred[1])) |
438 | continue; | 580 | continue; |
439 | 581 | ||
440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 582 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
441 | "Found issuer\n"); | 583 | "Found issuer\n"); |
442 | vrh->credential = GNUNET_malloc (rd[i].data_size); | 584 | vrh->credential = GNUNET_malloc (cred_pointer->data_size); |
443 | memcpy (vrh->credential, | 585 | vrh->credential_size = cred_pointer->data_size; |
444 | rd[i].data, | 586 | vrh->chain_end = dq_entry; |
445 | rd[i].data_size); | 587 | //Found match |
446 | vrh->credential_size = rd[i].data_size; | ||
447 | //Found match | ||
448 | send_lookup_response (vrh); | 588 | send_lookup_response (vrh); |
449 | return; | 589 | return; |
450 | 590 | ||
451 | } | 591 | } |
452 | } | 592 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
453 | 593 | "Building new lookup request\n"); | |
454 | 594 | //Continue with backward resolution | |
595 | char issuer_attribute_name[strlen (dq_entry->unresolved_attribute_delegation)+1]; | ||
596 | strcpy (issuer_attribute_name, | ||
597 | dq_entry->unresolved_attribute_delegation); | ||
598 | char *next_attr = strtok (issuer_attribute_name, "."); | ||
599 | GNUNET_asprintf (&dq_entry->lookup_attribute, | ||
600 | "%s.gnu", | ||
601 | next_attr); | ||
602 | if (strlen (next_attr) == strlen (dq_entry->unresolved_attribute_delegation)) | ||
603 | { | ||
604 | dq_entry->attr_trailer = NULL; | ||
605 | } else { | ||
606 | next_attr += strlen (next_attr) + 1; | ||
607 | dq_entry->attr_trailer = GNUNET_strdup (next_attr); | ||
608 | } | ||
455 | 609 | ||
456 | //Start from next to head | 610 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
457 | vrh->current_attribute = vrh->attr_queue_head; | 611 | "Looking up %s\n", dq_entry->lookup_attribute); |
612 | if (NULL != dq_entry->attr_trailer) | ||
613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
614 | "%s still to go...\n", dq_entry->attr_trailer); | ||
615 | |||
616 | vrh->pending_lookups++; | ||
617 | dq_entry->handle = vrh; | ||
618 | dq_entry->lookup_request = GNUNET_GNS_lookup (gns, | ||
619 | dq_entry->lookup_attribute, | ||
620 | dq_entry->issuer_key, //issuer_key, | ||
621 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, | ||
622 | GNUNET_GNS_LO_DEFAULT, | ||
623 | NULL, //shorten_key, always NULL | ||
624 | &backward_resolution, | ||
625 | dq_entry); | ||
626 | } | ||
458 | 627 | ||
459 | if(NULL == vrh->current_attribute) | 628 | if(0 == vrh->pending_lookups) |
460 | { | 629 | { |
461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 630 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
462 | "We are all out of attributes...\n"); | 631 | "We are all out of attributes...\n"); |
463 | send_lookup_response (vrh); | 632 | send_lookup_response (vrh); |
464 | return; | 633 | return; |
465 | } | ||
466 | |||
467 | GNUNET_CONTAINER_DLL_remove (vrh->attr_queue_head, | ||
468 | vrh->attr_queue_tail, | ||
469 | vrh->current_attribute); | ||
470 | |||
471 | |||
472 | 634 | ||
473 | //Start with backward resolution | ||
474 | char issuer_attribute_name[strlen ((char*)&vrh->current_attribute->data[1])]; | ||
475 | char *lookup_attr; | ||
476 | strcpy (issuer_attribute_name, | ||
477 | (char*)&vrh->current_attribute->data[1]); | ||
478 | char *next_attr = strtok (issuer_attribute_name, "."); | ||
479 | GNUNET_asprintf (&lookup_attr, | ||
480 | "%s.gnu", | ||
481 | next_attr); | ||
482 | if (strlen (next_attr) == strlen ((char*)&vrh->current_attribute->data[1])) | ||
483 | { | ||
484 | vrh->current_attribute->attr_trailer = NULL; | ||
485 | } else { | ||
486 | next_attr += strlen (next_attr) + 1; | ||
487 | vrh->current_attribute->attr_trailer = GNUNET_strdup (next_attr); | ||
488 | } | 635 | } |
489 | |||
490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
491 | "Looking up %s\n", lookup_attr); | ||
492 | if (NULL != vrh->current_attribute->attr_trailer) | ||
493 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
494 | "%s still to go...\n", vrh->current_attribute->attr_trailer); | ||
495 | |||
496 | vrh->lookup_request = GNUNET_GNS_lookup (gns, | ||
497 | lookup_attr, | ||
498 | &vrh->current_attribute->data->subject_key, //issuer_key, | ||
499 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, | ||
500 | GNUNET_GNS_LO_DEFAULT, | ||
501 | NULL, //shorten_key, always NULL | ||
502 | &start_backward_resolution, | ||
503 | vrh); | ||
504 | GNUNET_free (lookup_attr); | ||
505 | } | 636 | } |
506 | 637 | ||
507 | 638 | ||
508 | |||
509 | /** | 639 | /** |
510 | * Result from GNS lookup. | 640 | * Result from GNS lookup. |
511 | * | 641 | * |
@@ -519,11 +649,13 @@ handle_credential_query (void* cls, | |||
519 | const struct GNUNET_GNSRECORD_Data *rd) | 649 | const struct GNUNET_GNSRECORD_Data *rd) |
520 | { | 650 | { |
521 | struct VerifyRequestHandle *vrh = cls; | 651 | struct VerifyRequestHandle *vrh = cls; |
522 | int cred_record_count; | 652 | struct DelegationQueueEntry *dq_entry; |
523 | int i; | ||
524 | const struct GNUNET_CREDENTIAL_CredentialRecordData *crd; | 653 | const struct GNUNET_CREDENTIAL_CredentialRecordData *crd; |
525 | struct CredentialRecordEntry *cr_entry; | 654 | struct CredentialRecordEntry *cr_entry; |
655 | int cred_record_count; | ||
656 | int i; | ||
526 | 657 | ||
658 | vrh->lookup_request = NULL; | ||
527 | cred_record_count = 0; | 659 | cred_record_count = 0; |
528 | for (i=0; i < rd_count; i++) | 660 | for (i=0; i < rd_count; i++) |
529 | { | 661 | { |
@@ -561,6 +693,7 @@ handle_credential_query (void* cls, | |||
561 | rd[i].data, | 693 | rd[i].data, |
562 | rd[i].data_size); | 694 | rd[i].data_size); |
563 | vrh->credential_size = rd[i].data_size; | 695 | vrh->credential_size = rd[i].data_size; |
696 | vrh->chain_end = NULL; | ||
564 | //Found match prematurely | 697 | //Found match prematurely |
565 | send_lookup_response (vrh); | 698 | send_lookup_response (vrh); |
566 | return; | 699 | return; |
@@ -576,18 +709,24 @@ handle_credential_query (void* cls, | |||
576 | vrh->issuer_attribute); | 709 | vrh->issuer_attribute); |
577 | strcpy (issuer_attribute_name + strlen (vrh->issuer_attribute), | 710 | strcpy (issuer_attribute_name + strlen (vrh->issuer_attribute), |
578 | ".gnu"); | 711 | ".gnu"); |
579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 712 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
580 | "Looking up %s\n", issuer_attribute_name); | 713 | "Looking up %s\n", issuer_attribute_name); |
581 | 714 | dq_entry = GNUNET_new (struct DelegationQueueEntry); | |
715 | dq_entry->issuer_key = &vrh->issuer_key; | ||
716 | dq_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); | ||
717 | dq_entry->handle = vrh; | ||
718 | dq_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute); | ||
719 | vrh->chain_start = dq_entry; | ||
720 | vrh->pending_lookups = 1; | ||
582 | //Start with backward resolution | 721 | //Start with backward resolution |
583 | GNUNET_GNS_lookup (gns, | 722 | dq_entry->lookup_request = GNUNET_GNS_lookup (gns, |
584 | issuer_attribute_name, | 723 | issuer_attribute_name, |
585 | &vrh->issuer_key, //issuer_key, | 724 | &vrh->issuer_key, //issuer_key, |
586 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, | 725 | GNUNET_GNSRECORD_TYPE_ATTRIBUTE, |
587 | GNUNET_GNS_LO_DEFAULT, | 726 | GNUNET_GNS_LO_DEFAULT, |
588 | NULL, //shorten_key, always NULL | 727 | NULL, //shorten_key, always NULL |
589 | &start_backward_resolution, | 728 | &backward_resolution, |
590 | vrh); | 729 | dq_entry); |
591 | } | 730 | } |
592 | 731 | ||
593 | 732 | ||
@@ -610,7 +749,7 @@ handle_verify (void *cls, | |||
610 | char *attrptr = attrs; | 749 | char *attrptr = attrs; |
611 | const char *utf_in; | 750 | const char *utf_in; |
612 | 751 | ||
613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 752 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
614 | "Received VERIFY message\n"); | 753 | "Received VERIFY message\n"); |
615 | 754 | ||
616 | utf_in = (const char *) &v_msg[1]; | 755 | utf_in = (const char *) &v_msg[1]; |
@@ -644,6 +783,9 @@ handle_verify (void *cls, | |||
644 | send_lookup_response (vrh); | 783 | send_lookup_response (vrh); |
645 | return; | 784 | return; |
646 | } | 785 | } |
786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
787 | "Looking up %s\n", | ||
788 | subject_attribute); | ||
647 | /** | 789 | /** |
648 | * First, get attribute from subject | 790 | * First, get attribute from subject |
649 | */ | 791 | */ |
@@ -669,7 +811,7 @@ client_disconnect_cb (void *cls, | |||
669 | struct GNUNET_SERVICE_Client *client, | 811 | struct GNUNET_SERVICE_Client *client, |
670 | void *app_ctx) | 812 | void *app_ctx) |
671 | { | 813 | { |
672 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 814 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
673 | "Client %p disconnected\n", | 815 | "Client %p disconnected\n", |
674 | client); | 816 | client); |
675 | } | 817 | } |
@@ -687,7 +829,7 @@ client_connect_cb (void *cls, | |||
687 | struct GNUNET_SERVICE_Client *client, | 829 | struct GNUNET_SERVICE_Client *client, |
688 | struct GNUNET_MQ_Handle *mq) | 830 | struct GNUNET_MQ_Handle *mq) |
689 | { | 831 | { |
690 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 832 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
691 | "Client %p connected\n", | 833 | "Client %p connected\n", |
692 | client); | 834 | client); |
693 | return client; | 835 | return client; |