gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (a5b4c84 -> d0a484e)


From: gnunet
Subject: [taler-anastasis] branch master updated (a5b4c84 -> d0a484e)
Date: Sun, 03 May 2020 18:02:24 +0200

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a change to branch master
in repository anastasis.

    from a5b4c84  fix
     new 3f49bd9  json_dumps with JSON_COMPACT and JSON_SORT_KEYS
     new 06095a1  deleted salt cb etc. from anastasis.c
     new ac3b957  changed user identifier derivation to use 
GNUNET_CRYPTO_hash_pow()
     new 71fec95  changed user identifier derivation to use 
GNUNET_CRYPTO_hash_pow()
     new b1fe803  modified truth trait
     new e9c7c44  big O to small o, json_pack
     new 5356b54  fixed http server not shutting down
     new bd2fab0  Initial work on testing policy creation
     new 0050236  created policy trait
     new 0c41437  modified Makefile
     new 649e611  worked on testing policy creation
     new c21e046  Some error fixes
     new d0a484e  fixed truth array problems

The 13 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/anastasis.h                            |   5 +-
 src/include/anastasis_crypto_lib.h                 |   2 +-
 src/include/anastasis_testing_lib.h                |  67 +++--
 src/lib/Makefile.am                                |   4 +-
 src/lib/anastasis.c                                | 110 +++++---
 src/lib/test_anastasis.c                           |  18 +-
 src/lib/testing_cmd_policy_create.c                | 281 +++++++++++++++++++++
 src/lib/testing_cmd_truth_upload.c                 |  45 +---
 ...ing_api_trait_uuid.c => testing_trait_policy.c} |  41 ++-
 src/lib/testing_trait_truth.c                      |  48 +---
 src/util/anastasis_crypto.c                        |  28 +-
 src/util/test_anastasis_crypto.c                   |   6 +-
 12 files changed, 455 insertions(+), 200 deletions(-)
 create mode 100644 src/lib/testing_cmd_policy_create.c
 copy src/lib/{testing_api_trait_uuid.c => testing_trait_policy.c} (56%)

diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 2eae470..aab80ed 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -204,8 +204,8 @@ struct ANASTASIS_Recovery;
 *
 * @param id_data contains the users identity, (user account on providers)
 * @param version defines the version which will be downloaded NULL for latest 
version
-* @param anastasis_provider_url_candidates NULL terminated list of possible 
provider urls
-* @param provider_candidates_length length of the provider list
+* @param anastasis_provider_url NULL terminated list of possible provider urls
+* @param salt the server salt
 * @param pc opens the policy call back which holds the downloaded version and 
the policies
 * @param pc_cls closure for callback
 * @param csc core secret callback is opened, with this the core secert is 
