diff options
Diffstat (limited to 'src/identity/plugin_rest_identity.c')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 97a7bf513..009a01f16 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -57,6 +57,11 @@ | |||
57 | #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" | 57 | #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Parameter private key | ||
61 | */ | ||
62 | #define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" | ||
63 | |||
64 | /** | ||
60 | * Parameter subsystem | 65 | * Parameter subsystem |
61 | */ | 66 | */ |
62 | #define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM "subsystem" | 67 | #define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM "subsystem" |
@@ -463,9 +468,11 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
463 | struct RequestHandle *handle = cls; | 468 | struct RequestHandle *handle = cls; |
464 | struct EgoEntry *ego_entry; | 469 | struct EgoEntry *ego_entry; |
465 | struct MHD_Response *resp; | 470 | struct MHD_Response *resp; |
471 | struct GNUNET_HashCode key; | ||
466 | json_t *json_root; | 472 | json_t *json_root; |
467 | json_t *json_ego; | 473 | json_t *json_ego; |
468 | char *result_str; | 474 | char *result_str; |
475 | char *privkey_str; | ||
469 | 476 | ||
470 | json_root = json_array (); | 477 | json_root = json_array (); |
471 | // Return ego/egos | 478 | // Return ego/egos |
@@ -476,6 +483,19 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
476 | json_object_set_new (json_ego, | 483 | json_object_set_new (json_ego, |
477 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, | 484 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, |
478 | json_string (ego_entry->keystring)); | 485 | json_string (ego_entry->keystring)); |
486 | GNUNET_CRYPTO_hash ("private", strlen ("private"), &key); | ||
487 | if (GNUNET_YES == | ||
488 | GNUNET_CONTAINER_multihashmap_contains ( | ||
489 | handle->rest_handle->url_param_map, &key)) | ||
490 | { | ||
491 | privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string ( | ||
492 | GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); | ||
493 | json_object_set_new (json_ego, | ||
494 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, | ||
495 | json_string (privkey_str)); | ||
496 | GNUNET_free (privkey_str); | ||
497 | } | ||
498 | |||
479 | json_object_set_new (json_ego, | 499 | json_object_set_new (json_ego, |
480 | GNUNET_REST_IDENTITY_PARAM_NAME, | 500 | GNUNET_REST_IDENTITY_PARAM_NAME, |
481 | json_string (ego_entry->identifier)); | 501 | json_string (ego_entry->identifier)); |
@@ -504,8 +524,10 @@ void | |||
504 | ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) | 524 | ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) |
505 | { | 525 | { |
506 | struct MHD_Response *resp; | 526 | struct MHD_Response *resp; |
527 | struct GNUNET_HashCode key; | ||
507 | json_t *json_ego; | 528 | json_t *json_ego; |
508 | char *result_str; | 529 | char *result_str; |
530 | char *privkey_str; | ||
509 | 531 | ||
510 | json_ego = json_object (); | 532 | json_ego = json_object (); |
511 | json_object_set_new (json_ego, | 533 | json_object_set_new (json_ego, |
@@ -514,6 +536,18 @@ ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
514 | json_object_set_new (json_ego, | 536 | json_object_set_new (json_ego, |
515 | GNUNET_REST_IDENTITY_PARAM_NAME, | 537 | GNUNET_REST_IDENTITY_PARAM_NAME, |
516 | json_string (ego_entry->identifier)); | 538 | json_string (ego_entry->identifier)); |
539 | GNUNET_CRYPTO_hash ("private", strlen ("private"), &key); | ||
540 | if (GNUNET_YES == | ||
541 | GNUNET_CONTAINER_multihashmap_contains ( | ||
542 | handle->rest_handle->url_param_map, &key)) | ||
543 | { | ||
544 | privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string ( | ||
545 | GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); | ||
546 | json_object_set_new (json_ego, | ||
547 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, | ||
548 | json_string (privkey_str)); | ||
549 | GNUNET_free (privkey_str); | ||
550 | } | ||
517 | 551 | ||
518 | result_str = json_dumps (json_ego, 0); | 552 | result_str = json_dumps (json_ego, 0); |
519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 553 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
@@ -956,6 +990,9 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
956 | json_t *data_js; | 990 | json_t *data_js; |
957 | json_error_t err; | 991 | json_error_t err; |
958 | char *egoname; | 992 | char *egoname; |
993 | char *privkey; | ||
994 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | ||
995 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk_ptr; | ||
959 | int json_unpack_state; | 996 | int json_unpack_state; |
960 | char term_data[handle->data_size + 1]; | 997 | char term_data[handle->data_size + 1]; |
961 | 998 | ||
@@ -982,8 +1019,11 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
982 | return; | 1019 | return; |
983 | } | 1020 | } |
984 | json_unpack_state = 0; | 1021 | json_unpack_state = 0; |
1022 | privkey = NULL; | ||
985 | json_unpack_state = | 1023 | json_unpack_state = |
986 | json_unpack (data_js, "{s:s!}", GNUNET_REST_IDENTITY_PARAM_NAME, &egoname); | 1024 | json_unpack (data_js, "{s:s, s?:s!}", |
1025 | GNUNET_REST_IDENTITY_PARAM_NAME, &egoname, | ||
1026 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, &privkey); | ||
987 | if (0 != json_unpack_state) | 1027 | if (0 != json_unpack_state) |
988 | { | 1028 | { |
989 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 1029 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
@@ -1020,10 +1060,21 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1020 | } | 1060 | } |
1021 | } | 1061 | } |
1022 | handle->name = GNUNET_strdup (egoname); | 1062 | handle->name = GNUNET_strdup (egoname); |
1063 | if (NULL != privkey) | ||
1064 | { | ||
1065 | GNUNET_STRINGS_string_to_data (privkey, | ||
1066 | strlen (privkey), | ||
1067 | &pk, | ||
1068 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
1069 | pk_ptr = &pk; | ||
1070 | } | ||
1071 | else | ||
1072 | pk_ptr = NULL; | ||
1023 | json_decref (data_js); | 1073 | json_decref (data_js); |
1024 | handle->response_code = MHD_HTTP_CREATED; | 1074 | handle->response_code = MHD_HTTP_CREATED; |
1025 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 1075 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, |
1026 | handle->name, | 1076 | handle->name, |
1077 | pk_ptr, | ||
1027 | &do_finished_create, | 1078 | &do_finished_create, |
1028 | handle); | 1079 | handle); |
1029 | } | 1080 | } |