diff options
Diffstat (limited to 'src/identity/identity_api.c')
-rw-r--r-- | src/identity/identity_api.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index 29d9b9011..9176acc27 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c | |||
@@ -74,7 +74,7 @@ struct GNUNET_IDENTITY_Operation | |||
74 | /** | 74 | /** |
75 | * Private key to return to @e create_cont, or NULL. | 75 | * Private key to return to @e create_cont, or NULL. |
76 | */ | 76 | */ |
77 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 77 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Continuation to invoke with the result of the transmission for | 80 | * Continuation to invoke with the result of the transmission for |
@@ -156,14 +156,18 @@ const struct GNUNET_IDENTITY_Ego * | |||
156 | GNUNET_IDENTITY_ego_get_anonymous () | 156 | GNUNET_IDENTITY_ego_get_anonymous () |
157 | { | 157 | { |
158 | static struct GNUNET_IDENTITY_Ego anon; | 158 | static struct GNUNET_IDENTITY_Ego anon; |
159 | static int setup; | ||
159 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 160 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
160 | 161 | ||
161 | if (NULL != anon.pk) | 162 | if (setup) |
162 | return &anon; | 163 | return &anon; |
163 | anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) | 164 | anon.pk = *GNUNET_CRYPTO_ecdsa_key_get_anonymous (); |
164 | GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | 165 | GNUNET_CRYPTO_ecdsa_key_get_public (&anon.pk, |
165 | GNUNET_CRYPTO_ecdsa_key_get_public (anon.pk, &pub); | 166 | &pub); |
166 | GNUNET_CRYPTO_hash (&pub, sizeof(pub), &anon.id); | 167 | GNUNET_CRYPTO_hash (&pub, |
168 | sizeof(pub), | ||
169 | &anon.id); | ||
170 | setup = 1; | ||
167 | return &anon; | 171 | return &anon; |
168 | } | 172 | } |
169 | 173 | ||
@@ -193,7 +197,6 @@ free_ego (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
193 | 197 | ||
194 | if (NULL != h->cb) | 198 | if (NULL != h->cb) |
195 | h->cb (h->cb_cls, ego, &ego->ctx, NULL); | 199 | h->cb (h->cb_cls, ego, &ego->ctx, NULL); |
196 | GNUNET_free (ego->pk); | ||
197 | GNUNET_free (ego->name); | 200 | GNUNET_free (ego->name); |
198 | GNUNET_assert (GNUNET_YES == | 201 | GNUNET_assert (GNUNET_YES == |
199 | GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value)); | 202 | GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value)); |
@@ -230,7 +233,6 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h) | |||
230 | op->create_cont (op->cls, | 233 | op->create_cont (op->cls, |
231 | NULL, | 234 | NULL, |
232 | "Failed to communicate with the identity service"); | 235 | "Failed to communicate with the identity service"); |
233 | GNUNET_free_non_null (op->pk); | ||
234 | GNUNET_free (op); | 236 | GNUNET_free (op); |
235 | } | 237 | } |
236 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); | 238 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); |
@@ -304,8 +306,7 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
304 | else if (NULL != op->cb) | 306 | else if (NULL != op->cb) |
305 | op->cb (op->cls, NULL, NULL, NULL); | 307 | op->cb (op->cls, NULL, NULL, NULL); |
306 | else if (NULL != op->create_cont) | 308 | else if (NULL != op->create_cont) |
307 | op->create_cont (op->cls, (NULL == str) ? op->pk : NULL, str); | 309 | op->create_cont (op->cls, (NULL == str) ? &op->pk : NULL, str); |
308 | GNUNET_free_non_null (op->pk); | ||
309 | GNUNET_free (op); | 310 | GNUNET_free (op); |
310 | } | 311 | } |
311 | 312 | ||
@@ -371,8 +372,7 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
371 | return; | 372 | return; |
372 | } | 373 | } |
373 | ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); | 374 | ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); |
374 | ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 375 | ego->pk = um->private_key; |
375 | *ego->pk = um->private_key; | ||
376 | ego->name = GNUNET_strdup (str); | 376 | ego->name = GNUNET_strdup (str); |
377 | ego->id = id; | 377 | ego->id = id; |
378 | GNUNET_assert (GNUNET_YES == | 378 | GNUNET_assert (GNUNET_YES == |
@@ -401,7 +401,6 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
401 | /* complete deletion */ | 401 | /* complete deletion */ |
402 | if (NULL == str) | 402 | if (NULL == str) |
403 | { | 403 | { |
404 | GNUNET_free (ego->pk); | ||
405 | GNUNET_free (ego->name); | 404 | GNUNET_free (ego->name); |
406 | GNUNET_free (ego); | 405 | GNUNET_free (ego); |
407 | } | 406 | } |
@@ -554,7 +553,7 @@ GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
554 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * | 553 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * |
555 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) | 554 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) |
556 | { | 555 | { |
557 | return ego->pk; | 556 | return &ego->pk; |
558 | } | 557 | } |
559 | 558 | ||
560 | 559 | ||
@@ -568,7 +567,8 @@ void | |||
568 | GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, | 567 | GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, |
569 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk) | 568 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk) |
570 | { | 569 | { |
571 | GNUNET_CRYPTO_ecdsa_key_get_public (ego->pk, pk); | 570 | GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk, |
571 | pk); | ||
572 | } | 572 | } |
573 | 573 | ||
574 | 574 | ||
@@ -657,7 +657,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | |||
657 | GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); | 657 | GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); |
658 | sdm->name_len = htons (slen); | 658 | sdm->name_len = htons (slen); |
659 | sdm->reserved = htons (0); | 659 | sdm->reserved = htons (0); |
660 | sdm->private_key = *ego->pk; | 660 | sdm->private_key = ego->pk; |
661 | GNUNET_memcpy (&sdm[1], service_name, slen); | 661 | GNUNET_memcpy (&sdm[1], service_name, slen); |
662 | GNUNET_MQ_send (h->mq, env); | 662 | GNUNET_MQ_send (h->mq, env); |
663 | return op; | 663 | return op; |
@@ -682,7 +682,6 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
682 | struct GNUNET_IDENTITY_Operation *op; | 682 | struct GNUNET_IDENTITY_Operation *op; |
683 | struct GNUNET_MQ_Envelope *env; | 683 | struct GNUNET_MQ_Envelope *env; |
684 | struct CreateRequestMessage *crm; | 684 | struct CreateRequestMessage *crm; |
685 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | ||
686 | size_t slen; | 685 | size_t slen; |
687 | 686 | ||
688 | if (NULL == h->mq) | 687 | if (NULL == h->mq) |
@@ -701,9 +700,8 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
701 | env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); | 700 | env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); |
702 | crm->name_len = htons (slen); | 701 | crm->name_len = htons (slen); |
703 | crm->reserved = htons (0); | 702 | crm->reserved = htons (0); |
704 | pk = GNUNET_CRYPTO_ecdsa_key_create (); | 703 | GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key); |
705 | crm->private_key = *pk; | 704 | op->pk = crm->private_key; |
706 | op->pk = pk; | ||
707 | GNUNET_memcpy (&crm[1], name, slen); | 705 | GNUNET_memcpy (&crm[1], name, slen); |
708 | GNUNET_MQ_send (h->mq, env); | 706 | GNUNET_MQ_send (h->mq, env); |
709 | return op; | 707 | return op; |
@@ -820,11 +818,9 @@ GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op) | |||
820 | op->cont = NULL; | 818 | op->cont = NULL; |
821 | op->cb = NULL; | 819 | op->cb = NULL; |
822 | op->create_cont = NULL; | 820 | op->create_cont = NULL; |
823 | if (NULL != op->pk) | 821 | memset (&op->pk, |
824 | { | 822 | 0, |
825 | GNUNET_free (op->pk); | 823 | sizeof (op->pk)); |
826 | op->pk = NULL; | ||
827 | } | ||
828 | } | 824 | } |
829 | 825 | ||
830 | 826 | ||
@@ -854,7 +850,9 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h) | |||
854 | { | 850 | { |
855 | GNUNET_break (NULL == op->cont); | 851 | GNUNET_break (NULL == op->cont); |
856 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 852 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
857 | GNUNET_free_non_null (op->pk); | 853 | memset (&op->pk, |
854 | 0, | ||
855 | sizeof (op->pk)); | ||
858 | GNUNET_free (op); | 856 | GNUNET_free (op); |
859 | } | 857 | } |
860 | if (NULL != h->mq) | 858 | if (NULL != h->mq) |