passed to the client after the authentication
@@ -215,6 +215,7 @@ struct ANASTASIS_Recovery *
 ANASTASIS_recovery_begin (const json_t *id_data,
                           unsigned int version,
                           const char *anastasis_provider_url,
+                          const struct ANASTASIS_CRYPTO_SaltP *salt,
                           ANASTASIS_PolicyCallback pc,
                           void *pc_cls,
                           ANASTASIS_CoreSecretCallback csc,
diff --git a/src/include/anastasis_crypto_lib.h 
b/src/include/anastasis_crypto_lib.h
index a7e21f4..6fe6490 100644
--- a/src/include/anastasis_crypto_lib.h
+++ b/src/include/anastasis_crypto_lib.h
@@ -153,7 +153,7 @@ struct ANASTASIS_CRYPTO_EscrowMasterKeyP
  */
 struct ANASTASIS_CRYPTO_UserIdentifierP
 {
-  uint32_t hash[8];
+  struct GNUNET_HashCode hash GNUNET_PACKED;
 };
 
 GNUNET_NETWORK_STRUCT_END
diff --git a/src/include/anastasis_testing_lib.h 
b/src/include/anastasis_testing_lib.h
index 60ccef8..b72f3e1 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -460,33 +460,6 @@ ANASTASIS_TESTING_cmd_salt (const char *label,
 
 /* ********************* test truth upload ********************* */
 
-/**
- * Obtain numbers of truth traits from @a cmd.
- *
- * @param cmd command to extract the number from.
- * @param index the index of the number
- * @param n[out] set to the number coming from @a cmd.
- * @return #GNUNET_OK on success.
- */
-int
-ANASTASIS_TESTING_get_trait_truth_number (const struct
-                                          TALER_TESTING_Command *cmd,
-                                          unsigned int index,
-                                          const unsigned int **n);
-
-
-/**
- * Offer the number of truth traits.
- *
- * @param index the number's index number (usually zero).
- * @param n the number to offer.
- * @return #GNUNET_OK on success.
- */
-struct TALER_TESTING_Trait
-ANASTASIS_TESTING_make_trait_truth_number (unsigned int index,
-                                           const unsigned int *n);
-
-
 /**
  * Obtain a truth from @a cmd.
  *
@@ -552,6 +525,46 @@ ANASTASIS_TESTING_cmd_truth_upload (const char *label,
                                     const char *upload_ref);
 
 
+/* ********************* test policy create ********************* */
+
+/**
+ * Obtain a policy from @a cmd.
+ *
+ * @param cmd command to extract the policy from.
+ * @param index the index of the policy
+ * @param t[out] set to the policy coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_policy (const struct TALER_TESTING_Command *cmd,
+                                    unsigned int index,
+                                    const struct ANASTASIS_Policy **p);
+
+
+/**
+ * Offer a policy.
+ *
+ * @param index the policy's index number.
+ * @param t the policy to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_policy (unsigned int index,
+                                     const struct ANASTASIS_Policy *p);
+
+
+/**
+ * Make the "policy create" command.
+ *
+ * @param label command label
+ * @param ... NULL-terminated list of truth upload commands
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_policy_create (const char *label,
+                                     ...);
+
+
 /* ********************* test secret share ********************* */
 
 /**
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index e3c837d..8fb04e4 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -69,9 +69,11 @@ libanastasistesting_la_SOURCES = \
   testing_api_trait_hash.c \
   testing_api_trait_salt.c \
   testing_cmd_truth_upload.c \
+  testing_cmd_policy_create.c \
   testing_cmd_secret_share.c \
   testing_cmd_recover_secret.c \
-  testing_trait_truth.c
+  testing_trait_truth.c \
+  testing_trait_policy.c
 libanastasistesting_la_LIBADD = \
   $(top_builddir)/src/lib/libanastasisrest.la \
   -ltalerexchange \
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 1d98ceb..f8884e2 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -26,7 +26,7 @@
 
 
 /**
- * FIXME: Needed?
+ * FIXME: Needed? -> maybe needed in ANASTASIS_secret_share()
  * State for a "salt" CMD.
  */
 struct SaltState
@@ -54,7 +54,7 @@ struct SaltState
 
 
 /**
- * FIXME: Needed?
+ * FIXME: Needed? -> maybe needed in ANASTASIS_secret_share()
  * Function called with the results of a #ANASTASIS_salt().
  *
  * @param cls closure
@@ -95,7 +95,7 @@ salt_cb (void *cls,
 
 
 /**
- * FIXME: Needed?
+ * FIXME: Needed? -> maybe needed in ANASTASIS_secret_share()
  * Free the state of a "salt" CMD, and possibly
  * cancel it if it did not complete.
  *
@@ -409,8 +409,8 @@ policy_lookup_cb (void *cls,
 *
 * @param id_data contains the users identity, (user account on providers)
 * @param version defines the version which will be downloaded NULL for latest 
version
-* @param anastasis_provider_url_candidates NULL terminated list of possible 
provider urls
-* @param provider_candidates_length length of the provider list
+* @param anastasis_provider_url NULL terminated list of possible provider urls
+* @param salt the server salt
 * @param pc opens the policy call back which holds the downloaded version and 
the policies
 * @param pc_cls closure for callback
 * @param csc core secret callback is opened, with this the core secert is 
passed to the client after the authentication
@@ -420,6 +420,7 @@ struct ANASTASIS_Recovery *
 ANASTASIS_recovery_begin (const json_t *id_data,
                           unsigned int version,
                           const char *anastasis_provider_url,
+                          const struct ANASTASIS_CRYPTO_SaltP *salt,
                           ANASTASIS_PolicyCallback pc,
                           void *pc_cls,
                           ANASTASIS_CoreSecretCallback csc,
@@ -436,17 +437,10 @@ ANASTASIS_recovery_begin (const json_t *id_data,
   json_t *dec_policies = json_array ();
   json_t *esc_methods = json_array ();
   r->key_share_pos = 0;
-  struct SaltState *ss = pc_cls;
   r->http_status = MHD_HTTP_OK;
-  ss->http_status = MHD_HTTP_OK;
-  ss->so = ANASTASIS_salt (r->ctx,
-                           anastasis_provider_url,
-                           &salt_cb,
-                           ss);
   ANASTASIS_CRYPTO_user_identifier_derive (id_data,
-                                           &ss->so->salt,
+                                           salt,
                                            &r->id);
-  salt_cleanup (ss);
   ANASTASIS_CRYPTO_account_public_key_derive (&r->id,
                                               &r->pub_key);
   if (version != 0)
@@ -768,7 +762,6 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
 
   tu = GNUNET_new (struct ANASTASIS_TruthUpload);
   t = GNUNET_new (struct ANASTASIS_Truth);
-  // ss = GNUNET_new (struct SaltState); FIXME: Needed?
   tu->tc_cls = tc_cls;
   tu->tpc_cls = tpc_cls;
   tu->tpc = tpc;
@@ -778,27 +771,15 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
   t->method = method;
   t->instructions = instructions;
   t->mime_type = mime_type;
-  uuid_generate (t->uuid);
-
-  /*
-  FIXME: Needed?
-  ss->http_status = MHD_HTTP_OK;
-  ss->so = ANASTASIS_salt (tu->ctx,
-                           provider_url,
-                           &salt_cb,
-                           ss);
-  */
 
-  if (NULL == id_data)
-  {
-    GNUNET_break (0);
-    return;
-  }
-
-  if (NULL == ss->salt)
-  {
-
-  }
+  uuid_generate (t->uuid);
+  GNUNET_assert (NULL != &t->uuid);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d uuid is %s-%llu b\n", __FILE__, __LINE__,
+              TALER_B2S (&t->uuid),
+              (unsigned long long) sizeof (t->uuid));
+  GNUNET_assert (NULL != id_data);
+  GNUNET_assert (NULL != salt);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "At %s:%d server salt is %s-%llu b\n", __FILE__, __LINE__,
               TALER_B2S (salt),
@@ -836,9 +817,9 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
                                   &encrypted_truth,
                                   &encrypted_truth_size);
 
