diff options
-rw-r--r-- | src/identity-token/plugin_rest_identity_token.c | 76 | ||||
-rw-r--r-- | src/rest/rest.c | 9 |
2 files changed, 66 insertions, 19 deletions
diff --git a/src/identity-token/plugin_rest_identity_token.c b/src/identity-token/plugin_rest_identity_token.c index 8af6e8a00..cea0dbcf5 100644 --- a/src/identity-token/plugin_rest_identity_token.c +++ b/src/identity-token/plugin_rest_identity_token.c | |||
@@ -185,6 +185,11 @@ struct RequestHandle | |||
185 | struct GNUNET_NAMESTORE_ZoneIterator *ns_it; | 185 | struct GNUNET_NAMESTORE_ZoneIterator *ns_it; |
186 | 186 | ||
187 | /** | 187 | /** |
188 | * NS Handle | ||
189 | */ | ||
190 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | ||
191 | |||
192 | /** | ||
188 | * Desired timeout for the lookup (default is no timeout). | 193 | * Desired timeout for the lookup (default is no timeout). |
189 | */ | 194 | */ |
190 | struct GNUNET_TIME_Relative timeout; | 195 | struct GNUNET_TIME_Relative timeout; |
@@ -274,6 +279,8 @@ cleanup_handle (struct RequestHandle *handle) | |||
274 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | 279 | GNUNET_IDENTITY_disconnect (handle->identity_handle); |
275 | if (NULL != handle->ns_it) | 280 | if (NULL != handle->ns_it) |
276 | GNUNET_NAMESTORE_zone_iteration_stop (handle->ns_it); | 281 | GNUNET_NAMESTORE_zone_iteration_stop (handle->ns_it); |
282 | if (NULL != handle->ns_qe) | ||
283 | GNUNET_NAMESTORE_cancel (handle->ns_qe); | ||
277 | if (NULL != handle->ns_handle) | 284 | if (NULL != handle->ns_handle) |
278 | GNUNET_NAMESTORE_disconnect (handle->ns_handle); | 285 | GNUNET_NAMESTORE_disconnect (handle->ns_handle); |
279 | 286 | ||
@@ -319,6 +326,44 @@ do_error (void *cls, | |||
319 | } | 326 | } |
320 | 327 | ||
321 | /** | 328 | /** |
329 | * Task run on shutdown. Cleans up everything. | ||
330 | * | ||
331 | * @param cls unused | ||
332 | * @param tc scheduler context | ||
333 | */ | ||
334 | static void | ||
335 | do_cleanup_handle_delayed (void *cls, | ||
336 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
337 | { | ||
338 | struct RequestHandle *handle = cls; | ||
339 | cleanup_handle(handle); | ||
340 | } | ||
341 | |||
342 | void | ||
343 | store_token_cont (void *cls, | ||
344 | int32_t success, | ||
345 | const char *emsg) | ||
346 | { | ||
347 | char *result_str; | ||
348 | struct MHD_Response *resp; | ||
349 | struct RequestHandle *handle = cls; | ||
350 | |||
351 | handle->ns_qe = NULL; | ||
352 | if (GNUNET_SYSERR == success) | ||
353 | { | ||
354 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
355 | return; | ||
356 | } | ||
357 | GNUNET_REST_jsonapi_data_serialize (handle->resp_object, &result_str); | ||
358 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Result %s\n", result_str); | ||
359 | resp = GNUNET_REST_create_json_response (result_str); | ||
360 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | ||
361 | GNUNET_free (result_str); | ||
362 | GNUNET_SCHEDULER_add_now (&do_cleanup_handle_delayed, handle); | ||
363 | } | ||
364 | |||
365 | |||
366 | /** | ||
322 | * Build a GNUid token for identity | 367 | * Build a GNUid token for identity |
323 | * @param handle the handle | 368 | * @param handle the handle |
324 | * @param ego_entry the ego to build the token for | 369 | * @param ego_entry the ego to build the token for |
@@ -337,7 +382,6 @@ sign_and_return_token (void *cls, | |||
337 | char *payload_base64; | 382 | char *payload_base64; |
338 | char *sig_str; | 383 | char *sig_str; |
339 | char *lbl_str; | 384 | char *lbl_str; |
340 | char *result_str; | ||
341 | char *token; | 385 | char *token; |
342 | uint64_t time; | 386 | uint64_t time; |
343 | uint64_t lbl; | 387 | uint64_t lbl; |
@@ -346,9 +390,9 @@ sign_and_return_token (void *cls, | |||
346 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 390 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; |
347 | struct GNUNET_CRYPTO_EcdsaSignature sig; | 391 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
348 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; | 392 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; |
349 | struct MHD_Response *resp; | ||
350 | struct JsonApiResource *json_resource; | 393 | struct JsonApiResource *json_resource; |
351 | struct RequestHandle *handle = cls; | 394 | struct RequestHandle *handle = cls; |
395 | struct GNUNET_GNSRECORD_Data token_record; | ||
352 | 396 | ||
353 | time = GNUNET_TIME_absolute_get().abs_value_us; | 397 | time = GNUNET_TIME_absolute_get().abs_value_us; |
354 | lbl = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | 398 | lbl = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
@@ -407,7 +451,6 @@ sign_and_return_token (void *cls, | |||
407 | 451 | ||
408 | json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_IDENTITY_TOKEN, | 452 | json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_IDENTITY_TOKEN, |
409 | lbl_str); | 453 | lbl_str); |
410 | GNUNET_free (lbl_str); | ||
411 | name_str = json_string (handle->ego_entry->identifier); | 454 | name_str = json_string (handle->ego_entry->identifier); |
412 | GNUNET_REST_jsonapi_resource_add_attr (json_resource, | 455 | GNUNET_REST_jsonapi_resource_add_attr (json_resource, |
413 | GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST, | 456 | GNUNET_REST_JSONAPI_IDENTITY_ISS_REQUEST, |
@@ -417,21 +460,32 @@ sign_and_return_token (void *cls, | |||
417 | 460 | ||
418 | 461 | ||
419 | token_str = json_string (token); | 462 | token_str = json_string (token); |
420 | GNUNET_free (token); | ||
421 | GNUNET_REST_jsonapi_resource_add_attr (json_resource, | 463 | GNUNET_REST_jsonapi_resource_add_attr (json_resource, |
422 | GNUNET_REST_JSONAPI_IDENTITY_TOKEN, | 464 | GNUNET_REST_JSONAPI_IDENTITY_TOKEN, |
423 | token_str); | 465 | token_str); |
424 | json_decref (token_str); | ||
425 | GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource); | 466 | GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource); |
426 | GNUNET_REST_jsonapi_data_serialize (handle->resp_object, &result_str); | 467 | token_record.data = token; |
427 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Result %s\n", result_str); | 468 | token_record.data_size = strlen (token); |
428 | resp = GNUNET_REST_create_json_response (result_str); | 469 | token_record.expiration_time = time+GNUNET_GNUID_TOKEN_EXPIRATION_MICROSECONDS; |
429 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 470 | token_record.record_type = GNUNET_GNSRECORD_TYPE_ID_TOKEN; |
430 | GNUNET_free (result_str); | 471 | token_record.flags = GNUNET_GNSRECORD_RF_NONE; |
431 | cleanup_handle (handle); | 472 | //Persist token |
473 | handle->ns_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | ||
474 | priv_key, | ||
475 | lbl_str, | ||
476 | 1, | ||
477 | &token_record, | ||
478 | &store_token_cont, | ||
479 | handle); | ||
480 | GNUNET_free (lbl_str); | ||
481 | GNUNET_free (token); | ||
482 | json_decref (token_str); | ||
432 | } | 483 | } |
433 | 484 | ||
434 | 485 | ||
486 | |||
487 | |||
488 | |||
435 | static void | 489 | static void |
436 | attr_collect (void *cls, | 490 | attr_collect (void *cls, |
437 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 491 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
diff --git a/src/rest/rest.c b/src/rest/rest.c index d04bfdee1..cc3a318c2 100644 --- a/src/rest/rest.c +++ b/src/rest/rest.c | |||
@@ -435,14 +435,7 @@ GNUNET_REST_jsonapi_data_serialize (const struct JsonApiObject *resp, | |||
435 | int | 435 | int |
436 | GNUNET_REST_namespace_match (const char *url, const char *namespace) | 436 | GNUNET_REST_namespace_match (const char *url, const char *namespace) |
437 | { | 437 | { |
438 | if (0 != strncmp (namespace, url, strlen (namespace))) | 438 | return 0 == strncmp (namespace, url, strlen (namespace)); |
439 | return GNUNET_NO; | ||
440 | |||
441 | if ((strlen (namespace) < strlen (url)) && | ||
442 | (url[strlen (namespace)] != '/')) | ||
443 | return GNUNET_NO; | ||
444 | |||
445 | return GNUNET_YES; | ||
446 | } | 439 | } |
447 | 440 | ||
448 | /** | 441 | /** |