[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: add option to create identity from priva
From: |
gnunet |
Subject: |
[gnunet] branch master updated: add option to create identity from private key |
Date: |
Tue, 26 May 2020 09:13:44 +0200 |
This is an automated email from the git hooks/post-receive script.
spaethj pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new a32de45ce add option to create identity from private key
new 7b48b9e29 Merge branch 'spaeth/import_identity'
a32de45ce is described below
commit a32de45ceffeb69038ecfa7b963f30b7fed83a41
Author: jospaeth <address@hidden>
AuthorDate: Mon May 25 21:38:58 2020 +0200
add option to create identity from private key
---
src/conversation/test_conversation_api.c | 4 +--
src/conversation/test_conversation_api_reject.c | 4 +--
src/conversation/test_conversation_api_twocalls.c | 4 +--
src/identity/gnunet-identity.c | 42 ++++++++++++++++++++---
src/identity/identity_api.c | 7 +++-
src/identity/plugin_rest_identity.c | 21 ++++++++++--
src/identity/test_identity.c | 2 +-
src/identity/test_identity_defaults.c | 2 +-
src/include/gnunet_identity_service.h | 2 ++
src/revocation/test_revocation.c | 2 ++
10 files changed, 74 insertions(+), 16 deletions(-)
diff --git a/src/conversation/test_conversation_api.c
b/src/conversation/test_conversation_api.c
index 2b717367a..dbb742d91 100644
--- a/src/conversation/test_conversation_api.c
+++ b/src/conversation/test_conversation_api.c
@@ -402,7 +402,7 @@ namestore_put_cont (void *cls, int32_t success, const char
*emsg)
GNUNET_assert (GNUNET_YES == success);
GNUNET_assert (NULL == emsg);
GNUNET_assert (NULL == op);
- op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont,
NULL);
+ op = GNUNET_IDENTITY_create (id, "caller-ego", NULL,
&caller_ego_create_cont, NULL);
}
@@ -483,7 +483,7 @@ run (void *cls,
cfg = c;
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
- op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
+ op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont,
NULL);
ns = GNUNET_NAMESTORE_connect (cfg);
}
diff --git a/src/conversation/test_conversation_api_reject.c
b/src/conversation/test_conversation_api_reject.c
index 62e4109b0..855b21fd7 100644
--- a/src/conversation/test_conversation_api_reject.c
+++ b/src/conversation/test_conversation_api_reject.c
@@ -255,7 +255,7 @@ namestore_put_cont (void *cls, int32_t success, const char
*emsg)
GNUNET_assert (GNUNET_YES == success);
GNUNET_assert (NULL == emsg);
GNUNET_assert (NULL == op);
- op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont,
NULL);
+ op = GNUNET_IDENTITY_create (id, "caller-ego", NULL,
&caller_ego_create_cont, NULL);
}
@@ -336,7 +336,7 @@ run (void *cls,
cfg = c;
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
- op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
+ op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont,
NULL);
ns = GNUNET_NAMESTORE_connect (cfg);
}
diff --git a/src/conversation/test_conversation_api_twocalls.c
b/src/conversation/test_conversation_api_twocalls.c
index fab49f7d7..6d434a3e1 100644
--- a/src/conversation/test_conversation_api_twocalls.c
+++ b/src/conversation/test_conversation_api_twocalls.c
@@ -524,7 +524,7 @@ namestore_put_cont (void *cls, int32_t success, const char
*emsg)
GNUNET_assert (GNUNET_YES == success);
GNUNET_assert (NULL == emsg);
GNUNET_assert (NULL == op);
- op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont,
NULL);
+ op = GNUNET_IDENTITY_create (id, "caller-ego", NULL,
&caller_ego_create_cont, NULL);
}
@@ -613,7 +613,7 @@ run (void *cls,
timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
- op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
+ op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont,
NULL);
ns = GNUNET_NAMESTORE_connect (cfg);
}
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index fd73048c4..cf44afd1f 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -75,6 +75,11 @@ static char *create_ego;
*/
static char *delete_ego;
+/**
+ * -P option
+ */
+static char *privkey_ego;
+
/**
* -s option.
*/
@@ -100,6 +105,11 @@ static struct GNUNET_IDENTITY_Operation *create_op;
*/
static struct GNUNET_IDENTITY_Operation *delete_op;
+/**
+ * Private key from command line option, or NULL.
+ */
+struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
+
/**
* Value to return from #main().
*/
@@ -390,11 +400,28 @@ run (void *cls,
&delete_finished,
&delete_op);
if (NULL != create_ego)
- create_op =
- GNUNET_IDENTITY_create (sh,
- create_ego,
- &create_finished,
- &create_op);
+ {
+ if (NULL != privkey_ego)
+ {
+ GNUNET_STRINGS_string_to_data (privkey_ego,
+ strlen (privkey_ego),
+ &pk,
+ sizeof(struct
GNUNET_CRYPTO_EcdsaPrivateKey));
+ create_op =
+ GNUNET_IDENTITY_create (sh,
+ create_ego,
+ &pk,
+ &create_finished,
+ &create_op);
+ }
+ else
+ create_op =
+ GNUNET_IDENTITY_create (sh,
+ create_ego,
+ NULL,
+ &create_finished,
+ &create_op);
+ }
GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
NULL);
test_finished ();
@@ -422,6 +449,11 @@ main (int argc, char *const *argv)
"NAME",
gettext_noop ("delete ego NAME "),
&delete_ego),
+ GNUNET_GETOPT_option_string ('P',
+ "privkey",
+ "PRIVATE_KEY",
+ gettext_noop ("set the private key for the
identity to PRIVATE_KEY (use together with -C)"),
+ &privkey_ego),
GNUNET_GETOPT_option_flag ('d',
"display",
gettext_noop ("display all egos"),
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index c2fcc5075..5d17ac5d5 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -715,6 +715,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
*
* @param h identity service to use
* @param name desired name
+ * @param privkey desired private key or NULL to create one
* @param cont function to call with the result (will only be called once)
* @param cont_cls closure for @a cont
* @return handle to abort the operation
@@ -722,6 +723,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
const char *name,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey,
GNUNET_IDENTITY_CreateContinuation cont,
void *cont_cls)
{
@@ -746,7 +748,10 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
crm->name_len = htons (slen);
crm->reserved = htons (0);
- GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key);
+ if (NULL == privkey)
+ GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key);
+ else
+ crm->private_key = *privkey;
op->pk = crm->private_key;
GNUNET_memcpy (&crm[1], name, slen);
GNUNET_MQ_send (h->mq, env);
diff --git a/src/identity/plugin_rest_identity.c
b/src/identity/plugin_rest_identity.c
index ef01cc578..009a01f16 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -57,7 +57,7 @@
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey"
/**
- * Parameter public key
+ * Parameter private key
*/
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey"
@@ -990,6 +990,9 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle,
json_t *data_js;
json_error_t err;
char *egoname;
+ char *privkey;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey *pk_ptr;
int json_unpack_state;
char term_data[handle->data_size + 1];
@@ -1016,8 +1019,11 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
json_unpack_state = 0;
+ privkey = NULL;
json_unpack_state =
- json_unpack (data_js, "{s:s!}", GNUNET_REST_IDENTITY_PARAM_NAME, &egoname);
+ json_unpack (data_js, "{s:s, s?:s!}",
+ GNUNET_REST_IDENTITY_PARAM_NAME, &egoname,
+ GNUNET_REST_IDENTITY_PARAM_PRIVKEY, &privkey);
if (0 != json_unpack_state)
{
handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID);
@@ -1054,10 +1060,21 @@ ego_create (struct GNUNET_REST_RequestHandle
*con_handle,
}
}
handle->name = GNUNET_strdup (egoname);
+ if (NULL != privkey)
+ {
+ GNUNET_STRINGS_string_to_data (privkey,
+ strlen (privkey),
+ &pk,
+ sizeof(struct
GNUNET_CRYPTO_EcdsaPrivateKey));
+ pk_ptr = &pk;
+ }
+ else
+ pk_ptr = NULL;
json_decref (data_js);
handle->response_code = MHD_HTTP_CREATED;
handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
handle->name,
+ pk_ptr,
&do_finished_create,
handle);
}
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c
index aaa435d4f..37eeab238 100644
--- a/src/identity/test_identity.c
+++ b/src/identity/test_identity.c
@@ -279,7 +279,7 @@ run (void *cls,
GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL);
CHECK (NULL != h);
- op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL);
+ op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL);
}
diff --git a/src/identity/test_identity_defaults.c
b/src/identity/test_identity_defaults.c
index 1dd05f1b9..53eec1252 100644
--- a/src/identity/test_identity_defaults.c
+++ b/src/identity/test_identity_defaults.c
@@ -266,7 +266,7 @@ run_set (void *cls,
GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL);
CHECK (NULL != h);
- op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL);
+ op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL);
}
diff --git a/src/include/gnunet_identity_service.h
b/src/include/gnunet_identity_service.h
index 81af671e2..f4e653598 100644
--- a/src/include/gnunet_identity_service.h
+++ b/src/include/gnunet_identity_service.h
@@ -233,6 +233,7 @@ typedef void
*
* @param id identity service to use
* @param name desired name
+ * @param privkey desired private key or NULL to create one
* @param cont function to call with the result (will only be called once)
* @param cont_cls closure for @a cont
* @return handle to abort the operation
@@ -240,6 +241,7 @@ typedef void
struct GNUNET_IDENTITY_Operation *
GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
const char *name,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey,
GNUNET_IDENTITY_CreateContinuation cont,
void *cont_cls);
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c
index f193d5f6c..1c2efa60f 100644
--- a/src/revocation/test_revocation.c
+++ b/src/revocation/test_revocation.c
@@ -237,10 +237,12 @@ identity_completion_cb (void *cls,
fprintf (stderr, "All peers connected @ IDENTITY ...\n");
testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh,
"client",
+ NULL,
&identity_create_cb,
&testpeers[0]);
testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh,
"toberevoked",
+ NULL,
&identity_create_cb,
&testpeers[1]);
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: add option to create identity from private key,
gnunet <=