diff options
-rw-r--r-- | src/reclaim/json_reclaim.c | 2 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 76 |
2 files changed, 77 insertions, 1 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index 775ab58d6..a464a9088 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -322,7 +322,7 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
322 | (void **) &data, | 322 | (void **) &data, |
323 | &data_size))) | 323 | &data_size))) |
324 | { | 324 | { |
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); | 325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attestation value invalid!\n"); |
326 | return GNUNET_SYSERR; | 326 | return GNUNET_SYSERR; |
327 | } | 327 | } |
328 | attr = GNUNET_RECLAIM_ATTESTATION_claim_new (name_str, type, data, data_size); | 328 | attr = GNUNET_RECLAIM_ATTESTATION_claim_new (name_str, type, data, data_size); |
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index a495c5e85..dcda75b65 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -534,6 +534,69 @@ add_attestation_ref_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
534 | GNUNET_JSON_parse_free (attrspec); | 534 | GNUNET_JSON_parse_free (attrspec); |
535 | } | 535 | } |
536 | 536 | ||
537 | static void | ||
538 | parse_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | ||
539 | const char *url, | ||
540 | void *cls) | ||
541 | { | ||
542 | struct RequestHandle *handle = cls; | ||
543 | |||
544 | char term_data[handle->rest_handle->data_size + 1]; | ||
545 | json_t *data_json; | ||
546 | json_error_t err; | ||
547 | int unpack_state; | ||
548 | struct MHD_Response *resp; | ||
549 | char *val_str = NULL; | ||
550 | const char *type_str = NULL; | ||
551 | term_data[handle->rest_handle->data_size] = '\0'; | ||
552 | GNUNET_memcpy (term_data, | ||
553 | handle->rest_handle->data, | ||
554 | handle->rest_handle->data_size); | ||
555 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); | ||
556 | GNUNET_assert (NULL != data_json); | ||
557 | if (! json_is_object (data_json)) | ||
558 | { | ||
559 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
560 | "Error json is not array nor object!\n"); | ||
561 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
562 | return; | ||
563 | } | ||
564 | unpack_state = json_unpack (data_json, | ||
565 | "{s:s, s:s!}", | ||
566 | "value", | ||
567 | &val_str, | ||
568 | "type", | ||
569 | &type_str); | ||
570 | if ((0 != unpack_state) || (NULL == val_str) || (NULL == type_str)) | ||
571 | { | ||
572 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
573 | "Error json object has a wrong format!\n"); | ||
574 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
575 | return; | ||
576 | } | ||
577 | if (0 == strcmp (type_str, "JWT")) | ||
578 | { | ||
579 | // The value is a JWT | ||
580 | char *decoded_jwt; | ||
581 | char delim[] = "."; | ||
582 | char *jwt_body = strtok (val_str, delim); | ||
583 | jwt_body = strtok (NULL, delim); | ||
584 | GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body), | ||
585 | (void **) &decoded_jwt); | ||
586 | resp = GNUNET_REST_create_response (decoded_jwt); | ||
587 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | ||
588 | GNUNET_free (decoded_jwt); | ||
589 | } | ||
590 | else | ||
591 | { | ||
592 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
593 | "Error requested parsing type not supported!\n"); | ||
594 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
595 | return; | ||
596 | } | ||
597 | cleanup_handle (handle); | ||
598 | json_decref (data_json); | ||
599 | } | ||
537 | 600 | ||
538 | static void | 601 | static void |
539 | add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | 602 | add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, |
@@ -554,6 +617,19 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
554 | return; | 617 | return; |
555 | } | 618 | } |
556 | } | 619 | } |
620 | /* Check for substring "parse" */ | ||
621 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) < strlen ( | ||
622 | handle->url)) | ||
623 | { | ||
624 | if ( strncmp ("parse", (handle->url + strlen ( | ||
625 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) | ||
626 | + 1), strlen ( | ||
627 | "parse")) == 0) | ||
628 | { | ||
629 | parse_attestation_cont (con_handle,url,cls); | ||
630 | return; | ||
631 | } | ||
632 | } | ||
557 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 633 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
558 | const char *identity; | 634 | const char *identity; |
559 | struct EgoEntry *ego_entry; | 635 | struct EgoEntry *ego_entry; |