-  truth = json_pack ("{s:O," /* encrypted KeyShare */
+  truth = json_pack ("{s:o," /* encrypted KeyShare */
                      " s:s," /* method */
-                     " s:O," /* nonce */
+                     " s:o," /* nonce */
                      " s:s}", /* truth_mime */
                      "keyshare_data", GNUNET_JSON_from_data_auto (
                        encrypted_key_share),
@@ -859,7 +840,6 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
                                    tu->paid_order_id,
                                    &truth_store_callback,
                                    tu);
-  // salt_cleanup (ss); FIXME: Needed?
   // SETUP TRUTH CALLBACK
   tu->tc = tc;
   tu->tc_cls = tc_cls;
@@ -934,21 +914,69 @@ ANASTASIS_policy_create (struct ANASTASIS_Truth *truths[],
                          unsigned int truths_len)
 {
   struct ANASTASIS_Policy *p;
-  p = GNUNET_new (struct ANASTASIS_Policy);
+  struct ANASTASIS_Truth *truth;
   struct ANASTASIS_CRYPTO_KeyShareP key_shares[truths_len];
   uuid_t uuids[truths_len];
+
+  p = GNUNET_new (struct ANASTASIS_Policy);
+  truth = truths;
+
+  GNUNET_assert (NULL != *truths);
+  GNUNET_assert (truths_len > 0);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d truth array is %s\n", __FILE__, __LINE__,
+              TALER_b2s (truths,
+                         truths_len
+                         * sizeof (struct ANASTASIS_Truth)));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d truth array length is %i\n", __FILE__, __LINE__,
+              truths_len);
+
   for (unsigned int i = 0; i < truths_len; i++)
   {
-    key_shares[i] = truths[i]->key_share;
-    memcpy (uuids[i], truths[i]->uuid, sizeof(uuid_t));
+    if (i > 0)
+      truth = &truth[1];
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d truth is %s-%llu b\n", __FILE__, __LINE__,
+                TALER_B2S (truth),
+                (unsigned long long) sizeof (struct ANASTASIS_Truth));
+    key_shares[i] = truth->key_share;
+    GNUNET_assert (NULL != &key_shares[i]);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d key share is %s-%llu b\n", __FILE__, __LINE__,
+                TALER_B2S (&key_shares[i]),
+                (unsigned long long) sizeof (key_shares[i]));
+    uuid_copy (&uuids[i], &truth->uuid);
+    GNUNET_assert (NULL != &uuids[i]);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d uuid is %s-%llu b\n", __FILE__, __LINE__,
+                TALER_B2S (&uuids[i]),
+                (unsigned long long) sizeof (uuids[i]));
   }
