diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-06 14:18:31 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-06 14:18:31 +0000 |
commit | fe76c075e315c0351e2fe465434ae39087daf014 (patch) | |
tree | 436887ccaf331932a3c13a8b9d2a2a710dad4be6 /src/identity/gnunet-service-identity.c | |
parent | 7eb2835d8a494c83aedb720a2ac6f6e5ba23f22f (diff) | |
download | gnunet-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/gnunet-service-identity.c')
-rw-r--r-- | src/identity/gnunet-service-identity.c | 81 |
1 files changed, 27 insertions, 54 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 * | |||
209 | create_update_message (struct Ego *ego) | 209 | create_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 | |||
383 | key_cmp (const struct GNUNET_CRYPTO_EccPrivateKey *pk1, | 370 | key_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, |