gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (f6eeec7 -> 445ff4d)


From: gnunet
Subject: [taler-anastasis] branch master updated (f6eeec7 -> 445ff4d)
Date: Wed, 20 May 2020 23:51:47 +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 f6eeec7  work on assembler
     new 096d7fa  fixed config api
     new 6a8d070  worked on splitter
     new 445ff4d  worked on splitter...

The 3 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:
 .gitignore                           |   4 +
 src/backend/anastasis-httpd_config.c |   2 +-
 src/backend/anastasis-httpd_truth.c  |   4 +-
 src/cli/anastasis-cli-assembler.c    |   2 +-
 src/cli/anastasis-cli-splitter.c     | 723 ++++++++++++++++++++++++++++-------
 src/lib/anastasis.c                  |   3 +-
 src/lib/anastasis_api_config.c       |   3 +-
 src/lib/test_anastasis.c             |   6 +-
 src/lib/test_anastasis_api.c         |   2 +-
 src/lib/test_anastasis_api.conf      |   2 +-
 10 files changed, 608 insertions(+), 143 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5c131a5..0364a3f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -96,3 +96,7 @@ src/cli/anastasis-assembler
 src/cli/.deps/
 src/cli/.deps/anastasis-cli-splitter.Po
 src/cli/.deps/anastasis-cli-assembler.Po