-  // FIXME SALT
+  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+                              &p->salt,
+                              sizeof (struct ANASTASIS_CRYPTO_SaltP));
+  GNUNET_assert (NULL != &p->salt);
+
   ANASTASIS_CRYPTO_policy_key_derive (key_shares,
                                       truths_len,
                                       &p->salt,
                                       &p->policy_key);
+  GNUNET_assert (NULL != &p->policy_key);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d policy key is %s-%llu b\n", __FILE__, __LINE__,
+              TALER_B2S (&p->policy_key),
+              (unsigned long long) sizeof (p->policy_key));
   p->uuids = uuids;
   p->uuid_length = truths_len;
+
+  GNUNET_assert (NULL != p->uuids);
+  GNUNET_assert (p->uuid_length == truths_len);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d policy is %s-%llu b\n", __FILE__, __LINE__,
+              TALER_B2S (p),
+              (unsigned long long) sizeof (*p));
   return p;
 }
 
diff --git a/src/lib/test_anastasis.c b/src/lib/test_anastasis.c
index 7867d14..7348529 100644
--- a/src/lib/test_anastasis.c
+++ b/src/lib/test_anastasis.c
@@ -185,7 +185,7 @@ run (void *cls,
 
   struct TALER_TESTING_Command anastasis[] = {
     // FIXME: testing logic here
-    ANASTASIS_TESTING_cmd_salt ("truth-create-1",
+    ANASTASIS_TESTING_cmd_salt ("salt-request-1",
                                 anastasis_url,
                                 MHD_HTTP_OK),
 
@@ -200,9 +200,9 @@ run (void *cls,
                                         strlen ("HashOfSomeTruth"),
                                         MHD_HTTP_NO_CONTENT,
                                         ANASTASIS_TESTING_TSO_NONE,
-                                        NULL),
+                                        "salt-request-1"),
 
-    ANASTASIS_TESTING_cmd_salt ("truth-create-2",
+    ANASTASIS_TESTING_cmd_salt ("salt-request-2",
                                 anastasis_url,
                                 MHD_HTTP_OK),
 
@@ -217,9 +217,9 @@ run (void *cls,
                                         strlen ("HashOfSomeTruth"),
                                         MHD_HTTP_NO_CONTENT,
                                         ANASTASIS_TESTING_TSO_NONE,
-                                        "truth-create-1"),
+                                        "salt-request-2"),
 
-    ANASTASIS_TESTING_cmd_salt ("truth-create-3",
+    ANASTASIS_TESTING_cmd_salt ("salt-request-3",
                                 anastasis_url,
                                 MHD_HTTP_OK),
 
@@ -234,7 +234,13 @@ run (void *cls,
                                         strlen ("HashOfSomeTruth"),
                                         MHD_HTTP_NO_CONTENT,
                                         ANASTASIS_TESTING_TSO_NONE,
-                                        "truth-create-2"),
+                                        "salt-request-3"),
+
+    ANASTASIS_TESTING_cmd_policy_create ("policy-create-1",
+                                         "truth-create-1",
+                                         "truth-create-2",
+                                         "truth-create-3",
+                                         NULL),
     /*
     ANASTASIS_TESTING_cmd_secret_share ("secret-share-1",
                                         anastasis_url,
diff --git a/src/lib/testing_cmd_policy_create.c 
b/src/lib/testing_cmd_policy_create.c
new file mode 100644
index 0000000..cce0f25
--- /dev/null
+++ b/src/lib/testing_cmd_policy_create.c
@@ -0,0 +1,281 @@
+/*
+  This file is part of Anastasis
+  Copyright (C) 2020 Taler Systems SA
+
+  Anastasis is free software; you can redistribute it and/or modify it under 
the
+  terms of the GNU Lesser General Public License as published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  Anastasis; see the file COPYING.GPL.  If not, see 
<http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/testing_cmd_policy_create.c
+ * @brief command to execute the anastasis secret share service
+ * @author Christian Grothoff
+ * @author Dennis Neufeld
+ * @author Dominik Meister
+ */
+
+#include "platform.h"
+#include "anastasis_testing_lib.h"
+#include <taler/taler_util.h>
+#include <taler/taler_testing_lib.h>
+
+
+/**
+ * State for a "policy create" CMD.
+ */
+struct PolicyCreateState
+{
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Label of this command.
+   */
+  const char *label;
+
+  /**
+   * References to upload commands of previous truth uploads.
+   */
+  const char **cmd_label_array;
+
+  /**
+   * Length of array of command labels (cmd_label_array).
+   */
+  unsigned int cmd_label_array_length;
+
+  /**
+   * Policy object
+   */
+  const struct ANASTASIS_Policy *policy;
+};
+
+/**
+ * Th Truth.
+ * FIXME: Is there a more elegant way to fix "incomplete type" error?
+ * see sizeof (*truth)
+ */
+struct Truth
+{
+  /**
+   * url to the server
+   */
+  const char *url;
+  /**
+   * identification of the truth
+   */
+  uuid_t uuid;
+  /**
+   * method used for this truth
+   */
+  const char *method;
+  /**
+   * method used for this truth
+   */
+  const char *instructions;
+  /**
+   * mime type of the truth
+   */
+  const char *mime_type;
+  /**
+   * keyshare of this truth, used to generate policy keys
+   */
+  struct ANASTASIS_CRYPTO_KeyShareP key_share;
+  /**
+   * key used to encrypt this truth
+   */
+  struct ANASTASIS_CRYPTO_TruthKeyP truth_key;
+  /**
+   * salt used to encrypt the truth
+   */
+  struct ANASTASIS_CRYPTO_SaltP *salt;
+};
+
+
+
+/**
+ * Run a "policy create" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+policy_create_run (void *cls,
+                   const struct TALER_TESTING_Command *cmd,
+                   struct TALER_TESTING_Interpreter *is)
+{
+  struct PolicyCreateState *pcs = cls;
+  struct Truth truths[pcs->cmd_label_array_length];
+
+  GNUNET_assert (pcs->cmd_label_array_length > 0);
+  GNUNET_assert (NULL != pcs->cmd_label_array);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d cmd label array length is %i\n", __FILE__, __LINE__,
+              pcs->cmd_label_array_length);
+
+  pcs->is = is;
+  if (NULL != pcs->cmd_label_array)
+  {
+    for (unsigned int i = 0; i < pcs->cmd_label_array_length; i++)
+    {
+      const struct TALER_TESTING_Command *ref;
+      struct Truth *truth;
+
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "At %s:%d truth upload cmd is %s\n", __FILE__, __LINE__,
+                  pcs->cmd_label_array[i]);
+
+      ref = TALER_TESTING_interpreter_lookup_command
+              (is,
+              pcs->cmd_label_array[i]);
+      if (NULL == ref)
+      {
+        GNUNET_break (0);
+        TALER_TESTING_interpreter_fail (pcs->is);
+        return;
+      }
+      if (GNUNET_OK !=
+          ANASTASIS_TESTING_get_trait_truth (ref,
+                                             0,
+                                             &truth))
+      {
+        GNUNET_break (0);
+        TALER_TESTING_interpreter_fail (pcs->is);
+        return;
+      }
+      GNUNET_assert (NULL != truth);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "At %s:%d truth is %s-%llu b\n", __FILE__, __LINE__,
+                  TALER_B2S (truth),
+                  (unsigned long long) sizeof (*truth));
+      truths[i] = *truth;
+      GNUNET_assert (0 ==
+                     GNUNET_memcmp (&truths[i],
+                                    truth));
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "At %s:%d truth is %s-%llu b\n", __FILE__, __LINE__,
+                  TALER_B2S (&truths[i]),
+                  (unsigned long long) sizeof (truths[i]));
+    }
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d truth array is %s\n", __FILE__, __LINE__,
+              TALER_b2s (&truths,
+                         pcs->cmd_label_array_length
+                         * sizeof (struct Truth)));
+  pcs->policy = ANASTASIS_policy_create (&truths,
+                                         pcs->cmd_label_array_length);
+  if (NULL == &pcs->policy)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (pcs->is);
+    return;
+  }
+  TALER_TESTING_interpreter_next (pcs->is);
+}
+
+
+/**
+ * Free the state of a "policy create" CMD, and possibly
+ * cancel it if it did not complete.
+ *
+ * @param cls closure.
+ * @param cmd command being freed.
+ */
+static void
+policy_create_cleanup (void *cls,
+                       const struct TALER_TESTING_Command *cmd)
+{
+  // FIXME: Cleanup logic
+  struct PolicyCreateState *pcs = cls;
+
+  GNUNET_free (pcs);
+}
+
+
+/**
+ * Offer internal data to other commands.
+ *
+ * @param cls closure
+ * @param ret[out] result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+policy_create_traits (void *cls,
+                      const void **ret,
+                      const char *trait,
+                      unsigned int index)
+{
+  struct PolicyCreateState *pcs = cls;
+  struct TALER_TESTING_Trait traits[] = {
+    ANASTASIS_TESTING_make_trait_policy (0,
+                                         pcs->policy),
+    TALER_TESTING_trait_end ()
+  };
+
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+
+/**
+ * Make the "policy create" command.
+ *
+ * @param label command label
+ * @param ... NULL-terminated list of truth upload commands
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_policy_create (const char *label,
+                                     ...)
+{
+  struct PolicyCreateState *pcs;
+  va_list ap;
+
+  pcs = GNUNET_new (struct PolicyCreateState);
+  pcs->label = label;
+
+  va_start (ap, label);
+  char *truth_upload_cmd;
+  while (NULL != (truth_upload_cmd = va_arg (ap, const char *)))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d truth upload cmd is %s\n", __FILE__, __LINE__,
+                truth_upload_cmd);
+    GNUNET_array_append (pcs->cmd_label_array,
+                         pcs->cmd_label_array_length,
+                         truth_upload_cmd);
+  }
+  va_end (ap);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d cmd label array length is %i\n", __FILE__, __LINE__,
+              pcs->cmd_label_array_length);
+
+  struct TALER_TESTING_Command cmd = {
+    .cls = pcs,
+    .label = label,
+    .run = &policy_create_run,
+    .cleanup = &policy_create_cleanup,
+    .traits = &policy_create_traits
+  };
+
+  return cmd;
+}
+
+
+/* end of testing_cmd_policy_create.c */
\ No newline at end of file
diff --git a/src/lib/testing_cmd_truth_upload.c 
b/src/lib/testing_cmd_truth_upload.c
index e6eb6a2..519fcab 100644
--- a/src/lib/testing_cmd_truth_upload.c
+++ b/src/lib/testing_cmd_truth_upload.c
@@ -107,11 +107,6 @@ struct TruthUploadState
    * Truth object
    */
   const struct ANASTASIS_Truth *truth;
-
-  /**
-   * index of truth (for trait)
-   */
-  unsigned int truth_number;
 };
 
 
@@ -136,7 +131,6 @@ truth_upload_cb (void *cls,
     return;
   }
   tus->truth = t;
-
   TALER_TESTING_interpreter_next (tus->is);
 }
 
@@ -188,42 +182,15 @@ truth_upload_run (void *cls,
       TALER_TESTING_interpreter_fail (tus->is);
       return;
     }
-    const unsigned int *number;
-
     if (GNUNET_OK !=
-        ANASTASIS_TESTING_get_trait_truth_number (ref,
-                                                  0,
-                                                  &number))
+        ANASTASIS_TESTING_get_trait_salt (ref,
+                                          0,
+                                          &salt))
     {
       GNUNET_break (0);
       TALER_TESTING_interpreter_fail (tus->is);
       return;
     }
-    tus->truth_number = *number + 1;
-  }
-  else
-  {
-    tus->truth_number = 0;
-  }
-
-  ref = TALER_TESTING_interpreter_lookup_command
-          (is,
-          tus->label);
-  if (NULL == ref)
-  {
-    GNUNET_break (0);
-    TALER_TESTING_interpreter_fail (tus->is);
-    return;
-  }
-
-  if (GNUNET_OK !=
-      ANASTASIS_TESTING_get_trait_salt (ref,
-                                        0,
-                                        &salt))
-  {
-    GNUNET_break (0);
-    TALER_TESTING_interpreter_fail (tus->is);
-    return;
   }
 
   tus->tuo = ANASTASIS_truth_upload (is->ctx,
@@ -271,8 +238,6 @@ truth_upload_cleanup (void *cls,
     ANASTASIS_truth_upload_cancel (tus->tuo);
     tus->tuo = NULL;
   }
-  GNUNET_free_non_null ((void *) tus->truth);
-  GNUNET_free_non_null ((void *) tus->truth_data);
   GNUNET_free (tus);
 }
 
