diff options
Diffstat (limited to 'src/identity')
-rw-r--r-- | src/identity/gnunet-identity.c | 42 | ||||
-rw-r--r-- | src/identity/identity_api.c | 7 | ||||
-rw-r--r-- | src/identity/plugin_rest_identity.c | 21 | ||||
-rw-r--r-- | src/identity/test_identity.c | 2 | ||||
-rw-r--r-- | src/identity/test_identity_defaults.c | 2 |
5 files changed, 64 insertions, 10 deletions
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 | |||
@@ -76,6 +76,11 @@ static char *create_ego; | |||
76 | static char *delete_ego; | 76 | static char *delete_ego; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * -P option | ||
80 | */ | ||
81 | static char *privkey_ego; | ||
82 | |||
83 | /** | ||
79 | * -s option. | 84 | * -s option. |
80 | */ | 85 | */ |
81 | static char *set_ego; | 86 | static char *set_ego; |
@@ -101,6 +106,11 @@ static struct GNUNET_IDENTITY_Operation *create_op; | |||
101 | static struct GNUNET_IDENTITY_Operation *delete_op; | 106 | static struct GNUNET_IDENTITY_Operation *delete_op; |
102 | 107 | ||
103 | /** | 108 | /** |
109 | * Private key from command line option, or NULL. | ||
110 | */ | ||
111 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | ||
112 | |||
113 | /** | ||
104 | * Value to return from #main(). | 114 | * Value to return from #main(). |
105 | */ | 115 | */ |
106 | static int global_ret; | 116 | static int global_ret; |
@@ -390,11 +400,28 @@ run (void *cls, | |||
390 | &delete_finished, | 400 | &delete_finished, |
391 | &delete_op); | 401 | &delete_op); |
392 | if (NULL != create_ego) | 402 | if (NULL != create_ego) |
393 | create_op = | 403 | { |
394 | GNUNET_IDENTITY_create (sh, | 404 | if (NULL != privkey_ego) |
395 | create_ego, | 405 | { |
396 | &create_finished, | 406 | GNUNET_STRINGS_string_to_data (privkey_ego, |
397 | &create_op); | 407 | strlen (privkey_ego), |
408 | &pk, | ||
409 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
410 | create_op = | ||
411 | GNUNET_IDENTITY_create (sh, | ||
412 | create_ego, | ||
413 | &pk, | ||
414 | &create_finished, | ||
415 | &create_op); | ||
416 | } | ||
417 | else | ||
418 | create_op = | ||
419 | GNUNET_IDENTITY_create (sh, | ||
420 | create_ego, | ||
421 | NULL, | ||
422 | &create_finished, | ||
423 | &create_op); | ||
424 | } | ||
398 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 425 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
399 | NULL); | 426 | NULL); |
400 | test_finished (); | 427 | test_finished (); |
@@ -422,6 +449,11 @@ main (int argc, char *const *argv) | |||
422 | "NAME", | 449 | "NAME", |
423 | gettext_noop ("delete ego NAME "), | 450 | gettext_noop ("delete ego NAME "), |
424 | &delete_ego), | 451 | &delete_ego), |
452 | GNUNET_GETOPT_option_string ('P', | ||
453 | "privkey", | ||
454 | "PRIVATE_KEY", | ||
455 | gettext_noop ("set the private key for the identity to PRIVATE_KEY (use together with -C)"), | ||
456 | &privkey_ego), | ||
425 | GNUNET_GETOPT_option_flag ('d', | 457 | GNUNET_GETOPT_option_flag ('d', |
426 | "display", | 458 | "display", |
427 | gettext_noop ("display all egos"), | 459 | 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, | |||
715 | * | 715 | * |
716 | * @param h identity service to use | 716 | * @param h identity service to use |
717 | * @param name desired name | 717 | * @param name desired name |
718 | * @param privkey desired private key or NULL to create one | ||
718 | * @param cont function to call with the result (will only be called once) | 719 | * @param cont function to call with the result (will only be called once) |
719 | * @param cont_cls closure for @a cont | 720 | * @param cont_cls closure for @a cont |
720 | * @return handle to abort the operation | 721 | * @return handle to abort the operation |
@@ -722,6 +723,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | |||
722 | struct GNUNET_IDENTITY_Operation * | 723 | struct GNUNET_IDENTITY_Operation * |
723 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | 724 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, |
724 | const char *name, | 725 | const char *name, |
726 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey, | ||
725 | GNUNET_IDENTITY_CreateContinuation cont, | 727 | GNUNET_IDENTITY_CreateContinuation cont, |
726 | void *cont_cls) | 728 | void *cont_cls) |
727 | { | 729 | { |
@@ -746,7 +748,10 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
746 | env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); | 748 | env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); |
747 | crm->name_len = htons (slen); | 749 | crm->name_len = htons (slen); |
748 | crm->reserved = htons (0); | 750 | crm->reserved = htons (0); |
749 | GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key); | 751 | if (NULL == privkey) |
752 | GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key); | ||
753 | else | ||
754 | crm->private_key = *privkey; | ||
750 | op->pk = crm->private_key; | 755 | op->pk = crm->private_key; |
751 | GNUNET_memcpy (&crm[1], name, slen); | 756 | GNUNET_memcpy (&crm[1], name, slen); |
752 | GNUNET_MQ_send (h->mq, env); | 757 | 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 @@ | |||
57 | #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" | 57 | #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Parameter public key | 60 | * Parameter private key |
61 | */ | 61 | */ |
62 | #define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" | 62 | #define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" |
63 | 63 | ||
@@ -990,6 +990,9 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
990 | json_t *data_js; | 990 | json_t *data_js; |
991 | json_error_t err; | 991 | json_error_t err; |
992 | char *egoname; | 992 | char *egoname; |
993 | char *privkey; | ||
994 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | ||
995 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk_ptr; | ||
993 | int json_unpack_state; | 996 | int json_unpack_state; |
994 | char term_data[handle->data_size + 1]; | 997 | char term_data[handle->data_size + 1]; |
995 | 998 | ||
@@ -1016,8 +1019,11 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1016 | return; | 1019 | return; |
1017 | } | 1020 | } |
1018 | json_unpack_state = 0; | 1021 | json_unpack_state = 0; |
1022 | privkey = NULL; | ||
1019 | json_unpack_state = | 1023 | json_unpack_state = |
1020 | 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); | ||
1021 | if (0 != json_unpack_state) | 1027 | if (0 != json_unpack_state) |
1022 | { | 1028 | { |
1023 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 1029 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
@@ -1054,10 +1060,21 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1054 | } | 1060 | } |
1055 | } | 1061 | } |
1056 | 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; | ||
1057 | json_decref (data_js); | 1073 | json_decref (data_js); |
1058 | handle->response_code = MHD_HTTP_CREATED; | 1074 | handle->response_code = MHD_HTTP_CREATED; |
1059 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 1075 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, |
1060 | handle->name, | 1076 | handle->name, |
1077 | pk_ptr, | ||
1061 | &do_finished_create, | 1078 | &do_finished_create, |
1062 | handle); | 1079 | handle); |
1063 | } | 1080 | } |
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, | |||
279 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | 279 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
280 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | 280 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); |
281 | CHECK (NULL != h); | 281 | CHECK (NULL != h); |
282 | op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); | 282 | op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL); |
283 | } | 283 | } |
284 | 284 | ||
285 | 285 | ||
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, | |||
266 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | 266 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
267 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | 267 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); |
268 | CHECK (NULL != h); | 268 | CHECK (NULL != h); |
269 | op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); | 269 | op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL); |
270 | } | 270 | } |
271 | 271 | ||
272 | 272 | ||