diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-05-08 14:54:42 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-05-08 14:54:42 +0200 |
commit | 1b80ff9ee79b3fbe2028a8c22a01e45e9131cda2 (patch) | |
tree | 742185e47289bbed654eb641bf8f3d2409ee7976 /src/identity | |
parent | fba6afbd58e0b37b33850db4b1341dbf9392d1f3 (diff) | |
download | gnunet-1b80ff9ee79b3fbe2028a8c22a01e45e9131cda2.tar.gz gnunet-1b80ff9ee79b3fbe2028a8c22a01e45e9131cda2.zip |
make generated ego key available in continuation when creating egos
Diffstat (limited to 'src/identity')
-rw-r--r-- | src/identity/gnunet-identity.c | 24 | ||||
-rw-r--r-- | src/identity/identity_api.c | 38 | ||||
-rw-r--r-- | src/identity/plugin_rest_identity.c | 22 | ||||
-rw-r--r-- | src/identity/test_identity.c | 3 | ||||
-rw-r--r-- | src/identity/test_identity_defaults.c | 3 |
5 files changed, 82 insertions, 8 deletions
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 051f08cd3..583305710 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c | |||
@@ -51,6 +51,11 @@ static int list; | |||
51 | static int monitor; | 51 | static int monitor; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Was "verbose" specified? | ||
55 | */ | ||
56 | static unsigned int verbose; | ||
57 | |||
58 | /** | ||
54 | * -C option | 59 | * -C option |
55 | */ | 60 | */ |
56 | static char *create_ego; | 61 | static char *create_ego; |
@@ -164,22 +169,37 @@ delete_finished (void *cls, | |||
164 | * Creation operation finished. | 169 | * Creation operation finished. |
165 | * | 170 | * |
166 | * @param cls pointer to operation handle | 171 | * @param cls pointer to operation handle |
172 | * @param pk private key of the ego, or NULL on error | ||
167 | * @param emsg error message, NULL on success | 173 | * @param emsg error message, NULL on success |
168 | */ | 174 | */ |
169 | static void | 175 | static void |
170 | create_finished (void *cls, | 176 | create_finished (void *cls, |
177 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | ||
171 | const char *emsg) | 178 | const char *emsg) |
172 | { | 179 | { |
173 | struct GNUNET_IDENTITY_Operation **op = cls; | 180 | struct GNUNET_IDENTITY_Operation **op = cls; |
174 | 181 | ||
175 | *op = NULL; | 182 | *op = NULL; |
176 | if (NULL != emsg) | 183 | if (NULL == pk) |
177 | { | 184 | { |
178 | fprintf (stderr, | 185 | fprintf (stderr, |
179 | _("Failed to create ego: %s\n"), | 186 | _("Failed to create ego: %s\n"), |
180 | emsg); | 187 | emsg); |
181 | global_ret = 1; | 188 | global_ret = 1; |
182 | } | 189 | } |
190 | else if (verbose) | ||
191 | { | ||
192 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
193 | char *pubs; | ||
194 | |||
195 | GNUNET_CRYPTO_ecdsa_key_get_public (pk, | ||
196 | &pub); | ||
197 | pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub); | ||
198 | fprintf (stdout, | ||
199 | "%s\n", | ||
200 | pubs); | ||
201 | GNUNET_free (pubs); | ||
202 | } | ||
183 | test_finished (); | 203 | test_finished (); |
184 | } | 204 | } |
185 | 205 | ||
@@ -383,7 +403,7 @@ main (int argc, char *const *argv) | |||
383 | "SUBSYSTEM", | 403 | "SUBSYSTEM", |
384 | gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), | 404 | gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), |
385 | &set_subsystem), | 405 | &set_subsystem), |
386 | 406 | GNUNET_GETOPT_option_verbose (&verbose), | |
387 | GNUNET_GETOPT_OPTION_END | 407 | GNUNET_GETOPT_OPTION_END |
388 | }; | 408 | }; |
389 | int res; | 409 | int res; |
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index a058c5426..f16500ab5 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c | |||
@@ -88,13 +88,24 @@ struct GNUNET_IDENTITY_Operation | |||
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Continuation to invoke with the result of the transmission; @e cb | 90 | * Continuation to invoke with the result of the transmission; @e cb |
91 | * will be NULL in this case. | 91 | * and @e create_cont will be NULL in this case. |
92 | */ | 92 | */ |
93 | GNUNET_IDENTITY_Continuation cont; | 93 | GNUNET_IDENTITY_Continuation cont; |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Continuation to invoke with the result of the transmission; @e cb | ||
97 | * and @a cb will be NULL in this case. | ||
98 | */ | ||
99 | GNUNET_IDENTITY_CreateContinuation create_cont; | ||
100 | |||
101 | /** | ||
102 | * Private key to return to @e create_cont, or NULL. | ||
103 | */ | ||
104 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | ||
105 | |||
106 | /** | ||
96 | * Continuation to invoke with the result of the transmission for | 107 | * Continuation to invoke with the result of the transmission for |
97 | * 'get' operations (@e cont will be NULL in this case). | 108 | * 'get' operations (@e cont and @a create_cont will be NULL in this case). |
98 | */ | 109 | */ |
99 | GNUNET_IDENTITY_Callback cb; | 110 | GNUNET_IDENTITY_Callback cb; |
100 | 111 | ||
@@ -259,6 +270,11 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h) | |||
259 | NULL, | 270 | NULL, |
260 | NULL, | 271 | NULL, |
261 | NULL); | 272 | NULL); |
273 | else if (NULL != op->create_cont) | ||
274 | op->create_cont (op->cls, | ||
275 | NULL, | ||
276 | "Failed to communicate with the identity service"); | ||
277 | GNUNET_free_non_null (op->pk); | ||
262 | GNUNET_free (op); | 278 | GNUNET_free (op); |
263 | } | 279 | } |
264 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, | 280 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, |
@@ -350,6 +366,11 @@ handle_identity_result_code (void *cls, | |||
350 | str); | 366 | str); |
351 | else if (NULL != op->cb) | 367 | else if (NULL != op->cb) |
352 | op->cb (op->cls, NULL, NULL, NULL); | 368 | op->cb (op->cls, NULL, NULL, NULL); |
369 | else if (NULL != op->create_cont) | ||
370 | op->create_cont (op->cls, | ||
371 | (NULL == str) ? op->pk : NULL, | ||
372 | str); | ||
373 | GNUNET_free_non_null (op->pk); | ||
353 | GNUNET_free (op); | 374 | GNUNET_free (op); |
354 | } | 375 | } |
355 | 376 | ||
@@ -761,7 +782,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | |||
761 | struct GNUNET_IDENTITY_Operation * | 782 | struct GNUNET_IDENTITY_Operation * |
762 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | 783 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, |
763 | const char *name, | 784 | const char *name, |
764 | GNUNET_IDENTITY_Continuation cont, | 785 | GNUNET_IDENTITY_CreateContinuation cont, |
765 | void *cont_cls) | 786 | void *cont_cls) |
766 | { | 787 | { |
767 | struct GNUNET_IDENTITY_Operation *op; | 788 | struct GNUNET_IDENTITY_Operation *op; |
@@ -780,7 +801,7 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
780 | } | 801 | } |
781 | op = GNUNET_new (struct GNUNET_IDENTITY_Operation); | 802 | op = GNUNET_new (struct GNUNET_IDENTITY_Operation); |
782 | op->h = h; | 803 | op->h = h; |
783 | op->cont = cont; | 804 | op->create_cont = cont; |
784 | op->cls = cont_cls; | 805 | op->cls = cont_cls; |
785 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, | 806 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, |
786 | h->op_tail, | 807 | h->op_tail, |
@@ -792,7 +813,7 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
792 | crm->reserved = htons (0); | 813 | crm->reserved = htons (0); |
793 | pk = GNUNET_CRYPTO_ecdsa_key_create (); | 814 | pk = GNUNET_CRYPTO_ecdsa_key_create (); |
794 | crm->private_key = *pk; | 815 | crm->private_key = *pk; |
795 | GNUNET_free (pk); | 816 | op->pk = pk; |
796 | GNUNET_memcpy (&crm[1], | 817 | GNUNET_memcpy (&crm[1], |
797 | name, | 818 | name, |
798 | slen); | 819 | slen); |
@@ -924,6 +945,12 @@ GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op) | |||
924 | { | 945 | { |
925 | op->cont = NULL; | 946 | op->cont = NULL; |
926 | op->cb = NULL; | 947 | op->cb = NULL; |
948 | op->create_cont = NULL; | ||
949 | if (NULL != op->pk) | ||
950 | { | ||
951 | GNUNET_free (op->pk); | ||
952 | op->pk = NULL; | ||
953 | } | ||
927 | } | 954 | } |
928 | 955 | ||
929 | 956 | ||
@@ -957,6 +984,7 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h) | |||
957 | GNUNET_CONTAINER_DLL_remove (h->op_head, | 984 | GNUNET_CONTAINER_DLL_remove (h->op_head, |
958 | h->op_tail, | 985 | h->op_tail, |
959 | op); | 986 | op); |
987 | GNUNET_free_non_null (op->pk); | ||
960 | GNUNET_free (op); | 988 | GNUNET_free (op); |
961 | } | 989 | } |
962 | if (NULL != h->mq) | 990 | if (NULL != h->mq) |
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 89f590d3e..e6537070a 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -642,6 +642,26 @@ do_finished (void *cls, const char *emsg) | |||
642 | 642 | ||
643 | 643 | ||
644 | /** | 644 | /** |
645 | * Processing finished, when creating an ego. | ||
646 | * | ||
647 | * @param cls request handle | ||
648 | * @param private key of the ego, or NULL on error | ||
649 | * @param emsg error message | ||
650 | */ | ||
651 | static void | ||
652 | do_finished_create (void *cls, | ||
653 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | ||
654 | const char *emsg) | ||
655 | { | ||
656 | struct RequestHandle *handle = cls; | ||
657 | |||
658 | (void) pk; | ||
659 | do_finished (handle, | ||
660 | emsg); | ||
661 | } | ||
662 | |||
663 | |||
664 | /** | ||
645 | * Processing edit ego with EgoEntry ego_entry | 665 | * Processing edit ego with EgoEntry ego_entry |
646 | * | 666 | * |
647 | * @param handle the struct RequestHandle | 667 | * @param handle the struct RequestHandle |
@@ -1014,7 +1034,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1014 | json_decref (data_js); | 1034 | json_decref (data_js); |
1015 | handle->response_code = MHD_HTTP_CREATED; | 1035 | handle->response_code = MHD_HTTP_CREATED; |
1016 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, handle->name, | 1036 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, handle->name, |
1017 | &do_finished, handle); | 1037 | &do_finished_create, handle); |
1018 | } | 1038 | } |
1019 | 1039 | ||
1020 | /** | 1040 | /** |
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c index cfd759050..163394801 100644 --- a/src/identity/test_identity.c +++ b/src/identity/test_identity.c | |||
@@ -253,12 +253,15 @@ success_rename_cont (void *cls, | |||
253 | * Called with events about created ego. | 253 | * Called with events about created ego. |
254 | * | 254 | * |
255 | * @param cls NULL | 255 | * @param cls NULL |
256 | * @param pk private key of the ego, or NULL on error | ||
256 | * @param emsg error message | 257 | * @param emsg error message |
257 | */ | 258 | */ |
258 | static void | 259 | static void |
259 | create_cb (void *cls, | 260 | create_cb (void *cls, |
261 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | ||
260 | const char *emsg) | 262 | const char *emsg) |
261 | { | 263 | { |
264 | GNUNET_assert (NULL != pk); | ||
262 | GNUNET_assert (NULL == emsg); | 265 | GNUNET_assert (NULL == emsg); |
263 | op = GNUNET_IDENTITY_rename (h, | 266 | op = GNUNET_IDENTITY_rename (h, |
264 | "test-id", | 267 | "test-id", |
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c index a7559cd94..bcd75e84c 100644 --- a/src/identity/test_identity_defaults.c +++ b/src/identity/test_identity_defaults.c | |||
@@ -225,13 +225,16 @@ notification_cb (void *cls, | |||
225 | * Called with events about created ego. | 225 | * Called with events about created ego. |
226 | * | 226 | * |
227 | * @param cls NULL | 227 | * @param cls NULL |
228 | * @param pk private key of the ego, or NULL on error | ||
228 | * @param emsg error message | 229 | * @param emsg error message |
229 | */ | 230 | */ |
230 | static void | 231 | static void |
231 | create_cb (void *cls, | 232 | create_cb (void *cls, |
233 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | ||
232 | const char *emsg) | 234 | const char *emsg) |
233 | { | 235 | { |
234 | GNUNET_assert (NULL == emsg); | 236 | GNUNET_assert (NULL == emsg); |
237 | GNUNET_assert (NULL != pk); | ||
235 | op = NULL; | 238 | op = NULL; |
236 | } | 239 | } |
237 | 240 | ||