diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-29 19:21:45 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-29 19:21:45 +0000 |
commit | 3ca1463193aadba06be89135c7a0ab34a3052de3 (patch) | |
tree | 4e2ec261d4eec5d02408f3e5b392b562249d127e | |
parent | e2eb1cbf30d6f59d9ad94e104317b245ef9b1d56 (diff) | |
download | gnunet-3ca1463193aadba06be89135c7a0ab34a3052de3.tar.gz gnunet-3ca1463193aadba06be89135c7a0ab34a3052de3.zip |
- namestore
-rw-r--r-- | src/namestore/Makefile.am | 7 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 152 | ||||
-rw-r--r-- | src/namestore/namestore.h | 17 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 51 | ||||
-rw-r--r-- | src/namestore/test_namestore_api_put.c | 4 | ||||
-rw-r--r-- | src/namestore/test_namestore_record_serialization.c | 26 |
6 files changed, 205 insertions, 52 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 39765b496..2e2f08042 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -27,6 +27,7 @@ check_PROGRAMS = \ | |||
27 | test_namestore_api \ | 27 | test_namestore_api \ |
28 | test_namestore_api_put \ | 28 | test_namestore_api_put \ |
29 | test_namestore_api_lookup \ | 29 | test_namestore_api_lookup \ |
30 | test_namestore_api_create \ | ||
30 | test_namestore_api_zone_iteration \ | 31 | test_namestore_api_zone_iteration \ |
31 | test_namestore_record_serialization | 32 | test_namestore_record_serialization |
32 | 33 | ||
@@ -93,6 +94,12 @@ test_namestore_api_lookup_LDADD = \ | |||
93 | $(top_builddir)/src/util/libgnunetutil.la \ | 94 | $(top_builddir)/src/util/libgnunetutil.la \ |
94 | $(top_builddir)/src/namestore/libgnunetnamestore.la | 95 | $(top_builddir)/src/namestore/libgnunetnamestore.la |
95 | 96 | ||
97 | test_namestore_api_create_SOURCES = \ | ||
98 | test_namestore_api_create.c | ||
99 | test_namestore_api_create_LDADD = \ | ||
100 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
101 | $(top_builddir)/src/namestore/libgnunetnamestore.la | ||
102 | |||
96 | test_namestore_api_zone_iteration_SOURCES = \ | 103 | test_namestore_api_zone_iteration_SOURCES = \ |
97 | test_namestore_api_zone_iteration.c | 104 | test_namestore_api_zone_iteration.c |
98 | test_namestore_api_zone_iteration_LDADD = \ | 105 | test_namestore_api_zone_iteration_LDADD = \ |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 1fbf108d2..0b85733ce 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "gnunet_service_lib.h" | 28 | #include "gnunet_service_lib.h" |
29 | #include "gnunet_namestore_service.h" | 29 | #include "gnunet_namestore_service.h" |
30 | #include "gnunet_namestore_plugin.h" | 30 | #include "gnunet_namestore_plugin.h" |
31 | #include "gnunet_signatures.h" | ||
31 | #include "namestore.h" | 32 | #include "namestore.h" |
32 | 33 | ||
33 | 34 | ||
@@ -262,6 +263,7 @@ handle_lookup_name_it (void *cls, | |||
262 | rd_selected = NULL; | 263 | rd_selected = NULL; |
263 | rd_ser = NULL; | 264 | rd_ser = NULL; |
264 | rd_ser_len = 0; | 265 | rd_ser_len = 0; |
266 | expire = GNUNET_TIME_UNIT_ZERO_ABS; | ||
265 | } | 267 | } |
266 | 268 | ||
267 | if ((copied_elements == rd_count) && (signature != NULL)) | 269 | if ((copied_elements == rd_count) && (signature != NULL)) |
@@ -281,7 +283,7 @@ handle_lookup_name_it (void *cls, | |||
281 | lnr_msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE); | 283 | lnr_msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE); |
282 | lnr_msg->header.size = ntohs (r_size); | 284 | lnr_msg->header.size = ntohs (r_size); |
283 | lnr_msg->op_id = htonl (lnc->id); | 285 | lnr_msg->op_id = htonl (lnc->id); |
284 | lnr_msg->rd_len = htonl (rd_ser_len); | 286 | lnr_msg->rd_len = htons (rd_ser_len); |
285 | lnr_msg->name_len = htons (name_len); | 287 | lnr_msg->name_len = htons (name_len); |
286 | lnr_msg->expire = GNUNET_TIME_absolute_hton(expire); | 288 | lnr_msg->expire = GNUNET_TIME_absolute_hton(expire); |
287 | lnr_msg->contains_sig = htons (contains_signature); | 289 | lnr_msg->contains_sig = htons (contains_signature); |
@@ -383,6 +385,7 @@ static void handle_record_put (void *cls, | |||
383 | size_t name_len; | 385 | size_t name_len; |
384 | size_t msg_size; | 386 | size_t msg_size; |
385 | size_t msg_size_exp; | 387 | size_t msg_size_exp; |
388 | size_t key_len; | ||
386 | char * name; | 389 | char * name; |
387 | char * rd_ser; | 390 | char * rd_ser; |
388 | uint32_t id = 0; | 391 | uint32_t id = 0; |
@@ -406,11 +409,13 @@ static void handle_record_put (void *cls, | |||
406 | } | 409 | } |
407 | 410 | ||
408 | struct RecordPutMessage * rp_msg = (struct RecordPutMessage *) message; | 411 | struct RecordPutMessage * rp_msg = (struct RecordPutMessage *) message; |
412 | |||
409 | id = ntohl (rp_msg->op_id); | 413 | id = ntohl (rp_msg->op_id); |
414 | key_len = sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); | ||
410 | name_len = ntohs (rp_msg->name_len); | 415 | name_len = ntohs (rp_msg->name_len); |
411 | rd_ser_len = ntohs(rp_msg->rd_len); | 416 | rd_ser_len = ntohs(rp_msg->rd_len); |
412 | msg_size = ntohs (message->size); | 417 | msg_size = ntohs (message->size); |
413 | msg_size_exp = sizeof (struct RecordPutMessage) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + name_len + rd_ser_len; | 418 | msg_size_exp = sizeof (struct RecordPutMessage) + key_len + name_len + rd_ser_len; |
414 | 419 | ||
415 | if (msg_size != msg_size_exp) | 420 | if (msg_size != msg_size_exp) |
416 | { | 421 | { |
@@ -429,7 +434,7 @@ static void handle_record_put (void *cls, | |||
429 | } | 434 | } |
430 | 435 | ||
431 | zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &rp_msg[1]; | 436 | zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &rp_msg[1]; |
432 | name = (char *) &zone_key[1]; | 437 | name = &((char *)zone_key)[key_len]; |
433 | 438 | ||
434 | if (name[name_len -1] != '\0') | 439 | if (name[name_len -1] != '\0') |
435 | { | 440 | { |
@@ -443,6 +448,11 @@ static void handle_record_put (void *cls, | |||
443 | rd_ser = &name[name_len]; | 448 | rd_ser = &name[name_len]; |
444 | rd_count = GNUNET_NAMESTORE_records_deserialize(&rd, rd_ser, rd_ser_len); | 449 | rd_count = GNUNET_NAMESTORE_records_deserialize(&rd, rd_ser, rd_ser_len); |
445 | 450 | ||
451 | GNUNET_HashCode zone_hash; | ||
452 | GNUNET_CRYPTO_hash (zone_key, key_len, &zone_hash); | ||
453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT ZONE HASH: `%s'\n", GNUNET_h2s_full(&zone_hash)); | ||
454 | |||
455 | |||
446 | /* Database operation */ | 456 | /* Database operation */ |
447 | res = GSN_database->put_records(GSN_database->cls, | 457 | res = GSN_database->put_records(GSN_database->cls, |
448 | zone_key, | 458 | zone_key, |
@@ -471,6 +481,84 @@ static void handle_record_put (void *cls, | |||
471 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 481 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
472 | } | 482 | } |
473 | 483 | ||
484 | struct CreateRecordContext | ||
485 | { | ||
486 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
487 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | ||
488 | struct GNUNET_TIME_Absolute expire; | ||
489 | uint32_t op_id; | ||
490 | struct GNUNET_NAMESTORE_Client *nc; | ||
491 | }; | ||
492 | |||
493 | struct GNUNET_CRYPTO_RsaSignature * | ||
494 | GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key, struct GNUNET_NAMESTORE_RecordData *rd, unsigned int rd_count) | ||
495 | { | ||
496 | struct GNUNET_CRYPTO_RsaSignature *sig = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaSignature)); | ||
497 | struct GNUNET_CRYPTO_RsaSignaturePurpose *sig_purpose; | ||
498 | size_t rd_ser_len; | ||
499 | char *rd_ser; | ||
500 | |||
501 | rd_ser_len = GNUNET_NAMESTORE_records_serialize(&rd_ser, rd_count, rd); | ||
502 | sig_purpose = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + rd_ser_len); | ||
503 | |||
504 | sig_purpose->size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)+ rd_ser_len); | ||
505 | sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | ||
506 | memcpy (&sig_purpose[1], rd_ser, rd_ser_len); | ||
507 | |||
508 | GNUNET_CRYPTO_rsa_sign (key, sig_purpose, sig); | ||
509 | |||
510 | GNUNET_free (rd_ser); | ||
511 | GNUNET_free (sig_purpose); | ||
512 | return sig; | ||
513 | } | ||
514 | |||
515 | static void | ||
516 | handle_create_record_it (void *cls, | ||
517 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
518 | struct GNUNET_TIME_Absolute expire, | ||
519 | const char *name, | ||
520 | unsigned int rd_count, | ||
521 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
522 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
523 | { | ||
524 | struct CreateRecordContext * crc = cls; | ||
525 | struct GNUNET_CRYPTO_RsaSignature *signature_new; | ||
526 | struct RecordCreateResponseMessage rcr_msg; | ||
527 | int res; | ||
528 | |||
529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u existing records for `%s'\n", rd_count, name); | ||
530 | struct GNUNET_NAMESTORE_RecordData *rd_new = GNUNET_malloc ((rd_count+1) * sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
531 | memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
532 | |||
533 | rd_new[rd_count] = *(crc->rd); | ||
534 | |||
535 | signature_new = GNUNET_NAMESTORE_create_signature (crc->pkey, rd_new, rd_count+1); | ||
536 | |||
537 | /* Database operation */ | ||
538 | res = GSN_database->put_records(GSN_database->cls, | ||
539 | zone_key, | ||
540 | expire, | ||
541 | name, | ||
542 | rd_count +1, rd_new, | ||
543 | signature_new); | ||
544 | |||
545 | GNUNET_free (rd_new); | ||
546 | GNUNET_free (signature_new); | ||
547 | |||
548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update result for name %u\n", res); | ||
549 | /* Send response */ | ||
550 | |||
551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_CREATE_RESPONSE"); | ||
552 | rcr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE); | ||
553 | rcr_msg.op_id = htonl (crc->op_id); | ||
554 | rcr_msg.header.size = htons (sizeof (struct RecordCreateResponseMessage)); | ||
555 | if (GNUNET_OK == res) | ||
556 | rcr_msg.op_result = htons (GNUNET_OK); | ||
557 | else | ||
558 | rcr_msg.op_result = htons (GNUNET_NO); | ||
559 | GNUNET_SERVER_notification_context_unicast (snc, crc->nc->client, (const struct GNUNET_MessageHeader *) &rcr_msg, GNUNET_NO); | ||
560 | |||
561 | } | ||
474 | 562 | ||
475 | static void handle_record_create (void *cls, | 563 | static void handle_record_create (void *cls, |
476 | struct GNUNET_SERVER_Client * client, | 564 | struct GNUNET_SERVER_Client * client, |
@@ -478,11 +566,21 @@ static void handle_record_create (void *cls, | |||
478 | { | 566 | { |
479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); | 567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); |
480 | struct GNUNET_NAMESTORE_Client *nc; | 568 | struct GNUNET_NAMESTORE_Client *nc; |
481 | struct RecordCreateResponseMessage rcr_msg; | 569 | struct GNUNET_NAMESTORE_RecordData *rd; |
570 | struct CreateRecordContext crc; | ||
571 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | ||
572 | GNUNET_HashCode pubkey_hash; | ||
482 | size_t name_len; | 573 | size_t name_len; |
483 | size_t msg_size; | 574 | size_t msg_size; |
484 | size_t msg_size_exp; | 575 | size_t msg_size_exp; |
576 | size_t rd_ser_len; | ||
577 | size_t key_len; | ||
485 | uint32_t id = 0; | 578 | uint32_t id = 0; |
579 | char *pkey_tmp; | ||
580 | char *name_tmp; | ||
581 | char *rd_ser; | ||
582 | int rd_count; | ||
583 | |||
486 | 584 | ||
487 | int res = GNUNET_SYSERR; | 585 | int res = GNUNET_SYSERR; |
488 | 586 | ||
@@ -505,7 +603,9 @@ static void handle_record_create (void *cls, | |||
505 | id = ntohl (rp_msg->op_id); | 603 | id = ntohl (rp_msg->op_id); |
506 | name_len = ntohs (rp_msg->name_len); | 604 | name_len = ntohs (rp_msg->name_len); |
507 | msg_size = ntohs (message->size); | 605 | msg_size = ntohs (message->size); |
508 | msg_size_exp = sizeof (struct RecordCreateMessage) + name_len + sizeof (struct GNUNET_NAMESTORE_RecordData); | 606 | rd_ser_len = ntohs (rp_msg->rd_len); |
607 | key_len = ntohs (rp_msg->pkey_len); | ||
608 | msg_size_exp = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len; | ||
509 | 609 | ||
510 | if (msg_size != msg_size_exp) | 610 | if (msg_size != msg_size_exp) |
511 | { | 611 | { |
@@ -515,38 +615,49 @@ static void handle_record_create (void *cls, | |||
515 | return; | 615 | return; |
516 | } | 616 | } |
517 | 617 | ||
518 | |||
519 | if ((name_len == 0) || (name_len > 256)) | 618 | if ((name_len == 0) || (name_len > 256)) |
520 | { | 619 | { |
521 | GNUNET_break_op (0); | 620 | GNUNET_break_op (0); |
522 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 621 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
523 | return; | 622 | return; |
524 | } | 623 | } |
525 | /* | 624 | |
526 | if (name[name_len -1] != '\0') | 625 | pkey_tmp = (char *) &rp_msg[1]; |
626 | name_tmp = &pkey_tmp[key_len]; | ||
627 | rd_ser = &name_tmp[name_len]; | ||
628 | |||
629 | if (name_tmp[name_len -1] != '\0') | ||
527 | { | 630 | { |
528 | GNUNET_break_op (0); | 631 | GNUNET_break_op (0); |
529 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 632 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
530 | return; | 633 | return; |
531 | } | 634 | } |
532 | */ | ||
533 | /* DO WORK HERE */ | ||
534 | 635 | ||
535 | /* Send response */ | 636 | rd_count = GNUNET_NAMESTORE_records_deserialize(&rd, rd_ser, rd_ser_len); |
637 | GNUNET_assert (rd_count == 1); | ||
536 | 638 | ||
537 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_CREATE_RESPONSE"); | 639 | /* Extracting and converting private key */ |
538 | rcr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE); | 640 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); |
539 | rcr_msg.op_id = rp_msg->op_id; | 641 | GNUNET_assert (pkey != NULL); |
540 | rcr_msg.header.size = htons (sizeof (struct RecordCreateResponseMessage)); | 642 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); |
541 | if (GNUNET_OK == res) | 643 | GNUNET_CRYPTO_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); |
542 | rcr_msg.op_result = htons (GNUNET_OK); | 644 | |
543 | else | 645 | crc.pkey = pkey; |
544 | rcr_msg.op_result = htons (GNUNET_NO); | 646 | crc.rd = rd; |
545 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rcr_msg, GNUNET_NO); | 647 | crc.nc = nc; |
648 | crc.op_id = id; | ||
649 | |||
650 | /* Get existing records for name */ | ||
651 | res = GSN_database->iterate_records(GSN_database->cls, &pubkey_hash, name_tmp, 0, &handle_create_record_it, &crc); | ||
652 | |||
653 | GNUNET_CRYPTO_rsa_key_free(pkey); | ||
654 | GNUNET_NAMESTORE_records_free(rd_count, rd); | ||
546 | 655 | ||
547 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 656 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
548 | } | 657 | } |
549 | 658 | ||
659 | |||
660 | |||
550 | static void handle_record_remove (void *cls, | 661 | static void handle_record_remove (void *cls, |
551 | struct GNUNET_SERVER_Client * client, | 662 | struct GNUNET_SERVER_Client * client, |
552 | const struct GNUNET_MessageHeader * message) | 663 | const struct GNUNET_MessageHeader * message) |
@@ -712,7 +823,6 @@ static void handle_iteration_start (void *cls, | |||
712 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); | 823 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); |
713 | 824 | ||
714 | res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, &zipr); | 825 | res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, &zipr); |
715 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "iterate_records result %u\n", res); | ||
716 | switch (res) { | 826 | switch (res) { |
717 | case GNUNET_OK: | 827 | case GNUNET_OK: |
718 | /* GNUNET_OK on success */ | 828 | /* GNUNET_OK on success */ |
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index 14a13801a..760d491e2 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h | |||
@@ -171,7 +171,7 @@ struct LookupNameResponseMessage | |||
171 | uint16_t contains_sig; | 171 | uint16_t contains_sig; |
172 | 172 | ||
173 | /* Requested record type */ | 173 | /* Requested record type */ |
174 | uint32_t rd_len; | 174 | uint16_t rd_len; |
175 | }; | 175 | }; |
176 | GNUNET_NETWORK_STRUCT_END | 176 | GNUNET_NETWORK_STRUCT_END |
177 | 177 | ||
@@ -202,6 +202,9 @@ struct RecordPutMessage | |||
202 | /* Length of serialized rd data */ | 202 | /* Length of serialized rd data */ |
203 | uint16_t rd_len; | 203 | uint16_t rd_len; |
204 | 204 | ||
205 | /* Length of pubkey */ | ||
206 | uint16_t key_len; | ||
207 | |||
205 | struct GNUNET_TIME_AbsoluteNBO expire; | 208 | struct GNUNET_TIME_AbsoluteNBO expire; |
206 | 209 | ||
207 | struct GNUNET_CRYPTO_RsaSignature signature; | 210 | struct GNUNET_CRYPTO_RsaSignature signature; |
@@ -235,9 +238,9 @@ GNUNET_NETWORK_STRUCT_END | |||
235 | 238 | ||
236 | 239 | ||
237 | /** | 240 | /** |
238 | * Put a record to the namestore | 241 | * Create a record and put it to the namestore |
239 | * Memory layout: | 242 | * Memory layout: |
240 | * [struct RecordPutMessage][struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData] | 243 | * [struct RecordCreateMessage][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData] |
241 | */ | 244 | */ |
242 | GNUNET_NETWORK_STRUCT_BEGIN | 245 | GNUNET_NETWORK_STRUCT_BEGIN |
243 | struct RecordCreateMessage | 246 | struct RecordCreateMessage |
@@ -257,7 +260,11 @@ struct RecordCreateMessage | |||
257 | /* name length */ | 260 | /* name length */ |
258 | uint16_t name_len; | 261 | uint16_t name_len; |
259 | 262 | ||
260 | struct GNUNET_CRYPTO_RsaSignature signature; | 263 | /* Record data length */ |
264 | uint16_t rd_len; | ||
265 | |||
266 | /* private key length */ | ||
267 | uint16_t pkey_len; | ||
261 | }; | 268 | }; |
262 | GNUNET_NETWORK_STRUCT_END | 269 | GNUNET_NETWORK_STRUCT_END |
263 | 270 | ||
@@ -285,6 +292,8 @@ struct RecordCreateResponseMessage | |||
285 | * name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success | 292 | * name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success |
286 | */ | 293 | */ |
287 | uint16_t op_result; | 294 | uint16_t op_result; |
295 | |||
296 | |||
288 | }; | 297 | }; |
289 | GNUNET_NETWORK_STRUCT_END | 298 | GNUNET_NETWORK_STRUCT_END |
290 | 299 | ||
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index e764c0949..61bd29dc1 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -27,10 +27,18 @@ | |||
27 | 27 | ||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_crypto_lib.h" | ||
30 | #include "gnunet_constants.h" | 31 | #include "gnunet_constants.h" |
31 | #include "gnunet_arm_service.h" | 32 | #include "gnunet_arm_service.h" |
32 | #include "gnunet_namestore_service.h" | 33 | #include "gnunet_namestore_service.h" |
33 | #include "namestore.h" | 34 | #include "namestore.h" |
35 | |||
36 | #include "platform.h" | ||
37 | #include <gcrypt.h> | ||
38 | #include "gnunet_common.h" | ||
39 | #include "gnunet_crypto_lib.h" | ||
40 | #include "gnunet_disk_lib.h" | ||
41 | |||
34 | #define DEBUG_GNS_API GNUNET_EXTRA_LOGGING | 42 | #define DEBUG_GNS_API GNUNET_EXTRA_LOGGING |
35 | 43 | ||
36 | #define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__) | 44 | #define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__) |
@@ -212,7 +220,7 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
212 | int contains_sig = GNUNET_NO; | 220 | int contains_sig = GNUNET_NO; |
213 | int rd_count = 0; | 221 | int rd_count = 0; |
214 | 222 | ||
215 | rd_len = ntohl (msg->rd_len); | 223 | rd_len = ntohs (msg->rd_len); |
216 | msg_len = ntohs (msg->header.size); | 224 | msg_len = ntohs (msg->header.size); |
217 | name_len = ntohs (msg->name_len); | 225 | name_len = ntohs (msg->name_len); |
218 | contains_sig = ntohs (msg->contains_sig); | 226 | contains_sig = ntohs (msg->contains_sig); |
@@ -749,7 +757,7 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
749 | struct PendingMessage *pe; | 757 | struct PendingMessage *pe; |
750 | 758 | ||
751 | /* pointer to elements */ | 759 | /* pointer to elements */ |
752 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key_tmp; | 760 | char * zone_key_tmp; |
753 | char * rd_tmp; | 761 | char * rd_tmp; |
754 | char * rd_ser; | 762 | char * rd_ser; |
755 | char * name_tmp; | 763 | char * name_tmp; |
@@ -757,6 +765,7 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
757 | size_t msg_size = 0; | 765 | size_t msg_size = 0; |
758 | size_t name_len = 0; | 766 | size_t name_len = 0; |
759 | size_t rd_ser_len = 0; | 767 | size_t rd_ser_len = 0; |
768 | size_t pubkey_len = 0; | ||
760 | uint32_t id = 0; | 769 | uint32_t id = 0; |
761 | 770 | ||
762 | GNUNET_assert (NULL != h); | 771 | GNUNET_assert (NULL != h); |
@@ -782,29 +791,31 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
782 | 791 | ||
783 | /* set msg_size*/ | 792 | /* set msg_size*/ |
784 | rd_ser_len = GNUNET_NAMESTORE_records_serialize(&rd_ser, rd_count, rd); | 793 | rd_ser_len = GNUNET_NAMESTORE_records_serialize(&rd_ser, rd_count, rd); |
785 | 794 | pubkey_len = sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); | |
786 | struct RecordPutMessage * msg; | 795 | struct RecordPutMessage * msg; |
787 | msg_size = sizeof (struct RecordPutMessage) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + name_len + rd_ser_len; | 796 | msg_size = sizeof (struct RecordPutMessage) + pubkey_len + name_len + rd_ser_len; |
788 | 797 | ||
789 | /* create msg here */ | 798 | /* create msg here */ |
790 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | 799 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); |
791 | pe->size = msg_size; | 800 | pe->size = msg_size; |
792 | pe->is_init = GNUNET_NO; | 801 | pe->is_init = GNUNET_NO; |
793 | msg = (struct RecordPutMessage *) &pe[1]; | 802 | msg = (struct RecordPutMessage *) &pe[1]; |
794 | zone_key_tmp = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &msg[1]; | 803 | zone_key_tmp = (char *) &msg[1]; |
795 | name_tmp = (char *) &zone_key_tmp[1]; | 804 | name_tmp = (char *) &zone_key_tmp[pubkey_len]; |
796 | rd_tmp = &name_tmp[name_len]; | 805 | rd_tmp = &name_tmp[name_len]; |
797 | 806 | ||
798 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT); | 807 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT); |
799 | msg->header.size = htons (msg_size); | 808 | msg->header.size = htons (msg_size); |
800 | msg->op_id = htonl (id); | 809 | msg->op_id = htonl (id); |
801 | memcpy (zone_key_tmp, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 810 | msg->key_len = htons (pubkey_len); |
811 | memcpy (zone_key_tmp, zone_key, pubkey_len); | ||
802 | msg->signature = *signature; | 812 | msg->signature = *signature; |
803 | msg->name_len = htons (name_len); | 813 | msg->name_len = htons (name_len); |
804 | memcpy (name_tmp, name, name_len); | 814 | memcpy (name_tmp, name, name_len); |
805 | msg->expire = GNUNET_TIME_absolute_hton (expire); | 815 | msg->expire = GNUNET_TIME_absolute_hton (expire); |
806 | msg->rd_len = htons (rd_ser_len); | 816 | msg->rd_len = htons (rd_ser_len); |
807 | 817 | ||
818 | |||
808 | memcpy (rd_tmp, rd_ser, rd_ser_len); | 819 | memcpy (rd_tmp, rd_ser, rd_ser_len); |
809 | GNUNET_free (rd_ser); | 820 | GNUNET_free (rd_ser); |
810 | 821 | ||
@@ -862,14 +873,26 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, | |||
862 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 873 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
863 | struct PendingMessage *pe; | 874 | struct PendingMessage *pe; |
864 | char * name_tmp; | 875 | char * name_tmp; |
876 | char * pkey_tmp; | ||
865 | char * rd_tmp; | 877 | char * rd_tmp; |
866 | char * rd_ser; | 878 | char * rd_ser; |
867 | size_t rd_ser_len = 0; | 879 | size_t rd_ser_len = 0; |
868 | size_t msg_size = 0; | 880 | size_t msg_size = 0; |
869 | size_t name_len = 0; | 881 | size_t name_len = 0; |
882 | size_t key_len = 0; | ||
870 | uint32_t id = 0; | 883 | uint32_t id = 0; |
871 | 884 | ||
872 | GNUNET_assert (NULL != h); | 885 | GNUNET_assert (NULL != h); |
886 | GNUNET_assert (NULL != pkey); | ||
887 | GNUNET_assert (NULL != name); | ||
888 | GNUNET_assert (NULL != rd); | ||
889 | |||
890 | name_len = strlen(name) + 1; | ||
891 | if (name_len > 256) | ||
892 | { | ||
893 | GNUNET_break (0); | ||
894 | return NULL; | ||
895 | } | ||
873 | 896 | ||
874 | id = get_op_id(h); | 897 | id = get_op_id(h); |
875 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | 898 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); |
@@ -877,11 +900,15 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, | |||
877 | qe->cont = cont; | 900 | qe->cont = cont; |
878 | qe->cont_cls = cont_cls; | 901 | qe->cont_cls = cont_cls; |
879 | qe->op_id = id; | 902 | qe->op_id = id; |
903 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); | ||
880 | 904 | ||
881 | /* set msg_size*/ | 905 | /* set msg_size*/ |
906 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * pkey_enc = GNUNET_CRYPTO_rsa_encode_key (pkey); | ||
907 | GNUNET_assert (pkey_enc != NULL); | ||
908 | key_len = ntohs (pkey_enc->len); | ||
882 | rd_ser_len = GNUNET_NAMESTORE_records_serialize(&rd_ser, 1, rd); | 909 | rd_ser_len = GNUNET_NAMESTORE_records_serialize(&rd_ser, 1, rd); |
883 | struct RecordCreateMessage * msg; | 910 | struct RecordCreateMessage * msg; |
884 | msg_size = sizeof (struct RecordCreateMessage) + name_len + rd_ser_len; | 911 | msg_size = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len; |
885 | 912 | ||
886 | /* create msg here */ | 913 | /* create msg here */ |
887 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | 914 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); |
@@ -889,17 +916,21 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, | |||
889 | pe->is_init = GNUNET_NO; | 916 | pe->is_init = GNUNET_NO; |
890 | msg = (struct RecordCreateMessage *) &pe[1]; | 917 | msg = (struct RecordCreateMessage *) &pe[1]; |
891 | 918 | ||
892 | name_tmp = (char *) &msg[1]; | 919 | pkey_tmp = (char *) &msg[1]; |
920 | name_tmp = &pkey_tmp[key_len]; | ||
893 | rd_tmp = &name_tmp[name_len]; | 921 | rd_tmp = &name_tmp[name_len]; |
894 | 922 | ||
895 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE); | 923 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE); |
896 | msg->header.size = htons (msg_size); | 924 | msg->header.size = htons (msg_size); |
897 | msg->op_id = htonl (id); | 925 | msg->op_id = htonl (id); |
898 | //msg->signature = *signature; | ||
899 | msg->name_len = htons (name_len); | 926 | msg->name_len = htons (name_len); |
927 | msg->rd_len = htons (rd_ser_len); | ||
928 | msg->pkey_len = htons (key_len); | ||
929 | memcpy (pkey_tmp, pkey_enc, key_len); | ||
900 | memcpy (name_tmp, name, name_len); | 930 | memcpy (name_tmp, name, name_len); |
901 | memcpy (rd_tmp, rd_ser, rd_ser_len); | 931 | memcpy (rd_tmp, rd_ser, rd_ser_len); |
902 | GNUNET_free (rd_ser); | 932 | GNUNET_free (rd_ser); |
933 | GNUNET_free (pkey_enc); | ||
903 | 934 | ||
904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s' with size %u\n", "NAMESTORE_RECORD_CREATE", name, msg_size); | 935 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s' with size %u\n", "NAMESTORE_RECORD_CREATE", name, msg_size); |
905 | 936 | ||
diff --git a/src/namestore/test_namestore_api_put.c b/src/namestore/test_namestore_api_put.c index 99f8e25b7..7310946b1 100644 --- a/src/namestore/test_namestore_api_put.c +++ b/src/namestore/test_namestore_api_put.c | |||
@@ -41,7 +41,6 @@ static struct GNUNET_OS_Process *arm; | |||
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 42 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
43 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 43 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
44 | static GNUNET_HashCode zone; | ||
45 | 44 | ||
46 | struct GNUNET_NAMESTORE_RecordData *rd; | 45 | struct GNUNET_NAMESTORE_RecordData *rd; |
47 | 46 | ||
@@ -163,9 +162,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
163 | /* get public key */ | 162 | /* get public key */ |
164 | GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); | 163 | GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); |
165 | 164 | ||
166 | /* create random zone hash */ | ||
167 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &zone); | ||
168 | |||
169 | struct GNUNET_CRYPTO_RsaSignature signature; | 165 | struct GNUNET_CRYPTO_RsaSignature signature; |
170 | 166 | ||
171 | start_arm (cfgfile); | 167 | start_arm (cfgfile); |
diff --git a/src/namestore/test_namestore_record_serialization.c b/src/namestore/test_namestore_record_serialization.c index 5ea345bef..cd60a5dda 100644 --- a/src/namestore/test_namestore_record_serialization.c +++ b/src/namestore/test_namestore_record_serialization.c | |||
@@ -36,10 +36,10 @@ static void | |||
36 | run (void *cls, char *const *args, const char *cfgfile, | 36 | run (void *cls, char *const *args, const char *cfgfile, |
37 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 37 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
38 | { | 38 | { |
39 | char * dest = NULL; | 39 | char * rd_ser = NULL; |
40 | size_t len; | 40 | size_t len; |
41 | int c; | 41 | int c; |
42 | int elem = 0; | 42 | int dst_elem = 0; |
43 | 43 | ||
44 | int rd_count = 3; | 44 | int rd_count = 3; |
45 | size_t data_len; | 45 | size_t data_len; |
@@ -61,18 +61,18 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
61 | } | 61 | } |
62 | res = 0; | 62 | res = 0; |
63 | 63 | ||
64 | len = GNUNET_NAMESTORE_records_serialize (&dest, rd_count, src); | 64 | len = GNUNET_NAMESTORE_records_serialize (&rd_ser, rd_count, src); |
65 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Serialized data len: %u\n",len); | 65 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Serialized data len: %u\n",len); |
66 | 66 | ||
67 | GNUNET_assert (dest != NULL); | 67 | GNUNET_assert (rd_ser != NULL); |
68 | 68 | ||
69 | elem = GNUNET_NAMESTORE_records_deserialize(&dst, dest, len); | 69 | dst_elem = GNUNET_NAMESTORE_records_deserialize(&dst, rd_ser, len); |
70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deserialized elements: %u\n",elem); | 70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deserialized elements: %u\n",dst_elem); |
71 | 71 | ||
72 | GNUNET_assert (elem == rd_count); | 72 | GNUNET_assert (dst_elem == rd_count); |
73 | GNUNET_assert (dst != NULL); | 73 | GNUNET_assert (dst != NULL); |
74 | 74 | ||
75 | for (c = 0; c < elem; c++) | 75 | for (c = 0; c < dst_elem; c++) |
76 | { | 76 | { |
77 | if (src[c].data_size != dst[c].data_size) | 77 | if (src[c].data_size != dst[c].data_size) |
78 | { | 78 | { |
@@ -115,12 +115,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
115 | } | 115 | } |
116 | 116 | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c); | 117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c); |
118 | /* clean up */ | ||
119 | GNUNET_free((char *) dst[c].data); | ||
120 | GNUNET_free((char *) src[c].data); | ||
121 | } | 118 | } |
122 | GNUNET_free (dest); | 119 | |
123 | GNUNET_free (dst); | 120 | for (c = 0; c < rd_count; c++) |
121 | GNUNET_free ((void *) src[c].data); | ||
122 | GNUNET_NAMESTORE_records_free (dst_elem, dst); | ||
123 | GNUNET_free (rd_ser); | ||
124 | } | 124 | } |
125 | 125 | ||
126 | static int | 126 | static int |