aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-09 21:08:16 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-09 21:08:16 +0000
commit01e6bbb6ccd7337c7a9286016418d03d3d365d90 (patch)
tree817c8a18aa395b06b67195055dab608f8affb6e9 /src
parentb0ee2cbddcdf5a2361ff168b8aeef5fb28d37014 (diff)
downloadgnunet-01e6bbb6ccd7337c7a9286016418d03d3d365d90.tar.gz
gnunet-01e6bbb6ccd7337c7a9286016418d03d3d365d90.zip
-unindex needs to decrypt KBlock
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs_api.c2
-rw-r--r--src/fs/fs_api.h7
-rw-r--r--src/fs/fs_unindex.c48
3 files changed, 38 insertions, 19 deletions
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c
index 9acec5be4..669b8cc39 100644
--- a/src/fs/fs_api.c
+++ b/src/fs/fs_api.c
@@ -1991,7 +1991,7 @@ deserialize_unindex_file (void *cls, const char *filename)
1991 (GNUNET_OK != read_start_time (rh, &uc->start_time)) || 1991 (GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
1992 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || 1992 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) ||
1993 (GNUNET_OK != GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || 1993 (GNUNET_OK != GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) ||
1994 (GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || 1994 (GNUNET_OK != GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
1995 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)) ) 1995 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)) )
1996 { 1996 {
1997 GNUNET_break (0); 1997 GNUNET_break (0);
diff --git a/src/fs/fs_api.h b/src/fs/fs_api.h
index 924911b63..e75b75f41 100644
--- a/src/fs/fs_api.h
+++ b/src/fs/fs_api.h
@@ -1382,11 +1382,16 @@ struct GNUNET_FS_UnindexContext
1382 struct GNUNET_DATASTORE_QueueEntry *dqe; 1382 struct GNUNET_DATASTORE_QueueEntry *dqe;
1383 1383
1384 /** 1384 /**
1385 * Current query key of 'get_key' operation. 1385 * Current key for decrypting KBLocks from 'get_key' operation.
1386 */ 1386 */
1387 GNUNET_HashCode key; 1387 GNUNET_HashCode key;
1388 1388
1389 /** 1389 /**
1390 * Current query of 'get_key' operation.
1391 */
1392 GNUNET_HashCode query;
1393
1394 /**
1390 * First content UID, 0 for none. 1395 * First content UID, 0 for none.
1391 */ 1396 */
1392 uint64_t first_uid; 1397 uint64_t first_uid;
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 07b9cccd3..9e477c111 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -446,7 +446,6 @@ process_kblock_for_unindex (void *cls,
446{ 446{
447 struct GNUNET_FS_UnindexContext *uc = cls; 447 struct GNUNET_FS_UnindexContext *uc = cls;
448 const struct KBlock *kb; 448 const struct KBlock *kb;
449 const char *uris;
450 struct GNUNET_FS_Uri *chk_uri; 449 struct GNUNET_FS_Uri *chk_uri;
451 450
452 uc->dqe = NULL; 451 uc->dqe = NULL;
@@ -476,17 +475,33 @@ process_kblock_for_unindex (void *cls,
476 goto get_next; 475 goto get_next;
477 } 476 }
478 kb = data; 477 kb = data;
479 uris = (const char*) &kb[1];
480 if (NULL == memchr (uris, 0, size - sizeof (struct KBlock)))
481 { 478 {
482 GNUNET_break (0); 479 char pt[size - sizeof (struct KBlock)];
483 goto get_next; 480 struct GNUNET_CRYPTO_AesSessionKey skey;
484 } 481 struct GNUNET_CRYPTO_AesInitializationVector iv;
485 chk_uri = GNUNET_FS_uri_parse (uris, NULL); 482
486 if (NULL == chk_uri) 483 GNUNET_CRYPTO_hash_to_aes_key (&uc->key, &skey, &iv);
487 { 484 if (-1 ==
488 GNUNET_break (0); 485 GNUNET_CRYPTO_aes_decrypt (&kb[1], size - sizeof (struct KBlock), &skey,
489 goto get_next; 486 &iv, pt))
487 {
488 GNUNET_break (0);
489 goto get_next;
490 }
491 if (NULL == memchr (pt, 0, sizeof (pt)))
492 {
493 GNUNET_break (0);
494 goto get_next;
495 }
496 chk_uri = GNUNET_FS_uri_parse (pt, NULL);
497 if (NULL == chk_uri)
498 {
499 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
500 _("Failed to parse URI `%s' from KBlock!\n"),
501 pt);
502 GNUNET_break (0);
503 goto get_next;
504 }
490 } 505 }
491 if (0 != memcmp (&uc->chk, 506 if (0 != memcmp (&uc->chk,
492 &chk_uri->data.chk.chk, 507 &chk_uri->data.chk.chk,
@@ -507,7 +522,7 @@ process_kblock_for_unindex (void *cls,
507 get_next: 522 get_next:
508 uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, 523 uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh,
509 uc->roff++, 524 uc->roff++,
510 &uc->key, 525 &uc->query,
511 GNUNET_BLOCK_TYPE_FS_KBLOCK, 526 GNUNET_BLOCK_TYPE_FS_KBLOCK,
512 0 /* priority */, 1 /* queue size */, 527 0 /* priority */, 1 /* queue size */,
513 GNUNET_TIME_UNIT_FOREVER_REL, 528 GNUNET_TIME_UNIT_FOREVER_REL,
@@ -525,7 +540,6 @@ void
525GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) 540GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc)
526{ 541{
527 const char *keyword; 542 const char *keyword;
528 GNUNET_HashCode hc;
529 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; 543 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
530 struct GNUNET_CRYPTO_RsaPrivateKey *pk; 544 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
531 545
@@ -547,19 +561,19 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc)
547 } 561 }
548 /* FIXME: code duplication with fs_search.c here... */ 562 /* FIXME: code duplication with fs_search.c here... */
549 keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; 563 keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1];
550 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc); 564 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &uc->key);
551 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc); 565 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&uc->key);
552 GNUNET_assert (pk != NULL); 566 GNUNET_assert (pk != NULL);
553 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); 567 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
554 GNUNET_CRYPTO_rsa_key_free (pk); 568 GNUNET_CRYPTO_rsa_key_free (pk);
555 GNUNET_CRYPTO_hash (&pub, 569 GNUNET_CRYPTO_hash (&pub,
556 sizeof (struct 570 sizeof (struct
557 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 571 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
558 &uc->key); 572 &uc->query);
559 uc->first_uid = 0; 573 uc->first_uid = 0;
560 uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, 574 uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh,
561 uc->roff++, 575 uc->roff++,
562 &uc->key, 576 &uc->query,
563 GNUNET_BLOCK_TYPE_FS_KBLOCK, 577 GNUNET_BLOCK_TYPE_FS_KBLOCK,
564 0 /* priority */, 1 /* queue size */, 578 0 /* priority */, 1 /* queue size */,
565 GNUNET_TIME_UNIT_FOREVER_REL, 579 GNUNET_TIME_UNIT_FOREVER_REL,