aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c61
1 files changed, 28 insertions, 33 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index f8663775b..a4e463642 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -283,10 +283,9 @@ write_key_to_file (const char *filename,
283 struct GNUNET_NAMESTORE_CryptoContainer *c) 283 struct GNUNET_NAMESTORE_CryptoContainer *c)
284{ 284{
285 struct GNUNET_CRYPTO_EccPrivateKey *ret = c->privkey; 285 struct GNUNET_CRYPTO_EccPrivateKey *ret = c->privkey;
286 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
287 struct GNUNET_DISK_FileHandle *fd; 286 struct GNUNET_DISK_FileHandle *fd;
288 struct GNUNET_CRYPTO_ShortHashCode zone; 287 struct GNUNET_CRYPTO_ShortHashCode zone;
289 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey; 288 struct GNUNET_CRYPTO_EccPublicKey pubkey;
290 struct GNUNET_CRYPTO_EccPrivateKey *privkey; 289 struct GNUNET_CRYPTO_EccPrivateKey *privkey;
291 290
292 fd = GNUNET_DISK_file_open (filename, 291 fd = GNUNET_DISK_file_open (filename,
@@ -305,7 +304,7 @@ write_key_to_file (const char *filename,
305 } 304 }
306 GNUNET_CRYPTO_ecc_key_get_public (privkey, &pubkey); 305 GNUNET_CRYPTO_ecc_key_get_public (privkey, &pubkey);
307 GNUNET_CRYPTO_short_hash (&pubkey, 306 GNUNET_CRYPTO_short_hash (&pubkey,
308 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), 307 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
309 &zone); 308 &zone);
310 GNUNET_CRYPTO_ecc_key_free (privkey); 309 GNUNET_CRYPTO_ecc_key_free (privkey);
311 if (0 == memcmp (&zone, &c->zone, sizeof(zone))) 310 if (0 == memcmp (&zone, &c->zone, sizeof(zone)))
@@ -326,17 +325,21 @@ write_key_to_file (const char *filename,
326 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); 325 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
327 return GNUNET_SYSERR; 326 return GNUNET_SYSERR;
328 } 327 }
329 if (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded), GNUNET_YES)) 328 if (GNUNET_YES !=
329 GNUNET_DISK_file_lock (fd, 0,
330 sizeof (struct GNUNET_CRYPTO_EccPrivateKey),
331 GNUNET_YES))
330 { 332 {
331 GNUNET_break (GNUNET_YES == GNUNET_DISK_file_close (fd)); 333 GNUNET_break (GNUNET_YES == GNUNET_DISK_file_close (fd));
332 return GNUNET_SYSERR; 334 return GNUNET_SYSERR;
333 } 335 }
334 enc = GNUNET_CRYPTO_ecc_encode_key (ret); 336 GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EccPrivateKey) ==
335 GNUNET_assert (NULL != enc); 337 GNUNET_DISK_file_write (fd, ret,
336 GNUNET_assert (ntohs (enc->size) == GNUNET_DISK_file_write (fd, enc, ntohs (enc->size))); 338 sizeof (struct GNUNET_CRYPTO_EccPrivateKey)));
337 GNUNET_free (enc);
338 GNUNET_DISK_file_sync (fd); 339 GNUNET_DISK_file_sync (fd);
339 if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded))) 340 if (GNUNET_YES !=
341 GNUNET_DISK_file_unlock (fd, 0,
342 sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
340 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 343 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
341 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 344 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -387,14 +390,14 @@ zone_to_disk_it (void *cls,
387static void 390static void
388learn_private_key (struct GNUNET_CRYPTO_EccPrivateKey *pkey) 391learn_private_key (struct GNUNET_CRYPTO_EccPrivateKey *pkey)
389{ 392{
390 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub; 393 struct GNUNET_CRYPTO_EccPublicKey pub;
391 struct GNUNET_HashCode long_hash; 394 struct GNUNET_HashCode long_hash;
392 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; 395 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
393 struct GNUNET_NAMESTORE_CryptoContainer *cc; 396 struct GNUNET_NAMESTORE_CryptoContainer *cc;
394 397
395 GNUNET_CRYPTO_ecc_key_get_public (pkey, &pub); 398 GNUNET_CRYPTO_ecc_key_get_public (pkey, &pub);
396 GNUNET_CRYPTO_short_hash (&pub, 399 GNUNET_CRYPTO_short_hash (&pub,
397 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), 400 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
398 &pubkey_hash); 401 &pubkey_hash);
399 GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); 402 GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash);
400 403
@@ -643,7 +646,7 @@ struct LookupNameContext
643 */ 646 */
644static void 647static void
645handle_lookup_name_it (void *cls, 648handle_lookup_name_it (void *cls,
646 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key, 649 const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
647 struct GNUNET_TIME_Absolute expire, 650 struct GNUNET_TIME_Absolute expire,
648 const char *name, 651 const char *name,
649 unsigned int rd_count, 652 unsigned int rd_count,
@@ -680,7 +683,7 @@ handle_lookup_name_it (void *cls,
680 if (NULL != zone_key) 683 if (NULL != zone_key)
681 { 684 {
682 GNUNET_CRYPTO_short_hash (zone_key, 685 GNUNET_CRYPTO_short_hash (zone_key,
683 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), 686 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
684 &zone_key_hash); 687 &zone_key_hash);
685 GNUNET_CRYPTO_short_hash_double (&zone_key_hash, &long_hash); 688 GNUNET_CRYPTO_short_hash_double (&zone_key_hash, &long_hash);
686 if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get (zonekeys, &long_hash))) 689 if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get (zonekeys, &long_hash)))
@@ -991,7 +994,7 @@ static void
991send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, 994send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
992 struct GNUNET_SERVER_Client *client, 995 struct GNUNET_SERVER_Client *client,
993 uint32_t request_id, 996 uint32_t request_id,
994 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key, 997 const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
995 struct GNUNET_TIME_Absolute expire, 998 struct GNUNET_TIME_Absolute expire,
996 const char *name, 999 const char *name,
997 unsigned int rd_count, 1000 unsigned int rd_count,
@@ -1198,16 +1201,14 @@ handle_record_create (void *cls,
1198 size_t msg_size; 1201 size_t msg_size;
1199 size_t msg_size_exp; 1202 size_t msg_size_exp;
1200 size_t rd_ser_len; 1203 size_t rd_ser_len;
1201 size_t key_len;
1202 uint32_t rid; 1204 uint32_t rid;
1203 const char *pkey_tmp;
1204 const char *name_tmp; 1205 const char *name_tmp;
1205 char *conv_name; 1206 char *conv_name;
1206 const char *rd_ser; 1207 const char *rd_ser;
1207 unsigned int rd_count; 1208 unsigned int rd_count;
1208 int res; 1209 int res;
1209 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; 1210 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
1210 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey; 1211 struct GNUNET_CRYPTO_EccPublicKey pubkey;
1211 1212
1212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1213 "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); 1214 "Received `%s' message\n", "NAMESTORE_RECORD_CREATE");
@@ -1229,8 +1230,8 @@ handle_record_create (void *cls,
1229 msg_size = ntohs (message->size); 1230 msg_size = ntohs (message->size);
1230 rd_count = ntohs (rp_msg->rd_count); 1231 rd_count = ntohs (rp_msg->rd_count);
1231 rd_ser_len = ntohs (rp_msg->rd_len); 1232 rd_ser_len = ntohs (rp_msg->rd_len);
1232 key_len = ntohs (rp_msg->pkey_len); 1233 GNUNET_break (0 == ntohs (rp_msg->reserved));
1233 msg_size_exp = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len; 1234 msg_size_exp = sizeof (struct RecordCreateMessage) + name_len + rd_ser_len;
1234 if (msg_size != msg_size_exp) 1235 if (msg_size != msg_size_exp)
1235 { 1236 {
1236 GNUNET_break (0); 1237 GNUNET_break (0);
@@ -1243,8 +1244,7 @@ handle_record_create (void *cls,
1243 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1244 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1244 return; 1245 return;
1245 } 1246 }
1246 pkey_tmp = (const char *) &rp_msg[1]; 1247 name_tmp = (const char *) &rp_msg[1];
1247 name_tmp = &pkey_tmp[key_len];
1248 rd_ser = &name_tmp[name_len]; 1248 rd_ser = &name_tmp[name_len];
1249 if ('\0' != name_tmp[name_len -1]) 1249 if ('\0' != name_tmp[name_len -1])
1250 { 1250 {
@@ -1252,13 +1252,8 @@ handle_record_create (void *cls,
1252 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1252 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1253 return; 1253 return;
1254 } 1254 }
1255 if (NULL == (pkey = GNUNET_CRYPTO_ecc_decode_key (pkey_tmp, key_len, 1255 pkey = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
1256 GNUNET_NO))) 1256 memcpy (pkey, &rp_msg->private_key, sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
1257 {
1258 GNUNET_break (0);
1259 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1260 return;
1261 }
1262 { 1257 {
1263 struct GNUNET_NAMESTORE_RecordData rd[rd_count]; 1258 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
1264 1259
@@ -1274,7 +1269,7 @@ handle_record_create (void *cls,
1274 /* Extracting and converting private key */ 1269 /* Extracting and converting private key */
1275 GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey); 1270 GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey);
1276 GNUNET_CRYPTO_short_hash (&pubkey, 1271 GNUNET_CRYPTO_short_hash (&pubkey,
1277 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), 1272 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
1278 &pubkey_hash); 1273 &pubkey_hash);
1279 learn_private_key (pkey); 1274 learn_private_key (pkey);
1280 conv_name = GNUNET_NAMESTORE_normalize_string (name_tmp); 1275 conv_name = GNUNET_NAMESTORE_normalize_string (name_tmp);
@@ -1373,7 +1368,7 @@ struct ZoneToNameCtx
1373 */ 1368 */
1374static void 1369static void
1375handle_zone_to_name_it (void *cls, 1370handle_zone_to_name_it (void *cls,
1376 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key, 1371 const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
1377 struct GNUNET_TIME_Absolute expire, 1372 struct GNUNET_TIME_Absolute expire,
1378 const char *name, 1373 const char *name,
1379 unsigned int rd_count, 1374 unsigned int rd_count,
@@ -1552,7 +1547,7 @@ struct ZoneIterationProcResult
1552 */ 1547 */
1553static void 1548static void
1554zone_iteraterate_proc (void *cls, 1549zone_iteraterate_proc (void *cls,
1555 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key, 1550 const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
1556 struct GNUNET_TIME_Absolute expire, 1551 struct GNUNET_TIME_Absolute expire,
1557 const char *name, 1552 const char *name,
1558 unsigned int rd_count, 1553 unsigned int rd_count,
@@ -1633,7 +1628,7 @@ zone_iteraterate_proc (void *cls,
1633 /* compute / obtain signature, but only if we (a) have records and (b) expiration times were 1628 /* compute / obtain signature, but only if we (a) have records and (b) expiration times were
1634 converted to absolute expiration times */ 1629 converted to absolute expiration times */
1635 GNUNET_CRYPTO_short_hash (zone_key, 1630 GNUNET_CRYPTO_short_hash (zone_key,
1636 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), 1631 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
1637 &zone_hash); 1632 &zone_hash);
1638 GNUNET_CRYPTO_short_hash_double (&zone_hash, &long_hash); 1633 GNUNET_CRYPTO_short_hash_double (&zone_hash, &long_hash);
1639 if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get (zonekeys, &long_hash))) 1634 if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get (zonekeys, &long_hash)))
@@ -1976,7 +1971,7 @@ monitor_next (void *cls,
1976 */ 1971 */
1977static void 1972static void
1978monitor_iterate_cb (void *cls, 1973monitor_iterate_cb (void *cls,
1979 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key, 1974 const struct GNUNET_CRYPTO_EccPublicKey *zone_key,
1980 struct GNUNET_TIME_Absolute expire, 1975 struct GNUNET_TIME_Absolute expire,
1981 const char *name, 1976 const char *name,
1982 unsigned int rd_count, 1977 unsigned int rd_count,