gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: minimized usage of GNUNET_CRYPT


From: gnunet
Subject: [taler-anastasis] branch master updated: minimized usage of GNUNET_CRYPTO_pow_hash
Date: Fri, 19 Jun 2020 11:07:17 +0200

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

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

The following commit(s) were added to refs/heads/master by this push:
     new d9cb62f  minimized usage of GNUNET_CRYPTO_pow_hash
d9cb62f is described below

commit d9cb62f8001458cb7f3d35f0800a0af3f20f9cab
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Fri Jun 19 09:07:09 2020 +0000

    minimized usage of GNUNET_CRYPTO_pow_hash
---
 src/cli/anastasis-cli-assembler.c  | 44 +++++++++++++++++++++++++++++++++++++-
 src/cli/anastasis-cli-splitter.c   | 27 ++++++++++++++++++++++-
 src/include/anastasis.h            |  4 ++--
 src/lib/anastasis.c                | 18 +++++++---------
 src/lib/test_anastasis_api.conf    |  4 ++--
 src/lib/testing_cmd_truth_upload.c |  7 +++++-
 6 files changed, 87 insertions(+), 17 deletions(-)

diff --git a/src/cli/anastasis-cli-assembler.c 
b/src/cli/anastasis-cli-assembler.c
index 6953f7c..8d1c4d4 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -229,6 +229,18 @@ challenge_answer_cb (void *af_cls,
 }
 
 
+static void
+challenge_try_cb (void *af_cls,
+                  enum TALER_ErrorCode ec)
+{
+  /**
+   * FIXME: Implement mechanism to be able to try if payment is needed
+  struct ChallengeState *cs = af_cls;
+  */
+  return;
+}
+
+
 /**
  * @brief Read the character from stdin and activate the selected task
  *
@@ -411,7 +423,37 @@ read_keyboard_command (void *cls)
                     buffer,
                     strlen ("try")))
   {
-    // FIXME "try" logic here
+    struct ChallengeState *cs = GNUNET_new (struct ChallengeState);
+    char *token_start = &buffer[strlen ("try ")];
+    char *token = strtok (token_start, " ");
+
+    unsigned int truth_index;
+    if (0 != strncmp ("truth#",
+                      token,
+                      strlen ("truth#")))
+    {
+      printf ("Wrong argument: %s!\n", token);
+      free (buffer);
+      start_read_keyboard ();
+      return;
+    }
+    truth_index = (int) token[strlen ("truth#")] - 48;
+
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d truth index is %u\n", __FILE__, __LINE__,
+                truth_index);
+
+    cs->http_status = MHD_HTTP_PAYMENT_REQUIRED;
+    cs->answer = "try";
+    cs->answer_size = strlen ("try");
+    cs->challenge_index = truth_index;
+
+    ANASTASIS_challenge_answer (ctx,
+                                challenges[truth_index].challenge,
+                                cs->answer,
+                                cs->answer_size,
+                                &challenge_try_cb,
+                                cs);
     start_read_keyboard ();
     GNUNET_free (buffer);
     buffer = NULL;
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index 0fa7b7e..0a0f4fd 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -148,6 +148,11 @@ struct ServerInfo
    * cost of using the anastasis backend.
    */
   const struct TALER_Amount *backend_cost;
+
+  /**
+   * user identifier derived from user data and backend salt
+   */
+  const struct ANASTASIS_CRYPTO_UserIdentifierP *user_id;
 };
 
 /**
@@ -644,6 +649,26 @@ salt_cb (void *cls,
   ss->server->backend_salt = &ss->salt;
 
   cs->server = ss->server;
+  json_error_t error;
+  const json_t *id_data;
+  if (NULL == (id_data = json_load_file (import_id,
+                                         JSON_DECODE_ANY,
+                                         &error)))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to parse `%s': %s at %d:%d (%d)\n",
+                import_id,
+                error.text,
+                error.line,
+                error.column,
+                error.position);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  cs->server->user_id = GNUNET_new (struct ANASTASIS_CRYPTO_UserIdentifierP);
+  ANASTASIS_CRYPTO_user_identifier_derive (id_data,
+                                           salt,
+                                           cs->server->user_id);
   cs->http_status = MHD_HTTP_OK;
   cs->co = ANASTASIS_get_config (ctx,
                                  cs->server->backend_url,
@@ -904,7 +929,7 @@ read_keyboard_command (void *cls)
           }
           tus->index = tu_states_length;
           tus->tuo = ANASTASIS_truth_upload (ctx,
-                                             tus->id_data,
+                                             servers[server_num].user_id,
                                              servers[server_num].backend_url,
                                              tus->method,
                                              tus->instructions,
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index f4f6038..5ef5954 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -300,7 +300,7 @@ typedef void
 * Uploads a truth object onto a escrow provider
 *
 * @param ctx the CURL context used to connect to the backend
-* @param id_data user provided authentication for generation of the truth 
encryption
+* @param user_id user identifier derived from user data and backend salt
 * @param method defines the method of the challenge (secure question, sms, 
email)
 * @param instructions depending on method! usually only for security 
question/answer!
 * @param mime_type format of the challenge
@@ -314,7 +314,7 @@ typedef void
 */
 struct ANASTASIS_TruthUpload *
 ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
