- changes to signing verfifying: includes block expiration
[oweals/gnunet.git] / src / namestore / test_namestore_api_create_update.c
index 2c91a00f4014560d741ab853cea1edbefc666823..9e8f9c4d4448a3ef43f1919acd02f6b0af81ea9c 100644 (file)
@@ -19,7 +19,7 @@
 */
 /**
  * @file namestore/test_namestore_api.c
- * @brief testcase for namestore_api.c
+ * @brief testcase for namestore_api.c for updating an existing record
  */
 #include "platform.h"
 #include "gnunet_common.h"
@@ -176,7 +176,7 @@ void name_lookup_second_proc (void *cls,
       }
     }
 
-    if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature(&pubkey, n, rd_count, rd, signature))
+    if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature(&pubkey, expire, n, rd_count, rd, signature))
     {
       GNUNET_break (0);
       failed = GNUNET_YES;
@@ -185,7 +185,7 @@ void name_lookup_second_proc (void *cls,
     struct GNUNET_NAMESTORE_RecordData rd_new[2];
     rd_new[0] = *s_first_record;
     rd_new[1] = *s_second_record;
-    s_signature_updated = GNUNET_NAMESTORE_create_signature(privkey, s_name, rd_new, 2);
+    s_signature_updated = GNUNET_NAMESTORE_create_signature(privkey, expire, s_name, rd_new, 2);
 
     if (0 != memcmp (s_signature_updated, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
     {
@@ -274,7 +274,7 @@ void name_lookup_initial_proc (void *cls,
       }
     }
 
-    if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature(&pubkey, n, rd_count, rd, signature))
+    if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature(&pubkey, expire, n, rd_count, rd, signature))
     {
       GNUNET_break (0);
       failed = GNUNET_YES;
@@ -321,36 +321,40 @@ void
 create_updated_cont (void *cls, int32_t success, const char *emsg)
 {
   char *name = cls;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
-  if (success == GNUNET_OK)
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating expiration for record `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
+  if (success == GNUNET_NO)
   {
     res = 0;
-    GNUNET_SCHEDULER_add_now(&end, NULL);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updated record for name `%s'\n", name);
+  }
+  else if (success == GNUNET_OK)
+  {
+    res = 1;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FAIL, Create new record for name `%s'\n", name);
   }
   else
   {
     res = 1;
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name);
-    GNUNET_SCHEDULER_add_now(&end, NULL);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create records for name `%s'\n", name);
   }
-
+  GNUNET_SCHEDULER_add_now(&end, NULL);
 }
 
 void
 create_identical_cont (void *cls, int32_t success, const char *emsg)
 {
   char *name = cls;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create updated record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
-  if (success == GNUNET_OK)
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating identical record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
+  if (success == GNUNET_NO)
   {
     res = 0;
-    s_first_record->expiration = GNUNET_TIME_absolute_get_zero();
+    s_first_record->expiration = GNUNET_TIME_absolute_get ();
     GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_updated_cont, s_name);
   }
   else
   {
     res = 1;
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating identical record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
     GNUNET_SCHEDULER_add_now(&end, NULL);
   }
 
@@ -402,7 +406,7 @@ create_record (int count)
 
   for (c = 0; c < count; c++)
   {
-  rd[c].expiration = GNUNET_TIME_absolute_get();
+  rd[c].expiration = GNUNET_TIME_absolute_get_zero();
   rd[c].record_type = TEST_RECORD_TYPE;
   rd[c].data_size = TEST_RECORD_DATALEN;
   rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
@@ -440,7 +444,12 @@ run (void *cls, char *const *args, const char *cfgfile,
   size_t rd_ser_len;
 
   /* load privat key */
-  privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
+  char *hostkey_file;
+  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "4UCICULTINKC87UO4326KEEDQ9MTEP2AJT88MJFVGTGNK12QNGMQI2S41VI07UUU6EO19BTB06PDL0HE6VP1OM50HOJEI75RHP4JP80.zone");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+  privkey = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file);
+  GNUNET_free (hostkey_file);
+
   GNUNET_assert (privkey != NULL);
   /* get public key */
   GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
@@ -453,7 +462,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   char rd_ser[rd_ser_len];
   GNUNET_NAMESTORE_records_serialize(1, s_first_record, rd_ser_len, rd_ser);
 
-  s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_name, s_first_record, 1);
+  s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_first_record->expiration, s_name, s_first_record, 1);
 
   /* create random zone hash */
   GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone);