gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 03/04: worked on cli assembler command 'truth'


From: gnunet
Subject: [taler-anastasis] 03/04: worked on cli assembler command 'truth'
Date: Tue, 16 Jun 2020 15:25:47 +0200

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

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

commit a74c1a53df36b32eb92ba02534e192a218c36733
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Jun 16 11:25:57 2020 +0000

    worked on cli assembler command 'truth'
---
 src/backend/anastasis-httpd.c           |  19 ++++++
 src/backend/anastasis-httpd.h           |   7 +++
 src/backend/anastasis-httpd_config.c    |   4 +-
 src/cli/anastasis-cli-assembler.c       | 101 ++++++++++++++++++++++++++++++--
 src/cli/anastasis-cli-splitter.c        |  16 ++---
 src/include/anastasis.h                 |   2 +
 src/include/anastasis_service.h         |  10 +++-
 src/lib/anastasis.c                     |   5 ++
 src/lib/anastasis_api_config.c          |   5 +-
 src/lib/anastasis_api_keyshare_lookup.c |   2 +
 10 files changed, 157 insertions(+), 14 deletions(-)

diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 7b1db5a..437f330 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -55,6 +55,13 @@ char *AH_supported_methods;
  */
 struct TALER_Amount AH_annual_fee;
 
+/**
+ * Cost of authentication by question
+ * FIXME: Implement a more elegant way to
+ * list costs of authentication methods
+ */
+struct TALER_Amount AH_question_cost;
+
 /**
  * Our Taler backend to process payments.
  */
