gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r20420 - gnunet/src/fs


From: gnunet
Subject: [GNUnet-SVN] r20420 - gnunet/src/fs
Date: Fri, 9 Mar 2012 22:08:16 +0100

Author: grothoff
Date: 2012-03-09 22:08:16 +0100 (Fri, 09 Mar 2012)
New Revision: 20420

Modified:
   gnunet/src/fs/fs_api.c
   gnunet/src/fs/fs_api.h
   gnunet/src/fs/fs_unindex.c
Log:
-unindex needs to decrypt KBlock

Modified: gnunet/src/fs/fs_api.c
===================================================================
--- gnunet/src/fs/fs_api.c      2012-03-09 20:57:28 UTC (rev 20419)
+++ gnunet/src/fs/fs_api.c      2012-03-09 21:08:16 UTC (rev 20420)
@@ -1991,7 +1991,7 @@
       (GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
       (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) ||
       (GNUNET_OK != GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct 
ContentHashKey))) ||
-      (GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
+      (GNUNET_OK != GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 
1024)) ||
       (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)) )
   {
     GNUNET_break (0);

Modified: gnunet/src/fs/fs_api.h
===================================================================
--- gnunet/src/fs/fs_api.h      2012-03-09 20:57:28 UTC (rev 20419)
+++ gnunet/src/fs/fs_api.h      2012-03-09 21:08:16 UTC (rev 20420)
@@ -1382,11 +1382,16 @@
   struct GNUNET_DATASTORE_QueueEntry *dqe;
 
   /**
-   * Current query key of 'get_key' operation.
+   * Current key for decrypting KBLocks from 'get_key' operation.
    */
   GNUNET_HashCode key;
 
   /**
+   * Current query of 'get_key' operation.
+   */
+  GNUNET_HashCode query;
+
+  /**
    * First content UID, 0 for none.
    */
   uint64_t first_uid;

Modified: gnunet/src/fs/fs_unindex.c
===================================================================
--- gnunet/src/fs/fs_unindex.c  2012-03-09 20:57:28 UTC (rev 20419)
+++ gnunet/src/fs/fs_unindex.c  2012-03-09 21:08:16 UTC (rev 20420)
@@ -446,7 +446,6 @@
 {
   struct GNUNET_FS_UnindexContext *uc = cls;
   const struct KBlock *kb;
-  const char *uris;
   struct GNUNET_FS_Uri *chk_uri;
 
   uc->dqe = NULL;
@@ -476,18 +475,34 @@
     goto get_next;
   }
   kb = data;
-  uris = (const char*) &kb[1];
-  if (NULL == memchr (uris, 0, size - sizeof (struct KBlock)))
   {
-    GNUNET_break (0);
-    goto get_next;
+    char pt[size - sizeof (struct KBlock)];  
+    struct GNUNET_CRYPTO_AesSessionKey skey;
+    struct GNUNET_CRYPTO_AesInitializationVector iv;
+ 
+    GNUNET_CRYPTO_hash_to_aes_key (&uc->key, &skey, &iv);
+    if (-1 ==
+       GNUNET_CRYPTO_aes_decrypt (&kb[1], size - sizeof (struct KBlock), &skey,
+                                  &iv, pt))
+    {
+      GNUNET_break (0);
+      goto get_next;
+    }       
+    if (NULL == memchr (pt, 0, sizeof (pt)))
+    {
+      GNUNET_break (0);
+      goto get_next;
+    }
+    chk_uri = GNUNET_FS_uri_parse (pt, NULL);
+    if (NULL == chk_uri)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Failed to parse URI `%s' from KBlock!\n"),
+                 pt);
+      GNUNET_break (0);
+      goto get_next;
+    }
   }
-  chk_uri = GNUNET_FS_uri_parse (uris, NULL);
-  if (NULL == chk_uri)
-  {
-    GNUNET_break (0);
-    goto get_next;
-  }
   if (0 != memcmp (&uc->chk,
                   &chk_uri->data.chk.chk,
                   sizeof (struct ContentHashKey)))
@@ -507,7 +522,7 @@
  get_next:
   uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh,
                                      uc->roff++,
-                                     &uc->key,
+                                     &uc->query,
                                      GNUNET_BLOCK_TYPE_FS_KBLOCK,
                                      0 /* priority */, 1 /* queue size */,
                                      GNUNET_TIME_UNIT_FOREVER_REL,
@@ -525,7 +540,6 @@
 GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc)
 {
   const char *keyword;
-  GNUNET_HashCode hc;
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
   struct GNUNET_CRYPTO_RsaPrivateKey *pk;
 
@@ -547,19 +561,19 @@
   }
   /* FIXME: code duplication with fs_search.c here... */
   keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1];
-  GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc);
-  pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc);
+  GNUNET_CRYPTO_hash (keyword, strlen (keyword), &uc->key);
+  pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&uc->key);
   GNUNET_assert (pk != NULL);
   GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
   GNUNET_CRYPTO_rsa_key_free (pk);
   GNUNET_CRYPTO_hash (&pub,
                      sizeof (struct
                              GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
-                     &uc->key);
+                     &uc->query);
   uc->first_uid = 0;
   uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh,
                                      uc->roff++,
-                                     &uc->key,
+                                     &uc->query,
                                      GNUNET_BLOCK_TYPE_FS_KBLOCK,
                                      0 /* priority */, 1 /* queue size */,
                                      GNUNET_TIME_UNIT_FOREVER_REL,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]