aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-10-29 18:06:26 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-10-29 18:06:26 +0900
commit0f2da4636e108c70697c589d9e38781f2bafefba (patch)
tree0e831befd71d4323596cdae55e8431df7720c531 /src/namestore
parent4e2259f14be320c8e2fe2a672a473e09677269c4 (diff)
downloadgnunet-0f2da4636e108c70697c589d9e38781f2bafefba.tar.gz
gnunet-0f2da4636e108c70697c589d9e38781f2bafefba.zip
IDENTITY
This commit is a major rework of the unclean GNUNET_IDENTITY_*Key structures and its use in serialized objects (e.g. RPC messages). The structures are now no longer to be used directly but instead through their serialization helper functions whenever needed.
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/Makefile.am1
-rw-r--r--src/namestore/gnunet-namestore.c15
-rw-r--r--src/namestore/gnunet-service-namestore.c241
-rw-r--r--src/namestore/namestore.h65
-rw-r--r--src/namestore/namestore_api.c137
-rw-r--r--src/namestore/namestore_api_monitor.c47
6 files changed, 389 insertions, 117 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 2a1558e09..fb2a670bc 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -179,7 +179,6 @@ gnunet_namestore_fcfsd_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
179 179
180gnunet_service_namestore_SOURCES = \ 180gnunet_service_namestore_SOURCES = \
181 gnunet-service-namestore.c 181 gnunet-service-namestore.c
182
183gnunet_service_namestore_LDADD = \ 182gnunet_service_namestore_LDADD = \
184 $(top_builddir)/src/namecache/libgnunetnamecache.la \ 183 $(top_builddir)/src/namecache/libgnunetnamecache.la \
185 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 184 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 843158c68..6444d446d 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -129,11 +129,6 @@ static struct GNUNET_IDENTITY_EgoLookup *el;
129static struct GNUNET_IDENTITY_Handle *idh; 129static struct GNUNET_IDENTITY_Handle *idh;
130 130
131/** 131/**
132 * Obtain default ego
133 */
134struct GNUNET_IDENTITY_Operation *get_default;
135
136/**
137 * Name of the ego controlling the zone. 132 * Name of the ego controlling the zone.
138 */ 133 */
139static char *ego_name; 134static char *ego_name;
@@ -342,10 +337,10 @@ do_shutdown (void *cls)
342 struct MarkedRecord *mrec; 337 struct MarkedRecord *mrec;
343 struct MarkedRecord *mrec_tmp; 338 struct MarkedRecord *mrec_tmp;
344 (void) cls; 339 (void) cls;
345 if (NULL != get_default) 340 if (NULL != ego_name)
346 { 341 {
347 GNUNET_IDENTITY_cancel (get_default); 342 GNUNET_free (ego_name);
348 get_default = NULL; 343 ego_name = NULL;
349 } 344 }
350 if (NULL != purge_task) 345 if (NULL != purge_task)
351 { 346 {
@@ -1530,7 +1525,7 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg)
1530 } 1525 }
1531 memset (&rd, 0, sizeof(rd)); 1526 memset (&rd, 0, sizeof(rd));
1532 rd.data = &pkey; 1527 rd.data = &pkey;
1533 rd.data_size = GNUNET_IDENTITY_key_get_length (&pkey); 1528 rd.data_size = GNUNET_IDENTITY_public_key_get_length (&pkey);
1534 rd.record_type = ntohl (pkey.type); 1529 rd.record_type = ntohl (pkey.type);
1535 rd.expiration_time = etime; 1530 rd.expiration_time = etime;
1536 if (GNUNET_YES == etime_is_rel) 1531 if (GNUNET_YES == etime_is_rel)
@@ -1589,8 +1584,6 @@ identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
1589 return; 1584 return;
1590 } 1585 }
1591 zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); 1586 zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
1592 GNUNET_free (ego_name);
1593 ego_name = NULL;
1594 run_with_zone_pkey (cfg); 1587 run_with_zone_pkey (cfg);
1595} 1588}
1596 1589
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 92c81c4eb..f0739cbeb 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -711,6 +711,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc,
711 unsigned int res_count; 711 unsigned int res_count;
712 unsigned int rd_nf_count; 712 unsigned int rd_nf_count;
713 size_t name_len; 713 size_t name_len;
714 size_t key_len;
714 ssize_t rd_ser_len; 715 ssize_t rd_ser_len;
715 char *name_tmp; 716 char *name_tmp;
716 char *rd_ser; 717 char *rd_ser;
@@ -778,16 +779,20 @@ send_lookup_response_with_filter (struct NamestoreClient *nc,
778 GNUNET_SERVICE_client_drop (nc->client); 779 GNUNET_SERVICE_client_drop (nc->client);
779 return 0; 780 return 0;
780 } 781 }
782 key_len = GNUNET_IDENTITY_private_key_get_length (zone_key);
781 env = GNUNET_MQ_msg_extra (zir_msg, 783 env = GNUNET_MQ_msg_extra (zir_msg,
782 name_len + rd_ser_len, 784 name_len + rd_ser_len + key_len,
783 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); 785 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
784 zir_msg->gns_header.r_id = htonl (request_id); 786 zir_msg->gns_header.r_id = htonl (request_id);
785 zir_msg->name_len = htons (name_len); 787 zir_msg->name_len = htons (name_len);
786 zir_msg->rd_count = htons (res_count); 788 zir_msg->rd_count = htons (res_count);
787 zir_msg->rd_len = htons ((uint16_t) rd_ser_len); 789 zir_msg->rd_len = htons ((uint16_t) rd_ser_len);
788 zir_msg->private_key = *zone_key; 790 zir_msg->key_len = htonl (key_len);
791 GNUNET_IDENTITY_write_private_key_to_buffer (zone_key,
792 &zir_msg[1],
793 key_len);
789 zir_msg->expire = GNUNET_TIME_absolute_hton (block_exp); 794 zir_msg->expire = GNUNET_TIME_absolute_hton (block_exp);
790 name_tmp = (char *) &zir_msg[1]; 795 name_tmp = (char *) &zir_msg[1] + key_len;
791 GNUNET_memcpy (name_tmp, name, name_len); 796 GNUNET_memcpy (name_tmp, name, name_len);
792 rd_ser = &name_tmp[name_len]; 797 rd_ser = &name_tmp[name_len];
793 GNUNET_assert ( 798 GNUNET_assert (
@@ -1309,16 +1314,17 @@ check_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1309{ 1314{
1310 uint32_t name_len; 1315 uint32_t name_len;
1311 size_t src_size; 1316 size_t src_size;
1317 size_t key_len;
1312 1318
1313 (void) cls; 1319 (void) cls;
1314 name_len = ntohl (ll_msg->label_len); 1320 name_len = ntohl (ll_msg->label_len);
1321 key_len = ntohl (ll_msg->key_len);
1315 src_size = ntohs (ll_msg->gns_header.header.size); 1322 src_size = ntohs (ll_msg->gns_header.header.size);
1316 if (name_len != src_size - sizeof(struct LabelLookupMessage)) 1323 if (name_len + key_len != src_size - sizeof(struct LabelLookupMessage))
1317 { 1324 {
1318 GNUNET_break (0); 1325 GNUNET_break (0);
1319 return GNUNET_SYSERR; 1326 return GNUNET_SYSERR;
1320 } 1327 }
1321 GNUNET_MQ_check_zero_termination (ll_msg);
1322 return GNUNET_OK; 1328 return GNUNET_OK;
1323} 1329}
1324 1330
@@ -1332,6 +1338,7 @@ check_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1332static void 1338static void
1333handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) 1339handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1334{ 1340{
1341 struct GNUNET_IDENTITY_PrivateKey zone;
1335 struct NamestoreClient *nc = cls; 1342 struct NamestoreClient *nc = cls;
1336 struct GNUNET_MQ_Envelope *env; 1343 struct GNUNET_MQ_Envelope *env;
1337 struct LabelLookupResponseMessage *llr_msg; 1344 struct LabelLookupResponseMessage *llr_msg;
@@ -1341,8 +1348,23 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1341 char *conv_name; 1348 char *conv_name;
1342 uint32_t name_len; 1349 uint32_t name_len;
1343 int res; 1350 int res;
1344 1351 size_t key_len;
1345 name_tmp = (const char *) &ll_msg[1]; 1352 size_t kb_read;
1353
1354 key_len = ntohl (ll_msg->key_len);
1355 if ((GNUNET_SYSERR ==
1356 GNUNET_IDENTITY_read_private_key_from_buffer (&ll_msg[1],
1357 key_len,
1358 &zone,
1359 &kb_read)) ||
1360 (kb_read != key_len))
1361 {
1362 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1363 "Error reading private key\n");
1364 GNUNET_SERVICE_client_drop (nc->client);
1365 return;
1366 }
1367 name_tmp = (const char *) &ll_msg[1] + key_len;
1346 GNUNET_SERVICE_client_continue (nc->client); 1368 GNUNET_SERVICE_client_continue (nc->client);
1347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1348 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n", 1370 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n",
@@ -1366,37 +1388,38 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1366 rlc.res_rd_count = 0; 1388 rlc.res_rd_count = 0;
1367 rlc.res_rd = NULL; 1389 rlc.res_rd = NULL;
1368 rlc.rd_ser_len = 0; 1390 rlc.rd_ser_len = 0;
1369 rlc.nick = get_nick_record (&ll_msg->zone); 1391 rlc.nick = get_nick_record (&zone);
1370 if (GNUNET_YES != ntohl (ll_msg->is_edit_request)) 1392 if (GNUNET_YES != ntohl (ll_msg->is_edit_request))
1371 res = nc->GSN_database->lookup_records (nc->GSN_database->cls, 1393 res = nc->GSN_database->lookup_records (nc->GSN_database->cls,
1372 &ll_msg->zone, 1394 &zone,
1373 conv_name, 1395 conv_name,
1374 &lookup_it, 1396 &lookup_it,
1375 &rlc); 1397 &rlc);
1376 else 1398 else
1377 res = nc->GSN_database->edit_records (nc->GSN_database->cls, 1399 res = nc->GSN_database->edit_records (nc->GSN_database->cls,
1378 &ll_msg->zone, 1400 &zone,
1379 conv_name, 1401 conv_name,
1380 &lookup_it, 1402 &lookup_it,
1381 &rlc); 1403 &rlc);
1382 1404
1383 env = 1405 env =
1384 GNUNET_MQ_msg_extra (llr_msg, 1406 GNUNET_MQ_msg_extra (llr_msg,
1385 name_len + rlc.rd_ser_len, 1407 key_len + name_len + rlc.rd_ser_len,
1386 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE); 1408 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE);
1387 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id; 1409 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id;
1388 llr_msg->private_key = ll_msg->zone; 1410 GNUNET_memcpy (&llr_msg[1], &ll_msg[1], key_len);
1411 llr_msg->key_len = ll_msg->key_len;
1389 llr_msg->name_len = htons (name_len); 1412 llr_msg->name_len = htons (name_len);
1390 llr_msg->rd_count = htons (rlc.res_rd_count); 1413 llr_msg->rd_count = htons (rlc.res_rd_count);
1391 llr_msg->rd_len = htons (rlc.rd_ser_len); 1414 llr_msg->rd_len = htons (rlc.rd_ser_len);
1392 res_name = (char *) &llr_msg[1]; 1415 res_name = ((char *) &llr_msg[1]) + key_len;
1393 if (GNUNET_YES == rlc.found) 1416 if (GNUNET_YES == rlc.found)
1394 llr_msg->found = htons (GNUNET_YES); 1417 llr_msg->found = htons (GNUNET_YES);
1395 else if (GNUNET_SYSERR == res) 1418 else if (GNUNET_SYSERR == res)
1396 llr_msg->found = htons (GNUNET_SYSERR); 1419 llr_msg->found = htons (GNUNET_SYSERR);
1397 else 1420 else
1398 llr_msg->found = htons (GNUNET_NO); 1421 llr_msg->found = htons (GNUNET_NO);
1399 GNUNET_memcpy (&llr_msg[1], conv_name, name_len); 1422 GNUNET_memcpy (res_name, conv_name, name_len);
1400 GNUNET_memcpy (&res_name[name_len], rlc.res_rd, rlc.rd_ser_len); 1423 GNUNET_memcpy (&res_name[name_len], rlc.res_rd, rlc.rd_ser_len);
1401 GNUNET_MQ_send (nc->mq, env); 1424 GNUNET_MQ_send (nc->mq, env);
1402 GNUNET_free (rlc.res_rd); 1425 GNUNET_free (rlc.res_rd);
@@ -1418,11 +1441,14 @@ check_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1418 size_t msg_size; 1441 size_t msg_size;
1419 size_t min_size_exp; 1442 size_t min_size_exp;
1420 size_t rd_set_count; 1443 size_t rd_set_count;
1444 size_t key_len;
1421 1445
1422 (void) cls; 1446 (void) cls;
1423 msg_size = ntohs (rp_msg->gns_header.header.size); 1447 msg_size = ntohs (rp_msg->gns_header.header.size);
1424 rd_set_count = ntohs (rp_msg->rd_set_count); 1448 rd_set_count = ntohs (rp_msg->rd_set_count);
1425 min_size_exp = sizeof(struct RecordStoreMessage) + sizeof (struct RecordSet) 1449 key_len = ntohl (rp_msg->key_len);
1450
1451 min_size_exp = sizeof(*rp_msg) + key_len + sizeof (struct RecordSet)
1426 * rd_set_count; 1452 * rd_set_count;
1427 if (msg_size < min_size_exp) 1453 if (msg_size < min_size_exp)
1428 { 1454 {
@@ -1701,24 +1727,40 @@ store_record_set (struct NamestoreClient *nc,
1701static void 1727static void
1702handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) 1728handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1703{ 1729{
1730 struct GNUNET_IDENTITY_PrivateKey zone;
1704 struct NamestoreClient *nc = cls; 1731 struct NamestoreClient *nc = cls;
1705 uint32_t rid; 1732 uint32_t rid;
1706 uint16_t rd_set_count; 1733 uint16_t rd_set_count;
1707 const char *buf; 1734 const char *buf;
1708 ssize_t read; 1735 ssize_t read;
1736 size_t key_len;
1737 size_t kb_read;
1709 struct StoreActivity *sa; 1738 struct StoreActivity *sa;
1710 struct RecordSet *rs; 1739 struct RecordSet *rs;
1711 enum GNUNET_ErrorCode res; 1740 enum GNUNET_ErrorCode res;
1712 1741
1742 key_len = ntohl (rp_msg->key_len);
1743 if ((GNUNET_SYSERR ==
1744 GNUNET_IDENTITY_read_private_key_from_buffer (&rp_msg[1],
1745 key_len,
1746 &zone,
1747 &kb_read)) ||
1748 (kb_read != key_len))
1749 {
1750 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1751 "Error reading private key\n");
1752 GNUNET_SERVICE_client_drop (nc->client);
1753 return;
1754 }
1713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1714 "Received NAMESTORE_RECORD_STORE message\n"); 1756 "Received NAMESTORE_RECORD_STORE message\n");
1715 rid = ntohl (rp_msg->gns_header.r_id); 1757 rid = ntohl (rp_msg->gns_header.r_id);
1716 rd_set_count = ntohs (rp_msg->rd_set_count); 1758 rd_set_count = ntohs (rp_msg->rd_set_count);
1717 buf = (const char *) &rp_msg[1]; 1759 buf = (const char *) &rp_msg[1] + key_len;
1718 for (int i = 0; i < rd_set_count; i++) 1760 for (int i = 0; i < rd_set_count; i++)
1719 { 1761 {
1720 rs = (struct RecordSet *) buf; 1762 rs = (struct RecordSet *) buf;
1721 res = store_record_set (nc, &rp_msg->private_key, 1763 res = store_record_set (nc, &zone,
1722 rs, &read); 1764 rs, &read);
1723 if (GNUNET_EC_NONE != res) 1765 if (GNUNET_EC_NONE != res)
1724 { 1766 {
@@ -1735,11 +1777,11 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1735 sa->nc = nc; 1777 sa->nc = nc;
1736 sa->rs = (struct RecordSet *) &sa[1]; 1778 sa->rs = (struct RecordSet *) &sa[1];
1737 sa->rd_set_count = rd_set_count; 1779 sa->rd_set_count = rd_set_count;
1738 GNUNET_memcpy (&sa[1], (char *) &rp_msg[1], 1780 GNUNET_memcpy (&sa[1], (char *) &rp_msg[1] + key_len,
1739 ntohs (rp_msg->gns_header.header.size) - sizeof (*rp_msg)); 1781 ntohs (rp_msg->gns_header.header.size) - sizeof (*rp_msg));
1740 sa->rid = rid; 1782 sa->rid = rid;
1741 sa->rd_set_pos = 0; 1783 sa->rd_set_pos = 0;
1742 sa->private_key = rp_msg->private_key; 1784 sa->private_key = zone;
1743 sa->zm_pos = monitor_head; 1785 sa->zm_pos = monitor_head;
1744 sa->uncommited = nc->in_transaction; 1786 sa->uncommited = nc->in_transaction;
1745 continue_store_activity (sa, GNUNET_YES); 1787 continue_store_activity (sa, GNUNET_YES);
@@ -1913,6 +1955,7 @@ handle_zone_to_name_it (void *cls,
1913 struct GNUNET_MQ_Envelope *env; 1955 struct GNUNET_MQ_Envelope *env;
1914 struct ZoneToNameResponseMessage *ztnr_msg; 1956 struct ZoneToNameResponseMessage *ztnr_msg;
1915 size_t name_len; 1957 size_t name_len;
1958 size_t key_len;
1916 ssize_t rd_ser_len; 1959 ssize_t rd_ser_len;
1917 size_t msg_size; 1960 size_t msg_size;
1918 char *name_tmp; 1961 char *name_tmp;
@@ -1931,7 +1974,9 @@ handle_zone_to_name_it (void *cls,
1931 ztn_ctx->ec = htonl (GNUNET_EC_NAMESTORE_UNKNOWN); 1974 ztn_ctx->ec = htonl (GNUNET_EC_NAMESTORE_UNKNOWN);
1932 return; 1975 return;
1933 } 1976 }
1934 msg_size = sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len; 1977 key_len = GNUNET_IDENTITY_private_key_get_length (zone_key);
1978 msg_size = sizeof(struct ZoneToNameResponseMessage)
1979 + name_len + rd_ser_len + key_len;
1935 if (msg_size >= GNUNET_MAX_MESSAGE_SIZE) 1980 if (msg_size >= GNUNET_MAX_MESSAGE_SIZE)
1936 { 1981 {
1937 GNUNET_break (0); 1982 GNUNET_break (0);
@@ -1940,7 +1985,7 @@ handle_zone_to_name_it (void *cls,
1940 } 1985 }
1941 env = 1986 env =
1942 GNUNET_MQ_msg_extra (ztnr_msg, 1987 GNUNET_MQ_msg_extra (ztnr_msg,
1943 name_len + rd_ser_len, 1988 key_len + name_len + rd_ser_len,
1944 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); 1989 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1945 ztnr_msg->gns_header.header.size = htons (msg_size); 1990 ztnr_msg->gns_header.header.size = htons (msg_size);
1946 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid); 1991 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid);
@@ -1948,8 +1993,11 @@ handle_zone_to_name_it (void *cls,
1948 ztnr_msg->rd_len = htons (rd_ser_len); 1993 ztnr_msg->rd_len = htons (rd_ser_len);
1949 ztnr_msg->rd_count = htons (rd_count); 1994 ztnr_msg->rd_count = htons (rd_count);
1950 ztnr_msg->name_len = htons (name_len); 1995 ztnr_msg->name_len = htons (name_len);
1951 ztnr_msg->zone = *zone_key; 1996 ztnr_msg->key_len = htonl (key_len);
1952 name_tmp = (char *) &ztnr_msg[1]; 1997 GNUNET_IDENTITY_write_private_key_to_buffer (zone_key,
1998 &ztnr_msg[1],
1999 key_len);
2000 name_tmp = (char *) &ztnr_msg[1] + key_len;
1953 GNUNET_memcpy (name_tmp, name, name_len); 2001 GNUNET_memcpy (name_tmp, name, name_len);
1954 rd_tmp = &name_tmp[name_len]; 2002 rd_tmp = &name_tmp[name_len];
1955 GNUNET_assert ( 2003 GNUNET_assert (
@@ -1959,6 +2007,13 @@ handle_zone_to_name_it (void *cls,
1959 GNUNET_MQ_send (ztn_ctx->nc->mq, env); 2007 GNUNET_MQ_send (ztn_ctx->nc->mq, env);
1960} 2008}
1961 2009
2010static enum GNUNET_GenericReturnValue
2011check_zone_to_name (void *cls,
2012 const struct ZoneToNameMessage *zis_msg)
2013{
2014 return GNUNET_OK;
2015}
2016
1962 2017
1963/** 2018/**
1964 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME message 2019 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME message
@@ -1969,18 +2024,52 @@ handle_zone_to_name_it (void *cls,
1969static void 2024static void
1970handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg) 2025handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg)
1971{ 2026{
2027 struct GNUNET_IDENTITY_PrivateKey zone;
2028 struct GNUNET_IDENTITY_PublicKey value_zone;
1972 struct NamestoreClient *nc = cls; 2029 struct NamestoreClient *nc = cls;
1973 struct ZoneToNameCtx ztn_ctx; 2030 struct ZoneToNameCtx ztn_ctx;
1974 struct GNUNET_MQ_Envelope *env; 2031 struct GNUNET_MQ_Envelope *env;
1975 struct ZoneToNameResponseMessage *ztnr_msg; 2032 struct ZoneToNameResponseMessage *ztnr_msg;
2033 size_t key_len;
2034 size_t pkey_len;
2035 size_t kb_read;
1976 2036
1977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME message\n"); 2037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME message\n");
1978 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 2038 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1979 ztn_ctx.nc = nc; 2039 ztn_ctx.nc = nc;
1980 ztn_ctx.ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; 2040 ztn_ctx.ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND;
2041 key_len = ntohl (ztn_msg->key_len);
2042 if ((GNUNET_SYSERR ==
2043 GNUNET_IDENTITY_read_private_key_from_buffer (&ztn_msg[1],
2044 key_len,
2045 &zone,
2046 &kb_read)) ||
2047 (kb_read != key_len))
2048 {
2049 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2050 "Error parsing private key.\n");
2051 GNUNET_SERVICE_client_drop (nc->client);
2052 GNUNET_break (0);
2053 return;
2054 }
2055 pkey_len = ntohl (ztn_msg->pkey_len);
2056 if ((GNUNET_SYSERR ==
2057 GNUNET_IDENTITY_read_public_key_from_buffer ((char*) &ztn_msg[1]
2058 + key_len,
2059 pkey_len,
2060 &value_zone,
2061 &kb_read)) ||
2062 (kb_read != pkey_len))
2063 {
2064 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2065 "Error parsing public key.\n");
2066 GNUNET_SERVICE_client_drop (nc->client);
2067 GNUNET_break (0);
2068 return;
2069 }
1981 if (GNUNET_SYSERR == nc->GSN_database->zone_to_name (nc->GSN_database->cls, 2070 if (GNUNET_SYSERR == nc->GSN_database->zone_to_name (nc->GSN_database->cls,
1982 &ztn_msg->zone, 2071 &zone,
1983 &ztn_msg->value_zone, 2072 &value_zone,
1984 &handle_zone_to_name_it, 2073 &handle_zone_to_name_it,
1985 &ztn_ctx)) 2074 &ztn_ctx))
1986 { 2075 {
@@ -2133,6 +2222,24 @@ run_zone_iteration_round (struct ZoneIteration *zi, uint64_t limit)
2133 zone_iteration_done_client_continue (zi); 2222 zone_iteration_done_client_continue (zi);
2134} 2223}
2135 2224
2225static enum GNUNET_GenericReturnValue
2226check_iteration_start (void *cls,
2227 const struct ZoneIterationStartMessage *zis_msg)
2228{
2229 uint16_t size;
2230 size_t key_len;
2231
2232 size = ntohs (zis_msg->gns_header.header.size);
2233 key_len = ntohs (zis_msg->key_len);
2234
2235 if (size < key_len + sizeof(*zis_msg))
2236 {
2237 GNUNET_break (0);
2238 return GNUNET_SYSERR;
2239 }
2240 return GNUNET_OK;
2241}
2242
2136 2243
2137/** 2244/**
2138 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START message 2245 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START message
@@ -2144,18 +2251,35 @@ static void
2144handle_iteration_start (void *cls, 2251handle_iteration_start (void *cls,
2145 const struct ZoneIterationStartMessage *zis_msg) 2252 const struct ZoneIterationStartMessage *zis_msg)
2146{ 2253{
2254 struct GNUNET_IDENTITY_PrivateKey zone;
2147 struct NamestoreClient *nc = cls; 2255 struct NamestoreClient *nc = cls;
2148 struct ZoneIteration *zi; 2256 struct ZoneIteration *zi;
2257 size_t key_len;
2258 size_t kb_read;
2149 2259
2150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2151 "Received ZONE_ITERATION_START message\n"); 2261 "Received ZONE_ITERATION_START message\n");
2262 key_len = ntohl (zis_msg->key_len);
2152 zi = GNUNET_new (struct ZoneIteration); 2263 zi = GNUNET_new (struct ZoneIteration);
2264 if (0 < key_len)
2265 {
2266 if ((GNUNET_SYSERR ==
2267 GNUNET_IDENTITY_read_private_key_from_buffer (&zis_msg[1],
2268 key_len,
2269 &zone,
2270 &kb_read)) ||
2271 (kb_read != key_len))
2272 {
2273 GNUNET_SERVICE_client_drop (nc->client);
2274 GNUNET_free (zi);
2275 return;
2276 }
2277 zi->zone = zone;
2278 }
2153 zi->request_id = ntohl (zis_msg->gns_header.r_id); 2279 zi->request_id = ntohl (zis_msg->gns_header.r_id);
2154 zi->filter = ntohs (zis_msg->filter); 2280 zi->filter = ntohs (zis_msg->filter);
2155 zi->offset = 0; 2281 zi->offset = 0;
2156 zi->nc = nc; 2282 zi->nc = nc;
2157 zi->zone = zis_msg->zone;
2158
2159 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); 2283 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
2160 run_zone_iteration_round (zi, 1); 2284 run_zone_iteration_round (zi, 1);
2161} 2285}
@@ -2349,6 +2473,24 @@ monitor_iterate_cb (void *cls,
2349 } 2473 }
2350} 2474}
2351 2475
2476static enum GNUNET_GenericReturnValue
2477check_monitor_start (void *cls,
2478 const struct ZoneMonitorStartMessage *zis_msg)
2479{
2480 uint16_t size;
2481 size_t key_len;
2482
2483 size = ntohs (zis_msg->header.size);
2484 key_len = ntohs (zis_msg->key_len);
2485
2486 if (size < key_len + sizeof(*zis_msg))
2487 {
2488 GNUNET_break (0);
2489 return GNUNET_SYSERR;
2490 }
2491 return GNUNET_OK;
2492}
2493
2352 2494
2353/** 2495/**
2354 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message 2496 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message
@@ -2360,14 +2502,33 @@ static void
2360handle_monitor_start (void *cls, const struct 2502handle_monitor_start (void *cls, const struct
2361 ZoneMonitorStartMessage *zis_msg) 2503 ZoneMonitorStartMessage *zis_msg)
2362{ 2504{
2505 struct GNUNET_IDENTITY_PrivateKey zone;
2363 struct NamestoreClient *nc = cls; 2506 struct NamestoreClient *nc = cls;
2364 struct ZoneMonitor *zm; 2507 struct ZoneMonitor *zm;
2508 size_t key_len;
2509 size_t kb_read;
2365 2510
2366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2367 "Received ZONE_MONITOR_START message\n"); 2512 "Received ZONE_MONITOR_START message\n");
2368 zm = GNUNET_new (struct ZoneMonitor); 2513 zm = GNUNET_new (struct ZoneMonitor);
2369 zm->nc = nc; 2514 zm->nc = nc;
2370 zm->zone = zis_msg->zone; 2515 key_len = ntohl (zis_msg->key_len);
2516 if (0 < key_len)
2517 {
2518 if ((GNUNET_SYSERR ==
2519 GNUNET_IDENTITY_read_private_key_from_buffer (&zis_msg[1],
2520 key_len,
2521 &zone,
2522 &kb_read)) ||
2523 (kb_read != key_len))
2524 {
2525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2526 "Error reading private key\n");
2527 GNUNET_SERVICE_client_drop (nc->client);
2528 return;
2529 }
2530 zm->zone = zone;
2531 }
2371 zm->limit = 1; 2532 zm->limit = 1;
2372 zm->filter = ntohs (zis_msg->filter); 2533 zm->filter = ntohs (zis_msg->filter);
2373 zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first)); 2534 zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
@@ -2557,14 +2718,14 @@ GNUNET_SERVICE_MAIN (
2557 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, 2718 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP,
2558 struct LabelLookupMessage, 2719 struct LabelLookupMessage,
2559 NULL), 2720 NULL),
2560 GNUNET_MQ_hd_fixed_size (zone_to_name, 2721 GNUNET_MQ_hd_var_size (zone_to_name,
2561 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 2722 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME,
2562 struct ZoneToNameMessage, 2723 struct ZoneToNameMessage,
2563 NULL), 2724 NULL),
2564 GNUNET_MQ_hd_fixed_size (iteration_start, 2725 GNUNET_MQ_hd_var_size (iteration_start,
2565 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, 2726 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START,
2566 struct ZoneIterationStartMessage, 2727 struct ZoneIterationStartMessage,
2567 NULL), 2728 NULL),
2568 GNUNET_MQ_hd_fixed_size (iteration_next, 2729 GNUNET_MQ_hd_fixed_size (iteration_next,
2569 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 2730 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT,
2570 struct ZoneIterationNextMessage, 2731 struct ZoneIterationNextMessage,
@@ -2573,10 +2734,10 @@ GNUNET_SERVICE_MAIN (
2573 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 2734 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP,
2574 struct ZoneIterationStopMessage, 2735 struct ZoneIterationStopMessage,
2575 NULL), 2736 NULL),
2576 GNUNET_MQ_hd_fixed_size (monitor_start, 2737 GNUNET_MQ_hd_var_size (monitor_start,
2577 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, 2738 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START,
2578 struct ZoneMonitorStartMessage, 2739 struct ZoneMonitorStartMessage,
2579 NULL), 2740 NULL),
2580 GNUNET_MQ_hd_fixed_size (monitor_next, 2741 GNUNET_MQ_hd_fixed_size (monitor_next,
2581 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT, 2742 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT,
2582 struct ZoneMonitorNextMessage, 2743 struct ZoneMonitorNextMessage,
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index 37c1576bc..0b50ac1ab 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -91,16 +91,17 @@ struct RecordStoreMessage
91 struct GNUNET_NAMESTORE_Header gns_header; 91 struct GNUNET_NAMESTORE_Header gns_header;
92 92
93 /** 93 /**
94 * The private key of the authority. 94 * Number of record sets
95 */ 95 */
96 struct GNUNET_IDENTITY_PrivateKey private_key; 96 uint16_t rd_set_count;
97 97
98 /** 98 /**
99 * Number of record sets 99 * Length of the zone key
100 */ 100 */
101 uint16_t rd_set_count; 101 uint32_t key_len GNUNET_PACKED;
102 102
103 /** 103 /**
104 * Followed by the private zone key
104 * Followed by rd_set_count RecordSets 105 * Followed by rd_set_count RecordSets
105 */ 106 */
106}; 107};
@@ -150,11 +151,12 @@ struct LabelLookupMessage
150 uint16_t filter; 151 uint16_t filter;
151 152
152 /** 153 /**
153 * The private key of the zone to look up in 154 * Length of the zone key
154 */ 155 */
155 struct GNUNET_IDENTITY_PrivateKey zone; 156 uint32_t key_len GNUNET_PACKED;
156 157
157 /* followed by: 158 /* followed by:
159 * the private zone key
158 * name with length name_len 160 * name with length name_len
159 */ 161 */
160}; 162};
@@ -192,11 +194,12 @@ struct LabelLookupResponseMessage
192 int16_t found GNUNET_PACKED; 194 int16_t found GNUNET_PACKED;
193 195
194 /** 196 /**
195 * The private key of the authority. 197 * Length of the zone key
196 */ 198 */
197 struct GNUNET_IDENTITY_PrivateKey private_key; 199 uint32_t key_len GNUNET_PACKED;
198 200
199 /* followed by: 201 /* followed by:
202 * the private zone key
200 * name with length name_len 203 * name with length name_len
201 * serialized record data with rd_count records 204 * serialized record data with rd_count records
202 */ 205 */
@@ -214,14 +217,20 @@ struct ZoneToNameMessage
214 struct GNUNET_NAMESTORE_Header gns_header; 217 struct GNUNET_NAMESTORE_Header gns_header;
215 218
216 /** 219 /**
217 * The private key of the zone to look up in 220 * Length of the zone key
221 */
222 uint32_t key_len GNUNET_PACKED;
223
224 /**
225 * Length of the public value zone key
218 */ 226 */
219 struct GNUNET_IDENTITY_PrivateKey zone; 227 uint32_t pkey_len GNUNET_PACKED;
220 228
221 /** 229 /**
222 * The public key of the target zone 230 * Followed by
231 * - the private zone key to look up in
232 * - the public key of the target zone
223 */ 233 */
224 struct GNUNET_IDENTITY_PublicKey value_zone;
225}; 234};
226 235
227 236
@@ -259,11 +268,12 @@ struct ZoneToNameResponseMessage
259 int32_t ec GNUNET_PACKED; 268 int32_t ec GNUNET_PACKED;
260 269
261 /** 270 /**
262 * The private key of the zone that contained the name. 271 * Length of the zone key
263 */ 272 */
264 struct GNUNET_IDENTITY_PrivateKey zone; 273 uint32_t key_len GNUNET_PACKED;
265 274
266 /* followed by: 275 /* followed by:
276 * the private zone key
267 * name with length name_len 277 * name with length name_len
268 * serialized record data with rd_count records 278 * serialized record data with rd_count records
269 */ 279 */
@@ -307,11 +317,12 @@ struct RecordResultMessage
307 uint16_t reserved GNUNET_PACKED; 317 uint16_t reserved GNUNET_PACKED;
308 318
309 /** 319 /**
310 * The private key of the authority. 320 * Length of the zone key
311 */ 321 */
312 struct GNUNET_IDENTITY_PrivateKey private_key; 322 uint32_t key_len GNUNET_PACKED;
313 323
314 /* followed by: 324 /* followed by:
325 * the private key of the authority
315 * name with length name_len 326 * name with length name_len
316 * serialized record data with rd_count records 327 * serialized record data with rd_count records
317 */ 328 */
@@ -386,9 +397,13 @@ struct ZoneMonitorStartMessage
386 uint16_t reserved; 397 uint16_t reserved;
387 398
388 /** 399 /**
389 * Zone key. 400 * Length of the zone key
401 */
402 uint32_t key_len GNUNET_PACKED;
403
404 /**
405 * Followed by the private zone key.
390 */ 406 */
391 struct GNUNET_IDENTITY_PrivateKey zone;
392}; 407};
393 408
394 409
@@ -427,11 +442,6 @@ struct ZoneIterationStartMessage
427 struct GNUNET_NAMESTORE_Header gns_header; 442 struct GNUNET_NAMESTORE_Header gns_header;
428 443
429 /** 444 /**
430 * Zone key. All zeros for "all zones".
431 */
432 struct GNUNET_IDENTITY_PrivateKey zone;
433
434 /**
435 * Record set filter control flags. 445 * Record set filter control flags.
436 * See GNUNET_NAMESTORE_Filter enum. 446 * See GNUNET_NAMESTORE_Filter enum.
437 */ 447 */
@@ -441,6 +451,15 @@ struct ZoneIterationStartMessage
441 * Reserved for alignment 451 * Reserved for alignment
442 */ 452 */
443 uint16_t reserved; 453 uint16_t reserved;
454
455 /**
456 * Length of the zone key
457 */
458 uint32_t key_len GNUNET_PACKED;
459
460 /**
461 * Followed by the private zone key (optional)
462 */
444}; 463};
445 464
446 465
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 41c1fcc73..e020b9e42 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -401,18 +401,20 @@ check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
401 size_t msg_len; 401 size_t msg_len;
402 size_t name_len; 402 size_t name_len;
403 size_t rd_len; 403 size_t rd_len;
404 size_t key_len;
404 405
405 (void) cls; 406 (void) cls;
406 rd_len = ntohs (msg->rd_len); 407 rd_len = ntohs (msg->rd_len);
407 msg_len = ntohs (msg->gns_header.header.size); 408 msg_len = ntohs (msg->gns_header.header.size);
408 name_len = ntohs (msg->name_len); 409 name_len = ntohs (msg->name_len);
409 exp_msg_len = sizeof(*msg) + name_len + rd_len; 410 key_len = ntohl (msg->key_len);
411 exp_msg_len = sizeof(*msg) + name_len + rd_len + key_len;
410 if (msg_len != exp_msg_len) 412 if (msg_len != exp_msg_len)
411 { 413 {
412 GNUNET_break (0); 414 GNUNET_break (0);
413 return GNUNET_SYSERR; 415 return GNUNET_SYSERR;
414 } 416 }
415 name = (const char *) &msg[1]; 417 name = (const char *) &msg[1] + key_len;
416 if ((name_len > 0) && ('\0' != name[name_len - 1])) 418 if ((name_len > 0) && ('\0' != name[name_len - 1]))
417 { 419 {
418 GNUNET_break (0); 420 GNUNET_break (0);
@@ -443,10 +445,13 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
443{ 445{
444 struct GNUNET_NAMESTORE_Handle *h = cls; 446 struct GNUNET_NAMESTORE_Handle *h = cls;
445 struct GNUNET_NAMESTORE_QueueEntry *qe; 447 struct GNUNET_NAMESTORE_QueueEntry *qe;
448 struct GNUNET_IDENTITY_PrivateKey private_key;
446 const char *name; 449 const char *name;
447 const char *rd_tmp; 450 const char *rd_tmp;
448 size_t name_len; 451 size_t name_len;
449 size_t rd_len; 452 size_t rd_len;
453 size_t key_len;
454 size_t kbytes_read;
450 unsigned int rd_count; 455 unsigned int rd_count;
451 int16_t found = (int16_t) ntohs (msg->found); 456 int16_t found = (int16_t) ntohs (msg->found);
452 457
@@ -458,12 +463,19 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
458 rd_len = ntohs (msg->rd_len); 463 rd_len = ntohs (msg->rd_len);
459 rd_count = ntohs (msg->rd_count); 464 rd_count = ntohs (msg->rd_count);
460 name_len = ntohs (msg->name_len); 465 name_len = ntohs (msg->name_len);
461 name = (const char *) &msg[1]; 466 key_len = ntohl (msg->key_len);
467 GNUNET_assert (GNUNET_SYSERR !=
468 GNUNET_IDENTITY_read_private_key_from_buffer (&msg[1],
469 key_len,
470 &private_key,
471 &kbytes_read));
472 GNUNET_assert (kbytes_read == key_len);
473 name = (const char *) &msg[1] + key_len;
462 if (GNUNET_NO == found) 474 if (GNUNET_NO == found)
463 { 475 {
464 /* label was not in namestore */ 476 /* label was not in namestore */
465 if (NULL != qe->proc) 477 if (NULL != qe->proc)
466 qe->proc (qe->proc_cls, &msg->private_key, name, 0, NULL); 478 qe->proc (qe->proc_cls, &private_key, name, 0, NULL);
467 free_qe (qe); 479 free_qe (qe);
468 return; 480 return;
469 } 481 }
@@ -486,7 +498,7 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
486 name = NULL; 498 name = NULL;
487 if (NULL != qe->proc) 499 if (NULL != qe->proc)
488 qe->proc (qe->proc_cls, 500 qe->proc (qe->proc_cls,
489 &msg->private_key, 501 &private_key,
490 name, 502 name,
491 rd_count, 503 rd_count,
492 (rd_count > 0) ? rd : NULL); 504 (rd_count > 0) ? rd : NULL);
@@ -506,33 +518,35 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
506static int 518static int
507check_record_result (void *cls, const struct RecordResultMessage *msg) 519check_record_result (void *cls, const struct RecordResultMessage *msg)
508{ 520{
509 static struct GNUNET_IDENTITY_PrivateKey priv_dummy;
510 const char *name; 521 const char *name;
511 size_t msg_len; 522 size_t msg_len;
512 size_t name_len; 523 size_t name_len;
513 size_t rd_len; 524 size_t rd_len;
525 size_t key_len;
514 526
515 (void) cls; 527 (void) cls;
516 rd_len = ntohs (msg->rd_len); 528 rd_len = ntohs (msg->rd_len);
517 msg_len = ntohs (msg->gns_header.header.size); 529 msg_len = ntohs (msg->gns_header.header.size);
530 key_len = ntohl (msg->key_len);
518 name_len = ntohs (msg->name_len); 531 name_len = ntohs (msg->name_len);
519 if (0 != ntohs (msg->reserved)) 532 if (0 != ntohs (msg->reserved))
520 { 533 {
521 GNUNET_break (0); 534 GNUNET_break (0);
522 return GNUNET_SYSERR; 535 return GNUNET_SYSERR;
523 } 536 }
524 if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len) 537 if (msg_len != sizeof(struct RecordResultMessage) + key_len + name_len
538 + rd_len)
525 { 539 {
526 GNUNET_break (0); 540 GNUNET_break (0);
527 return GNUNET_SYSERR; 541 return GNUNET_SYSERR;
528 } 542 }
529 name = (const char *) &msg[1]; 543 name = (const char *) &msg[1] + key_len;
530 if ((0 == name_len) || ('\0' != name[name_len - 1])) 544 if ((0 == name_len) || ('\0' != name[name_len - 1]))
531 { 545 {
532 GNUNET_break (0); 546 GNUNET_break (0);
533 return GNUNET_SYSERR; 547 return GNUNET_SYSERR;
534 } 548 }
535 if (0 == GNUNET_memcmp (&msg->private_key, &priv_dummy)) 549 if (0 == key_len)
536 { 550 {
537 GNUNET_break (0); 551 GNUNET_break (0);
538 return GNUNET_SYSERR; 552 return GNUNET_SYSERR;
@@ -554,16 +568,20 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
554 struct GNUNET_NAMESTORE_Handle *h = cls; 568 struct GNUNET_NAMESTORE_Handle *h = cls;
555 struct GNUNET_NAMESTORE_QueueEntry *qe; 569 struct GNUNET_NAMESTORE_QueueEntry *qe;
556 struct GNUNET_NAMESTORE_ZoneIterator *ze; 570 struct GNUNET_NAMESTORE_ZoneIterator *ze;
571 struct GNUNET_IDENTITY_PrivateKey private_key;
557 const char *name; 572 const char *name;
558 const char *rd_tmp; 573 const char *rd_tmp;
559 size_t name_len; 574 size_t name_len;
560 size_t rd_len; 575 size_t rd_len;
576 size_t key_len;
577 size_t kbytes_read;
561 unsigned int rd_count; 578 unsigned int rd_count;
562 579
563 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n"); 580 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
564 rd_len = ntohs (msg->rd_len); 581 rd_len = ntohs (msg->rd_len);
565 rd_count = ntohs (msg->rd_count); 582 rd_count = ntohs (msg->rd_count);
566 name_len = ntohs (msg->name_len); 583 name_len = ntohs (msg->name_len);
584 key_len = ntohl (msg->key_len);
567 ze = find_zi (h, ntohl (msg->gns_header.r_id)); 585 ze = find_zi (h, ntohl (msg->gns_header.r_id));
568 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 586 qe = find_qe (h, ntohl (msg->gns_header.r_id));
569 if ((NULL == ze) && (NULL == qe)) 587 if ((NULL == ze) && (NULL == qe))
@@ -574,7 +592,13 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
574 force_reconnect (h); 592 force_reconnect (h);
575 return; 593 return;
576 } 594 }
577 name = (const char *) &msg[1]; 595 name = (const char *) &msg[1] + key_len;
596 GNUNET_assert (GNUNET_SYSERR !=
597 GNUNET_IDENTITY_read_private_key_from_buffer (&msg[1],
598 key_len,
599 &private_key,
600 &kbytes_read));
601 GNUNET_assert (kbytes_read == key_len);
578 rd_tmp = &name[name_len]; 602 rd_tmp = &name[name_len];
579 { 603 {
580 struct GNUNET_GNSRECORD_Data rd[rd_count]; 604 struct GNUNET_GNSRECORD_Data rd[rd_count];
@@ -588,7 +612,7 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
588 { 612 {
589 if (NULL != qe->proc) 613 if (NULL != qe->proc)
590 qe->proc (qe->proc_cls, 614 qe->proc (qe->proc_cls,
591 &msg->private_key, 615 &private_key,
592 name, 616 name,
593 rd_count, 617 rd_count,
594 (rd_count > 0) ? rd : NULL); 618 (rd_count > 0) ? rd : NULL);
@@ -598,9 +622,9 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
598 if (NULL != ze) 622 if (NULL != ze)
599 { 623 {
600 if (NULL != ze->proc) 624 if (NULL != ze->proc)
601 ze->proc (ze->proc_cls, &msg->private_key, name, rd_count, rd); 625 ze->proc (ze->proc_cls, &private_key, name, rd_count, rd);
602 if (NULL != ze->proc2) 626 if (NULL != ze->proc2)
603 ze->proc2 (ze->proc_cls, &msg->private_key, name, 627 ze->proc2 (ze->proc_cls, &private_key, name,
604 rd_count, rd, GNUNET_TIME_absolute_ntoh (msg->expire)); 628 rd_count, rd, GNUNET_TIME_absolute_ntoh (msg->expire));
605 return; 629 return;
606 } 630 }
@@ -680,20 +704,23 @@ check_zone_to_name_response (void *cls,
680{ 704{
681 size_t name_len; 705 size_t name_len;
682 size_t rd_ser_len; 706 size_t rd_ser_len;
707 size_t key_len;
683 const char *name_tmp; 708 const char *name_tmp;
684 709
685 (void) cls; 710 (void) cls;
686 if (GNUNET_EC_NONE != ntohl (msg->ec)) 711 if (GNUNET_EC_NONE != ntohl (msg->ec))
687 return GNUNET_OK; 712 return GNUNET_OK;
713 key_len = ntohl (msg->key_len);
688 name_len = ntohs (msg->name_len); 714 name_len = ntohs (msg->name_len);
689 rd_ser_len = ntohs (msg->rd_len); 715 rd_ser_len = ntohs (msg->rd_len);
690 if (ntohs (msg->gns_header.header.size) != 716 if (ntohs (msg->gns_header.header.size) !=
691 sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len) 717 sizeof(struct ZoneToNameResponseMessage) + key_len + name_len
718 + rd_ser_len)
692 { 719 {
693 GNUNET_break (0); 720 GNUNET_break (0);
694 return GNUNET_SYSERR; 721 return GNUNET_SYSERR;
695 } 722 }
696 name_tmp = (const char *) &msg[1]; 723 name_tmp = (const char *) &msg[1] + key_len;
697 if ((name_len > 0) && ('\0' != name_tmp[name_len - 1])) 724 if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
698 { 725 {
699 GNUNET_break (0); 726 GNUNET_break (0);
@@ -716,12 +743,15 @@ handle_zone_to_name_response (void *cls,
716{ 743{
717 struct GNUNET_NAMESTORE_Handle *h = cls; 744 struct GNUNET_NAMESTORE_Handle *h = cls;
718 struct GNUNET_NAMESTORE_QueueEntry *qe; 745 struct GNUNET_NAMESTORE_QueueEntry *qe;
746 struct GNUNET_IDENTITY_PrivateKey zone;
719 enum GNUNET_ErrorCode res; 747 enum GNUNET_ErrorCode res;
720 size_t name_len; 748 size_t name_len;
721 size_t rd_ser_len; 749 size_t rd_ser_len;
722 unsigned int rd_count; 750 unsigned int rd_count;
723 const char *name_tmp; 751 const char *name_tmp;
724 const char *rd_tmp; 752 const char *rd_tmp;
753 size_t key_len;
754 size_t kbytes_read;
725 755
726 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n"); 756 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
727 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 757 qe = find_qe (h, ntohl (msg->gns_header.r_id));
@@ -732,6 +762,13 @@ handle_zone_to_name_response (void *cls,
732 return; 762 return;
733 } 763 }
734 res = ntohl (msg->ec); 764 res = ntohl (msg->ec);
765 key_len = ntohl (msg->key_len);
766 GNUNET_assert (GNUNET_SYSERR !=
767 GNUNET_IDENTITY_read_private_key_from_buffer (&msg[1],
768 key_len,
769 &zone,
770 &kbytes_read));
771 GNUNET_assert (kbytes_read == key_len);
735 switch (res) 772 switch (res)
736 { 773 {
737 break; 774 break;
@@ -740,7 +777,7 @@ handle_zone_to_name_response (void *cls,
740 LOG (GNUNET_ERROR_TYPE_DEBUG, 777 LOG (GNUNET_ERROR_TYPE_DEBUG,
741 "Namestore has no result for zone to name mapping \n"); 778 "Namestore has no result for zone to name mapping \n");
742 if (NULL != qe->proc) 779 if (NULL != qe->proc)
743 qe->proc (qe->proc_cls, &msg->zone, NULL, 0, NULL); 780 qe->proc (qe->proc_cls, &zone, NULL, 0, NULL);
744 free_qe (qe); 781 free_qe (qe);
745 return; 782 return;
746 783
@@ -750,7 +787,7 @@ handle_zone_to_name_response (void *cls,
750 name_len = ntohs (msg->name_len); 787 name_len = ntohs (msg->name_len);
751 rd_count = ntohs (msg->rd_count); 788 rd_count = ntohs (msg->rd_count);
752 rd_ser_len = ntohs (msg->rd_len); 789 rd_ser_len = ntohs (msg->rd_len);
753 name_tmp = (const char *) &msg[1]; 790 name_tmp = (const char *) &msg[1] + key_len;
754 rd_tmp = &name_tmp[name_len]; 791 rd_tmp = &name_tmp[name_len];
755 { 792 {
756 struct GNUNET_GNSRECORD_Data rd[rd_count]; 793 struct GNUNET_GNSRECORD_Data rd[rd_count];
@@ -762,7 +799,7 @@ handle_zone_to_name_response (void *cls,
762 rd)); 799 rd));
763 /* normal end, call continuation with result */ 800 /* normal end, call continuation with result */
764 if (NULL != qe->proc) 801 if (NULL != qe->proc)
765 qe->proc (qe->proc_cls, &msg->zone, name_tmp, rd_count, rd); 802 qe->proc (qe->proc_cls, &zone, name_tmp, rd_count, rd);
766 /* return is important here: break would call continuation with error! */ 803 /* return is important here: break would call continuation with error! */
767 free_qe (qe); 804 free_qe (qe);
768 return; 805 return;
@@ -1050,7 +1087,10 @@ GNUNET_NAMESTORE_records_store2 (
1050 ssize_t sret; 1087 ssize_t sret;
1051 int i; 1088 int i;
1052 size_t rd_set_len = 0; 1089 size_t rd_set_len = 0;
1053 size_t max_len = UINT16_MAX - sizeof (struct RecordStoreMessage); 1090 size_t key_len = 0;
1091 size_t max_len;
1092 key_len = GNUNET_IDENTITY_private_key_get_length (pkey);
1093 max_len = UINT16_MAX - key_len - sizeof (struct RecordStoreMessage);
1054 1094
1055 *rds_sent = 0; 1095 *rds_sent = 0;
1056 for (i = 0; i < rd_set_count; i++) 1096 for (i = 0; i < rd_set_count; i++)
@@ -1093,17 +1133,19 @@ GNUNET_NAMESTORE_records_store2 (
1093 qe->cont_cls = cont_cls; 1133 qe->cont_cls = cont_cls;
1094 qe->op_id = rid; 1134 qe->op_id = rid;
1095 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1135 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1096
1097 /* setup msg */ 1136 /* setup msg */
1098 env = GNUNET_MQ_msg_extra (msg, 1137 env = GNUNET_MQ_msg_extra (msg,
1099 rd_set_len, 1138 key_len + rd_set_len,
1100 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); 1139 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE);
1101 GNUNET_assert (NULL != msg); 1140 GNUNET_assert (NULL != msg);
1102 GNUNET_assert (NULL != env); 1141 GNUNET_assert (NULL != env);
1103 msg->gns_header.r_id = htonl (rid); 1142 msg->gns_header.r_id = htonl (rid);
1143 msg->key_len = htonl (key_len);
1104 msg->rd_set_count = htons ((uint16_t) (*rds_sent)); 1144 msg->rd_set_count = htons ((uint16_t) (*rds_sent));
1105 msg->private_key = *pkey; 1145 GNUNET_IDENTITY_write_private_key_to_buffer (pkey,
1106 rd_set = (struct RecordSet*) &msg[1]; 1146 &msg[1],
1147 key_len);
1148 rd_set = (struct RecordSet*) (((char*) &msg[1]) + key_len);
1107 for (int i = 0; i < *rds_sent; i++) 1149 for (int i = 0; i < *rds_sent; i++)
1108 { 1150 {
1109 label = record_info[i].a_label; 1151 label = record_info[i].a_label;
@@ -1162,6 +1204,7 @@ records_lookup (
1162 struct GNUNET_MQ_Envelope *env; 1204 struct GNUNET_MQ_Envelope *env;
1163 struct LabelLookupMessage *msg; 1205 struct LabelLookupMessage *msg;
1164 size_t label_len; 1206 size_t label_len;
1207 size_t key_len;
1165 1208
1166 if (1 == (label_len = strlen (label) + 1)) 1209 if (1 == (label_len = strlen (label) + 1))
1167 { 1210 {
@@ -1178,15 +1221,20 @@ records_lookup (
1178 qe->op_id = get_op_id (h); 1221 qe->op_id = get_op_id (h);
1179 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1222 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1180 1223
1224 key_len = GNUNET_IDENTITY_private_key_get_length (pkey);
1181 env = GNUNET_MQ_msg_extra (msg, 1225 env = GNUNET_MQ_msg_extra (msg,
1182 label_len, 1226 label_len + key_len,
1183 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP); 1227 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP);
1184 msg->gns_header.r_id = htonl (qe->op_id); 1228 msg->gns_header.r_id = htonl (qe->op_id);
1185 msg->zone = *pkey; 1229 GNUNET_IDENTITY_write_private_key_to_buffer (pkey,
1230 &msg[1],
1231 key_len);
1232
1233 msg->key_len = htonl (key_len);
1186 msg->is_edit_request = htonl (is_edit_request); 1234 msg->is_edit_request = htonl (is_edit_request);
1187 msg->label_len = htonl (label_len); 1235 msg->label_len = htonl (label_len);
1188 msg->filter = htons (filter); 1236 msg->filter = htons (filter);
1189 GNUNET_memcpy (&msg[1], label, label_len); 1237 GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
1190 if (NULL == h->mq) 1238 if (NULL == h->mq)
1191 qe->env = env; 1239 qe->env = env;
1192 else 1240 else
@@ -1257,6 +1305,8 @@ GNUNET_NAMESTORE_zone_to_name (
1257 struct GNUNET_MQ_Envelope *env; 1305 struct GNUNET_MQ_Envelope *env;
1258 struct ZoneToNameMessage *msg; 1306 struct ZoneToNameMessage *msg;
1259 uint32_t rid; 1307 uint32_t rid;
1308 size_t key_len;
1309 ssize_t pkey_len;
1260 1310
1261 rid = get_op_id (h); 1311 rid = get_op_id (h);
1262 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1312 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
@@ -1268,10 +1318,17 @@ GNUNET_NAMESTORE_zone_to_name (
1268 qe->op_id = rid; 1318 qe->op_id = rid;
1269 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1319 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1270 1320
1271 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); 1321 key_len = GNUNET_IDENTITY_private_key_get_length (zone);
1322 pkey_len = GNUNET_IDENTITY_public_key_get_length (value_zone);
1323 env = GNUNET_MQ_msg_extra (msg, key_len + pkey_len,
1324 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME);
1272 msg->gns_header.r_id = htonl (rid); 1325 msg->gns_header.r_id = htonl (rid);
1273 msg->zone = *zone; 1326 msg->key_len = htonl (key_len);
1274 msg->value_zone = *value_zone; 1327 msg->pkey_len = htonl (pkey_len);
1328 GNUNET_IDENTITY_write_private_key_to_buffer (zone, &msg[1], key_len);
1329 GNUNET_IDENTITY_write_public_key_to_buffer (value_zone,
1330 (char*) &msg[1] + key_len,
1331 pkey_len);
1275 if (NULL == h->mq) 1332 if (NULL == h->mq)
1276 qe->env = env; 1333 qe->env = env;
1277 else 1334 else
@@ -1295,6 +1352,7 @@ GNUNET_NAMESTORE_zone_iteration_start (
1295 struct GNUNET_MQ_Envelope *env; 1352 struct GNUNET_MQ_Envelope *env;
1296 struct ZoneIterationStartMessage *msg; 1353 struct ZoneIterationStartMessage *msg;
1297 uint32_t rid; 1354 uint32_t rid;
1355 size_t key_len = 0;
1298 1356
1299 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n"); 1357 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1300 rid = get_op_id (h); 1358 rid = get_op_id (h);
@@ -1308,12 +1366,18 @@ GNUNET_NAMESTORE_zone_iteration_start (
1308 it->proc_cls = proc_cls; 1366 it->proc_cls = proc_cls;
1309 it->op_id = rid; 1367 it->op_id = rid;
1310 if (NULL != zone) 1368 if (NULL != zone)
1369 {
1311 it->zone = *zone; 1370 it->zone = *zone;
1371 key_len = GNUNET_IDENTITY_private_key_get_length (zone);
1372 }
1312 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it); 1373 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1313 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); 1374 env = GNUNET_MQ_msg_extra (msg,
1375 key_len,
1376 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
1314 msg->gns_header.r_id = htonl (rid); 1377 msg->gns_header.r_id = htonl (rid);
1378 msg->key_len = htonl (key_len);
1315 if (NULL != zone) 1379 if (NULL != zone)
1316 msg->zone = *zone; 1380 GNUNET_IDENTITY_write_private_key_to_buffer (zone, &msg[1], key_len);
1317 if (NULL == h->mq) 1381 if (NULL == h->mq)
1318 it->env = env; 1382 it->env = env;
1319 else 1383 else
@@ -1337,6 +1401,7 @@ GNUNET_NAMESTORE_zone_iteration_start2 (
1337 struct GNUNET_MQ_Envelope *env; 1401 struct GNUNET_MQ_Envelope *env;
1338 struct ZoneIterationStartMessage *msg; 1402 struct ZoneIterationStartMessage *msg;
1339 uint32_t rid; 1403 uint32_t rid;
1404 size_t key_len = 0;
1340 1405
1341 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n"); 1406 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1342 rid = get_op_id (h); 1407 rid = get_op_id (h);
@@ -1350,13 +1415,19 @@ GNUNET_NAMESTORE_zone_iteration_start2 (
1350 it->proc_cls = proc_cls; 1415 it->proc_cls = proc_cls;
1351 it->op_id = rid; 1416 it->op_id = rid;
1352 if (NULL != zone) 1417 if (NULL != zone)
1418 {
1353 it->zone = *zone; 1419 it->zone = *zone;
1420 key_len = GNUNET_IDENTITY_private_key_get_length (zone);
1421 }
1354 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it); 1422 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1355 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); 1423 env = GNUNET_MQ_msg_extra (msg,
1424 key_len,
1425 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
1356 msg->gns_header.r_id = htonl (rid); 1426 msg->gns_header.r_id = htonl (rid);
1427 msg->key_len = htonl (key_len);
1357 msg->filter = htons ((uint16_t) filter); 1428 msg->filter = htons ((uint16_t) filter);
1358 if (NULL != zone) 1429 if (NULL != zone)
1359 msg->zone = *zone; 1430 GNUNET_IDENTITY_write_private_key_to_buffer (zone, &msg[1], key_len);
1360 if (NULL == h->mq) 1431 if (NULL == h->mq)
1361 it->env = env; 1432 it->env = env;
1362 else 1433 else
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index 56ae8cb53..81ea41f7d 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -98,6 +98,11 @@ struct GNUNET_NAMESTORE_ZoneMonitor
98 * Do we first iterate over all existing records? 98 * Do we first iterate over all existing records?
99 */ 99 */
100 int iterate_first; 100 int iterate_first;
101
102 /**
103 * Zone key length
104 */
105 uint32_t key_len;
101}; 106};
102 107
103 108
@@ -146,10 +151,12 @@ check_result (void *cls, const struct RecordResultMessage *lrm)
146 unsigned rd_count; 151 unsigned rd_count;
147 const char *name_tmp; 152 const char *name_tmp;
148 const char *rd_ser_tmp; 153 const char *rd_ser_tmp;
154 size_t key_len;
149 155
156 (void) zm;
157 key_len = ntohl (lrm->key_len);
150 (void) cls; 158 (void) cls;
151 if ((0 != GNUNET_memcmp (&lrm->private_key, &zm->zone)) && 159 if (0 == key_len)
152 (GNUNET_NO == GNUNET_is_zero (&zm->zone)))
153 { 160 {
154 GNUNET_break (0); 161 GNUNET_break (0);
155 return GNUNET_SYSERR; 162 return GNUNET_SYSERR;
@@ -163,7 +170,7 @@ check_result (void *cls, const struct RecordResultMessage *lrm)
163 GNUNET_break (0); 170 GNUNET_break (0);
164 return GNUNET_SYSERR; 171 return GNUNET_SYSERR;
165 } 172 }
166 exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len; 173 exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len + key_len;
167 if (lrm_len != exp_lrm_len) 174 if (lrm_len != exp_lrm_len)
168 { 175 {
169 GNUNET_break (0); 176 GNUNET_break (0);
@@ -174,7 +181,7 @@ check_result (void *cls, const struct RecordResultMessage *lrm)
174 GNUNET_break (0); 181 GNUNET_break (0);
175 return GNUNET_SYSERR; 182 return GNUNET_SYSERR;
176 } 183 }
177 name_tmp = (const char *) &lrm[1]; 184 name_tmp = (const char *) &lrm[1] + key_len;
178 if (name_tmp[name_len - 1] != '\0') 185 if (name_tmp[name_len - 1] != '\0')
179 { 186 {
180 GNUNET_break (0); 187 GNUNET_break (0);
@@ -206,16 +213,26 @@ static void
206handle_result (void *cls, const struct RecordResultMessage *lrm) 213handle_result (void *cls, const struct RecordResultMessage *lrm)
207{ 214{
208 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 215 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
216 struct GNUNET_IDENTITY_PrivateKey private_key;
209 size_t name_len; 217 size_t name_len;
210 size_t rd_len; 218 size_t rd_len;
219 size_t key_len;
220 size_t kbytes_read;
211 unsigned rd_count; 221 unsigned rd_count;
212 const char *name_tmp; 222 const char *name_tmp;
213 const char *rd_ser_tmp; 223 const char *rd_ser_tmp;
214 224
225 key_len = ntohl (lrm->key_len);
215 rd_len = ntohs (lrm->rd_len); 226 rd_len = ntohs (lrm->rd_len);
216 rd_count = ntohs (lrm->rd_count); 227 rd_count = ntohs (lrm->rd_count);
217 name_len = ntohs (lrm->name_len); 228 name_len = ntohs (lrm->name_len);
218 name_tmp = (const char *) &lrm[1]; 229 name_tmp = (const char *) &lrm[1] + key_len;
230 GNUNET_assert (GNUNET_SYSERR !=
231 GNUNET_IDENTITY_read_private_key_from_buffer (&lrm[1],
232 key_len,
233 &private_key,
234 &kbytes_read));
235 GNUNET_assert (kbytes_read == key_len);
219 rd_ser_tmp = (const char *) &name_tmp[name_len]; 236 rd_ser_tmp = (const char *) &name_tmp[name_len];
220 { 237 {
221 struct GNUNET_GNSRECORD_Data rd[rd_count]; 238 struct GNUNET_GNSRECORD_Data rd[rd_count];
@@ -224,10 +241,10 @@ handle_result (void *cls, const struct RecordResultMessage *lrm)
224 GNUNET_OK == 241 GNUNET_OK ==
225 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)); 242 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd));
226 if (NULL != zm->monitor2) 243 if (NULL != zm->monitor2)
227 zm->monitor2 (zm->monitor_cls, &lrm->private_key, name_tmp, 244 zm->monitor2 (zm->monitor_cls, &private_key, name_tmp,
228 rd_count, rd, GNUNET_TIME_absolute_ntoh (lrm->expire)); 245 rd_count, rd, GNUNET_TIME_absolute_ntoh (lrm->expire));
229 else 246 else
230 zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd); 247 zm->monitor (zm->monitor_cls, &private_key, name_tmp, rd_count, rd);
231 } 248 }
232} 249}
233 250
@@ -283,9 +300,15 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
283 zm); 300 zm);
284 if (NULL == zm->mq) 301 if (NULL == zm->mq)
285 return; 302 return;
286 env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); 303 env = GNUNET_MQ_msg_extra (sm,
304 zm->key_len,
305 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START);
287 sm->iterate_first = htonl (zm->iterate_first); 306 sm->iterate_first = htonl (zm->iterate_first);
288 sm->zone = zm->zone; 307 if (0 < zm->key_len)
308 GNUNET_IDENTITY_write_private_key_to_buffer (&zm->zone,
309 &sm[1],
310 zm->key_len);
311 sm->key_len = htonl (zm->key_len);
289 sm->filter = htons (zm->filter); 312 sm->filter = htons (zm->filter);
290 GNUNET_MQ_send (zm->mq, env); 313 GNUNET_MQ_send (zm->mq, env);
291} 314}
@@ -307,7 +330,10 @@ GNUNET_NAMESTORE_zone_monitor_start (
307 330
308 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor); 331 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor);
309 if (NULL != zone) 332 if (NULL != zone)
333 {
334 zm->key_len = GNUNET_IDENTITY_private_key_get_length (zone);
310 zm->zone = *zone; 335 zm->zone = *zone;
336 }
311 zm->iterate_first = iterate_first; 337 zm->iterate_first = iterate_first;
312 zm->error_cb = error_cb; 338 zm->error_cb = error_cb;
313 zm->error_cb_cls = error_cb_cls; 339 zm->error_cb_cls = error_cb_cls;
@@ -342,7 +368,10 @@ GNUNET_NAMESTORE_zone_monitor_start2 (
342 368
343 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor); 369 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor);
344 if (NULL != zone) 370 if (NULL != zone)
371 {
372 zm->key_len = GNUNET_IDENTITY_private_key_get_length (zone);
345 zm->zone = *zone; 373 zm->zone = *zone;
374 }
346 zm->iterate_first = iterate_first; 375 zm->iterate_first = iterate_first;
347 zm->error_cb = error_cb; 376 zm->error_cb = error_cb;
348 zm->error_cb_cls = error_cb_cls; 377 zm->error_cb_cls = error_cb_cls;