+src/cli/.libs/
+src/cli/.libs/anastasis-assembler
+src/cli/.libs/anastasis-splitter
+
diff --git a/src/backend/anastasis-httpd_config.c 
b/src/backend/anastasis-httpd_config.c
index a33ef56..d5b0840 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -46,7 +46,7 @@ AH_handler_config (struct TMH_RequestHandler *rh,
                                     MHD_HTTP_OK,
                                     "{s:s, s:I, s:o, s:s}",
                                     "methods",
-                                    AH_supported_methods,
+                                    (char *) AH_supported_methods,
                                     "storage_limit_in_megabytes",
                                     (json_int_t) AH_upload_limit_mb,
                                     "annual_fee",
diff --git a/src/backend/anastasis-httpd_truth.c 
b/src/backend/anastasis-httpd_truth.c
index 350d621..e4e48fa 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -137,11 +137,11 @@ AH_handler_truth_get (struct MHD_Connection *connection,
   }
   {
     // validate challenge response
-    GNUNET_assert (strlen (method) == strlen ("Secure-Question"));
+    GNUNET_assert (strlen (method) == strlen ("question"));
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Method from db: %s\n",
                 method);
-    if (strncmp (method, "Secure-Question", strlen ("Secure-Question")) == 0)
+    if (strncmp (method, "question", strlen ("question")) == 0)
     {
       GNUNET_CRYPTO_hash_from_string (challenge_response_s,
                                       &challenge_response);
diff --git a/src/cli/anastasis-cli-assembler.c 
b/src/cli/anastasis-cli-assembler.c
index 95bcc12..c3b4425 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -425,7 +425,7 @@ run (void *cls,
   rc = GNUNET_CURL_gnunet_rc_create (ctx);
   // FIXME
   json_error_t error;
-  rss->id_data = json_load_file (import_id, JSON_DECODE_ANY,&error);
+  rss->id_data = json_load_file (import_id, JSON_DECODE_ANY, &error);
   rss->version = import_recovery_version;
   rss->anastasis_url = import_recovery_document;
   rss->http_status_salt = MHD_HTTP_OK;
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index 39301d3..38b663f 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -33,39 +33,9 @@
 struct TruthUploadState
 {
   /**
-   * URL of the anastasis backend.
-   */
-  char *backend_url;
-
-  /**
-   * label of the anastasis backend.
+   * Index of the truth.
    */
-  const char *backend_label;
-
-  /**
-   * supported methods of the anastasis backend.
-   */
-  const char *backend_methods;
-
-  /**
-   * server salt of the anastasis backend.
-   */
-  const struct ANASTASIS_CRYPTO_SaltP *backend_salt;
-
-  /**
-   * insurance of the anastasis backend.
-   */
-  const struct TALER_Amount *backend_insurance;
-
-  /**
-   * cost of using the anastasis backend.
-   */
-  const struct TALER_Amount *backend_cost;
-
-  /**
-   * Label of this command.
-   */
-  const char *label;
+  unsigned int index;
 
   /**
    * The ID data to generate user identifier
@@ -75,38 +45,38 @@ struct TruthUploadState
   /**
    * The escrow method
    */
-  const char *method;
+  char *method;
 
   /**
    * A secret question
    */
-  const char *secret_question;
+  char *secret_question;
 
   /**
    * Answer to secret question
    */
-  const char *secret_answer;
+  char *secret_answer;
 
   /**
    * Phonenumber for method SMS
    */
-  const char *phone;
+  char *phone;
 
   /**
    * E-Mail address
    */
-  const char *mail;
+  char *mail;
 
   /**
    * Instructions to be returned to client/user
    * (e.g. "Look at your smartphone. SMS was sent to you")
    */
-  const char *instructions;
+  char *instructions;
 
   /**
    * Mime type of truth_data (eg. jpeg, string etc.)
    */
-  const char *mime_type;
+  char *mime_type;
 
   /**
    * The truth_data (e.g. hash of answer to a secure question)
@@ -144,6 +114,42 @@ struct TruthUploadState
   const struct ANASTASIS_Truth *truth;
 };
 
+/**
+ * Server information
+ */
+struct ServerInfo
+{
+  /**
+   * URL of the anastasis backend.
+   */
+  char *backend_url;
+
+  /**
+   * label of the anastasis backend.
+   */
+  const char *backend_label;
+
+  /**
+   * supported methods of the anastasis backend.
+   */
+  const char *backend_methods;
+
+  /**
+   * server salt of the anastasis backend.
+   */
+  const struct ANASTASIS_CRYPTO_SaltP *backend_salt;
+
+  /**
+   * insurance of the anastasis backend.
+   */
+  const struct TALER_Amount *backend_insurance;
+
+  /**
+   * cost of using the anastasis backend.
+   */
+  const struct TALER_Amount *backend_cost;
+};
+
 /**
  * State for a "salt" CMD.
  */
@@ -165,9 +171,9 @@ struct SaltState
   struct ANASTASIS_CRYPTO_SaltP salt;
 
   /**
-   * Reference to a TruthUploadState.
+   * Reference to a ServerInfo.
    */
-  struct TruthUploadState *tus;
+  struct ServerInfo *server;
 };
 
 /**
@@ -186,9 +192,9 @@ struct ConfigState
   struct ANASTASIS_ConfigOperation *co;
 
   /**
-   * Reference to a TruthUploadState.
+   * Reference to a ServerInfo.
    */
-  struct TruthUploadState *tus;
+  struct ServerInfo *server;
 
   /**
    * Cost.
@@ -198,15 +204,93 @@ struct ConfigState
   /**
    * Supported methods.
    */
-  const char *methods;
+  char *methods;
 
   // FIXME add configs
 };
 
+/**
+ * State for a "policy create" CMD.
+ */
+struct PolicyCreateState
+{
+  /**
+   * Array of References to TruthUploadStates.
+   */
+  struct TruthUploadState **tu_states;
+
+  /**
+   * Lengths of truths.
+   */
+  unsigned int tu_states_len;
+
+  /**
+   * Policy object
+   */
+  const struct ANASTASIS_Policy *policy;
+};
+
+/**
+ * State for a "secret share" CMD.
+ */
+struct SecretShareState
+{
+  /**
+   * Data to derive user identifier from.
+   */
+  const json_t *id_data;
+
+  /**
+   * The core secret to backup/recover.
+   */
+  const void *core_secret;
+
+  /**
+   * Size of core_secret.
+   */
+  size_t core_secret_size;
+
+  /**
+   * URL of the anastasis backend.
+   */
+  const char *anastasis_url;
+
+  /**
+   * Expected status code.
+   */
+  unsigned int http_status;
+
+  /**
+   * The /truth GET operation handle.
+   */
+  struct ANASTASIS_SecretShare *sso;
+
+  /**
+   * closure for the payment callback
+   */
+  void *spc_cls;
+
+  /**
+   * closure for the result callback
+   */
+  void *src_cls;
+
+  /**
+   * Payment order ID we got back, if any. Otherwise NULL.
+   */
+  const char *payment_order_id;
+
+  /**
+   * Details of a past payment
+   */
+  struct ANASTASIS_PaymentDetails *pd;
+};
+
+
 /**
  * Global option '--me' to import json containing details of user.
  */
-static int import_id;
+static char *import_id;
 
 /**
  * Global option '--import' to import json containing recovery document.
@@ -238,6 +322,200 @@ static struct TruthUploadState *tu_states;
  */
 static unsigned int tu_states_length = 0;
 
+/**
+ * Information about the servers.
+ */
+static struct ServerInfo *servers;
+
+/**
+ * Amount of servers.
+ */
+static unsigned int servers_length = 0;
+
+/**
+ * State for a "policy create" CMD.
+ */
+static struct PolicyCreateState *pc_states;
+
+/**
+ * Amount of policy create states.
+ */
+static unsigned int pc_states_length = 0;
+
+
+static void
+start_read_keyboard (void);
+
+
+/**
+ * Function called for payment routine.
+ *
+ * @param cls closure
+ * @param taler_pay_url url for the payment (taler://pay/Foo)
+ * @param ec status of the request
+ */
+static void
+secret_share_payment_cb (void *cls,
+                         const char *taler_pay_url,
+                         enum TALER_ErrorCode ec)
+{
+  const char *m;
+  struct SecretShareState *sss = cls;
+  sss->sso = NULL;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "At %s:%d we are in SPC\n",
+              __FILE__, __LINE__);
+  if (sss->http_status != MHD_HTTP_PAYMENT_REQUIRED)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u/%d in %s:%u\n",
+                sss->http_status,
+                (int) ec,
+                __FILE__,
+                __LINE__);
+    GNUNET_break (0);
+    return;
+  }
+
+  if (0 != strncmp (taler_pay_url,
+                    "taler://pay/http",
+                    strlen ("taler://pay/http")))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Did not find `%s' in `%s'\n",
+                "/-/-/",
+                taler_pay_url);
+    GNUNET_break (0);
+    return;
+  }
+  m = strstr (taler_pay_url, "/-/-/");
+  if (NULL == m)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Did not find `%s' in `%s'\n",
+                "/-/-/",
+                taler_pay_url);
+    /* NOTE: The above is a simplifying assumption for the
+        test-logic, hitting this code merely means that
+        the assumptions for the test (i.e. no instance) are
+        not satisfied, it is not inherently the case that
+        the above token must appear in the payment request!
+
+        So if you hit this, you might just want to modify
+        the code here to handle this better! */return;
+  }
+  sss->payment_order_id = GNUNET_strdup (&m[strlen ("/-/-/")]);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "At %s:%d Order ID from Anastasis service is %s\n",
+              __FILE__, __LINE__,
+              sss->payment_order_id);
+
+  keyboard_task = NULL;
+  start_read_keyboard ();
+}
+
+
+/**
+ * Function called with the results of a #secret_share().
+ *
+ * @param cls closure
+ * @param @param current_etag sends back the etag of the upload (used to 
prevent redundant uploads)
+ * @param ec status code of the request
+ * @param http_status http status code
+ */
+static void
+secret_share_result_cb (void *cls,
+                        const struct GNUNET_HashCode *current_etag,
+                        const enum TALER_ErrorCode ec,
+                        unsigned int http_status)
+{
+  struct SecretShareState *sss = cls;
+  sss->sso = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "At %s:%d we are in SRC\n",
+              __FILE__, __LINE__);
+  if (NULL != sss)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d etag is %s-%llu b\n", __FILE__, __LINE__,
+                TALER_B2S (&current_etag),
+                (unsigned long long) sizeof (struct GNUNET_HashCode));
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d error code is %d\n", __FILE__, __LINE__,
+                ec);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d http status is %u\n", __FILE__, __LINE__,
+                http_status);
+
+    if (http_status != sss->http_status)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Unexpected response code %u/%d in %s:%u\n",
+                  http_status,
+                  (int) ec,
+                  __FILE__,
+                  __LINE__);
+      GNUNET_break (0);
+      return;
+    }
+    keyboard_task = NULL;
+    start_read_keyboard ();
+    return;
+  }
+  GNUNET_break (0);
+  return;
+}
+
+
+/**
+ * Initiates a callback for the payment of the truth upload
+ *
+ * @param cls closure
+ * @param taler_pay_url payment link for the transaction (taler://pay/Foo)
+ * @param ec status code of the request
+ */
+static void
+truth_payment_cb (void *cls,
+                  const char *taler_pay_url,
+                  enum TALER_ErrorCode ec)
+{
+  struct TruthUploadState *tus = cls;
+  tus->tuo = NULL;
+  // FIXME: Payment handling
+  keyboard_task = NULL;
+  start_read_keyboard ();
+  return;
+}
+
+
+/**
+* Upload information
+* caller MUST free 't' using ANASTASIS_truth_free()
+*
+* @param cls closure for callback
+* @param t Truth object (contains provider url and uuid)
+* @param t_size size of t
+*/
+static void
+truth_upload_cb (void *cls,
+                 struct ANASTASIS_Truth *t)
+{
+  struct TruthUploadState *tus = cls;
+  tus->tuo = NULL;
+
+  if (NULL == t)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  tus->truth = t;
+  keyboard_task = NULL;
+  start_read_keyboard ();
+  return;
+
+}
+
 
 /**
  * Function called with the results of a #ANASTASIS_get_config().
@@ -256,6 +534,9 @@ config_cb (void *cls,
   struct ConfigState *cs = cls;
 
   cs->co = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d url is %s\n", __FILE__, __LINE__,
+              cs->server->backend_url);
   if (http_status != cs->http_status)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -264,7 +545,9 @@ config_cb (void *cls,
                 __FILE__,
                 __LINE__);
     printf ("Server #%u is not available!\n",
-            tu_states_length);
+            servers_length);
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
   if (NULL == cost)
@@ -284,17 +567,22 @@ config_cb (void *cls,
     return;
   }
   cs->cost = *cost;
-  cs->methods = methods;
+  cs->methods = GNUNET_malloc (strlen (methods) + 1);
+  GNUNET_strlcpy (cs->methods,
+                  methods,
+                  strlen (methods) + 1);
   printf ("Server #%u is available\n",
-          tu_states_length);
+          servers_length);
 
-  cs->tus->backend_methods = cs->methods;
-  cs->tus->backend_cost = &cs->cost;
+  cs->server->backend_methods = cs->methods;
+  cs->server->backend_cost = &cs->cost;
   // FIXME add config max insurance amount
 
-  GNUNET_array_append (tu_states,
-                       tu_states_length,
-                       *cs->tus);
+  GNUNET_array_append (servers,
+                       servers_length,
+                       *cs->server);
+  keyboard_task = NULL;
+  start_read_keyboard ();
 }
 
 
@@ -314,6 +602,9 @@ salt_cb (void *cls,
   struct ConfigState *cs = GNUNET_new (struct ConfigState);
 
   ss->so = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d url is %s\n", __FILE__, __LINE__,
+              ss->server->backend_url);
   if (http_status != ss->http_status)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -322,23 +613,20 @@ salt_cb (void *cls,
                 __FILE__,
                 __LINE__);
     printf ("Server #%u is not available!\n",
-            tu_states_length);
+            servers_length);
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
   ss->salt = *salt;
-  ss->tus->backend_salt = &ss->salt;
+  ss->server->backend_salt = &ss->salt;
 
-  cs->tus = ss->tus;
+  cs->server = ss->server;
   cs->http_status = MHD_HTTP_OK;
   cs->co = ANASTASIS_get_config (ctx,
-                                 cs->tus->backend_url,
+                                 cs->server->backend_url,
                                  config_cb,
                                  cs);
-  // FIXME: DELETE THIS, WHEN ABOVE IS FIXED_
-  // cs->methods = "question"; // FIXME
-  // TALER_string_to_amount ("EUR:3.99",
-  //                        &cs->cost);
-
   if (NULL == cs->co)
   {
     GNUNET_break (0);
@@ -347,10 +635,6 @@ salt_cb (void *cls,
 }
 
 
-static void
-start_read_keyboard (void);
-
-
 /**
  * @brief Read the character from stdin and activate the selected task
  *
@@ -381,6 +665,7 @@ read_keyboard_command (void *cls)
       GNUNET_SCHEDULER_shutdown ();
       free (buffer);
       buffer = NULL;
+      keyboard_task = NULL;
       return;
     case 'o':
       printf (
@@ -407,8 +692,10 @@ read_keyboard_command (void *cls)
                buffer[0]);
       GNUNET_free (buffer);
       buffer = NULL;
+      keyboard_task = NULL;
       break;
     }
+    keyboard_task = NULL;
     start_read_keyboard ();
     return;
   }
@@ -419,26 +706,27 @@ read_keyboard_command (void *cls)
       && (characters == strlen ("server")))
   {
     // FIXME "server" logic here
-    if (NULL != tu_states)
+    if (NULL != servers)
     {
-      for (unsigned int i = 0; i < tu_states_length; i++)
+      for (unsigned int i = 0; i < servers_length; i++)
       {
-        if (NULL != tu_states[i].backend_url)
+        if (NULL != servers[i].backend_url)
           printf ("server#%u: %s %s, insured up to: %s, cost: %s\n",
                   i,
-                  tu_states[i].backend_url,
-                  tu_states[i].backend_methods,
+                  servers[i].backend_url,
+                  servers[i].backend_methods,
                   "test_insurance_amount", // FIXME
-                  TALER_amount_to_string (tu_states[i].backend_cost)
+                  TALER_amount_to_string (servers[i].backend_cost)
                   );
       }
     }
     else
       printf ("Please add a server before!\n");
 
-    start_read_keyboard ();
     free (buffer);
     buffer = NULL;
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
   if (0 == strncmp ("server add",
@@ -446,21 +734,24 @@ read_keyboard_command (void *cls)
                     strlen ("server add")))
   {
     // FIXME "server add" logic here
-    struct TruthUploadState tus;
-    struct SaltState *ss;
+    struct ServerInfo *server = GNUNET_new (struct ServerInfo);
+    struct SaltState *ss = GNUNET_new (struct SaltState);
+
     size_t url_len = characters - strlen ("server add ");
-    ss = GNUNET_new (struct SaltState);
 
     char *url = &buffer[strlen ("server add ")];
-    tus.backend_url = GNUNET_malloc (url_len);
-    strncpy (tus.backend_url,
+    server->backend_url = GNUNET_malloc (url_len);
+    strncpy (server->backend_url,
              url,
              url_len);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d url is %s\n", __FILE__, __LINE__,
+                server->backend_url);
 
     ss->http_status = MHD_HTTP_OK;
-    ss->tus = &tus;
+    ss->server = server;
     ss->so = ANASTASIS_salt (ctx,
-                             tus.backend_url,
+                             server->backend_url,
                              salt_cb,
                              ss);
     if (NULL == ss->so)
@@ -468,9 +759,10 @@ read_keyboard_command (void *cls)
       GNUNET_break (0);
       return;
     }
-    start_read_keyboard ();
     GNUNET_free (buffer);
     buffer = NULL;
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
 
@@ -484,29 +776,29 @@ read_keyboard_command (void *cls)
     {
       for (unsigned int i = 0; i < tu_states_length; i++)
       {
-        if (NULL != tu_states[i].truth)
+        if ((NULL != tu_states[i].method) &&
+            (0 == strcmp ("sms", tu_states[i].method)))
+          printf ("truth#%u: %s %s\n",
+                  i,
+                  tu_states[i].method,
+                  tu_states[i].phone);
+        if ((NULL != tu_states[i].method) &&
+            (0 == strcmp ("question", tu_states[i].method)))
         {
-          if (0 == strcmp ("SMS", tu_states[i].method))
-            printf ("truth#%u: %s %s\n",
-                    i,
-                    tu_states[i].method,
-                    tu_states[i].phone);
-          if (0 == strcmp ("Secure-Question", tu_states[i].method))
-          {
-            printf ("truth#%u: %s \"%s\" <OMITTED>\n",
-                    i,
-                    tu_states[i].method,
-                    tu_states[i].secret_question);
-          }
+          printf ("truth#%u: %s \"%s\" <OMITTED>\n",
+                  i,
+                  tu_states[i].method,
+                  tu_states[i].secret_question);
         }
       }
     }
     else
       printf ("Please add a truth before!\n");
 
-    start_read_keyboard ();
     GNUNET_free (buffer);
     buffer = NULL;
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
   if (0 == strncmp ("truth add",
@@ -514,9 +806,9 @@ read_keyboard_command (void *cls)
                     strlen ("truth add")))
   {
     // FIXME "truth add" logic here
-    if (NULL != tu_states)
+    if (NULL != servers)
     {
-      // FIXME
+      struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
       char *truth_details = &buffer[strlen ("truth add ")];
       char *token = strtok (truth_details, " ");
       int server_num;
@@ -533,58 +825,113 @@ read_keyboard_command (void *cls)
                     "At %s:%d server number is %u\n", __FILE__, __LINE__,
                     server_num);
         token = strtok (NULL, " ");
-        char *method = GNUNET_malloc (strlen (token));
-        strcpy (method, token);
+        tus->method = GNUNET_malloc (strlen (token) + 1);
+        GNUNET_strlcpy (tus->method,
+                        token,
+                        strlen (token) + 1);
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                     "At %s:%d method is %s\n", __FILE__, __LINE__,
-                    method);
+                    tus->method);
 
-        if (NULL != strstr (tu_states[server_num].backend_methods,
-                            method))
+        if (NULL != strstr (servers[server_num].backend_methods,
+                            tus->method))
         {
-          if (0 == strcmp ("question", method))
+          if (0 == strcmp ("question", tus->method))
           {
             token = strtok (NULL, "\"");
-            char *question = GNUNET_malloc (strlen (token));
-            strcpy (question, token);
+            tus->secret_question = GNUNET_malloc (strlen (token) + 1);
+            GNUNET_strlcpy (tus->secret_question,
+                            token,
+                            strlen (token) + 1);
             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                         "At %s:%d question is %s\n", __FILE__, __LINE__,
-                        question);
+                        tus->secret_question);
 
             token = strtok (NULL, "\"");
             token = strtok (NULL, "\"");
-            char *answer = GNUNET_malloc (strlen (token));
-            strcpy (answer, token);
+            tus->secret_answer = GNUNET_malloc (strlen (token) + 1);
+            GNUNET_strlcpy (tus->secret_answer,
+                            token,
+                            strlen (token) + 1);
             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                         "At %s:%d answer is %s\n", __FILE__, __LINE__,
-                        answer);
-
-            tu_states[server_num].method = "Secure-Question";
-            tu_states[server_num].secret_question = question;
-            tu_states[server_num].secret_answer = answer;
+                        tus->secret_answer);
+
+            tus->instructions = "Please answer the question.";
+            tus->mime_type = "text/plain";
+            struct GNUNET_HashCode truth_data;
+            GNUNET_CRYPTO_hash (tus->secret_answer,
+                                strlen (tus->secret_answer),
+                                &truth_data);
+            tus->truth_data = &truth_data;
+            tus->truth_data_size = sizeof (truth_data);
+          }
+          if (0 == strcmp ("sms", tus->method))
+          {
+            token = strtok (NULL, " ");
+            tus->phone = GNUNET_malloc (strlen (token) + 1);
+            GNUNET_strlcpy (tus->phone,
+                            token,
+                            strlen (token) + 1);
+            tus->instructions = "SMS was sent to you. Please type in the 
Code.";
+            tus->mime_type = "text/plain";
+            tus->truth_data = tus->phone;
+            tus->truth_data_size = strlen (tus->phone);
           }
-          if (0 == strcmp ("sms", method))
+          json_error_t error;
+          if (NULL == (tus->id_data = json_load_file (import_id,
+                                                      JSON_DECODE_ANY,
+                                                      &error)))
           {
-            char *phone = strtok (NULL, " ");
-            tu_states[server_num].method = "SMS";
-            tu_states[server_num].phone = phone;
+            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);
+            return;
           }
+          tus->index = (tu_states_length > 0) ? tu_states_length - 1 : 0;
+          tus->tuo = ANASTASIS_truth_upload (ctx,
+                                             tus->id_data,
+                                             servers[server_num].backend_url,
+                                             tus->method,
+                                             tus->instructions,
+                                             tus->mime_type,
+                                             servers[server_num].backend_salt,
+                                             tus->truth_data,
+                                             tus->truth_data_size,
+                                             &truth_payment_cb,
+                                             tus->tpc_cls,
+                                             &truth_upload_cb,
+                                             tus);
+
+          if (NULL == tus->tuo)
+          {
+            GNUNET_break (0);
+            return;
+          }
+          GNUNET_array_append (tu_states,
+                               tu_states_length,
+                               *tus);
+          printf ("Truth #%u added for server #%u\n",
+                  tus->index,
+                  server_num);
         }
         else
           printf ("Sorry, server#%u does not support '%s'\n",
                   server_num,
-                  method);
+                  tus->method);
       }
-
-
-
     }
     else
       printf ("Please add a server before!\n");
 
-    start_read_keyboard ();
     GNUNET_free (buffer);
     buffer = NULL;
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
   if ((0 == strncmp ("truth add question",
@@ -600,9 +947,10 @@ read_keyboard_command (void *cls)
     else
       printf ("Please add a server before!\n");
 
-    start_read_keyboard ();
     GNUNET_free (buffer);
     buffer = NULL;
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
   if (0 == strncmp ("truth --secrets",
@@ -621,7 +969,7 @@ read_keyboard_command (void *cls)
                   tu_states[i].method,
                   tu_states[i].phone);
         if ((NULL != tu_states[i].method) &&
-            (0 == strcmp ("Secure-Question", tu_states[i].method)))
+            (0 == strcmp ("question", tu_states[i].method)))
         {
           printf ("truth#%u: %s \"%s\" \"%s\"\n",
                   i,
@@ -634,9 +982,10 @@ read_keyboard_command (void *cls)
     else
       printf ("Please add a truth before!\n");
 
-    start_read_keyboard ();
     GNUNET_free (buffer);
     buffer = NULL;
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
 
@@ -646,9 +995,27 @@ read_keyboard_command (void *cls)
       && (characters == strlen ("policy")))
   {
     // FIXME "policy" logic here
-    start_read_keyboard ();
+    if (NULL != pc_states)
+    {
+      for (unsigned int i = 0; i < servers_length; i++)
+      {
+        if (NULL != pc_states[i].tu_states)
+        {
+          printf ("Policy#%u: ", i);
+          for (unsigned int j = 0; j < pc_states[i].tu_states_len; j++)
+            printf ("truth#%u ", pc_states[i].tu_states[j]->index);
+          printf ("\n");
+        }
+        else
+          printf ("Policy#%u: no truths added yet\n", i);
+      }
+    }
+    else
+      printf ("Please add a policy before!\n");
     GNUNET_free (buffer);
     buffer = NULL;
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
   if (0 == strncmp ("policy add",
@@ -656,9 +1023,41 @@ read_keyboard_command (void *cls)
                     strlen ("policy add")))
   {
     // FIXME "policy add" logic here
-    start_read_keyboard ();
+    struct PolicyCreateState *pcs = GNUNET_new (struct PolicyCreateState);
+    char *token_start = &buffer[strlen ("policy add ")];
+    char *token = strtok (token_start, " ");
+    while (token != NULL)
+    {
+      unsigned int tus_index;
+      if (0 != strncmp ("truth#",
+                        token,
+                        strlen ("truth#")))
+      {
+        printf ("Wrong argument: %s!\n", token);
+        GNUNET_free (buffer);
+        buffer = NULL;
+        keyboard_task = NULL;
+        start_read_keyboard ();
+        return;
+      }
+      tus_index = (int) token[strlen ("truth#")] - 48;
+
+      GNUNET_array_append (pcs->tu_states,
+                           pcs->tu_states_len,
+                           &tu_states[tus_index]);
+      token = strtok (NULL, " ");
+    }
+
+    GNUNET_array_append (pc_states,
+                         pc_states_length,
+                         *pcs);
+    printf ("Policy #%u defined\n",
+            (pc_states_length > 0) ? pc_states_length - 1 : 0);
+
     GNUNET_free (buffer);
     buffer = NULL;
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
 
@@ -668,9 +1067,67 @@ read_keyboard_command (void *cls)
       && (characters == strlen ("publish")))
   {
     // FIXME "publish" logic here
-    start_read_keyboard ();
+    if (NULL != pc_states)
+    {
+      struct SecretShareState *sss = GNUNET_new (struct SecretShareState);
+      const struct ANASTASIS_Policy *policies[pc_states_length];
+
+      for (unsigned int i = 0; i < pc_states_length; i++)
+      {
+        const struct ANASTASIS_Truth *truths[pc_states[i].tu_states_len];
+
+        for (unsigned int j = 0; j < pc_states[i].tu_states_len; j++)
+        {
+          truths[j] = pc_states[i].tu_states[j]->truth;
+        }
+
+        pc_states[i].policy = ANASTASIS_policy_create (truths,
+                                                       pc_states[i].
+                                                       tu_states_len);
+        policies[i] = pc_states[i].policy;
+      }
+
+      json_error_t error;
+      if (NULL == (sss->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);
+        return;
+      }
+      // core secret here is just for testing, if payment is needed
+      sss->core_secret = "test_payment";
+      sss->core_secret_size = strlen ("test_payment");
+      sss->sso = ANASTASIS_secret_share (ctx,
+                                         sss->id_data,
+                                         NULL,
+                                         policies,
+                                         pc_states_length,
+                                         NULL,
+                                         NULL,
+                                         &secret_share_payment_cb,
+                                         sss,
+                                         &secret_share_result_cb,
+                                         sss,
+                                         sss->core_secret,
+                                         sss->core_secret_size);
+      if (NULL == sss->sso)
+      {
+        GNUNET_break (0);
+        return;
+      }
+      return;
+    }
     GNUNET_free (buffer);
     buffer = NULL;
+    keyboard_task = NULL;
+    start_read_keyboard ();
     return;
   }
 
@@ -679,6 +1136,7 @@ read_keyboard_command (void *cls)
            (char*) buffer);
   GNUNET_free (buffer);
   buffer = NULL;
+  keyboard_task = NULL;
   start_read_keyboard ();
 }
 
@@ -783,10 +1241,11 @@ main (int argc,
   /* the available command line options */
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     // FIXME json is not an int...
-    GNUNET_GETOPT_option_flag ('m',
-                               "me",
-                               "import json file containing details to create 
user identifier",
-                               &import_id),
+    GNUNET_GETOPT_option_filename ('m',
+                                   "me",
+                                   "import json file containing details to 
create user identifier",
+                                   "import json file containing details to 
create user identifier",
+                                   &import_id),
     // FIXME recovery document also is not a int...
     GNUNET_GETOPT_option_flag ('i',
                                "import",
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 263c182..de2a9c4 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -1118,7 +1118,8 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
   if (NULL != tu->tc)
   {
     tu->tc (tu->tc_cls,
-            t);
+            t,
+            sizeof (*t));
     tu->tc = NULL;
   }
   // FIXME PAYMENT CALLBACK