-                        const json_t *id_data,
+                        const struct ANASTASIS_CRYPTO_UserIdentifierP *user_id,
                         const char *provider_url,
                         const char *method,
                         const char *instructions,
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 3ee561c..ca23698 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -951,8 +951,9 @@ struct ANASTASIS_TruthUpload
    */
   struct ANASTASIS_TruthStoreOperation *tso;
 
-  // FIXME not sure how to do payment
+  // FIXME: Implement payment for truth upload/keyshare download
   int payment_requested;
+
   const char *paid_order_id;
 };
 
@@ -1037,7 +1038,7 @@ truth_store_callback (void *cls,
 * Uploads a truth object onto a escrow provider
 *
 * @param ctx the CURL context used to connect to the backend
-* @param id_data user provided authentication for generation of the truth 
encryption
+* @param user_id user identifier derived from user data and backend salt
 * @param method defines the method of the challenge (secure question, sms, 
email)
 * @param instructions depending on method! usually only for security 
question/answer!
 * @param mime_type format of the challenge
@@ -1051,7 +1052,7 @@ truth_store_callback (void *cls,
 */
 struct ANASTASIS_TruthUpload *
 ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
-                        const json_t *id_data,
+                        const struct ANASTASIS_CRYPTO_UserIdentifierP *user_id,
                         const char *provider_url,
                         const char *method,
                         const char *instructions,
@@ -1073,6 +1074,9 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
   size_t encrypted_truth_size;
   json_t *truth;
 
+  GNUNET_assert (NULL != user_id);
+  GNUNET_assert (NULL != salt);
+
   tu = GNUNET_new (struct ANASTASIS_TruthUpload);
   t = GNUNET_new (struct ANASTASIS_Truth);
   tu->tc_cls = tc_cls;
@@ -1080,6 +1084,7 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
   tu->tpc = tpc;
   tu->tc = tc;
   tu->ctx = ctx;
+  tu->id = *user_id;
   t->url = provider_url;
   t->method = method;
   t->instructions = instructions;
@@ -1092,8 +1097,6 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
               "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),
@@ -1103,10 +1106,6 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
               "At %s:%d keyshare is %s-%llu b\n", __FILE__, __LINE__,
               TALER_B2S (&t->key_share),
               (unsigned long long) sizeof (t->key_share));
-  // FIXME: The useridentifier shall be derived once, not for every upload!
-  ANASTASIS_CRYPTO_user_identifier_derive (id_data,
-                                           salt,
-                                           &tu->id);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "At %s:%d user identifier is %s-%llu b\n", __FILE__, __LINE__,
               TALER_B2S (&tu->id),
@@ -1127,7 +1126,6 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
               TALER_B2S (&t->truth_key),
               (unsigned long long) sizeof (t->truth_key));
 
-
   struct GNUNET_HashCode hashed_answer;
   GNUNET_CRYPTO_hash (truth_data,
                       truth_data_size,
diff --git a/src/lib/test_anastasis_api.conf b/src/lib/test_anastasis_api.conf
index 32935e7..560b005 100644
--- a/src/lib/test_anastasis_api.conf
+++ b/src/lib/test_anastasis_api.conf
@@ -37,8 +37,8 @@ DB = postgres
 PAYMENT_BACKEND_URL = http://localhost:8080/
 
 # Annual fee we charge.
-#ANNUAL_FEE = EUR:4.99
-ANNUAL_FEE = EUR:0
+ANNUAL_FEE = EUR:4.99
+#ANNUAL_FEE = EUR:0
 
 # Cost of authentication by question
 QUESTION_COST = EUR:0
diff --git a/src/lib/testing_cmd_truth_upload.c 
b/src/lib/testing_cmd_truth_upload.c
index 519fcab..6769e3b 100644
--- a/src/lib/testing_cmd_truth_upload.c
+++ b/src/lib/testing_cmd_truth_upload.c
@@ -193,8 +193,13 @@ truth_upload_run (void *cls,
     }
   }
 
+  struct ANASTASIS_CRYPTO_UserIdentifierP user_id;
+  ANASTASIS_CRYPTO_user_identifier_derive (tus->id_data,
+                                           salt,
+                                           &user_id);
+
   tus->tuo = ANASTASIS_truth_upload (is->ctx,
-                                     tus->id_data,
+                                     &user_id,
                                      tus->anastasis_url,
                                      tus->method,
                                      tus->instructions,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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