aboutsummaryrefslogtreecommitdiff
path: root/src/identity
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-06 14:18:31 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-06 14:18:31 +0000
commitfe76c075e315c0351e2fe465434ae39087daf014 (patch)
tree436887ccaf331932a3c13a8b9d2a2a710dad4be6 /src/identity
parent7eb2835d8a494c83aedb720a2ac6f6e5ba23f22f (diff)
downloadgnunet-fe76c075e315c0351e2fe465434ae39087daf014.tar.gz
gnunet-fe76c075e315c0351e2fe465434ae39087daf014.zip
moving to new, fixed-size encoding of public and private ECC keys everywhere, also improving ECC API to better support ECRS/GADS operations
Diffstat (limited to 'src/identity')
-rw-r--r--src/identity/gnunet-service-identity.c81
-rw-r--r--src/identity/identity.h27
-rw-r--r--src/identity/identity_api.c158
3 files changed, 113 insertions, 153 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index eeaa4e253..b9384ea65 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -209,23 +209,16 @@ static struct GNUNET_IDENTITY_UpdateMessage *
209create_update_message (struct Ego *ego) 209create_update_message (struct Ego *ego)
210{ 210{
211 struct GNUNET_IDENTITY_UpdateMessage *um; 211 struct GNUNET_IDENTITY_UpdateMessage *um;
212 char *str;
213 uint16_t pk_len;
214 size_t name_len; 212 size_t name_len;
215 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc; 213
216
217 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); 214 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
218 enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk); 215 um = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + name_len);
219 pk_len = ntohs (enc->size);
220 um = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len);
221 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); 216 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
222 um->header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len); 217 um->header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + name_len);
223 um->name_len = htons (name_len); 218 um->name_len = htons (name_len);
224 um->pk_len = htons (pk_len); 219 um->end_of_list = htons (GNUNET_NO);
225 str = (char *) &um[1]; 220 um->private_key = *ego->pk;
226 memcpy (str, enc, pk_len); 221 memcpy (&um[1], ego->identifier, name_len);
227 memcpy (&str[pk_len], ego->identifier, name_len);
228 GNUNET_free (enc);
229 return um; 222 return um;
230} 223}
231 224
@@ -242,23 +235,16 @@ create_set_default_message (struct Ego *ego,
242 const char *servicename) 235 const char *servicename)
243{ 236{
244 struct GNUNET_IDENTITY_SetDefaultMessage *sdm; 237 struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
245 char *str;
246 uint16_t pk_len;
247 size_t name_len; 238 size_t name_len;
248 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
249 239
250 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1); 240 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
251 enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk); 241 sdm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + name_len);
252 pk_len = ntohs (enc->size);
253 sdm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len);
254 sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); 242 sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
255 sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len); 243 sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + name_len);
256 sdm->name_len = htons (name_len); 244 sdm->name_len = htons (name_len);
257 sdm->pk_len = htons (pk_len); 245 sdm->reserved = htons (0);
258 str = (char *) &sdm[1]; 246 sdm->private_key = *ego->pk;
259 memcpy (str, enc, pk_len); 247 memcpy (&sdm[1], servicename, name_len);
260 memcpy (&str[pk_len], servicename, name_len);
261 GNUNET_free (enc);
262 return sdm; 248 return sdm;
263} 249}
264 250
@@ -290,9 +276,10 @@ handle_start_message (void *cls, struct GNUNET_SERVER_Client *client,
290 GNUNET_SERVER_notification_context_unicast (nc, client, &um->header, GNUNET_NO); 276 GNUNET_SERVER_notification_context_unicast (nc, client, &um->header, GNUNET_NO);
291 GNUNET_free (um); 277 GNUNET_free (um);
292 } 278 }
279 memset (&ume, 0, sizeof (ume));
293 ume.header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); 280 ume.header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
294 ume.header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage)); 281 ume.header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage));
295 ume.pk_len = htons (0); 282 ume.end_of_list = htons (GNUNET_YES);
296 ume.name_len = htons (0); 283 ume.name_len = htons (0);
297 GNUNET_SERVER_notification_context_unicast (nc, client, &ume.header, GNUNET_NO); 284 GNUNET_SERVER_notification_context_unicast (nc, client, &ume.header, GNUNET_NO);
298 GNUNET_SERVER_receive_done (client, GNUNET_OK); 285 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -383,12 +370,7 @@ static int
383key_cmp (const struct GNUNET_CRYPTO_EccPrivateKey *pk1, 370key_cmp (const struct GNUNET_CRYPTO_EccPrivateKey *pk1,
384 const struct GNUNET_CRYPTO_EccPrivateKey *pk2) 371 const struct GNUNET_CRYPTO_EccPrivateKey *pk2)
385{ 372{
386 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p1; 373 return memcmp (pk1, pk2, sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
387 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded p2;
388
389 GNUNET_CRYPTO_ecc_key_get_public (pk1, &p1);
390 GNUNET_CRYPTO_ecc_key_get_public (pk2, &p2);
391 return memcmp (&p1, &p2, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
392} 374}
393 375
394 376
@@ -407,10 +389,8 @@ handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
407 const struct GNUNET_IDENTITY_SetDefaultMessage *sdm; 389 const struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
408 uint16_t size; 390 uint16_t size;
409 uint16_t name_len; 391 uint16_t name_len;
410 uint16_t pk_len;
411 struct Ego *ego; 392 struct Ego *ego;
412 const char *str; 393 const char *str;
413 struct GNUNET_CRYPTO_EccPrivateKey *pk;
414 394
415 size = ntohs (message->size); 395 size = ntohs (message->size);
416 if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) 396 if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
@@ -421,16 +401,14 @@ handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
421 } 401 }
422 sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) message; 402 sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) message;
423 name_len = ntohs (sdm->name_len); 403 name_len = ntohs (sdm->name_len);
424 pk_len = ntohs (sdm->pk_len); 404 GNUNET_break (0 == ntohs (sdm->reserved));
425 str = (const char *) &sdm[1]; 405 if (name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size)
426 if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size) ||
427 (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES))) )
428 { 406 {
429 GNUNET_break (0); 407 GNUNET_break (0);
430 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 408 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
431 return; 409 return;
432 } 410 }
433 str = &str[pk_len]; 411 str = (const char *) &sdm[1];
434 if ('\0' != str[name_len - 1]) 412 if ('\0' != str[name_len - 1])
435 { 413 {
436 GNUNET_break (0); 414 GNUNET_break (0);
@@ -443,7 +421,7 @@ handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
443 for (ego = ego_head; NULL != ego; ego = ego->next) 421 for (ego = ego_head; NULL != ego; ego = ego->next)
444 { 422 {
445 if (0 == key_cmp (ego->pk, 423 if (0 == key_cmp (ego->pk,
446 pk)) 424 &sdm->private_key))
447 { 425 {
448 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 426 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
449 str, 427 str,
@@ -457,13 +435,11 @@ handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
457 subsystem_cfg_file); 435 subsystem_cfg_file);
458 send_result_code (client, 0, NULL); 436 send_result_code (client, 0, NULL);
459 GNUNET_SERVER_receive_done (client, GNUNET_OK); 437 GNUNET_SERVER_receive_done (client, GNUNET_OK);
460 GNUNET_CRYPTO_ecc_key_free (pk);
461 return; 438 return;
462 } 439 }
463 } 440 }
464 send_result_code (client, 1, _("Unknown ego specified for service (internal error)")); 441 send_result_code (client, 1, _("Unknown ego specified for service (internal error)"));
465 GNUNET_SERVER_receive_done (client, GNUNET_OK); 442 GNUNET_SERVER_receive_done (client, GNUNET_OK);
466 GNUNET_CRYPTO_ecc_key_free (pk);
467} 443}
468 444
469 445
@@ -498,11 +474,8 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
498 const struct GNUNET_IDENTITY_CreateRequestMessage *crm; 474 const struct GNUNET_IDENTITY_CreateRequestMessage *crm;
499 uint16_t size; 475 uint16_t size;
500 uint16_t name_len; 476 uint16_t name_len;
501 uint16_t pk_len;
502 struct Ego *ego; 477 struct Ego *ego;
503 const char *pks;
504 const char *str; 478 const char *str;
505 struct GNUNET_CRYPTO_EccPrivateKey *pk;
506 char *fn; 479 char *fn;
507 480
508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -516,16 +489,14 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
516 } 489 }
517 crm = (const struct GNUNET_IDENTITY_CreateRequestMessage *) message; 490 crm = (const struct GNUNET_IDENTITY_CreateRequestMessage *) message;
518 name_len = ntohs (crm->name_len); 491 name_len = ntohs (crm->name_len);
519 pk_len = ntohs (crm->pk_len); 492 GNUNET_break (0 == ntohs (crm->reserved));
520 pks = (const char *) &crm[1]; 493 if (name_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size)
521 if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size) ||
522 (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (pks, pk_len, GNUNET_YES))) )
523 { 494 {
524 GNUNET_break (0); 495 GNUNET_break (0);
525 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 496 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
526 return; 497 return;
527 } 498 }
528 str = &pks[pk_len]; 499 str = (const char *) &crm[1];
529 if ('\0' != str[name_len - 1]) 500 if ('\0' != str[name_len - 1])
530 { 501 {
531 GNUNET_break (0); 502 GNUNET_break (0);
@@ -539,12 +510,12 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
539 { 510 {
540 send_result_code (client, 1, gettext_noop ("identifier already in use for another ego")); 511 send_result_code (client, 1, gettext_noop ("identifier already in use for another ego"));
541 GNUNET_SERVER_receive_done (client, GNUNET_OK); 512 GNUNET_SERVER_receive_done (client, GNUNET_OK);
542 GNUNET_CRYPTO_ecc_key_free (pk);
543 return; 513 return;
544 } 514 }
545 } 515 }
546 ego = GNUNET_new (struct Ego); 516 ego = GNUNET_new (struct Ego);
547 ego->pk = pk; 517 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
518 *ego->pk = crm->private_key;
548 ego->identifier = GNUNET_strdup (str); 519 ego->identifier = GNUNET_strdup (str);
549 GNUNET_CONTAINER_DLL_insert (ego_head, 520 GNUNET_CONTAINER_DLL_insert (ego_head,
550 ego_tail, 521 ego_tail,
@@ -552,8 +523,10 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
552 send_result_code (client, 0, NULL); 523 send_result_code (client, 0, NULL);
553 fn = get_ego_filename (ego); 524 fn = get_ego_filename (ego);
554 (void) GNUNET_DISK_directory_create_for_file (fn); 525 (void) GNUNET_DISK_directory_create_for_file (fn);
555 if (pk_len != 526 if (sizeof (struct GNUNET_CRYPTO_EccPrivateKey) !=
556 GNUNET_DISK_fn_write (fn, pks, pk_len, 527 GNUNET_DISK_fn_write (fn,
528 &crm->private_key,
529 sizeof (struct GNUNET_CRYPTO_EccPrivateKey),
557 GNUNET_DISK_PERM_USER_READ | 530 GNUNET_DISK_PERM_USER_READ |
558 GNUNET_DISK_PERM_USER_WRITE)) 531 GNUNET_DISK_PERM_USER_WRITE))
559 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 532 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/identity/identity.h b/src/identity/identity.h
index 181f5c353..13ac91e46 100644
--- a/src/identity/identity.h
+++ b/src/identity/identity.h
@@ -74,11 +74,14 @@ struct GNUNET_IDENTITY_UpdateMessage
74 uint16_t name_len GNUNET_PACKED; 74 uint16_t name_len GNUNET_PACKED;
75 75
76 /** 76 /**
77 * Number of bytes of private key data that follow, in NBO. 77 * Usually GNUNET_NO, GNUNET_YES to signal end of list.
78 */ 78 */
79 uint16_t pk_len GNUNET_PACKED; 79 uint16_t end_of_list GNUNET_PACKED;
80 80
81 /* followed by private key */ 81 /**
82 * The private key
83 */
84 struct GNUNET_CRYPTO_EccPrivateKey private_key;
82 85
83 /* followed by 0-terminated identity name */ 86 /* followed by 0-terminated identity name */
84 87
@@ -130,11 +133,14 @@ struct GNUNET_IDENTITY_SetDefaultMessage
130 uint16_t name_len GNUNET_PACKED; 133 uint16_t name_len GNUNET_PACKED;
131 134
132 /** 135 /**
133 * Number of bytes of private key data that follow, in NBO. 136 * Always zero.
134 */ 137 */
135 uint16_t pk_len GNUNET_PACKED; 138 uint16_t reserved GNUNET_PACKED;
136 139
137 /* followed by private key */ 140 /**
141 * The private key
142 */
143 struct GNUNET_CRYPTO_EccPrivateKey private_key;
138 144
139 /* followed by 0-terminated service name */ 145 /* followed by 0-terminated service name */
140 146
@@ -158,11 +164,14 @@ struct GNUNET_IDENTITY_CreateRequestMessage
158 uint16_t name_len GNUNET_PACKED; 164 uint16_t name_len GNUNET_PACKED;
159 165
160 /** 166 /**
161 * Number of bytes of private key data that follow, in NBO. 167 * Always zero.
162 */ 168 */
163 uint16_t pk_len GNUNET_PACKED; 169 uint16_t reserved GNUNET_PACKED;
164 170
165 /* followed by private key */ 171 /**
172 * The private key
173 */
174 struct GNUNET_CRYPTO_EccPrivateKey private_key;
166 175
167 /* followed by 0-terminated identity name */ 176 /* followed by 0-terminated identity name */
168 177
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index 54144c5bc..2062ddc63 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -48,9 +48,9 @@ struct GNUNET_IDENTITY_Ego
48 struct GNUNET_CRYPTO_EccPrivateKey *pk; 48 struct GNUNET_CRYPTO_EccPrivateKey *pk;
49 49
50 /** 50 /**
51 * Current identifier (name) associated with this ego. 51 * Current name associated with this ego.
52 */ 52 */
53 char *identifier; 53 char *name;
54 54
55 /** 55 /**
56 * Client context associated with this ego. 56 * Client context associated with this ego.
@@ -234,12 +234,10 @@ message_handler (void *cls,
234 const struct GNUNET_IDENTITY_ResultCodeMessage *rcm; 234 const struct GNUNET_IDENTITY_ResultCodeMessage *rcm;
235 const struct GNUNET_IDENTITY_UpdateMessage *um; 235 const struct GNUNET_IDENTITY_UpdateMessage *um;
236 const struct GNUNET_IDENTITY_SetDefaultMessage *sdm; 236 const struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
237 struct GNUNET_CRYPTO_EccPrivateKey *priv; 237 struct GNUNET_CRYPTO_EccPublicKey pub;
238 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
239 struct GNUNET_HashCode id; 238 struct GNUNET_HashCode id;
240 const char *str; 239 const char *str;
241 uint16_t size; 240 uint16_t size;
242 uint16_t pk_len;
243 uint16_t name_len; 241 uint16_t name_len;
244 242
245 if (NULL == msg) 243 if (NULL == msg)
@@ -291,39 +289,31 @@ message_handler (void *cls,
291 return; 289 return;
292 } 290 }
293 um = (const struct GNUNET_IDENTITY_UpdateMessage *) msg; 291 um = (const struct GNUNET_IDENTITY_UpdateMessage *) msg;
294 pk_len = ntohs (um->pk_len); 292 name_len = ntohs (um->name_len);
295 name_len = ntohs (um->name_len); 293
296 str = (const char *) &um[1]; 294 str = (const char *) &um[1];
297 if ( (size != pk_len + name_len + sizeof (struct GNUNET_IDENTITY_UpdateMessage)) || 295 if ( (size != name_len + sizeof (struct GNUNET_IDENTITY_UpdateMessage)) ||
298 ( (0 != name_len) && 296 ( (0 != name_len) &&
299 ('\0' != str[pk_len + name_len - 1])) ) 297 ('\0' != str[name_len - 1])) )
300 { 298 {
301 GNUNET_break (0); 299 GNUNET_break (0);
302 reschedule_connect (h); 300 reschedule_connect (h);
303 return; 301 return;
304 } 302 }
305 if ( (0 == pk_len) && 303 if (GNUNET_YES == ntohs (um->end_of_list))
306 (0 == name_len) )
307 { 304 {
308 /* end of initial list of data */ 305 /* end of initial list of data */
309 if (NULL != h->cb) 306 if (NULL != h->cb)
310 h->cb (h->cb_cls, NULL, NULL, NULL); 307 h->cb (h->cb_cls, NULL, NULL, NULL);
311 break; 308 break;
312 } 309 }
313 priv = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES); 310 GNUNET_CRYPTO_ecc_key_get_public (&um->private_key,
314 if (NULL == priv)
315 {
316 GNUNET_break (0);
317 reschedule_connect (h);
318 return;
319 }
320 GNUNET_CRYPTO_ecc_key_get_public (priv,
321 &pub); 311 &pub);
322 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id); 312 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id);
323 if (0 == name_len) 313 if (0 == name_len)
324 str = NULL; 314 str = NULL;
325 else 315 else
326 str = &str[pk_len]; 316 str = (const char *) &um[1];
327 ego = GNUNET_CONTAINER_multihashmap_get (h->egos, 317 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
328 &id); 318 &id);
329 if (NULL == ego) 319 if (NULL == ego)
@@ -333,13 +323,13 @@ message_handler (void *cls,
333 { 323 {
334 /* deletion of unknown ego? not allowed */ 324 /* deletion of unknown ego? not allowed */
335 GNUNET_break (0); 325 GNUNET_break (0);
336 GNUNET_CRYPTO_ecc_key_free (priv);
337 reschedule_connect (h); 326 reschedule_connect (h);
338 return; 327 return;
339 } 328 }
340 ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); 329 ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
341 ego->pk = priv; 330 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
342 ego->identifier = GNUNET_strdup (str); 331 *ego->pk = um->private_key;
332 ego->name = GNUNET_strdup (str);
343 ego->id = id; 333 ego->id = id;
344 GNUNET_assert (GNUNET_YES == 334 GNUNET_assert (GNUNET_YES ==
345 GNUNET_CONTAINER_multihashmap_put (h->egos, 335 GNUNET_CONTAINER_multihashmap_put (h->egos,
@@ -347,10 +337,6 @@ message_handler (void *cls,
347 ego, 337 ego,
348 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 338 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
349 } 339 }
350 else
351 {
352 GNUNET_CRYPTO_ecc_key_free (priv);
353 }
354 /* inform application about change */ 340 /* inform application about change */
355 if (NULL != h->cb) 341 if (NULL != h->cb)
356 h->cb (h->cb_cls, 342 h->cb (h->cb_cls,
@@ -365,14 +351,14 @@ message_handler (void *cls,
365 &ego->id, 351 &ego->id,
366 ego)); 352 ego));
367 GNUNET_CRYPTO_ecc_key_free (ego->pk); 353 GNUNET_CRYPTO_ecc_key_free (ego->pk);
368 GNUNET_free (ego->identifier); 354 GNUNET_free (ego->name);
369 GNUNET_free (ego); 355 GNUNET_free (ego);
370 } 356 }
371 else 357 else
372 { 358 {
373 /* ego changed name */ 359 /* ego changed name */
374 GNUNET_free (ego->identifier); 360 GNUNET_free (ego->name);
375 ego->identifier = GNUNET_strdup (str); 361 ego->name = GNUNET_strdup (str);
376 } 362 }
377 break; 363 break;
378 case GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT: 364 case GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT:
@@ -383,32 +369,24 @@ message_handler (void *cls,
383 return; 369 return;
384 } 370 }
385 sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) msg; 371 sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) msg;
386 pk_len = ntohs (sdm->pk_len); 372 GNUNET_break (0 == ntohs (sdm->reserved));
387 name_len = ntohs (sdm->name_len); 373 name_len = ntohs (sdm->name_len);
388 str = (const char *) &sdm[1]; 374 str = (const char *) &sdm[1];
389 if ( (size != pk_len + name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) || 375 if ( (size != name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) ||
390 ( (0 != name_len) && 376 ( (0 != name_len) &&
391 ('\0' != str[pk_len + name_len - 1]) ) ) 377 ('\0' != str[name_len - 1]) ) )
392 { 378 {
393 GNUNET_break (0); 379 GNUNET_break (0);
394 reschedule_connect (h); 380 reschedule_connect (h);
395 return; 381 return;
396 } 382 }
397 priv = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES); 383 GNUNET_CRYPTO_ecc_key_get_public (&sdm->private_key,
398 if (NULL == priv)
399 {
400 GNUNET_break (0);
401 reschedule_connect (h);
402 return;
403 }
404 GNUNET_CRYPTO_ecc_key_get_public (priv,
405 &pub); 384 &pub);
406 GNUNET_CRYPTO_ecc_key_free (priv);
407 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id); 385 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id);
408 if (0 == name_len) 386 if (0 == name_len)
409 str = NULL; 387 str = NULL;
410 else 388 else
411 str = &str[pk_len]; 389 str = (const char *) &sdm[1];
412 ego = GNUNET_CONTAINER_multihashmap_get (h->egos, 390 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
413 &id); 391 &id);
414 if (NULL == ego) 392 if (NULL == ego)
@@ -425,7 +403,7 @@ message_handler (void *cls,
425 op->cb (op->cls, 403 op->cb (op->cls,
426 ego, 404 ego,
427 &ego->ctx, 405 &ego->ctx,
428 ego->identifier); 406 ego->name);
429 GNUNET_free (op); 407 GNUNET_free (op);
430 break; 408 break;
431 default: 409 default:
@@ -588,13 +566,27 @@ GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
588 * @return associated ECC key, valid as long as the ego is valid 566 * @return associated ECC key, valid as long as the ego is valid
589 */ 567 */
590const struct GNUNET_CRYPTO_EccPrivateKey * 568const struct GNUNET_CRYPTO_EccPrivateKey *
591GNUNET_IDENTITY_ego_get_key (struct GNUNET_IDENTITY_Ego *ego) 569GNUNET_IDENTITY_ego_get_private_key (struct GNUNET_IDENTITY_Ego *ego)
592{ 570{
593 return ego->pk; 571 return ego->pk;
594} 572}
595 573
596 574
597/** 575/**
576 * Get the identifier (public key) of an ego.
577 *
578 * @param ego identity handle with the private key
579 * @param pk set to ego's public key
580 */
581void
582GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
583 struct GNUNET_CRYPTO_EccPublicKey *pk)
584{
585 GNUNET_assert (0);
586}
587
588
589/**
598 * Obtain the identity that is currently preferred/default 590 * Obtain the identity that is currently preferred/default
599 * for a service. 591 * for a service.
600 * 592 *
@@ -660,38 +652,30 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *id,
660 GNUNET_IDENTITY_Continuation cont, 652 GNUNET_IDENTITY_Continuation cont,
661 void *cont_cls) 653 void *cont_cls)
662{ 654{
663 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
664 struct GNUNET_IDENTITY_Operation *op; 655 struct GNUNET_IDENTITY_Operation *op;
665 struct GNUNET_IDENTITY_SetDefaultMessage *sdm; 656 struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
666 char *str;
667 uint16_t enc_len;
668 size_t slen; 657 size_t slen;
669 658
670 slen = strlen (service_name) + 1; 659 slen = strlen (service_name) + 1;
671 enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk); 660 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
672 enc_len = ntohs (enc->size);
673
674 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) - enc_len)
675 { 661 {
676 GNUNET_break (0); 662 GNUNET_break (0);
677 GNUNET_free (enc);
678 return NULL; 663 return NULL;
679 } 664 }
680 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) + 665 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
681 sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + 666 sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) +
682 enc_len + slen); 667 slen);
683 op->h = id; 668 op->h = id;
684 op->cont = cont; 669 op->cont = cont;
685 op->cls = cont_cls; 670 op->cls = cont_cls;
686 sdm = (struct GNUNET_IDENTITY_SetDefaultMessage *) &op[1]; 671 sdm = (struct GNUNET_IDENTITY_SetDefaultMessage *) &op[1];
687 sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); 672 sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
688 sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + 673 sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) +
689 slen + enc_len); 674 slen);
690 sdm->name_len = htons (slen); 675 sdm->name_len = htons (slen);
691 sdm->pk_len = htons (enc_len); 676 sdm->reserved = htons (0);
692 str = (char *) &sdm[1]; 677 sdm->private_key = *ego->pk;
693 memcpy (str, enc, enc_len); 678 memcpy (&sdm[1], service_name, slen);
694 memcpy (&str[enc_len], service_name, slen);
695 op->msg = &sdm->header; 679 op->msg = &sdm->header;
696 GNUNET_CONTAINER_DLL_insert_tail (id->op_head, 680 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
697 id->op_tail, 681 id->op_tail,
@@ -703,61 +687,55 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *id,
703 687
704 688
705/** 689/**
706 * Create a new identity with the given identifier. 690 * Create a new identity with the given name.
707 * 691 *
708 * @param id identity service to use 692 * @param id identity service to use
709 * @param identifier desired identifier 693 * @param name desired name
710 * @param cont function to call with the result (will only be called once) 694 * @param cont function to call with the result (will only be called once)
711 * @param cont_cls closure for cont 695 * @param cont_cls closure for cont
712 * @return handle to abort the operation 696 * @return handle to abort the operation
713 */ 697 */
714struct GNUNET_IDENTITY_Operation * 698struct GNUNET_IDENTITY_Operation *
715GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, 699GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
716 const char *identifier, 700 const char *name,
717 GNUNET_IDENTITY_Continuation cont, 701 GNUNET_IDENTITY_Continuation cont,
718 void *cont_cls) 702 void *cont_cls)
719{ 703{
720 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
721 struct GNUNET_IDENTITY_Operation *op; 704 struct GNUNET_IDENTITY_Operation *op;
722 struct GNUNET_IDENTITY_CreateRequestMessage *crm; 705 struct GNUNET_IDENTITY_CreateRequestMessage *crm;
723 struct GNUNET_CRYPTO_EccPrivateKey *pk; 706 struct GNUNET_CRYPTO_EccPrivateKey *pk;
724 char *str;
725 uint16_t enc_len;
726 size_t slen; 707 size_t slen;
727 708
728 slen = strlen (identifier) + 1; 709 slen = strlen (name) + 1;
729 pk = GNUNET_CRYPTO_ecc_key_create (); 710 pk = GNUNET_CRYPTO_ecc_key_create ();
730 enc = GNUNET_CRYPTO_ecc_encode_key (pk);
731 GNUNET_CRYPTO_ecc_key_free (pk);
732 enc_len = ntohs (enc->size);
733 711
734 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) - enc_len) 712 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_CreateRequestMessage))
735 { 713 {
736 GNUNET_break (0); 714 GNUNET_break (0);
737 GNUNET_free (enc); 715 GNUNET_CRYPTO_ecc_key_free (pk);
738 return NULL; 716 return NULL;
739 } 717 }
740 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) + 718 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
741 sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) + 719 sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
742 enc_len + slen); 720 slen);
743 op->h = id; 721 op->h = id;
744 op->cont = cont; 722 op->cont = cont;
745 op->cls = cont_cls; 723 op->cls = cont_cls;
746 crm = (struct GNUNET_IDENTITY_CreateRequestMessage *) &op[1]; 724 crm = (struct GNUNET_IDENTITY_CreateRequestMessage *) &op[1];
747 crm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); 725 crm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
748 crm->header.size = htons (sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) + 726 crm->header.size = htons (sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
749 slen + enc_len); 727 slen);
750 crm->name_len = htons (slen); 728 crm->name_len = htons (slen);
751 crm->pk_len = htons (enc_len); 729 crm->reserved = htons (0);
752 str = (char *) &crm[1]; 730 crm->private_key = *pk;
753 memcpy (str, enc, enc_len); 731 memcpy (&crm[1], name, slen);
754 memcpy (&str[enc_len], identifier, slen);
755 op->msg = &crm->header; 732 op->msg = &crm->header;
756 GNUNET_CONTAINER_DLL_insert_tail (id->op_head, 733 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
757 id->op_tail, 734 id->op_tail,
758 op); 735 op);
759 if (NULL == id->th) 736 if (NULL == id->th)
760 transmit_next (id); 737 transmit_next (id);
738 GNUNET_CRYPTO_ecc_key_free (pk);
761 return op; 739 return op;
762} 740}
763 741
@@ -766,16 +744,16 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
766 * Renames an existing identity. 744 * Renames an existing identity.
767 * 745 *
768 * @param id identity service to use 746 * @param id identity service to use
769 * @param old_identifier old identifier 747 * @param old_name old name
770 * @param new_identifier desired new identifier 748 * @param new_name desired new name
771 * @param cb function to call with the result (will only be called once) 749 * @param cb function to call with the result (will only be called once)
772 * @param cb_cls closure for cb 750 * @param cb_cls closure for cb
773 * @return handle to abort the operation 751 * @return handle to abort the operation
774 */ 752 */
775struct GNUNET_IDENTITY_Operation * 753struct GNUNET_IDENTITY_Operation *
776GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id, 754GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
777 const char *old_identifier, 755 const char *old_name,
778 const char *new_identifier, 756 const char *new_name,
779 GNUNET_IDENTITY_Continuation cb, 757 GNUNET_IDENTITY_Continuation cb,
780 void *cb_cls) 758 void *cb_cls)
781{ 759{
@@ -785,8 +763,8 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
785 size_t slen_new; 763 size_t slen_new;
786 char *dst; 764 char *dst;
787 765
788 slen_old = strlen (old_identifier) + 1; 766 slen_old = strlen (old_name) + 1;
789 slen_new = strlen (new_identifier) + 1; 767 slen_new = strlen (new_name) + 1;
790 if ( (slen_old >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 768 if ( (slen_old >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
791 (slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 769 (slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
792 (slen_old + slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_RenameMessage)) ) 770 (slen_old + slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_RenameMessage)) )
@@ -807,8 +785,8 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
807 grm->old_name_len = htons (slen_old); 785 grm->old_name_len = htons (slen_old);
808 grm->new_name_len = htons (slen_new); 786 grm->new_name_len = htons (slen_new);
809 dst = (char *) &grm[1]; 787 dst = (char *) &grm[1];
810 memcpy (dst, old_identifier, slen_old); 788 memcpy (dst, old_name, slen_old);
811 memcpy (&dst[slen_old], new_identifier, slen_new); 789 memcpy (&dst[slen_old], new_name, slen_new);
812 op->msg = &grm->header; 790 op->msg = &grm->header;
813 GNUNET_CONTAINER_DLL_insert_tail (id->op_head, 791 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
814 id->op_tail, 792 id->op_tail,
@@ -823,14 +801,14 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
823 * Delete an existing identity. 801 * Delete an existing identity.
824 * 802 *
825 * @param id identity service to use 803 * @param id identity service to use
826 * @param identifier identifier of the identity to delete 804 * @param name name of the identity to delete
827 * @param cb function to call with the result (will only be called once) 805 * @param cb function to call with the result (will only be called once)
828 * @param cb_cls closure for cb 806 * @param cb_cls closure for cb
829 * @return handle to abort the operation 807 * @return handle to abort the operation
830 */ 808 */
831struct GNUNET_IDENTITY_Operation * 809struct GNUNET_IDENTITY_Operation *
832GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id, 810GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id,
833 const char *identifier, 811 const char *name,
834 GNUNET_IDENTITY_Continuation cb, 812 GNUNET_IDENTITY_Continuation cb,
835 void *cb_cls) 813 void *cb_cls)
836{ 814{
@@ -838,7 +816,7 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id,
838 struct GNUNET_IDENTITY_DeleteMessage *gdm; 816 struct GNUNET_IDENTITY_DeleteMessage *gdm;
839 size_t slen; 817 size_t slen;
840 818
841 slen = strlen (identifier) + 1; 819 slen = strlen (name) + 1;
842 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_DeleteMessage)) 820 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_DeleteMessage))
843 { 821 {
844 GNUNET_break (0); 822 GNUNET_break (0);
@@ -856,7 +834,7 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id,
856 slen); 834 slen);
857 gdm->name_len = htons (slen); 835 gdm->name_len = htons (slen);
858 gdm->reserved = htons (0); 836 gdm->reserved = htons (0);
859 memcpy (&gdm[1], identifier, slen); 837 memcpy (&gdm[1], name, slen);
860 op->msg = &gdm->header; 838 op->msg = &gdm->header;
861 GNUNET_CONTAINER_DLL_insert_tail (id->op_head, 839 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
862 id->op_tail, 840 id->op_tail,
@@ -929,7 +907,7 @@ free_ego (void *cls,
929 &ego->ctx, 907 &ego->ctx,
930 NULL); 908 NULL);
931 GNUNET_CRYPTO_ecc_key_free (ego->pk); 909 GNUNET_CRYPTO_ecc_key_free (ego->pk);
932 GNUNET_free (ego->identifier); 910 GNUNET_free (ego->name);
933 GNUNET_free (ego); 911 GNUNET_free (ego);
934 return GNUNET_OK; 912 return GNUNET_OK;
935} 913}