@@ -294,10 +259,8 @@ truth_upload_traits (void *cls,
 {
   struct TruthUploadState *tus = cls;
   struct TALER_TESTING_Trait traits[] = {
-    ANASTASIS_TESTING_make_trait_truth (tus->truth_number,
+    ANASTASIS_TESTING_make_trait_truth (0,
                                         tus->truth),
-    ANASTASIS_TESTING_make_trait_truth_number (0,
-                                               &tus->truth_number),
     TALER_TESTING_trait_end ()
   };
 
diff --git a/src/lib/testing_api_trait_uuid.c b/src/lib/testing_trait_policy.c
similarity index 56%
copy from src/lib/testing_api_trait_uuid.c
copy to src/lib/testing_trait_policy.c
index 4a61eeb..45e773c 100644
--- a/src/lib/testing_api_trait_uuid.c
+++ b/src/lib/testing_trait_policy.c
@@ -17,8 +17,8 @@
   <http://www.gnu.org/licenses/>
 */
 /**
- * @file lib/testing_api_trait_uuid.c
- * @brief traits to offer a hash
+ * @file lib/testing_trait_policy.c
+ * @brief traits to offer a policy
  * @author Christian Grothoff
  * @author Dominik Meister
  * @author Dennis Neufeld
@@ -26,49 +26,48 @@
 #include "platform.h"
 #include "anastasis_testing_lib.h"
 
-#define ANASTASIS_TESTING_TRAIT_UUID "anastasis-uuid"
+#define ANASTASIS_TESTING_TRAIT_POLICY "anastasis-policy"
 
 
 /**
- * Obtain an uuid from @a cmd.
+ * Obtain a policy from @a cmd.
  *
- * @param cmd command to extract the number from.
- * @param index the number's index number.
- * @param u[out] set to the number coming from @a cmd.
+ * @param cmd command to extract the policy from.
+ * @param index the index of the policy
+ * @param t[out] set to the policy coming from @a cmd.
  * @return #GNUNET_OK on success.
  */
 int
-ANASTASIS_TESTING_get_trait_uuid
-  (const struct TALER_TESTING_Command *cmd,
-  unsigned int index,
-  const uuid_t **u)
+ANASTASIS_TESTING_get_trait_policy (const struct TALER_TESTING_Command *cmd,
+                                    unsigned int index,
+                                    const struct ANASTASIS_Policy **p)
 {
   return cmd->traits (cmd->cls,
-                      (const void **) u,
-                      ANASTASIS_TESTING_TRAIT_UUID,
+                      (const void **) p,
+                      ANASTASIS_TESTING_TRAIT_POLICY,
                       index);
 }
 
 
 /**
- * Offer an uuid.
+ * Offer a policy.
  *
- * @param index the number's index number.
- * @param u the uuid to offer.
+ * @param index the policy's index number.
+ * @param t the policy to offer.
  * @return #GNUNET_OK on success.
  */
 struct TALER_TESTING_Trait
-ANASTASIS_TESTING_make_trait_uuid
+ANASTASIS_TESTING_make_trait_policy
   (unsigned int index,
-  const uuid_t *u)
+  const struct ANASTASIS_Policy *p)
 {
   struct TALER_TESTING_Trait ret = {
     .index = index,
-    .trait_name = ANASTASIS_TESTING_TRAIT_UUID,
-    .ptr = (const void *) u
+    .trait_name = ANASTASIS_TESTING_TRAIT_POLICY,
+    .ptr = (const void *) p
   };
   return ret;
 }
 
 
-/* end of testing_api_trait_uuid.c */
+/* end of testing_trait_policy.c */
diff --git a/src/lib/testing_trait_truth.c b/src/lib/testing_trait_truth.c
index 2ed45a2..51696e1 100644
--- a/src/lib/testing_trait_truth.c
+++ b/src/lib/testing_trait_truth.c
@@ -17,8 +17,8 @@
   <http://www.gnu.org/licenses/>
 */
 /**
- * @file lib/testing_api_trait_uuid.c
- * @brief traits to offer a hash
+ * @file lib/testing_trait_truth.c
+ * @brief traits to offer a truth
  * @author Christian Grothoff
  * @author Dominik Meister
  * @author Dennis Neufeld
@@ -27,48 +27,6 @@
 #include "anastasis_testing_lib.h"
 
 #define ANASTASIS_TESTING_TRAIT_TRUTH "anastasis-truth"
-#define ANASTASIS_TESTING_TRAIT_TRUTH_NUMBER "anastasis-truth-number"
-
-/**
- * Obtain numbers of truth traits from @a cmd.
- *
- * @param cmd command to extract the number from.
- * @param index the index of the number
- * @param n[out] set to the number coming from @a cmd.
- * @return #GNUNET_OK on success.
- */
-int
-ANASTASIS_TESTING_get_trait_truth_number (const struct
-                                          TALER_TESTING_Command *cmd,
-                                          unsigned int index,
-                                          const unsigned int **n)
-{
-  return cmd->traits (cmd->cls,
-                      (const void **) n,
-                      ANASTASIS_TESTING_TRAIT_TRUTH_NUMBER,
-                      index);
-}
-
-
-/**
- * Offer the number of truth traits.
- *
- * @param index the number's index number (usually zero).
- * @param n the number to offer.
- * @return #GNUNET_OK on success.
- */
-struct TALER_TESTING_Trait
-ANASTASIS_TESTING_make_trait_truth_number
-  (unsigned int index,
-  const unsigned int *n)
-{
-  struct TALER_TESTING_Trait ret = {
-    .index = index,
-    .trait_name = ANASTASIS_TESTING_TRAIT_TRUTH_NUMBER,
-    .ptr = (const void *) n
-  };
-  return ret;
-}
 
 
 /**
@@ -92,7 +50,7 @@ ANASTASIS_TESTING_get_trait_truth (const struct 
TALER_TESTING_Command *cmd,
 
 
 /**
- * Offer an truth.
+ * Offer a truth.
  *
  * @param index the truth's index number.
  * @param t the truth to offer.
diff --git a/src/util/anastasis_crypto.c b/src/util/anastasis_crypto.c
index fab1c96..c44243e 100644
--- a/src/util/anastasis_crypto.c
+++ b/src/util/anastasis_crypto.c
@@ -323,21 +323,25 @@ ANASTASIS_CRYPTO_user_identifier_derive (
   struct ANASTASIS_CRYPTO_UserIdentifierP *id)
 {
   char *json_enc;
+  const char *salt_str;
+
+  GNUNET_assert (NULL != id_data);
+  GNUNET_assert (NULL != server_salt);
+
+  salt_str = GNUNET_STRINGS_data_to_string_alloc (server_salt,
+                                                  sizeof (*server_salt));
   json_enc = json_dumps (id_data,
-                         JSON_SORT_KEYS);
+                         JSON_COMPACT | JSON_SORT_KEYS);
   GNUNET_assert (NULL != json_enc);
-  GNUNET_assert (0 ==
-                 gcry_kdf_derive (json_enc,
-                                  strlen (json_enc),
-                                  GCRY_KDF_SCRYPT,
-                                  1, // subalgo
-                                  server_salt,
-                                  sizeof (*server_salt),
-                                  SCRYPT_ITERATION, // iterations
-                                  sizeof (struct
-                                          ANASTASIS_CRYPTO_UserIdentifierP),
-                                  id));
+  GNUNET_CRYPTO_pow_hash (salt_str,
+                          json_enc,
+                          strlen (json_enc),
+                          &id->hash);
+
   free (json_enc);
+  json_decref (id_data);
+  GNUNET_free (salt_str);
+  GNUNET_assert (NULL != id);
 }
 
 
diff --git a/src/util/test_anastasis_crypto.c b/src/util/test_anastasis_crypto.c
index 6a43fdf..9171119 100644
--- a/src/util/test_anastasis_crypto.c
+++ b/src/util/test_anastasis_crypto.c
@@ -315,9 +315,9 @@ test_public_key_derive ()
 
   json_t *id_data = json_object ();
 
-  GNUNET_CRYPTO_hash_from_string2 ("Server Salt",
-                                   strlen ("Server Salt"),
-                                   &server_salt.salt);
+  GNUNET_CRYPTO_hash ("Server Salt",
+                      strlen ("Server Salt"),
+                      &server_salt.salt);
 
   json_object_set_new (id_data, "arg1", json_string ("ID_DATA"));
   ANASTASIS_CRYPTO_user_identifier_derive (id_data,

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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