diff --git a/src/lib/anastasis_api_config.c b/src/lib/anastasis_api_config.c
index e9433fd..9aad899 100644
--- a/src/lib/anastasis_api_config.c
+++ b/src/lib/anastasis_api_config.c
@@ -27,6 +27,7 @@
 #include <gnunet/gnunet_util_lib.h>
 #include <gnunet/gnunet_curl_lib.h>
 #include <gnunet/gnunet_json_lib.h>
+#include <taler/taler_json_lib.h>
 #include "anastasis_service.h"
 #include "anastasis_api_curl_defaults.h"
 
@@ -59,7 +60,7 @@ handle_config_finished (void *cls,
     {
       struct GNUNET_JSON_Specification spec[] = {
         GNUNET_JSON_spec_string ("methods", &co->methods),
-        GNUNET_JSON_spec_fixed_auto ("annual_fee", &co->cost),
+        TALER_JSON_spec_amount ("annual_fee", &co->cost),
         // FIXME add configs
         GNUNET_JSON_spec_end ()
       };
diff --git a/src/lib/test_anastasis.c b/src/lib/test_anastasis.c
index 839ee51..c2f4b8e 100644
--- a/src/lib/test_anastasis.c
+++ b/src/lib/test_anastasis.c
@@ -193,7 +193,7 @@ run (void *cls,
                                         anastasis_url,
                                         ANASTASIS_TESTING_make_id_data_example 
(
                                           "MaxMuster123456789"),
-                                        "Secure-Question",
+                                        "question",
                                         "You have to answer the secure 
question.",
                                         "string",
                                         "HashOfSomeTruth1",
@@ -210,7 +210,7 @@ run (void *cls,
                                         anastasis_url,
                                         ANASTASIS_TESTING_make_id_data_example 
(
                                           "MaxMuster123456789"),
-                                        "Secure-Question",
+                                        "question",
                                         "You have to answer the secure 
question.",
                                         "string",
                                         "HashOfSomeTruth2",
@@ -227,7 +227,7 @@ run (void *cls,
                                         anastasis_url,
                                         ANASTASIS_TESTING_make_id_data_example 
(
                                           "MaxMuster123456789"),
-                                        "Secure-Question",
+                                        "question",
                                         "You have to answer the secure 
question.",
                                         "string",
                                         "HashOfSomeTruth3",
diff --git a/src/lib/test_anastasis_api.c b/src/lib/test_anastasis_api.c
index 2ecfd21..0aeff30 100644
--- a/src/lib/test_anastasis_api.c
+++ b/src/lib/test_anastasis_api.c
@@ -238,7 +238,7 @@ run (void *cls,
                                        MHD_HTTP_NO_CONTENT,
                                        ANASTASIS_TESTING_TSO_NONE,
                                        ANASTASIS_TESTING_make_truth_example (
-                                         "Secure-Question",
+                                         "question",
                                          "Truth mime",
                                          ANASTASIS_TESTING_make_hashed_answer (
                                            "Hashed-Answer",
diff --git a/src/lib/test_anastasis_api.conf b/src/lib/test_anastasis_api.conf
index 3a9fee2..8aa1c8f 100644
--- a/src/lib/test_anastasis_api.conf
+++ b/src/lib/test_anastasis_api.conf
@@ -42,7 +42,7 @@ ANNUAL_FEE = EUR:4.99
 # Upload limit
 UPLOAD_LIMIT_MB = 1
 
-SUPPORTED_METHODS = Secure-Question
+SUPPORTED_METHODS = question
 
 # This specifies which database the postgres backend uses.
 [anastasisdb-postgres]

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



reply via email to

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