aboutsummaryrefslogtreecommitdiff
path: root/src/identity
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-11 21:43:28 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-11 21:43:34 +0200
commit90ff9edfa9c5fcfa3a36d1653ff105e89b888e21 (patch)
tree780a2071f5072c8e8e044db741eb295c3f3ea2a7 /src/identity
parent3bcfe59f1ce533246bda271f00b3ee957cae304d (diff)
downloadgnunet-90ff9edfa9c5fcfa3a36d1653ff105e89b888e21.tar.gz
gnunet-90ff9edfa9c5fcfa3a36d1653ff105e89b888e21.zip
fixing #6149
Diffstat (limited to 'src/identity')
-rw-r--r--src/identity/gnunet-service-identity.c33
-rw-r--r--src/identity/identity.h2
-rw-r--r--src/identity/identity_api.c50
-rw-r--r--src/identity/identity_api_lookup.c2
4 files changed, 45 insertions, 42 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index b509e7e9a..42ad94df1 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -57,7 +57,7 @@ struct Ego
57 /** 57 /**
58 * Private key of the ego. 58 * Private key of the ego.
59 */ 59 */
60 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 60 struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
61 61
62 /** 62 /**
63 * String identifier for the ego. 63 * String identifier for the ego.
@@ -190,7 +190,6 @@ shutdown_task (void *cls)
190 while (NULL != (e = ego_head)) 190 while (NULL != (e = ego_head))
191 { 191 {
192 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e); 192 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e);
193 GNUNET_free (e->pk);
194 GNUNET_free (e->identifier); 193 GNUNET_free (e->identifier);
195 GNUNET_free (e); 194 GNUNET_free (e);
196 } 195 }
@@ -247,7 +246,7 @@ create_update_message (struct Ego *ego)
247 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); 246 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
248 um->name_len = htons (name_len); 247 um->name_len = htons (name_len);
249 um->end_of_list = htons (GNUNET_NO); 248 um->end_of_list = htons (GNUNET_NO);
250 um->private_key = *ego->pk; 249 um->private_key = ego->pk;
251 GNUNET_memcpy (&um[1], ego->identifier, name_len); 250 GNUNET_memcpy (&um[1], ego->identifier, name_len);
252 return env; 251 return env;
253} 252}
@@ -273,7 +272,7 @@ create_set_default_message (struct Ego *ego, const char *servicename)
273 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); 272 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
274 sdm->name_len = htons (name_len); 273 sdm->name_len = htons (name_len);
275 sdm->reserved = htons (0); 274 sdm->reserved = htons (0);
276 sdm->private_key = *ego->pk; 275 sdm->private_key = ego->pk;
277 GNUNET_memcpy (&sdm[1], servicename, name_len); 276 GNUNET_memcpy (&sdm[1], servicename, name_len);
278 return env; 277 return env;
279} 278}
@@ -584,7 +583,8 @@ handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm)
584 str); 583 str);
585 for (ego = ego_head; NULL != ego; ego = ego->next) 584 for (ego = ego_head; NULL != ego; ego = ego->next)
586 { 585 {
587 if (0 == key_cmp (ego->pk, &sdm->private_key)) 586 if (0 == key_cmp (&ego->pk,
587 &sdm->private_key))
588 { 588 {
589 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 589 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
590 str, 590 str,
@@ -627,7 +627,7 @@ notify_listeners (struct Ego *ego)
627 um->header.size = htons (sizeof(struct UpdateMessage) + name_len); 627 um->header.size = htons (sizeof(struct UpdateMessage) + name_len);
628 um->name_len = htons (name_len); 628 um->name_len = htons (name_len);
629 um->end_of_list = htons (GNUNET_NO); 629 um->end_of_list = htons (GNUNET_NO);
630 um->private_key = *ego->pk; 630 um->private_key = ego->pk;
631 GNUNET_memcpy (&um[1], ego->identifier, name_len); 631 GNUNET_memcpy (&um[1], ego->identifier, name_len);
632 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO); 632 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO);
633 GNUNET_free (um); 633 GNUNET_free (um);
@@ -704,8 +704,7 @@ handle_create_message (void *cls, const struct CreateRequestMessage *crm)
704 } 704 }
705 } 705 }
706 ego = GNUNET_new (struct Ego); 706 ego = GNUNET_new (struct Ego);
707 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); 707 ego->pk = crm->private_key;
708 *ego->pk = crm->private_key;
709 ego->identifier = GNUNET_strdup (str); 708 ego->identifier = GNUNET_strdup (str);
710 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); 709 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
711 send_result_code (client, 0, NULL); 710 send_result_code (client, 0, NULL);
@@ -997,7 +996,6 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm)
997 GNUNET_free (ego->identifier); 996 GNUNET_free (ego->identifier);
998 ego->identifier = NULL; 997 ego->identifier = NULL;
999 notify_listeners (ego); 998 notify_listeners (ego);
1000 GNUNET_free (ego->pk);
1001 GNUNET_free (ego); 999 GNUNET_free (ego);
1002 GNUNET_free (name); 1000 GNUNET_free (name);
1003 send_result_code (client, 0, NULL); 1001 send_result_code (client, 0, NULL);
@@ -1023,7 +1021,8 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm)
1023 * #GNUNET_SYSERR to abort iteration with error! 1021 * #GNUNET_SYSERR to abort iteration with error!
1024 */ 1022 */
1025static int 1023static int
1026process_ego_file (void *cls, const char *filename) 1024process_ego_file (void *cls,
1025 const char *filename)
1027{ 1026{
1028 struct Ego *ego; 1027 struct Ego *ego;
1029 const char *fn; 1028 const char *fn;
@@ -1035,8 +1034,10 @@ process_ego_file (void *cls, const char *filename)
1035 return GNUNET_OK; 1034 return GNUNET_OK;
1036 } 1035 }
1037 ego = GNUNET_new (struct Ego); 1036 ego = GNUNET_new (struct Ego);
1038 ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file (filename); 1037 if (GNUNET_OK !=
1039 if (NULL == ego->pk) 1038 GNUNET_CRYPTO_ecdsa_key_from_file (filename,
1039 GNUNET_NO,
1040 &ego->pk))
1040 { 1041 {
1041 GNUNET_free (ego); 1042 GNUNET_free (ego);
1042 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1043 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1044,7 +1045,9 @@ process_ego_file (void *cls, const char *filename)
1044 filename); 1045 filename);
1045 return GNUNET_OK; 1046 return GNUNET_OK;
1046 } 1047 }
1047 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1); 1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1049 "Loaded ego `%s'\n",
1050 fn + 1);
1048 ego->identifier = GNUNET_strdup (fn + 1); 1051 ego->identifier = GNUNET_strdup (fn + 1);
1049 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); 1052 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
1050 return GNUNET_OK; 1053 return GNUNET_OK;
@@ -1108,7 +1111,9 @@ run (void *cls,
1108 _ ("Failed to create directory `%s' for storing egos\n"), 1111 _ ("Failed to create directory `%s' for storing egos\n"),
1109 ego_directory); 1112 ego_directory);
1110 } 1113 }
1111 GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL); 1114 GNUNET_DISK_directory_scan (ego_directory,
1115 &process_ego_file,
1116 NULL);
1112 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 1117 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1113} 1118}
1114 1119
diff --git a/src/identity/identity.h b/src/identity/identity.h
index b3c03d1ce..2303bf214 100644
--- a/src/identity/identity.h
+++ b/src/identity/identity.h
@@ -247,7 +247,7 @@ struct GNUNET_IDENTITY_Ego
247 /** 247 /**
248 * Private key associated with this ego. 248 * Private key associated with this ego.
249 */ 249 */
250 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 250 struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
251 251
252 /** 252 /**
253 * Current name associated with this ego. 253 * Current name associated with this ego.
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 *
156GNUNET_IDENTITY_ego_get_anonymous () 156GNUNET_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,
554const struct GNUNET_CRYPTO_EcdsaPrivateKey * 553const struct GNUNET_CRYPTO_EcdsaPrivateKey *
555GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) 554GNUNET_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
568GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, 567GNUNET_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)
diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c
index 108fc7fcf..6c61d3977 100644
--- a/src/identity/identity_api_lookup.c
+++ b/src/identity/identity_api_lookup.c
@@ -134,7 +134,7 @@ handle_identity_update (void *cls, const struct UpdateMessage *um)
134 GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); 134 GNUNET_break (GNUNET_YES != ntohs (um->end_of_list));
135 GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); 135 GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub);
136 GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id); 136 GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id);
137 ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) &um->private_key; 137 ego.pk = um->private_key;
138 ego.name = (char *) str; 138 ego.name = (char *) str;
139 ego.id = id; 139 ego.id = id;
140 el->cb (el->cb_cls, &ego); 140 el->cb (el->cb_cls, &ego);