From: Martin Schanzenbach Date: Fri, 22 May 2020 07:44:22 +0000 (+0200) Subject: add option to show private key X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2fbc0f044f95f2a8ed8a87e980fe0ec4f4ddf650;p=oweals%2Fgnunet.git add option to show private key --- diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 97a7bf513..ef01cc578 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c @@ -56,6 +56,11 @@ */ #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" +/** + * Parameter public key + */ +#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" + /** * Parameter subsystem */ @@ -463,9 +468,11 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; struct MHD_Response *resp; + struct GNUNET_HashCode key; json_t *json_root; json_t *json_ego; char *result_str; + char *privkey_str; json_root = json_array (); // Return ego/egos @@ -476,6 +483,19 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, json_object_set_new (json_ego, GNUNET_REST_IDENTITY_PARAM_PUBKEY, json_string (ego_entry->keystring)); + GNUNET_CRYPTO_hash ("private", strlen ("private"), &key); + if (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_contains ( + handle->rest_handle->url_param_map, &key)) + { + privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string ( + GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); + json_object_set_new (json_ego, + GNUNET_REST_IDENTITY_PARAM_PRIVKEY, + json_string (privkey_str)); + GNUNET_free (privkey_str); + } + json_object_set_new (json_ego, GNUNET_REST_IDENTITY_PARAM_NAME, json_string (ego_entry->identifier)); @@ -504,8 +524,10 @@ void ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) { struct MHD_Response *resp; + struct GNUNET_HashCode key; json_t *json_ego; char *result_str; + char *privkey_str; json_ego = json_object (); json_object_set_new (json_ego, @@ -514,6 +536,18 @@ ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) json_object_set_new (json_ego, GNUNET_REST_IDENTITY_PARAM_NAME, json_string (ego_entry->identifier)); + GNUNET_CRYPTO_hash ("private", strlen ("private"), &key); + if (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_contains ( + handle->rest_handle->url_param_map, &key)) + { + privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string ( + GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); + json_object_set_new (json_ego, + GNUNET_REST_IDENTITY_PARAM_PRIVKEY, + json_string (privkey_str)); + GNUNET_free (privkey_str); + } result_str = json_dumps (json_ego, 0); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);