diff options
Diffstat (limited to 'src/reclaim/plugin_rest_reclaim.c')
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 186 |
1 files changed, 108 insertions, 78 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index c2d14825e..ff11d2a56 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -48,9 +48,9 @@ | |||
48 | #define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES "/reclaim/attributes" | 48 | #define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES "/reclaim/attributes" |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Attestation namespace | 51 | * Credential namespace |
52 | */ | 52 | */ |
53 | #define GNUNET_REST_API_NS_RECLAIM_ATTESTATION "/reclaim/attestation" | 53 | #define GNUNET_REST_API_NS_RECLAIM_CREDENTIAL "/reclaim/credential" |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Ticket namespace | 56 | * Ticket namespace |
@@ -154,6 +154,15 @@ struct EgoEntry | |||
154 | 154 | ||
155 | struct RequestHandle | 155 | struct RequestHandle |
156 | { | 156 | { |
157 | /** | ||
158 | * DLL | ||
159 | */ | ||
160 | struct RequestHandle *next; | ||
161 | |||
162 | /** | ||
163 | * DLL | ||
164 | */ | ||
165 | struct RequestHandle *prev; | ||
157 | 166 | ||
158 | /** | 167 | /** |
159 | * Selected ego | 168 | * Selected ego |
@@ -193,7 +202,7 @@ struct RequestHandle | |||
193 | /** | 202 | /** |
194 | * Attribute iterator | 203 | * Attribute iterator |
195 | */ | 204 | */ |
196 | struct GNUNET_RECLAIM_AttestationIterator *attest_it; | 205 | struct GNUNET_RECLAIM_CredentialIterator *cred_it; |
197 | 206 | ||
198 | /** | 207 | /** |
199 | * Ticket iterator | 208 | * Ticket iterator |
@@ -247,6 +256,17 @@ struct RequestHandle | |||
247 | }; | 256 | }; |
248 | 257 | ||
249 | /** | 258 | /** |
259 | * DLL | ||
260 | */ | ||
261 | static struct RequestHandle *requests_head; | ||
262 | |||
263 | /** | ||
264 | * DLL | ||
265 | */ | ||
266 | static struct RequestHandle *requests_tail; | ||
267 | |||
268 | |||
269 | /** | ||
250 | * Cleanup lookup handle | 270 | * Cleanup lookup handle |
251 | * @param handle Handle to clean up | 271 | * @param handle Handle to clean up |
252 | */ | 272 | */ |
@@ -262,8 +282,8 @@ cleanup_handle (void *cls) | |||
262 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 282 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
263 | if (NULL != handle->attr_it) | 283 | if (NULL != handle->attr_it) |
264 | GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); | 284 | GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); |
265 | if (NULL != handle->attest_it) | 285 | if (NULL != handle->cred_it) |
266 | GNUNET_RECLAIM_get_attestations_stop (handle->attest_it); | 286 | GNUNET_RECLAIM_get_credentials_stop (handle->cred_it); |
267 | if (NULL != handle->ticket_it) | 287 | if (NULL != handle->ticket_it) |
268 | GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); | 288 | GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); |
269 | if (NULL != handle->url) | 289 | if (NULL != handle->url) |
@@ -272,6 +292,9 @@ cleanup_handle (void *cls) | |||
272 | GNUNET_free (handle->emsg); | 292 | GNUNET_free (handle->emsg); |
273 | if (NULL != handle->attr_list) | 293 | if (NULL != handle->attr_list) |
274 | GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list); | 294 | GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list); |
295 | GNUNET_CONTAINER_DLL_remove (requests_head, | ||
296 | requests_tail, | ||
297 | handle); | ||
275 | GNUNET_free (handle); | 298 | GNUNET_free (handle); |
276 | } | 299 | } |
277 | 300 | ||
@@ -296,7 +319,7 @@ do_error (void *cls) | |||
296 | resp = GNUNET_REST_create_response (json_error); | 319 | resp = GNUNET_REST_create_response (json_error); |
297 | MHD_add_response_header (resp, "Content-Type", "application/json"); | 320 | MHD_add_response_header (resp, "Content-Type", "application/json"); |
298 | handle->proc (handle->proc_cls, resp, handle->response_code); | 321 | handle->proc (handle->proc_cls, resp, handle->response_code); |
299 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 322 | cleanup_handle (handle); |
300 | GNUNET_free (json_error); | 323 | GNUNET_free (json_error); |
301 | } | 324 | } |
302 | 325 | ||
@@ -319,7 +342,7 @@ do_timeout (void *cls) | |||
319 | static void | 342 | static void |
320 | collect_error_cb (void *cls) | 343 | collect_error_cb (void *cls) |
321 | { | 344 | { |
322 | do_error (cls); | 345 | GNUNET_SCHEDULER_add_now (&do_error, cls); |
323 | } | 346 | } |
324 | 347 | ||
325 | 348 | ||
@@ -329,6 +352,7 @@ finished_cont (void *cls, int32_t success, const char *emsg) | |||
329 | struct RequestHandle *handle = cls; | 352 | struct RequestHandle *handle = cls; |
330 | struct MHD_Response *resp; | 353 | struct MHD_Response *resp; |
331 | 354 | ||
355 | handle->idp_op = NULL; | ||
332 | resp = GNUNET_REST_create_response (emsg); | 356 | resp = GNUNET_REST_create_response (emsg); |
333 | MHD_add_response_header (resp, "Content-Type", "application/json"); | 357 | MHD_add_response_header (resp, "Content-Type", "application/json"); |
334 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | 358 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); |
@@ -389,7 +413,7 @@ collect_finished_cb (void *cls) | |||
389 | 413 | ||
390 | // Done | 414 | // Done |
391 | handle->attr_it = NULL; | 415 | handle->attr_it = NULL; |
392 | handle->attest_it = NULL; | 416 | handle->cred_it = NULL; |
393 | handle->ticket_it = NULL; | 417 | handle->ticket_it = NULL; |
394 | GNUNET_SCHEDULER_add_now (&return_response, handle); | 418 | GNUNET_SCHEDULER_add_now (&return_response, handle); |
395 | } | 419 | } |
@@ -436,7 +460,7 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
436 | 460 | ||
437 | 461 | ||
438 | static void | 462 | static void |
439 | add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | 463 | add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, |
440 | const char *url, | 464 | const char *url, |
441 | void *cls) | 465 | void *cls) |
442 | { | 466 | { |
@@ -444,19 +468,19 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
444 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 468 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
445 | const char *identity; | 469 | const char *identity; |
446 | struct EgoEntry *ego_entry; | 470 | struct EgoEntry *ego_entry; |
447 | struct GNUNET_RECLAIM_Attestation *attribute; | 471 | struct GNUNET_RECLAIM_Credential *attribute; |
448 | struct GNUNET_TIME_Relative exp; | 472 | struct GNUNET_TIME_Relative exp; |
449 | char term_data[handle->rest_handle->data_size + 1]; | 473 | char term_data[handle->rest_handle->data_size + 1]; |
450 | json_t *data_json; | 474 | json_t *data_json; |
451 | json_error_t err; | 475 | json_error_t err; |
452 | struct GNUNET_JSON_Specification attrspec[] = | 476 | struct GNUNET_JSON_Specification attrspec[] = |
453 | { GNUNET_RECLAIM_JSON_spec_claim_attest (&attribute), | 477 | { GNUNET_RECLAIM_JSON_spec_credential (&attribute), |
454 | GNUNET_JSON_spec_end () }; | 478 | GNUNET_JSON_spec_end () }; |
455 | 479 | ||
456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
457 | "Adding an attestation for %s.\n", | 481 | "Adding an credential for %s.\n", |
458 | handle->url); | 482 | handle->url); |
459 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION) >= strlen ( | 483 | if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen ( |
460 | handle->url)) | 484 | handle->url)) |
461 | { | 485 | { |
462 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | 486 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); |
@@ -464,7 +488,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
464 | return; | 488 | return; |
465 | } | 489 | } |
466 | identity = handle->url + strlen ( | 490 | identity = handle->url + strlen ( |
467 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; | 491 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) + 1; |
468 | 492 | ||
469 | for (ego_entry = ego_head; NULL != ego_entry; | 493 | for (ego_entry = ego_head; NULL != ego_entry; |
470 | ego_entry = ego_entry->next) | 494 | ego_entry = ego_entry->next) |
@@ -494,7 +518,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
494 | if (NULL == attribute) | 518 | if (NULL == attribute) |
495 | { | 519 | { |
496 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 520 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
497 | "Unable to parse attestation from %s\n", | 521 | "Unable to parse credential from %s\n", |
498 | term_data); | 522 | term_data); |
499 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 523 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
500 | return; | 524 | return; |
@@ -505,7 +529,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
505 | if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) | 529 | if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) |
506 | GNUNET_RECLAIM_id_generate (&attribute->id); | 530 | GNUNET_RECLAIM_id_generate (&attribute->id); |
507 | exp = GNUNET_TIME_UNIT_HOURS; | 531 | exp = GNUNET_TIME_UNIT_HOURS; |
508 | handle->idp_op = GNUNET_RECLAIM_attestation_store (idp, | 532 | handle->idp_op = GNUNET_RECLAIM_credential_store (idp, |
509 | identity_priv, | 533 | identity_priv, |
510 | attribute, | 534 | attribute, |
511 | &exp, | 535 | &exp, |
@@ -516,52 +540,52 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
516 | 540 | ||
517 | 541 | ||
518 | /** | 542 | /** |
519 | * Collect all attestations for an ego | 543 | * Collect all credentials for an ego |
520 | * | 544 | * |
521 | */ | 545 | */ |
522 | static void | 546 | static void |
523 | attest_collect (void *cls, | 547 | cred_collect (void *cls, |
524 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 548 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
525 | const struct GNUNET_RECLAIM_Attestation *attest) | 549 | const struct GNUNET_RECLAIM_Credential *cred) |
526 | { | 550 | { |
527 | struct RequestHandle *handle = cls; | 551 | struct RequestHandle *handle = cls; |
528 | struct GNUNET_RECLAIM_AttributeList *attrs; | 552 | struct GNUNET_RECLAIM_AttributeList *attrs; |
529 | struct GNUNET_RECLAIM_AttributeListEntry *ale; | 553 | struct GNUNET_RECLAIM_AttributeListEntry *ale; |
530 | struct GNUNET_TIME_Absolute exp; | 554 | struct GNUNET_TIME_Absolute exp; |
531 | json_t *attr_obj; | 555 | json_t *attr_obj; |
532 | json_t *attest_obj; | 556 | json_t *cred_obj; |
533 | const char *type; | 557 | const char *type; |
534 | char *tmp_value; | 558 | char *tmp_value; |
535 | char *id_str; | 559 | char *id_str; |
536 | char *issuer; | 560 | char *issuer; |
537 | 561 | ||
538 | 562 | ||
539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attestation: %s\n", | 563 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential: %s\n", |
540 | attest->name); | 564 | cred->name); |
541 | attrs = GNUNET_RECLAIM_attestation_get_attributes (attest); | 565 | attrs = GNUNET_RECLAIM_credential_get_attributes (cred); |
542 | issuer = GNUNET_RECLAIM_attestation_get_issuer (attest); | 566 | issuer = GNUNET_RECLAIM_credential_get_issuer (cred); |
543 | tmp_value = GNUNET_RECLAIM_attestation_value_to_string (attest->type, | 567 | tmp_value = GNUNET_RECLAIM_credential_value_to_string (cred->type, |
544 | attest->data, | 568 | cred->data, |
545 | attest->data_size); | 569 | cred->data_size); |
546 | attest_obj = json_object (); | 570 | cred_obj = json_object (); |
547 | json_object_set_new (attest_obj, "value", json_string (tmp_value)); | 571 | json_object_set_new (cred_obj, "value", json_string (tmp_value)); |
548 | json_object_set_new (attest_obj, "name", json_string (attest->name)); | 572 | json_object_set_new (cred_obj, "name", json_string (cred->name)); |
549 | type = GNUNET_RECLAIM_attestation_number_to_typename (attest->type); | 573 | type = GNUNET_RECLAIM_credential_number_to_typename (cred->type); |
550 | json_object_set_new (attest_obj, "type", json_string (type)); | 574 | json_object_set_new (cred_obj, "type", json_string (type)); |
551 | if (NULL != issuer) | 575 | if (NULL != issuer) |
552 | { | 576 | { |
553 | json_object_set_new (attest_obj, "issuer", json_string (issuer)); | 577 | json_object_set_new (cred_obj, "issuer", json_string (issuer)); |
554 | GNUNET_free (issuer); | 578 | GNUNET_free (issuer); |
555 | } | 579 | } |
556 | if (GNUNET_OK == GNUNET_RECLAIM_attestation_get_expiration (attest, | 580 | if (GNUNET_OK == GNUNET_RECLAIM_credential_get_expiration (cred, |
557 | &exp)) | 581 | &exp)) |
558 | { | 582 | { |
559 | json_object_set_new (attest_obj, "expiration", json_integer ( | 583 | json_object_set_new (cred_obj, "expiration", json_integer ( |
560 | exp.abs_value_us)); | 584 | exp.abs_value_us)); |
561 | } | 585 | } |
562 | id_str = GNUNET_STRINGS_data_to_string_alloc (&attest->id, | 586 | id_str = GNUNET_STRINGS_data_to_string_alloc (&cred->id, |
563 | sizeof(attest->id)); | 587 | sizeof(cred->id)); |
564 | json_object_set_new (attest_obj, "id", json_string (id_str)); | 588 | json_object_set_new (cred_obj, "id", json_string (id_str)); |
565 | GNUNET_free (tmp_value); | 589 | GNUNET_free (tmp_value); |
566 | GNUNET_free (id_str); | 590 | GNUNET_free (id_str); |
567 | if (NULL != attrs) | 591 | if (NULL != attrs) |
@@ -582,27 +606,27 @@ attest_collect (void *cls, | |||
582 | type = GNUNET_RECLAIM_attribute_number_to_typename (ale->attribute->type); | 606 | type = GNUNET_RECLAIM_attribute_number_to_typename (ale->attribute->type); |
583 | json_object_set_new (attr_obj, "type", json_string (type)); | 607 | json_object_set_new (attr_obj, "type", json_string (type)); |
584 | json_object_set_new (attr_obj, "id", json_string ("")); | 608 | json_object_set_new (attr_obj, "id", json_string ("")); |
585 | json_object_set_new (attr_obj, "attestation", json_string ("")); | 609 | json_object_set_new (attr_obj, "credential", json_string ("")); |
586 | json_array_append_new (attr_arr, attr_obj); | 610 | json_array_append_new (attr_arr, attr_obj); |
587 | GNUNET_free (tmp_value); | 611 | GNUNET_free (tmp_value); |
588 | } | 612 | } |
589 | json_object_set_new (attest_obj, "attributes", attr_arr); | 613 | json_object_set_new (cred_obj, "attributes", attr_arr); |
590 | } | 614 | } |
591 | json_array_append_new (handle->resp_object, attest_obj); | 615 | json_array_append_new (handle->resp_object, cred_obj); |
592 | GNUNET_RECLAIM_attribute_list_destroy (attrs); | 616 | GNUNET_RECLAIM_attribute_list_destroy (attrs); |
593 | GNUNET_RECLAIM_get_attestations_next (handle->attest_it); | 617 | GNUNET_RECLAIM_get_credentials_next (handle->cred_it); |
594 | } | 618 | } |
595 | 619 | ||
596 | 620 | ||
597 | /** | 621 | /** |
598 | * Lists attestation for identity request | 622 | * Lists credential for identity request |
599 | * | 623 | * |
600 | * @param con_handle the connection handle | 624 | * @param con_handle the connection handle |
601 | * @param url the url | 625 | * @param url the url |
602 | * @param cls the RequestHandle | 626 | * @param cls the RequestHandle |
603 | */ | 627 | */ |
604 | static void | 628 | static void |
605 | list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | 629 | list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, |
606 | const char *url, | 630 | const char *url, |
607 | void *cls) | 631 | void *cls) |
608 | { | 632 | { |
@@ -612,9 +636,9 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
612 | char *identity; | 636 | char *identity; |
613 | 637 | ||
614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
615 | "Getting attestations for %s.\n", | 639 | "Getting credentials for %s.\n", |
616 | handle->url); | 640 | handle->url); |
617 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION) >= strlen ( | 641 | if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen ( |
618 | handle->url)) | 642 | handle->url)) |
619 | { | 643 | { |
620 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | 644 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); |
@@ -622,7 +646,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
622 | return; | 646 | return; |
623 | } | 647 | } |
624 | identity = handle->url + strlen ( | 648 | identity = handle->url + strlen ( |
625 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; | 649 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) + 1; |
626 | 650 | ||
627 | for (ego_entry = ego_head; NULL != ego_entry; | 651 | for (ego_entry = ego_head; NULL != ego_entry; |
628 | ego_entry = ego_entry->next) | 652 | ego_entry = ego_entry->next) |
@@ -639,11 +663,11 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
639 | return; | 663 | return; |
640 | } | 664 | } |
641 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 665 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
642 | handle->attest_it = GNUNET_RECLAIM_get_attestations_start (idp, | 666 | handle->cred_it = GNUNET_RECLAIM_get_credentials_start (idp, |
643 | priv_key, | 667 | priv_key, |
644 | &collect_error_cb, | 668 | &collect_error_cb, |
645 | handle, | 669 | handle, |
646 | &attest_collect, | 670 | &cred_collect, |
647 | handle, | 671 | handle, |
648 | & | 672 | & |
649 | collect_finished_cb, | 673 | collect_finished_cb, |
@@ -652,27 +676,27 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
652 | 676 | ||
653 | 677 | ||
654 | /** | 678 | /** |
655 | * Deletes attestation from an identity | 679 | * Deletes credential from an identity |
656 | * | 680 | * |
657 | * @param con_handle the connection handle | 681 | * @param con_handle the connection handle |
658 | * @param url the url | 682 | * @param url the url |
659 | * @param cls the RequestHandle | 683 | * @param cls the RequestHandle |
660 | */ | 684 | */ |
661 | static void | 685 | static void |
662 | delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | 686 | delete_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, |
663 | const char *url, | 687 | const char *url, |
664 | void *cls) | 688 | void *cls) |
665 | { | 689 | { |
666 | struct RequestHandle *handle = cls; | 690 | struct RequestHandle *handle = cls; |
667 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 691 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; |
668 | struct GNUNET_RECLAIM_Attestation attr; | 692 | struct GNUNET_RECLAIM_Credential attr; |
669 | struct EgoEntry *ego_entry; | 693 | struct EgoEntry *ego_entry; |
670 | char *identity_id_str; | 694 | char *identity_id_str; |
671 | char *identity; | 695 | char *identity; |
672 | char *id; | 696 | char *id; |
673 | 697 | ||
674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attestation.\n"); | 698 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting credential.\n"); |
675 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION) >= strlen ( | 699 | if (strlen (GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) >= strlen ( |
676 | handle->url)) | 700 | handle->url)) |
677 | { | 701 | { |
678 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | 702 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); |
@@ -681,7 +705,7 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
681 | } | 705 | } |
682 | identity_id_str = | 706 | identity_id_str = |
683 | strdup (handle->url + strlen ( | 707 | strdup (handle->url + strlen ( |
684 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1); | 708 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL) + 1); |
685 | identity = strtok (identity_id_str, "/"); | 709 | identity = strtok (identity_id_str, "/"); |
686 | id = strtok (NULL, "/"); | 710 | id = strtok (NULL, "/"); |
687 | if ((NULL == identity) || (NULL == id)) | 711 | if ((NULL == identity) || (NULL == id)) |
@@ -706,10 +730,10 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
706 | return; | 730 | return; |
707 | } | 731 | } |
708 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 732 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
709 | memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attestation)); | 733 | memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Credential)); |
710 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); | 734 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); |
711 | attr.name = ""; | 735 | attr.name = ""; |
712 | handle->idp_op = GNUNET_RECLAIM_attestation_delete (idp, | 736 | handle->idp_op = GNUNET_RECLAIM_credential_delete (idp, |
713 | priv_key, | 737 | priv_key, |
714 | &attr, | 738 | &attr, |
715 | &delete_finished_cb, | 739 | &delete_finished_cb, |
@@ -787,7 +811,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
787 | json_t *data_json; | 811 | json_t *data_json; |
788 | json_error_t err; | 812 | json_error_t err; |
789 | struct GNUNET_JSON_Specification attrspec[] = | 813 | struct GNUNET_JSON_Specification attrspec[] = |
790 | { GNUNET_RECLAIM_JSON_spec_claim (&attribute), GNUNET_JSON_spec_end () }; | 814 | { GNUNET_RECLAIM_JSON_spec_attribute (&attribute), GNUNET_JSON_spec_end () }; |
791 | 815 | ||
792 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
793 | "Adding an attribute for %s.\n", | 817 | "Adding an attribute for %s.\n", |
@@ -853,13 +877,13 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
853 | /** | 877 | /** |
854 | * Parse a JWT and return the respective claim value as Attribute | 878 | * Parse a JWT and return the respective claim value as Attribute |
855 | * | 879 | * |
856 | * @param attest the jwt attestation | 880 | * @param cred the jwt credential |
857 | * @param claim the name of the claim in the JWT | 881 | * @param claim the name of the claim in the JWT |
858 | * | 882 | * |
859 | * @return a GNUNET_RECLAIM_Attribute, containing the new value | 883 | * @return a GNUNET_RECLAIM_Attribute, containing the new value |
860 | */ | 884 | */ |
861 | struct GNUNET_RECLAIM_Attribute * | 885 | struct GNUNET_RECLAIM_Attribute * |
862 | parse_jwt (const struct GNUNET_RECLAIM_Attestation *attest, | 886 | parse_jwt (const struct GNUNET_RECLAIM_Credential *cred, |
863 | const char *claim) | 887 | const char *claim) |
864 | { | 888 | { |
865 | char *jwt_string; | 889 | char *jwt_string; |
@@ -875,9 +899,9 @@ parse_jwt (const struct GNUNET_RECLAIM_Attestation *attest, | |||
875 | json_t *json_val; | 899 | json_t *json_val; |
876 | json_error_t *json_err = NULL; | 900 | json_error_t *json_err = NULL; |
877 | 901 | ||
878 | jwt_string = GNUNET_RECLAIM_attestation_value_to_string (attest->type, | 902 | jwt_string = GNUNET_RECLAIM_credential_value_to_string (cred->type, |
879 | attest->data, | 903 | cred->data, |
880 | attest->data_size); | 904 | cred->data_size); |
881 | char *jwt_body = strtok (jwt_string, delim); | 905 | char *jwt_body = strtok (jwt_string, delim); |
882 | jwt_body = strtok (NULL, delim); | 906 | jwt_body = strtok (NULL, delim); |
883 | GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body), | 907 | GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body), |
@@ -903,16 +927,16 @@ parse_jwt (const struct GNUNET_RECLAIM_Attestation *attest, | |||
903 | "Error: Referenced Claim Name not Found", | 927 | "Error: Referenced Claim Name not Found", |
904 | (void **) &data, | 928 | (void **) &data, |
905 | &data_size); | 929 | &data_size); |
906 | attr = GNUNET_RECLAIM_attribute_new (claim, &attest->id, | 930 | attr = GNUNET_RECLAIM_attribute_new (claim, &cred->id, |
907 | type, data, data_size); | 931 | type, data, data_size); |
908 | attr->id = attest->id; | 932 | attr->id = cred->id; |
909 | attr->flag = 1; | 933 | attr->flag = 1; |
910 | } | 934 | } |
911 | else | 935 | else |
912 | { | 936 | { |
913 | attr = GNUNET_RECLAIM_attribute_new (claim, &attest->id, | 937 | attr = GNUNET_RECLAIM_attribute_new (claim, &cred->id, |
914 | type, data, data_size); | 938 | type, data, data_size); |
915 | attr->id = attest->id; | 939 | attr->id = cred->id; |
916 | attr->flag = 1; | 940 | attr->flag = 1; |
917 | } | 941 | } |
918 | return attr; | 942 | return attr; |
@@ -941,7 +965,7 @@ attr_collect (void *cls, | |||
941 | json_object_set_new (attr_obj, "value", json_string (tmp_value)); | 965 | json_object_set_new (attr_obj, "value", json_string (tmp_value)); |
942 | json_object_set_new (attr_obj, "name", json_string (attr->name)); | 966 | json_object_set_new (attr_obj, "name", json_string (attr->name)); |
943 | 967 | ||
944 | if (GNUNET_RECLAIM_id_is_zero (&attr->attestation)) | 968 | if (GNUNET_RECLAIM_id_is_zero (&attr->credential)) |
945 | json_object_set_new (attr_obj, "flag", json_string ("0")); | 969 | json_object_set_new (attr_obj, "flag", json_string ("0")); |
946 | else | 970 | else |
947 | json_object_set_new (attr_obj, "flag", json_string ("1")); | 971 | json_object_set_new (attr_obj, "flag", json_string ("1")); |
@@ -950,9 +974,9 @@ attr_collect (void *cls, | |||
950 | id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id, | 974 | id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id, |
951 | sizeof(attr->id)); | 975 | sizeof(attr->id)); |
952 | json_object_set_new (attr_obj, "id", json_string (id_str)); | 976 | json_object_set_new (attr_obj, "id", json_string (id_str)); |
953 | id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->attestation, | 977 | id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->credential, |
954 | sizeof(attr->attestation)); | 978 | sizeof(attr->credential)); |
955 | json_object_set_new (attr_obj, "attestation", json_string (id_str)); | 979 | json_object_set_new (attr_obj, "credential", json_string (id_str)); |
956 | json_array_append (handle->resp_object, attr_obj); | 980 | json_array_append (handle->resp_object, attr_obj); |
957 | json_decref (attr_obj); | 981 | json_decref (attr_obj); |
958 | GNUNET_free (tmp_value); | 982 | GNUNET_free (tmp_value); |
@@ -1156,7 +1180,7 @@ static void | |||
1156 | consume_cont (void *cls, | 1180 | consume_cont (void *cls, |
1157 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 1181 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
1158 | const struct GNUNET_RECLAIM_Attribute *attr, | 1182 | const struct GNUNET_RECLAIM_Attribute *attr, |
1159 | const struct GNUNET_RECLAIM_Attestation *attest) | 1183 | const struct GNUNET_RECLAIM_Presentation *pres) |
1160 | { | 1184 | { |
1161 | struct RequestHandle *handle = cls; | 1185 | struct RequestHandle *handle = cls; |
1162 | char *val_str; | 1186 | char *val_str; |
@@ -1403,11 +1427,11 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1403 | { MHD_HTTP_METHOD_DELETE, | 1427 | { MHD_HTTP_METHOD_DELETE, |
1404 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont }, | 1428 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont }, |
1405 | { MHD_HTTP_METHOD_GET, | 1429 | { MHD_HTTP_METHOD_GET, |
1406 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &list_attestation_cont }, | 1430 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &list_credential_cont }, |
1407 | { MHD_HTTP_METHOD_POST, | 1431 | { MHD_HTTP_METHOD_POST, |
1408 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &add_attestation_cont }, | 1432 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &add_credential_cont }, |
1409 | { MHD_HTTP_METHOD_DELETE, | 1433 | { MHD_HTTP_METHOD_DELETE, |
1410 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &delete_attestation_cont }, | 1434 | GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &delete_credential_cont }, |
1411 | { MHD_HTTP_METHOD_GET, | 1435 | { MHD_HTTP_METHOD_GET, |
1412 | GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont }, | 1436 | GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont }, |
1413 | { MHD_HTTP_METHOD_POST, | 1437 | { MHD_HTTP_METHOD_POST, |
@@ -1422,12 +1446,16 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1422 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1446 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
1423 | handle->proc_cls = proc_cls; | 1447 | handle->proc_cls = proc_cls; |
1424 | handle->proc = proc; | 1448 | handle->proc = proc; |
1425 | state = ID_REST_STATE_INIT; | ||
1426 | handle->rest_handle = rest_handle; | 1449 | handle->rest_handle = rest_handle; |
1427 | 1450 | ||
1428 | handle->url = GNUNET_strdup (rest_handle->url); | 1451 | handle->url = GNUNET_strdup (rest_handle->url); |
1429 | if (handle->url[strlen (handle->url) - 1] == '/') | 1452 | if (handle->url[strlen (handle->url) - 1] == '/') |
1430 | handle->url[strlen (handle->url) - 1] = '\0'; | 1453 | handle->url[strlen (handle->url) - 1] = '\0'; |
1454 | handle->timeout_task = | ||
1455 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | ||
1456 | GNUNET_CONTAINER_DLL_insert (requests_head, | ||
1457 | requests_tail, | ||
1458 | handle); | ||
1431 | if (GNUNET_NO == | 1459 | if (GNUNET_NO == |
1432 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | 1460 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |
1433 | { | 1461 | { |
@@ -1435,8 +1463,6 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1435 | return GNUNET_NO; | 1463 | return GNUNET_NO; |
1436 | } | 1464 | } |
1437 | 1465 | ||
1438 | handle->timeout_task = | ||
1439 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | ||
1440 | return GNUNET_YES; | 1466 | return GNUNET_YES; |
1441 | } | 1467 | } |
1442 | 1468 | ||
@@ -1470,6 +1496,7 @@ libgnunet_plugin_rest_reclaim_init (void *cls) | |||
1470 | MHD_HTTP_METHOD_DELETE, | 1496 | MHD_HTTP_METHOD_DELETE, |
1471 | MHD_HTTP_METHOD_OPTIONS); | 1497 | MHD_HTTP_METHOD_OPTIONS); |
1472 | identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); | 1498 | identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); |
1499 | state = ID_REST_STATE_INIT; | ||
1473 | idp = GNUNET_RECLAIM_connect (cfg); | 1500 | idp = GNUNET_RECLAIM_connect (cfg); |
1474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1475 | _ ("Identity Provider REST API initialized\n")); | 1502 | _ ("Identity Provider REST API initialized\n")); |
@@ -1488,10 +1515,13 @@ libgnunet_plugin_rest_reclaim_done (void *cls) | |||
1488 | { | 1515 | { |
1489 | struct GNUNET_REST_Plugin *api = cls; | 1516 | struct GNUNET_REST_Plugin *api = cls; |
1490 | struct Plugin *plugin = api->cls; | 1517 | struct Plugin *plugin = api->cls; |
1518 | struct RequestHandle *request; | ||
1491 | struct EgoEntry *ego_entry; | 1519 | struct EgoEntry *ego_entry; |
1492 | struct EgoEntry *ego_tmp; | 1520 | struct EgoEntry *ego_tmp; |
1493 | 1521 | ||
1494 | plugin->cfg = NULL; | 1522 | plugin->cfg = NULL; |
1523 | while (NULL != (request = requests_head)) | ||
1524 | do_error (request); | ||
1495 | if (NULL != idp) | 1525 | if (NULL != idp) |
1496 | GNUNET_RECLAIM_disconnect (idp); | 1526 | GNUNET_RECLAIM_disconnect (idp); |
1497 | if (NULL != identity_handle) | 1527 | if (NULL != identity_handle) |