diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-09 14:14:01 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-09 14:14:01 +0000 |
commit | 5e828dc0248330d772913795257b3fda14fe9552 (patch) | |
tree | 362ecdb95dcb89c56a7f20d31b06efa7351fe8ba /src/namestore/gnunet-service-namestore.c | |
parent | 780fdda9a42441ecf36482461ebd35e4ec5c7510 (diff) | |
download | gnunet-5e828dc0248330d772913795257b3fda14fe9552.tar.gz gnunet-5e828dc0248330d772913795257b3fda14fe9552.zip |
- changes to signing verfifying: includes block expiration
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 87ecc9018..57d2dd007 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -212,6 +212,21 @@ int zone_to_disk_it (void *cls, | |||
212 | } | 212 | } |
213 | 213 | ||
214 | 214 | ||
215 | struct GNUNET_TIME_Absolute | ||
216 | get_block_expiration_time (unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) | ||
217 | { | ||
218 | int c; | ||
219 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get_forever(); | ||
220 | if (NULL == rd) | ||
221 | return GNUNET_TIME_absolute_get_zero(); | ||
222 | for (c = 0; c < rd_count; c++) | ||
223 | { | ||
224 | if (rd[c].expiration.abs_value < expire.abs_value) | ||
225 | expire = rd[c].expiration; | ||
226 | } | ||
227 | return expire; | ||
228 | } | ||
229 | |||
215 | /** | 230 | /** |
216 | * Task run during shutdown. | 231 | * Task run during shutdown. |
217 | * | 232 | * |
@@ -231,6 +246,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
231 | snc = NULL; | 246 | snc = NULL; |
232 | 247 | ||
233 | GNUNET_CONTAINER_multihashmap_iterate(zonekeys, &zone_to_disk_it, NULL); | 248 | GNUNET_CONTAINER_multihashmap_iterate(zonekeys, &zone_to_disk_it, NULL); |
249 | GNUNET_CONTAINER_multihashmap_destroy(zonekeys); | ||
234 | 250 | ||
235 | for (nc = client_head; nc != NULL; nc = next) | 251 | for (nc = client_head; nc != NULL; nc = next) |
236 | { | 252 | { |
@@ -364,6 +380,7 @@ handle_lookup_name_it (void *cls, | |||
364 | struct GNUNET_NAMESTORE_RecordData *rd_selected = NULL; | 380 | struct GNUNET_NAMESTORE_RecordData *rd_selected = NULL; |
365 | struct GNUNET_NAMESTORE_CryptoContainer *cc; | 381 | struct GNUNET_NAMESTORE_CryptoContainer *cc; |
366 | struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL; | 382 | struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL; |
383 | struct GNUNET_TIME_Absolute e; | ||
367 | GNUNET_HashCode zone_key_hash; | 384 | GNUNET_HashCode zone_key_hash; |
368 | char *rd_tmp; | 385 | char *rd_tmp; |
369 | char *name_tmp; | 386 | char *name_tmp; |
@@ -435,7 +452,8 @@ handle_lookup_name_it (void *cls, | |||
435 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &zone_key_hash)) | 452 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &zone_key_hash)) |
436 | { | 453 | { |
437 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &zone_key_hash); | 454 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &zone_key_hash); |
438 | signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, name, rd, rd_count); | 455 | e = get_block_expiration_time(rd_count, rd); |
456 | signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd, rd_count); | ||
439 | GNUNET_assert (signature_new != NULL); | 457 | GNUNET_assert (signature_new != NULL); |
440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for name `%s' with %u records in zone `%s'\n",name, copied_elements, GNUNET_h2s(&zone_key_hash)); | 458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for name `%s' with %u records in zone `%s'\n",name, copied_elements, GNUNET_h2s(&zone_key_hash)); |
441 | authoritative = GNUNET_YES; | 459 | authoritative = GNUNET_YES; |
@@ -444,9 +462,6 @@ handle_lookup_name_it (void *cls, | |||
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am not authoritative for name `%s' in zone `%s'\n",name, GNUNET_h2s(&zone_key_hash)); | 462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am not authoritative for name `%s' in zone `%s'\n",name, GNUNET_h2s(&zone_key_hash)); |
445 | } | 463 | } |
446 | 464 | ||
447 | if (rd_selected != rd) | ||
448 | GNUNET_free (rd_selected); | ||
449 | |||
450 | r_size = sizeof (struct LookupNameResponseMessage) + | 465 | r_size = sizeof (struct LookupNameResponseMessage) + |
451 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + | 466 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + |
452 | name_len + | 467 | name_len + |
@@ -460,7 +475,10 @@ handle_lookup_name_it (void *cls, | |||
460 | lnr_msg->rd_count = htons (copied_elements); | 475 | lnr_msg->rd_count = htons (copied_elements); |
461 | lnr_msg->rd_len = htons (rd_ser_len); | 476 | lnr_msg->rd_len = htons (rd_ser_len); |
462 | lnr_msg->name_len = htons (name_len); | 477 | lnr_msg->name_len = htons (name_len); |
463 | lnr_msg->expire = GNUNET_TIME_absolute_hton(expire); | 478 | lnr_msg->expire = GNUNET_TIME_absolute_hton(get_block_expiration_time(copied_elements, rd_selected)); |
479 | |||
480 | if (rd_selected != rd) | ||
481 | GNUNET_free (rd_selected); | ||
464 | 482 | ||
465 | if (zone_key != NULL) | 483 | if (zone_key != NULL) |
466 | lnr_msg->public_key = (*zone_key); | 484 | lnr_msg->public_key = (*zone_key); |
@@ -811,6 +829,7 @@ static void handle_record_create (void *cls, | |||
811 | { | 829 | { |
812 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); | 830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); |
813 | struct GNUNET_NAMESTORE_Client *nc; | 831 | struct GNUNET_NAMESTORE_Client *nc; |
832 | struct GNUNET_NAMESTORE_CryptoContainer *cc; | ||
814 | struct CreateRecordContext crc; | 833 | struct CreateRecordContext crc; |
815 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 834 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
816 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 835 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
@@ -895,6 +914,19 @@ static void handle_record_create (void *cls, | |||
895 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); | 914 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); |
896 | GNUNET_CRYPTO_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); | 915 | GNUNET_CRYPTO_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); |
897 | 916 | ||
917 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &pubkey_hash)) | ||
918 | { | ||
919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_h2s(&pubkey_hash)); | ||
920 | |||
921 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | ||
922 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | ||
923 | cc->pubkey = GNUNET_malloc(sizeof (pub)); | ||
924 | memcpy (cc->pubkey, &pub, sizeof(pub)); | ||
925 | cc->zone = pubkey_hash; | ||
926 | |||
927 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &pubkey_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
928 | } | ||
929 | |||
898 | crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); | 930 | crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); |
899 | crc.res = GNUNET_SYSERR; | 931 | crc.res = GNUNET_SYSERR; |
900 | crc.pkey = pkey; | 932 | crc.pkey = pkey; |
@@ -909,6 +941,7 @@ static void handle_record_create (void *cls, | |||
909 | if (res != GNUNET_SYSERR) | 941 | if (res != GNUNET_SYSERR) |
910 | res = GNUNET_OK; | 942 | res = GNUNET_OK; |
911 | GNUNET_CRYPTO_rsa_key_free(pkey); | 943 | GNUNET_CRYPTO_rsa_key_free(pkey); |
944 | pkey = NULL; | ||
912 | 945 | ||
913 | /* Send response */ | 946 | /* Send response */ |
914 | send: | 947 | send: |
@@ -1027,6 +1060,7 @@ static void handle_record_remove (void *cls, | |||
1027 | struct GNUNET_NAMESTORE_Client *nc; | 1060 | struct GNUNET_NAMESTORE_Client *nc; |
1028 | struct RecordRemoveResponseMessage rrr_msg; | 1061 | struct RecordRemoveResponseMessage rrr_msg; |
1029 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 1062 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
1063 | struct GNUNET_NAMESTORE_CryptoContainer *cc = NULL; | ||
1030 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 1064 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
1031 | GNUNET_HashCode pubkey_hash; | 1065 | GNUNET_HashCode pubkey_hash; |
1032 | char * pkey_tmp = NULL; | 1066 | char * pkey_tmp = NULL; |
@@ -1120,6 +1154,18 @@ static void handle_record_remove (void *cls, | |||
1120 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); | 1154 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); |
1121 | GNUNET_CRYPTO_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); | 1155 | GNUNET_CRYPTO_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); |
1122 | 1156 | ||
1157 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &pubkey_hash)) | ||
1158 | { | ||
1159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_h2s(&pubkey_hash)); | ||
1160 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | ||
1161 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | ||
1162 | cc->pubkey = GNUNET_malloc(sizeof (pub)); | ||
1163 | memcpy (cc->pubkey, &pub, sizeof(pub)); | ||
1164 | cc->zone = pubkey_hash; | ||
1165 | |||
1166 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &pubkey_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1167 | } | ||
1168 | |||
1123 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | 1169 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; |
1124 | res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd); | 1170 | res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd); |
1125 | if ((res != GNUNET_OK) || (rd_count != 1)) | 1171 | if ((res != GNUNET_OK) || (rd_count != 1)) |
@@ -1334,6 +1380,7 @@ void zone_iteration_proc (void *cls, | |||
1334 | struct GNUNET_NAMESTORE_Client *nc = zi->client; | 1380 | struct GNUNET_NAMESTORE_Client *nc = zi->client; |
1335 | struct GNUNET_NAMESTORE_CryptoContainer * cc; | 1381 | struct GNUNET_NAMESTORE_CryptoContainer * cc; |
1336 | struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL; | 1382 | struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL; |
1383 | struct GNUNET_TIME_Absolute e; | ||
1337 | GNUNET_HashCode zone_key_hash; | 1384 | GNUNET_HashCode zone_key_hash; |
1338 | int authoritative = GNUNET_NO; | 1385 | int authoritative = GNUNET_NO; |
1339 | 1386 | ||
@@ -1393,9 +1440,11 @@ void zone_iteration_proc (void *cls, | |||
1393 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &zone_key_hash)) | 1440 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &zone_key_hash)) |
1394 | { | 1441 | { |
1395 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &zone_key_hash); | 1442 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &zone_key_hash); |
1396 | signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, name, rd, rd_count); | 1443 | e = get_block_expiration_time(rd_count, rd); |
1444 | expire = e; | ||
1445 | signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd, rd_count); | ||
1397 | GNUNET_assert (signature_new != NULL); | 1446 | GNUNET_assert (signature_new != NULL); |
1398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for name `%s' with %u records in zone `%s'\n",name, rd_count, GNUNET_h2s(&zone_key_hash)); | 1447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for `%s' in zone `%s' with %u records and expiration %llu\n", name, GNUNET_h2s(&zone_key_hash), rd_count, e.abs_value); |
1399 | authoritative = GNUNET_YES; | 1448 | authoritative = GNUNET_YES; |
1400 | } | 1449 | } |
1401 | 1450 | ||