aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_search.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-06 20:46:22 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-06 20:46:22 +0000
commit303ab4dafbc680b1b362f95df5b12dae831b1593 (patch)
tree8b2f411b0b31e500ce2988404b2501db03bed945 /src/fs/fs_search.c
parent1360f8a1e5877a8796dc8e7d0c55d78481382e80 (diff)
downloadgnunet-303ab4dafbc680b1b362f95df5b12dae831b1593.tar.gz
gnunet-303ab4dafbc680b1b362f95df5b12dae831b1593.zip
-fixing main FS build, updating man page of gnunet-pseudonym
Diffstat (limited to 'src/fs/fs_search.c')
-rw-r--r--src/fs/fs_search.c114
1 files changed, 44 insertions, 70 deletions
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 10627753a..3b0db0429 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -27,6 +27,7 @@
27#include "gnunet_fs_service.h" 27#include "gnunet_fs_service.h"
28#include "gnunet_protocols.h" 28#include "gnunet_protocols.h"
29#include "fs_api.h" 29#include "fs_api.h"
30#include "fs_publish_ublock.h"
30 31
31 32
32/** 33/**
@@ -669,7 +670,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, const char *id_update,
669 * given ciphertext block. 670 * given ciphertext block.
670 * 671 *
671 * @param sc search context with the keywords 672 * @param sc search context with the keywords
672 * @param verification_key public key to use to lookup the keyword 673 * @param dpub derived public key used for the search
673 * @param edata encrypted data 674 * @param edata encrypted data
674 * @param edata_size number of bytes in 'edata' (and 'data') 675 * @param edata_size number of bytes in 'edata' (and 'data')
675 * @param data where to store the plaintext 676 * @param data where to store the plaintext
@@ -678,22 +679,20 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, const char *id_update,
678 */ 679 */
679static int 680static int
680decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, 681decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc,
681 const struct GNUNET_FS_PseudonymIdentifier *verification_key, 682 const struct GNUNET_CRYPTO_EccPublicKey *dpub,
682 const void *edata, 683 const void *edata,
683 size_t edata_size, 684 size_t edata_size,
684 char *data) 685 char *data)
685{ 686{
686 struct GNUNET_HashCode q; 687 const struct GNUNET_CRYPTO_EccPrivateKey *anon;
687 struct GNUNET_CRYPTO_AesSessionKey skey; 688 struct GNUNET_CRYPTO_EccPublicKey anon_pub;
688 struct GNUNET_CRYPTO_AesInitializationVector iv; 689 unsigned int i;
689 int i;
690 690
691 GNUNET_CRYPTO_hash (verification_key,
692 sizeof (struct GNUNET_FS_PseudonymIdentifier),
693 &q);
694 /* find key */ 691 /* find key */
695 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) 692 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
696 if (0 == memcmp (&q, &sc->requests[i].uquery, sizeof (struct GNUNET_HashCode))) 693 if (0 == memcmp (dpub,
694 &sc->requests[i].dpub,
695 sizeof (struct GNUNET_CRYPTO_EccPublicKey)))
697 break; 696 break;
698 if (i == sc->uri->data.ksk.keywordCount) 697 if (i == sc->uri->data.ksk.keywordCount)
699 { 698 {
@@ -702,14 +701,12 @@ decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc,
702 return GNUNET_SYSERR; 701 return GNUNET_SYSERR;
703 } 702 }
704 /* decrypt */ 703 /* decrypt */
705 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].ukey, &skey, &iv); 704 anon = GNUNET_CRYPTO_ecc_key_get_anonymous ();
706 if (-1 == 705 GNUNET_CRYPTO_ecc_key_get_public (anon, &anon_pub);
707 GNUNET_CRYPTO_aes_decrypt (edata, edata_size, &skey, 706 GNUNET_FS_ublock_decrypt_ (edata, edata_size,
708 &iv, data)) 707 &anon_pub,
709 { 708 sc->requests[i].keyword,
710 GNUNET_break (0); 709 data);
711 return GNUNET_SYSERR;
712 }
713 return i; 710 return i;
714} 711}
715 712
@@ -789,31 +786,18 @@ process_sblock (struct GNUNET_FS_SearchContext *sc,
789{ 786{
790 size_t len = size - sizeof (struct UBlock); 787 size_t len = size - sizeof (struct UBlock);
791 char pt[len]; 788 char pt[len];
792 struct GNUNET_CRYPTO_AesSessionKey skey;
793 struct GNUNET_CRYPTO_AesInitializationVector iv;
794 struct GNUNET_FS_Uri *uri; 789 struct GNUNET_FS_Uri *uri;
795 struct GNUNET_CONTAINER_MetaData *meta; 790 struct GNUNET_CONTAINER_MetaData *meta;
796 const char *id; 791 const char *id;
797 const char *uris; 792 const char *uris;
798 size_t off; 793 size_t off;
799 char *emsg; 794 char *emsg;
800 struct GNUNET_HashCode key;
801 struct GNUNET_HashCode id_hash;
802 struct GNUNET_HashCode ns_hash;
803 char *identifier;
804 795
805 /* decrypt */ 796 /* decrypt */
806 identifier = sc->uri->data.sks.identifier; 797 GNUNET_FS_ublock_decrypt_ (&ub[1], len,
807 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &id_hash); 798 &sc->uri->data.sks.ns,
808 GNUNET_CRYPTO_hash (&sc->uri->data.sks.ns, 799 sc->uri->data.sks.identifier,
809 sizeof (sc->uri->data.sks.ns), &ns_hash); 800 pt);
810 GNUNET_CRYPTO_hash_xor (&id_hash, &ns_hash, &key);
811 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
812 if (-1 == GNUNET_CRYPTO_aes_decrypt (&ub[1], len, &skey, &iv, pt))
813 {
814 GNUNET_break (0);
815 return;
816 }
817 /* parse */ 801 /* parse */
818 if (0 == (off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris))) 802 if (0 == (off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris)))
819 { 803 {
@@ -1050,12 +1034,7 @@ transmit_search_request (void *cls, size_t size, void *buf)
1050 struct MessageBuilderContext mbc; 1034 struct MessageBuilderContext mbc;
1051 size_t msize; 1035 size_t msize;
1052 struct SearchMessage *sm; 1036 struct SearchMessage *sm;
1053 const char *identifier; 1037 struct GNUNET_CRYPTO_EccPublicKey dpub;
1054 struct GNUNET_HashCode key;
1055 struct GNUNET_HashCode signing_key;
1056 struct GNUNET_HashCode ns_hash;
1057 struct GNUNET_HashCode id_hash;
1058 struct GNUNET_FS_PseudonymIdentifier verification_key;
1059 unsigned int sqms; 1038 unsigned int sqms;
1060 uint32_t options; 1039 uint32_t options;
1061 1040
@@ -1122,18 +1101,11 @@ transmit_search_request (void *cls, size_t size, void *buf)
1122 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK); 1101 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK);
1123 sm->anonymity_level = htonl (sc->anonymity); 1102 sm->anonymity_level = htonl (sc->anonymity);
1124 memset (&sm->target, 0, sizeof (struct GNUNET_HashCode)); 1103 memset (&sm->target, 0, sizeof (struct GNUNET_HashCode));
1125 1104 GNUNET_CRYPTO_ecc_public_key_derive (&sc->uri->data.sks.ns,
1126 identifier = sc->uri->data.sks.identifier; 1105 sc->uri->data.sks.identifier,
1127 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &id_hash); 1106 &dpub);
1128 GNUNET_CRYPTO_hash (&sc->uri->data.sks.ns, 1107 GNUNET_CRYPTO_hash (&dpub,
1129 sizeof (sc->uri->data.sks.ns), &ns_hash); 1108 sizeof (dpub),
1130 GNUNET_CRYPTO_hash_xor (&id_hash, &ns_hash, &key);
1131 GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &signing_key);
1132 GNUNET_FS_pseudonym_derive_verification_key (&sc->uri->data.sks.ns,
1133 &signing_key,
1134 &verification_key);
1135 GNUNET_CRYPTO_hash (&verification_key,
1136 sizeof (verification_key),
1137 &sm->query); 1109 &sm->query);
1138 mbc.put_cnt = (size - msize) / sizeof (struct GNUNET_HashCode); 1110 mbc.put_cnt = (size - msize) / sizeof (struct GNUNET_HashCode);
1139 sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map); 1111 sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map);
@@ -1297,35 +1269,34 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1297{ 1269{
1298 unsigned int i; 1270 unsigned int i;
1299 const char *keyword; 1271 const char *keyword;
1300 struct GNUNET_HashCode signing_key; 1272 const struct GNUNET_CRYPTO_EccPrivateKey *anon;
1301 struct GNUNET_FS_PseudonymHandle *ph; 1273 struct GNUNET_CRYPTO_EccPublicKey anon_pub;
1302 struct GNUNET_FS_PseudonymIdentifier anon; 1274 struct SearchRequestEntry *sre;
1303 struct GNUNET_FS_PseudonymIdentifier verification_key;
1304 1275
1305 GNUNET_assert (NULL == sc->client); 1276 GNUNET_assert (NULL == sc->client);
1306 if (GNUNET_FS_uri_test_ksk (sc->uri)) 1277 if (GNUNET_FS_uri_test_ksk (sc->uri))
1307 { 1278 {
1308 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); 1279 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
1309 ph = GNUNET_FS_pseudonym_get_anonymous_pseudonym_handle (); 1280 anon = GNUNET_CRYPTO_ecc_key_get_anonymous ();
1310 GNUNET_FS_pseudonym_get_identifier (ph, &anon); 1281 GNUNET_CRYPTO_ecc_key_get_public (anon, &anon_pub);
1311 GNUNET_FS_pseudonym_destroy (ph);
1312 sc->requests = 1282 sc->requests =
1313 GNUNET_malloc (sizeof (struct SearchRequestEntry) * 1283 GNUNET_malloc (sizeof (struct SearchRequestEntry) *
1314 sc->uri->data.ksk.keywordCount); 1284 sc->uri->data.ksk.keywordCount);
1315 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) 1285 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1316 { 1286 {
1317 keyword = &sc->uri->data.ksk.keywords[i][1]; 1287 keyword = &sc->uri->data.ksk.keywords[i][1];
1318 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &sc->requests[i].ukey); 1288 sre = &sc->requests[i];
1319 GNUNET_CRYPTO_hash (&sc->requests[i].ukey, sizeof (struct GNUNET_HashCode), &signing_key); 1289 sre->keyword = GNUNET_strdup (keyword);
1320 GNUNET_FS_pseudonym_derive_verification_key (&anon, 1290 GNUNET_CRYPTO_ecc_public_key_derive (&anon_pub,
1321 &signing_key, 1291 keyword,
1322 &verification_key); 1292 &sre->dpub);
1323 GNUNET_CRYPTO_hash (&verification_key, sizeof (struct GNUNET_FS_PseudonymIdentifier), 1293 GNUNET_CRYPTO_hash (&sre->dpub,
1324 &sc->requests[i].uquery); 1294 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
1325 sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+'); 1295 &sre->uquery);
1326 if (sc->requests[i].mandatory) 1296 sre->mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
1297 if (sre->mandatory)
1327 sc->mandatory_count++; 1298 sc->mandatory_count++;
1328 sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); 1299 sre->results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
1329 } 1300 }
1330 } 1301 }
1331 sc->client = GNUNET_CLIENT_connect ("fs", sc->h->cfg); 1302 sc->client = GNUNET_CLIENT_connect ("fs", sc->h->cfg);
@@ -1475,7 +1446,10 @@ GNUNET_FS_search_signal_suspend_ (void *cls)
1475 { 1446 {
1476 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); 1447 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
1477 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) 1448 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1449 {
1478 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); 1450 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
1451 GNUNET_free (sc->requests[i].keyword);
1452 }
1479 } 1453 }
1480 GNUNET_free_non_null (sc->requests); 1454 GNUNET_free_non_null (sc->requests);
1481 GNUNET_free_non_null (sc->emsg); 1455 GNUNET_free_non_null (sc->emsg);