@@ -578,6 +585,18 @@ run (void *cls,
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
+  if (GNUNET_OK !=
+      TALER_config_get_amount (config,
+                               "anastasis",
+                               "QUESTION_COST",
+                               &AH_question_cost))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+                               "anastasis",
+                               "QUESTION_COST");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (config,
                                              "taler",
diff --git a/src/backend/anastasis-httpd.h b/src/backend/anastasis-httpd.h
index ff14dbf..478de60 100644
--- a/src/backend/anastasis-httpd.h
+++ b/src/backend/anastasis-httpd.h
@@ -146,6 +146,13 @@ extern unsigned long long AH_upload_limit_mb;
  */
 extern struct TALER_Amount AH_annual_fee;
 
+/**
+ * Cost of authentication by question
+ * FIXME: Implement a more elegant way to
+ * list costs of authentication methods
+ */
+extern struct TALER_Amount AH_question_cost;
+
 /**
  * Our Taler backend to process payments.
  */
diff --git a/src/backend/anastasis-httpd_config.c 
b/src/backend/anastasis-httpd_config.c
index d5b0840..1fcb8b8 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -44,13 +44,15 @@ AH_handler_config (struct TMH_RequestHandler *rh,
 {
   return TALER_MHD_reply_json_pack (connection,
                                     MHD_HTTP_OK,
-                                    "{s:s, s:I, s:o, s:s}",
+                                    "{s:s, s:I, s:o, s:o, s:s}",
                                     "methods",
                                     (char *) AH_supported_methods,
                                     "storage_limit_in_megabytes",
                                     (json_int_t) AH_upload_limit_mb,
                                     "annual_fee",
                                     TALER_JSON_from_amount (&AH_annual_fee),
+                                    "question_cost",
+                                    TALER_JSON_from_amount 
(&AH_question_cost), // FIXME: implement a more elegant solution
                                     "version",
                                     "0.0");
 }
diff --git a/src/cli/anastasis-cli-assembler.c 
b/src/cli/anastasis-cli-assembler.c
index 62e159a..72df7e1 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -72,6 +72,39 @@ static unsigned int challenges_length = 0;
 static void
 start_read_keyboard (void);
 
+/**
+ * State for a "get config" CMD.
+ */
+struct ConfigState
+{
+  /**
+   * Expected status code.
+   */
+  unsigned int http_status;
+
+  /**
+   * The /config GET operation handle.
+   */
+  struct ANASTASIS_ConfigOperation *co;
+
+  /**
+   * Reference to a ServerInfo.
+   */
+  struct ServerInfo *server;
+
+  /**
+   * Cost.
+   */
+  struct TALER_Amount cost;
+
+  /**
+   * Supported methods.
+   */
+  char *methods;
+
+  // FIXME add configs
+};
+
 
 /**
  * State for a "recover secret" CMD.
@@ -175,11 +208,26 @@ read_keyboard_command (void *cls)
     return;
   }
 
-  if (0 == strncmp ("truth",
-                    buffer,
-                    strlen ("truth")))
+  if ((0 == strncmp ("truth",
+                     buffer,
+                     strlen ("truth")))
+      && (characters == strlen ("truth")))
   {
     // FIXME "truth" logic here
+    for (unsigned int i = 0; i < challenges_length; i++)
+    {
+      char solved_state = '-';
+      if (challenges[i].solved == 1)
+        solved_state = '+';
+      printf ("truth#%u(%c): %s %s ",
+              i,
+              solved_state,
+              TALER_amount_to_string (challenges[i].cost),
+              challenges[i].method);
+      if (0 == strcmp (challenges[i].method, "question"))
+        printf ("\"%s\"", challenges[i].instructions);
+      printf ("\n");
+    }
     start_read_keyboard ();
     GNUNET_free (buffer);
     buffer = NULL;
@@ -255,6 +303,39 @@ start_read_keyboard ()
 }
 
 
+/**
+ * Function called with the results of a #ANASTASIS_get_config().
+ *
+ * @param cls closure
+ * @param http_status HTTP status of the request
+ * @param methods supported methods by this provider
+ * @param annual_fee Annual fee of this service
+ * @param question_cost Cost for authentication by question
+ */
+static void
+config_cb (void *cls,
+           unsigned int http_status,
+           const char *methods,
+           const struct TALER_Amount *annual_fee,
+           const struct TALER_Amount *question_cost)
+{
+  struct ConfigState *cs = cls;
+
+  cs->co = NULL;
+  if (http_status != cs->http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u in %s:%u\n",
+                http_status,
+                __FILE__,
+                __LINE__);
+    return;
+  }
+
+  cs->cost = *question_cost;
+}
+
+
 /**
  * Defines a Challenge Callback which is initially sent with the get 
challenge. It gives back the previously
  * defined Challenge Information and a Status Code, like "payment missing".
@@ -268,8 +349,20 @@ challenge_cb (void *cls,
               enum TALER_ErrorCode ec)
 {
   // FIXME handle ec
-
   struct ANASTASIS_ChallengeInformation *ci = cls;
+  struct ConfigState *cs = GNUNET_new (struct ConfigState);
+
+  cs->http_status = MHD_HTTP_OK;
+  cs->co = ANASTASIS_get_config (ctx,
+                                 ci->url,
+                                 config_cb,
+                                 cs);
+  if (NULL == cs->co)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  ci->cost = &cs->cost;
   GNUNET_array_append (challenges,
                        challenges_length,
                        *ci);
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index 5f12d24..c6ab843 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -550,14 +550,16 @@ truth_upload_cb (void *cls,
  *
  * @param cls closure
  * @param http_status HTTP status of the request
- * @param cost Cost of this service
  * @param methods supported methods by this provider
+ * @param annual_fee Annual fee of this service
+ * @param question_cost Cost for authentication by question
  */
 static void
 config_cb (void *cls,
            unsigned int http_status,
            const char *methods,
-           const struct TALER_Amount *cost)
+           const struct TALER_Amount *annual_fee,
+           const struct TALER_Amount *question_cost)
 {
   struct ConfigState *cs = cls;
   struct ANASTASIS_PaymentDetails *pd = GNUNET_new (struct
@@ -581,7 +583,7 @@ config_cb (void *cls,
     return;
   }
 
-  cs->cost = *cost;
+  cs->cost = *annual_fee;
   cs->methods = GNUNET_malloc (strlen (methods) + 1);
   GNUNET_strlcpy (cs->methods,
                   methods,
@@ -721,7 +723,6 @@ read_keyboard_command (void *cls)
                      strlen ("server")))
       && (characters == strlen ("server")))
   {
-    // FIXME "server" logic here
     if (NULL != servers)
     {
       for (unsigned int i = 0; i < servers_length; i++)
@@ -870,8 +871,7 @@ read_keyboard_command (void *cls)
             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                         "At %s:%d answer is %s\n", __FILE__, __LINE__,
                         tus->secret_answer);
-
-            tus->instructions = "Please answer the question.";
+            tus->instructions = tus->secret_question;
             tus->mime_type = "text/plain";
             struct GNUNET_HashCode truth_data;
             GNUNET_CRYPTO_hash (tus->secret_answer,
@@ -908,7 +908,8 @@ read_keyboard_command (void *cls)
             GNUNET_SCHEDULER_shutdown ();
             return;
           }
-          tus->index = (tu_states_length > 0) ? tu_states_length - 1 : 0;
+          // tus->index = (tu_states_length > 0) ? tu_states_length - 1 : 0;
+          tus->index = tu_states_length;
           tus->tuo = ANASTASIS_truth_upload (ctx,
                                              tus->id_data,
                                              servers[server_num].backend_url,
@@ -1227,6 +1228,7 @@ shutdown_task (void *cls)
     {
       GNUNET_free (tu_states[i].truth);
       GNUNET_free (tu_states[i].method);
+      GNUNET_free (tu_states[i].instructions);
       GNUNET_free_non_null (tu_states[i].secret_question);
       GNUNET_free_non_null (tu_states[i].secret_answer);
     }
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index bc23c89..be47f6c 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -144,6 +144,8 @@ ANASTASIS_challenge_answer (struct GNUNET_CURL_Context *ctx,
  * @param method which method is this challenge (E-Mail, Security Question, 
SMS...)
  * @param url can be NULL defines the url or mail address used for the 
challenge
  * @param instructions defines which steps need to be done e.g. ( please look 
for the pin for recovery #1234)
+ * @param cost Cost to solve this challenge
+ * @param solved 1 if solved, else 0
  */
 struct ANASTASIS_ChallengeInformation
 {
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 7b46e8a..0311754 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -252,7 +252,8 @@ typedef void
 (*ANASTASIS_ConfigCallback)(void *cls,
                             unsigned int http_status,
                             const char *methods,
-                            const struct TALER_Amount *cost);
+                            const struct TALER_Amount *annual_fee,
+                            const struct TALER_Amount *question_cost);
 
 
 struct ANASTASIS_ConfigOperation *
@@ -306,6 +307,13 @@ struct ANASTASIS_ConfigOperation
    */
   const char *methods;
 
+  /**
+   * Cost of authentication by question
+   * FIXME: Implement a more elegant way to
+   * list costs of authentication methods
+   */
+  struct TALER_Amount question_cost;
+
   // FIXME add configs
 };
 
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 25b95fb..1533ea9 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -618,11 +618,13 @@ policy_lookup_cb (void *cls,
                    json_unpack (json_array_get (esc_methods, i),
                                 "{s:s,"       /* truth uuid */
                                 " s:s,"       /* provider url */
+                                " s:s,"       /* instructions */
                                 " s:s,"       /* truth key */
                                 " s:s,"       /* truth salt */
                                 " s:s}",       /* escrow method */
                                 "uuid", &uuid,
                                 "url", &cs[i]->url,
+                                "instructions", &cs[i]->instructions,
                                 "truth_key", &truth_key,
                                 "salt", &truth_salt,
                                 "escrow_method", &cs[i]->escrow_method));
@@ -1807,6 +1809,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
             esc_methods,
             json_pack ("{s:s," /* truth uuid */
                        " s:s," /* provider url */
+                       " s:s," /* instructions */
                        " s:o," /* truth key */
                        " s:o," /* truth salt */
                        " s:s}", /* escrow method */
@@ -1814,6 +1817,8 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                        &uuid,
                        "url",
                        policies[k]->truths[l]->url,
+                       "instructions",
+                       policies[k]->truths[l]->instructions,
                        "truth_key", GNUNET_JSON_from_data_auto (
                          &policies[k]->truths[l]->truth_key),
                        "salt", GNUNET_JSON_from_data_auto (
diff --git a/src/lib/anastasis_api_config.c b/src/lib/anastasis_api_config.c
index 9aad899..9f76a93 100644
--- a/src/lib/anastasis_api_config.c
+++ b/src/lib/anastasis_api_config.c
@@ -61,6 +61,7 @@ handle_config_finished (void *cls,
       struct GNUNET_JSON_Specification spec[] = {
         GNUNET_JSON_spec_string ("methods", &co->methods),
         TALER_JSON_spec_amount ("annual_fee", &co->cost),
+        TALER_JSON_spec_amount ("question_cost", &co->question_cost),
         // FIXME add configs
         GNUNET_JSON_spec_end ()
       };
@@ -77,7 +78,8 @@ handle_config_finished (void *cls,
       co->cb (co->cb_cls,
               response_code,
               co->methods,
-              &co->cost
+              &co->cost,
+              &co->question_cost
               // FIXME add configs
               );
       ANASTASIS_config_cancel (co);
@@ -108,6 +110,7 @@ handle_config_finished (void *cls,
     co->cb (co->cb_cls,
             response_code,
             NULL,
+            NULL,
             NULL);
     co->cb = NULL;
   }
diff --git a/src/lib/anastasis_api_keyshare_lookup.c 
b/src/lib/anastasis_api_keyshare_lookup.c
index 8e0dcaf..2dcaf4b 100644
--- a/src/lib/anastasis_api_keyshare_lookup.c
+++ b/src/lib/anastasis_api_keyshare_lookup.c
@@ -282,8 +282,10 @@ ANASTASIS_keyshare_lookup (struct GNUNET_CURL_Context *ctx,
   }
   kslo = GNUNET_new (struct ANASTASIS_KeyShareLookupOperation);
   kslo->ctx = ctx;
+  /** FIXME duplicate? see line 323
   kslo->cb = cb;
   kslo->cb_cls = cb_cls;
+  */
   kslo->truth_key = truth_key;
 
   GNUNET_assert (GNUNET_NO == uuid_is_null (*truth_uuid));

-- 
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]